tools/mesh-cfgclient: Add full support for numeric input
PATCH 1/1 tools/mesh-cfgclient: Add full support for numeric input
Add support for all the forms of numeric input requests to the Provisioner from a remote device:
"blink", "beep", "vibrate", "in-numeric"
--- tools/mesh-cfgclient.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/mesh-gatt/prov.c | 9 +++++---- tools/mesh/agent.c | 21 ++++++++++++++------- tools/mesh/agent.h | 4 ++-- 4 files changed, 59 insertions(+), 16 deletions(-)
tools/mesh-cfgclient.c +38 -3
@@ -402,23 +402,58 @@ static void agent_input_done(oob_type_t type, void *buf, uint16_t len, } } +struct requested_action { +const char *action; +const char *description; +}; + +static struct requested_action prompt_numeric_action_table[] = { + {"blink" ,"Enter the number of times remote LED blinked" }, + {"beep" ,"Enter the number of times remote device beeped" }, + {"vibrate" ,"Enter the number of times remote device vibrated" }, + {"in-numeric" ,"Enter the number displayed on remote device" } +}; + +static int get_action (char *str) +{ +size_t len; +int i, sz; + +if (!str) +return -1 ; + + len =strlen (str); + sz =L_ARRAY_SIZE (prompt_numeric_action_table); + +for (i =0 ; i < sz; ++i) +if (len ==strlen (prompt_numeric_action_table[i].action) && + !strcmp (str, prompt_numeric_action_table[i].action)) +return i; + +return -1 ; +} +static struct l_dbus_message *prompt_numeric_call (struct l_dbus *dbus,struct l_dbus_message *msg,void *user_data) {char *str; +int action_index; +const char *desc;if (!l_dbus_message_get_arguments (msg,"s" , &str)) {l_error ("Cannot parse \"PromptNumeric\" arguments" );return l_dbus_message_new_error (msg, dbus_err_fail,NULL ); } -if (!str ||strlen (str) !=strlen ("out-numeric" ) || -strncmp (str,"out-numeric" ,strlen ("out-numeric" ))) + action_index =get_action (str); +if (action_index <0 )return l_dbus_message_new_error (msg, dbus_err_support,NULL ); + desc = prompt_numeric_action_table[action_index].description; +l_dbus_message_ref (msg); -agent_input_request (DECIMAL ,8 , agent_input_done, msg); +agent_input_request (DECIMAL ,8 , desc, agent_input_done, msg);return NULL ; }
tools/mesh-gatt/prov.c +5 -4
@@ -333,18 +333,18 @@ static void prov_calc_ecdh(DBusMessage *message, void *node)case 1 :/* Static OOB */ agent_input_request (HEXADECIMAL , -16 , +16 ,NULL , prov_out_oob_done, node);break ;case 2 :/* Output OOB */ if (action <=3 )agent_input_request (DECIMAL , - size, + size,NULL , prov_out_oob_done, node);else agent_input_request (ASCII , - size, + size,NULL , prov_out_oob_done, node);break ;
@@ -421,7 +421,8 @@ static void prov_start_cmplt(DBusMessage *message, void *node)if (prov ==NULL )return ;if (prov->conf_in.start.pub_key) -agent_input_request (HEXADECIMAL ,64 , prov_oob_pub_key, node); +agent_input_request (HEXADECIMAL ,64 ,NULL , prov_oob_pub_key, + node);else prov_send_pub_key (node); }
tools/mesh/agent.c +14 -7
@@ -35,6 +35,8 @@#include "src/shared/shell.h" #include "tools/mesh/agent.h" +#define AGENT_PROMPT COLOR_BLUE "[mesh-agent]" COLOR_OFF "# " +struct input_request {oob_type_t type;uint16_t len;
@@ -124,7 +126,7 @@ static bool request_hexadecimal(uint16_t len)return false;bt_shell_printf ("Request hexadecimal key (hex %d octets)\n" , len); -bt_shell_prompt_input ("mesh" ,"Enter key (hex number):" , +bt_shell_prompt_input (AGENT_PROMPT ,"Enter key (hex number):" , response_hexadecimal,NULL );return true;
@@ -140,10 +142,15 @@ static uint32_t power_ten(uint8_t power)return ret; } -static bool request_decimal (uint16_t len) +static bool request_decimal (const char *desc,uint16_t len) { -bt_shell_printf ("Request decimal key (0 - %d)\n" ,power_ten (len) -1 ); -bt_shell_prompt_input ("mesh-agent" ,"Enter Numeric key:" , +if (!desc) +bt_shell_printf ("Request decimal key (0 - %d)\n" , +power_ten (len) -1 ); +else +bt_shell_printf ("%s (0 - %d)\n" , desc,power_ten (len) -1 ); + +bt_shell_prompt_input (AGENT_PROMPT ,"Enter decimal number:" , response_decimal,NULL );return true;
@@ -161,8 +168,8 @@ static bool request_ascii(uint16_t len)return true; } -bool agent_input_request (oob_type_t type,uint16_t max_len,agent_input_cb cb, -void *user_data) +bool agent_input_request (oob_type_t type,uint16_t max_len,const char *desc, +agent_input_cb cb,void *user_data) {bool result;
@@ -174,7 +181,7 @@ bool agent_input_request(oob_type_t type, uint16_t max_len, agent_input_cb cb, result =request_hexadecimal (max_len);break ;case DECIMAL : - result =request_decimal (max_len); + result =request_decimal (desc, max_len);break ;case ASCII : result =request_ascii (max_len);
tools/mesh/agent.h +2 -2
@@ -35,8 +35,8 @@ typedef enum {typedef void (*agent_input_cb )(oob_type_t type,void *input,uint16_t len,void *user_data); -bool agent_input_request (oob_type_t type,uint16_t max_len,agent_input_cb cb, -void *user_data); +bool agent_input_request (oob_type_t type,uint16_t max_len,const char *desc, +agent_input_cb cb,void *user_data);bool agent_output_request (const char * str);void agent_output_request_cancel (void );
Signature · 1 line
2.21.0