diff options
Diffstat (limited to 'test/uat-devices.c')
-rw-r--r-- | test/uat-devices.c | 696 |
1 files changed, 107 insertions, 589 deletions
diff --git a/test/uat-devices.c b/test/uat-devices.c index 75e4087..e124d43 100644 --- a/test/uat-devices.c +++ b/test/uat-devices.c @@ -31,14 +31,14 @@ ua_device_h g_device_h = NULL; /**< Device handle */ extern ua_user_h g_user_h; /**< User handle */ extern ua_service_h g_service_h; /**< Service handle */ -static char g_device_type[MENU_DATA_SIZE + 1] = {"3"}; /**< Sensor type of the selected device */ -static char g_device_type_str[MENU_DATA_SIZE + 1] = { "WIFI" }; /**< Readable sensor type string */ +char g_device_type[MENU_DATA_SIZE + 1] = {"3"}; /**< Sensor type of the selected device */ +char g_device_type_str[MENU_DATA_SIZE + 1] = { "WIFI" }; /**< Readable sensor type string */ static char g_os_type[MENU_DATA_SIZE + 1] = {"2"}; /**< OS type of the selected device */ -static char g_os_type_str[MENU_DATA_SIZE + 1] = { "Android" }; /**< Readable OS type string */ +char g_os_type_str[MENU_DATA_SIZE + 1] = { "Android" }; /**< Readable OS type string */ -static char g_device_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< Mobile ID of the selected device */ -static char g_mac_addr_str[MENU_DATA_SIZE + 1] = {0,}; /**< MAC of the selected device */ +char g_device_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< Mobile ID of the selected device */ +char g_mac_addr_str[MENU_DATA_SIZE + 1] = {0,}; /**< MAC of the selected device */ static char g_bss_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< BSSID of the selected device */ static char g_discriminant[MENU_DATA_SIZE + 1] = {"1",}; /**< Discrimniant for a device */ static char g_ipv4_address_str[MENU_DATA_SIZE + 1] = {0,}; /**< IPv4 of the selected device */ @@ -47,341 +47,119 @@ static char g_payload_service_id[MENU_DATA_SIZE + 1] = {0,}; /**< payload servic static char g_payload_device_icon[MENU_DATA_SIZE + 1] = {0,}; /**< payload device_icon for the selected device */ static char g_payload_purpose[MENU_DATA_SIZE + 1] = {0,}; /**< payload purpose for the selected device */ static char g_payload_duid_str[MENU_DATA_SIZE + 1] = {0,}; /**< payload duid for the selected device */ -static char g_service_device_discriminant[MENU_DATA_SIZE + 1] = {"1",}; /**< Discriminant for a device in a service */ -char g_selected_device_id[MENU_DATA_SIZE + 1] = {0,}; /**< Selected device id */ +char g_selected_device_idx[MENU_DATA_SIZE + 1] = {0,}; /**< Selected device id */ extern char g_service_str[MENU_DATA_SIZE + 1]; /**< Service name string */ extern char g_user_account_str[MENU_DATA_SIZE + 1]; /**< Find device by user ID */ -static GSList *g_device_list = NULL; /**< Device List */ -static int g_device_count = 0; /**< Seletected service name */ +extern GSList *g_device_list; /**< Device List */ +extern int g_device_count; /**< Seletected service name */ -static void ___free_device_handle(gpointer data) -{ - ua_device_h handle = data; - if (NULL == handle) - return; - ua_device_destroy(handle); - handle = NULL; -} - - -void ___print_duid(const char *duid) { - fprintf(stdout, ANSI_COLOR_LIGHTGREEN "payload duid :" ANSI_COLOR_NORMAL); - if(!duid) - goto done; - - for (int i = 0; i < UA_BLE_PAYLOAD_DUID_LEN; i++) - fprintf(stdout, ANSI_COLOR_LIGHTGREEN " %d" ANSI_COLOR_NORMAL, duid[i]); - -done: - fprintf(stdout, "\n"); - fflush(stdout); -} - - -static void __clear_device_list(void) +static bool __foreach_added_device_cb( + ua_device_h device_handle, void *user_data) { - if (NULL == g_device_list) - return; - - g_slist_free_full(g_device_list, ___free_device_handle); - g_device_list = NULL; - g_device_count = 0; -} + int ret, ret_temp; + ua_device_h handle = NULL; -static void __device_added_cb(int result, - ua_device_h handle, void *user_data) -{ - int ret; ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; char *device_id = NULL; char *mac = NULL; + char *wifi_bssid = NULL; char *ipv4 = NULL; + bool required = false; + unsigned long long timestamp = 0; + bool discriminant = false; + char service_id = 0; + char device_icon = 0; + char purpose = 0; + char *duid = NULL; - if (UA_ERROR_NONE != result) { - msgr("__device_added_cb() result: [0x%X] [%s]", - result, uat_get_error_str(result)); - return; + if (!device_handle) { + msgr("device_handle is NULL"); + return true; } - if (NULL == handle) { - msgr("Device handle is NULL"); - return; + ret = ua_device_clone(&handle, device_handle); + if (UA_ERROR_NONE != ret) { + msgr("ua_device_clone() result: [0x%X] [%s]", + ret, uat_get_error_str(ret)); } - msgb("__device_added_cb() result: [0x%X] [%s]", - result, uat_get_error_str(result)); + msgb("\n[%d]", ++g_device_count); - ret = ua_device_get_mac_type(handle, &mac_type); - if (UA_ERROR_NONE == ret) + ret_temp = ua_device_get_mac_type(handle, &mac_type); + if (UA_ERROR_NONE == ret_temp) msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - ret = ua_device_get_os_info(handle, &ostype); - if (UA_ERROR_NONE == ret) + ret_temp = ua_device_get_os_info(handle, &ostype); + if (UA_ERROR_NONE == ret_temp) { msgb("Device OS Type : %s", - ostype == 1 ? "Tizen" : - ostype == 2 ? "Android" : - ostype == 3 ? "iOS" : "N/A"); + ostype == 1 ? "Tizen" : + ostype == 2 ? "Android" : + ostype == 3 ? "iOS" : "N/A"); + } - ret = ua_device_get_device_id(handle, &device_id); - if (UA_ERROR_NONE == ret) { + ret_temp = ua_device_get_device_id(handle, &device_id); + if (UA_ERROR_NONE == ret_temp) { msgb("Device ID : %s", device_id); g_free(device_id); } - ret = ua_device_get_mac_address(handle, &mac); - if (UA_ERROR_NONE == ret) { + ret_temp = ua_device_get_mac_address(handle, &mac); + if (UA_ERROR_NONE == ret_temp) { msgb("Device MAC : %s", mac); g_free(mac); } - ret = ua_device_get_wifi_ipv4_address(handle, &ipv4); - if (UA_ERROR_NONE == ret) { + ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device BSSID : %s", wifi_bssid); + g_free(wifi_bssid); + } + + ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); + if (UA_ERROR_NONE == ret_temp) { msgb("Device IPv4 Addr : %s", ipv4); g_free(ipv4); } -} - -static bool __foreach_added_device_cb( - ua_device_h device_handle, void *user_data) -{ - int ret, ret_temp; + ret_temp = ua_device_get_discriminant(handle, &discriminant); + if (UA_ERROR_NONE == ret_temp) + msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; - ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; - char *device_id = NULL; - char *mac = NULL; - char *wifi_bssid = NULL; - char *ipv4 = NULL; - bool required = false; - unsigned long long timestamp = 0; - bool discriminant = false; - char service_id = 0; - char device_icon = 0; - char purpose = 0; - char *duid = NULL; + ret_temp = ua_device_get_pairing_required(handle, &required); + if (UA_ERROR_NONE == ret_temp) + msgb("Pairing Required : %s", required ? "YES" : "NO"); - if (device_handle) { - ua_device_h handle = NULL; - - ret = ua_device_clone(&handle, device_handle); - if (UA_ERROR_NONE == ret) { - - msgb("\n[%d]", ++g_device_count); - - ret_temp = ua_device_get_mac_type(handle, &mac_type); - if (UA_ERROR_NONE == ret_temp) - msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - - ret_temp = ua_device_get_os_info(handle, &ostype); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device OS Type : %s", - ostype == 1 ? "Tizen" : - ostype == 2 ? "Android" : - ostype == 3 ? "iOS" : "N/A"); - } - - ret_temp = ua_device_get_device_id(handle, &device_id); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device ID : %s", device_id); - g_free(device_id); - } - - ret_temp = ua_device_get_mac_address(handle, &mac); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device MAC : %s", mac); - g_free(mac); - } - - ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device BSSID : %s", wifi_bssid); - g_free(wifi_bssid); - } - - ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device IPv4 Addr : %s", ipv4); - g_free(ipv4); - } - - ret_temp = ua_device_get_discriminant(handle, &discriminant); - if (UA_ERROR_NONE == ret_temp) - msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - - ret_temp = ua_device_get_pairing_required(handle, &required); - if (UA_ERROR_NONE == ret_temp) - msgb("Pairing Required : %s", required ? "YES" : "NO"); - - ret_temp = ua_device_get_last_presence(handle, ×tamp); - if (UA_ERROR_NONE == ret_temp) - msgb("Last present at : %llu", timestamp); - - ret_temp = ua_device_get_payload_service_id(handle, &service_id); - if (UA_ERROR_NONE == ret_temp) - msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); - - ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); - if (UA_ERROR_NONE == ret_temp) - msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); - - ret_temp = ua_device_get_payload_purpose(handle, &purpose); - if (UA_ERROR_NONE == ret_temp) - msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); - - ret_temp = ua_device_get_payload_duid(handle, &duid); - if (UA_ERROR_NONE == ret_temp) { - ___print_duid(duid); - g_free(duid); - } - - g_device_list = g_slist_append(g_device_list, handle); - } - } + ret_temp = ua_device_get_last_presence(handle, ×tamp); + if (UA_ERROR_NONE == ret_temp) + msgb("Last present at : %llu", timestamp); - return true; -} + ret_temp = ua_device_get_payload_service_id(handle, &service_id); + if (UA_ERROR_NONE == ret_temp) + msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); -static bool __service_foreach_added_device_cb( - ua_service_h service_tmp, ua_device_h handle, void *user_data) -{ - int ret, ret_temp; + ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); + if (UA_ERROR_NONE == ret_temp) + msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); - char *service_name = NULL; - ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; - ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; - char *device_id = NULL; - char *mac = NULL; - char *wifi_bssid = NULL; - char *ipv4 = NULL; - bool required = false; - bool discriminant = false; - unsigned long long timestamp = 0; - char service_id = 0; - char device_icon = 0; - char purpose = 0; - char *duid = NULL; + ret_temp = ua_device_get_payload_purpose(handle, &purpose); + if (UA_ERROR_NONE == ret_temp) + msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); - ret = ua_service_get_name(service_tmp, &service_name); - if (UA_ERROR_NONE == ret) - msgb("CB: Service name : %s", service_name); - - g_free(service_name); - - if (handle) { - if (UA_ERROR_NONE == ret) { - - msgb("\n[%d]", ++g_device_count); - - ret_temp = ua_device_get_mac_type(handle, &mac_type); - if (UA_ERROR_NONE == ret_temp) - msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - - ret_temp = ua_device_get_os_info(handle, &ostype); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device OS Type : %s", - ostype == 1 ? "Tizen" : - ostype == 2 ? "Android" : - ostype == 3 ? "iOS" : "N/A"); - } - - ret_temp = ua_device_get_device_id(handle, &device_id); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device ID : %s", device_id); - g_free(device_id); - } - - ret_temp = ua_device_get_mac_address(handle, &mac); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device MAC : %s", mac); - g_free(mac); - } - - ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device BSSID : %s", wifi_bssid); - g_free(wifi_bssid); - } - - ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device IPv4 Addr : %s", ipv4); - g_free(ipv4); - } - - ret_temp = ua_device_get_pairing_required(handle, &required); - if (UA_ERROR_NONE == ret_temp) - msgb("Pairing Required : %s", required ? "YES" : "NO"); - - ret_temp = ua_device_get_discriminant(handle, &discriminant); - if (UA_ERROR_NONE == ret_temp) - msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - - ret_temp = ua_device_get_last_presence(handle, ×tamp); - if (UA_ERROR_NONE == ret_temp) - msgb("Last present at : %llu", timestamp); - - ret_temp = ua_device_get_payload_service_id(handle, &service_id); - if (UA_ERROR_NONE == ret_temp) - msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); - - ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); - if (UA_ERROR_NONE == ret_temp) - msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); - - ret_temp = ua_device_get_payload_purpose(handle, &purpose); - if (UA_ERROR_NONE == ret_temp) - msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); - - ret_temp = ua_device_get_payload_duid(handle, &duid); - if (UA_ERROR_NONE == ret_temp) { - ___print_duid(duid); - g_free(duid); - } - - g_device_list = g_slist_append(g_device_list, handle); - } + ret_temp = ua_device_get_payload_duid(handle, &duid); + if (UA_ERROR_NONE == ret_temp) { + uat_print_duid(duid); + g_free(duid); } - return true; -} - -ua_mac_type_e _convert_idx_to_device_type(int idx) -{ - switch (idx) { - case UAT_MAC_TYPE_BT: - return UA_MAC_TYPE_BT; - case UAT_MAC_TYPE_BLE: - return UA_MAC_TYPE_BLE; - case UAT_MAC_TYPE_WIFI: - return UA_MAC_TYPE_WIFI; - case UAT_MAC_TYPE_P2P: - return UA_MAC_TYPE_P2P; - default: - return UA_MAC_TYPE_INVALID; - } -} + g_device_list = g_slist_append(g_device_list, handle); -uat_mac_type_e _convert_device_type_to_idx(int mac_type) -{ - switch (mac_type) { - case UA_MAC_TYPE_BT: - return UAT_MAC_TYPE_BT; - case UA_MAC_TYPE_BLE: - return UAT_MAC_TYPE_BLE; - case UA_MAC_TYPE_WIFI: - return UAT_MAC_TYPE_WIFI; - case UA_MAC_TYPE_P2P: - return UAT_MAC_TYPE_P2P; - default: - return UAT_MAC_TYPE_MAX; - } + return true; } -static void _update_device_info(void) +void uat_update_device_info(void) { int ret = UA_ERROR_NONE; ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; @@ -405,7 +183,7 @@ static void _update_device_info(void) snprintf(g_device_type_str, MENU_DATA_SIZE, "%s", uat_get_mac_type_str(mac_type)); snprintf(g_device_type, MENU_DATA_SIZE, "%d", - _convert_device_type_to_idx(mac_type)); + uat_convert_device_type_to_idx(mac_type)); } ret = ua_device_get_os_info(g_device_h, &ostype); @@ -477,6 +255,7 @@ static void _update_device_info(void) } } + #ifndef SUPPORT_STRING_DUID static int _scan_payload_duid_str( MManager *mm, struct menu_data *menu) @@ -551,7 +330,7 @@ static int run_ua_device_set_mac_type( uat_get_str_from_uat_mac_type(mac_type)); } - ret = ua_device_set_mac_type(g_device_h, _convert_idx_to_device_type(mac_type)); + ret = ua_device_set_mac_type(g_device_h, uat_convert_idx_to_device_type(mac_type)); msg(" - ua_device_set_mac_type() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); @@ -760,7 +539,7 @@ static int run_ua_device_get_by_mac_address( ret = ua_device_get_by_mac_address(g_mac_addr_str, &_device); if (UA_ERROR_NONE == ret) { g_device_h = _device; - _update_device_info(); + uat_update_device_info(); } @@ -781,7 +560,7 @@ static int run_ua_device_get_by_device_id( if (strlen(g_device_type)) { int temp = (unsigned char)strtol(g_device_type, NULL, 10); - mac_type = _convert_idx_to_device_type(temp); + mac_type = uat_convert_idx_to_device_type(temp); snprintf(g_device_type_str, MENU_DATA_SIZE + 1, "%s", uat_get_mac_type_str(mac_type)); } @@ -790,7 +569,7 @@ static int run_ua_device_get_by_device_id( ret = ua_device_get_by_device_id(g_device_id_str, mac_type, &_device); if (UA_ERROR_NONE == ret) { g_device_h = _device; - _update_device_info(); + uat_update_device_info(); } msg(" - ua_device_get_by_device_id() ret: [0x%X] [%s]", @@ -806,7 +585,7 @@ static int run_ua_device_foreach_added( msg("ua_device_foreach_added"); - __clear_device_list(); + uat_clear_device_list(); ret = ua_device_foreach_added( __foreach_added_device_cb, NULL); @@ -817,24 +596,6 @@ static int run_ua_device_foreach_added( return RET_SUCCESS; } -static int run_ua_device_foreach_added_by_user(MManager *mm, - struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_device_foreach_added_by_user"); - - __clear_device_list(); - - ret = ua_device_foreach_added_by_user(g_user_h, - __foreach_added_device_cb, NULL); - - msg(" - ua_device_foreach_added_by_user() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - static int run_ua_device_update( MManager *mm, struct menu_data *menu) { @@ -850,185 +611,6 @@ static int run_ua_device_update( return RET_SUCCESS; } -static int run_ua_user_add_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_user_add_device"); - - check_if(NULL == g_device_h); - - ret = ua_user_add_device(g_user_h, g_device_h, __device_added_cb, NULL); - - msg(" - ua_user_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_user_remove_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_user_remove_device"); - - check_if(NULL == g_user_h); - check_if(NULL == g_device_h); - - ret = ua_user_remove_device(g_user_h, g_device_h); - - msg(" - ua_user_remove_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_user_remove_device_by_device_id( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - uat_mac_type_e idx = UAT_MAC_TYPE_MAX; - - msg("ua_user_remove_device_by_device_id"); - - if (strlen(g_device_type)) - idx = (unsigned char)strtol(g_device_type, NULL, 10); - - msgb("idx [%d] mac_type[%d]", idx, _convert_idx_to_device_type(idx)); - - ret = ua_user_remove_device_by_device_id(g_device_id_str, _convert_idx_to_device_type(idx)); - - msg(" - ua_user_remove_device_by_device_id() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_user_remove_device_by_mac_address( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - uat_mac_type_e idx = UAT_MAC_TYPE_MAX; - - msg("ua_user_remove_device_by_mac_address"); - - if (strlen(g_device_type)) - idx = (unsigned char)strtol(g_device_type, NULL, 10); - - msgb("idx [%d] mac_type[%d]", idx, _convert_idx_to_device_type(idx)); - - ret = ua_user_remove_device_by_mac_address(g_mac_addr_str); - - msg(" - ua_user_remove_device_by_mac_address() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_add_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_service_add_device"); - - check_if(NULL == g_user_h); - check_if(NULL == g_device_h); - - ret = ua_service_add_device(g_service_h, g_device_h); - - msg(" - ua_service_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_remove_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_service_remove_device"); - - check_if(NULL == g_user_h); - check_if(NULL == g_device_h); - - ret = ua_service_remove_device(g_service_h, g_device_h); - - msg(" - ua_service_remove_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_set_device_discriminant( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - int temp = 1; - gboolean discriminant = true; - - msg("ua_service_set_device_discriminant"); - - check_if(NULL == g_service_h); - check_if(NULL == g_device_h); - - if (strlen(g_service_device_discriminant)) - temp = (int)strtol(g_service_device_discriminant, NULL, 10); - - if (0 == temp) - discriminant = false; - ret = ua_service_set_device_discriminant(g_service_h, g_device_h, discriminant); - - msg(" - ua_service_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_get_device_discriminant( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - gboolean discriminant = true; - - msg("ua_service_get_device_discriminant"); - - check_if(NULL == g_service_h); - check_if(NULL == g_device_h); - - ret = ua_service_get_device_discriminant(g_service_h, g_device_h, &discriminant); - - msg(" - ua_service_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - if (UA_ERROR_NONE == ret) - msgb("Device Discriminant %d", discriminant); - - return RET_SUCCESS; -} - -static int run_ua_service_foreach_added_devices(MManager *mm, - struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_service_foreach_added_devices"); - - __clear_device_list(); - - ret = ua_service_foreach_added_devices(g_service_h, - __service_foreach_added_device_cb, NULL); - - msg(" - ua_service_foreach_added_devices() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - - static struct menu_data menu_ua_device_type[] = { { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", NULL, NULL, g_device_type }, @@ -1069,61 +651,6 @@ static struct menu_data menu_ua_ipv4_address[] = { { NULL, NULL, }, }; -static struct menu_data menu_ua_rm_dev_by_device_id[] = { - { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", - NULL, NULL, g_device_type }, - { "2", "device_id", - NULL, NULL, g_device_id_str }, - { "3", "run", NULL, - run_ua_user_remove_device_by_device_id, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_rm_dev_by_addr[] = { - { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", - NULL, NULL, g_device_type }, - { "2", "MAC", - NULL, NULL, g_mac_addr_str }, - { "3", "run", NULL, - run_ua_user_remove_device_by_mac_address, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_service_set_device_discriminant[] = { - { "1", "discriminant (0:disable 1:enable)", - NULL, NULL, g_service_device_discriminant }, - { "2", "run", NULL, - run_ua_service_set_device_discriminant, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_devlist_by_mac[] = { - { "1", "MAC", - NULL, NULL, g_mac_addr_str }, - { "2", "run", NULL, - run_ua_device_get_by_mac_address, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_devlist_by_device_id[] = { - { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", - NULL, NULL, g_device_type }, - { "2", "device_id", - NULL, NULL, g_device_id_str }, - { "3", "run", NULL, - run_ua_device_get_by_device_id, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_devlist_by_user[] = { -//TODO lk, fix here - { "1", "Account", - NULL, NULL, g_user_account_str }, - { "2", "run", NULL, - run_ua_device_foreach_added_by_user, NULL }, - { NULL, NULL, }, -}; - static struct menu_data menu_ua_discrminiant[] = { { "1", "discriminant (0: Disable 1: Enable)", NULL, NULL, g_discriminant }, @@ -1168,6 +695,24 @@ static struct menu_data menu_ua_device_set_payload_duid[] = { { NULL, NULL, }, }; +static struct menu_data menu_ua_devlist_by_mac[] = { + { "1", "MAC", + NULL, NULL, g_mac_addr_str }, + { "2", "run", NULL, + run_ua_device_get_by_mac_address, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_devlist_by_device_id[] = { + { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", + NULL, NULL, g_device_type }, + { "2", "device_id", + NULL, NULL, g_device_id_str }, + { "3", "run", NULL, + run_ua_device_get_by_device_id, NULL }, + { NULL, NULL, }, +}; + struct menu_data menu_ua_devices[] = { { "1", "ua_device_create", NULL, run_ua_device_create, NULL }, @@ -1199,49 +744,22 @@ struct menu_data menu_ua_devices[] = { menu_ua_devlist_by_mac, NULL, NULL }, { "15", "ua_device_get_by_device_id", menu_ua_devlist_by_device_id, NULL, NULL }, - { "16", "ua_device_foreach_added", - NULL, run_ua_device_foreach_added, NULL }, - { "17", "ua_device_foreach_added_by_user", - menu_ua_devlist_by_user, NULL, NULL }, - { "18", "ua_device_update", + { "16", "ua_device_update", NULL, run_ua_device_update, NULL }, - { "19", "ua_user_add_device", - NULL, run_ua_user_add_device, NULL }, - { "20", "ua_user_remove_device", - NULL, run_ua_user_remove_device, NULL }, - { "21", "ua_user_remove_device_by_device_id", - menu_ua_rm_dev_by_device_id, NULL, NULL }, - { "22", "ua_user_remove_device_by_mac_address", - menu_ua_rm_dev_by_addr, NULL, NULL }, - { "23", "ua_service_add_device", - NULL, run_ua_service_add_device, NULL }, - { "24", "ua_service_remove_device", - NULL, run_ua_service_remove_device, NULL }, - { "25", "ua_service_set_device_discriminant", - menu_ua_service_set_device_discriminant, NULL, NULL }, - { "26", "ua_service_get_device_discriminant", - NULL, run_ua_service_get_device_discriminant, NULL }, - { "27", "ua_service_foreach_added_devices", - NULL, run_ua_service_foreach_added_devices, NULL }, + { "17", "ua_device_foreach_added", + NULL, run_ua_device_foreach_added, NULL }, { NULL, NULL, }, }; -static int run_choose_device_list(MManager *mm, struct menu_data *menu) -{ - __clear_device_list(); - ua_device_foreach_added(__foreach_added_device_cb, NULL); - return RET_SUCCESS; -} - -static int run_select_device(MManager *mm, struct menu_data *menu) +int uat_select_device(MManager *mm, struct menu_data *menu) { GSList *iter = g_device_list; int id = 0; int selected_id = 0; - if (strlen(g_selected_device_id)) - selected_id = (unsigned char)strtol(g_selected_device_id, NULL, 10); + if (strlen(g_selected_device_idx)) + selected_id = (unsigned char)strtol(g_selected_device_idx, NULL, 10); if (selected_id <= 0) { msg("Please select device first"); @@ -1253,7 +771,7 @@ static int run_select_device(MManager *mm, struct menu_data *menu) ua_device_h *handle = iter->data; if (handle && ++id == selected_id) { g_device_h = handle; /* Make selected device as a current one */ - _update_device_info(); /* Update device info. */ + uat_update_device_info(); /* Update device info. */ msg("[%d] device selected", selected_id); return RET_SUCCESS; } @@ -1264,8 +782,8 @@ static int run_select_device(MManager *mm, struct menu_data *menu) } struct menu_data menu_sel_device[] = { - { "1", "Device list", NULL, run_choose_device_list, g_selected_device_id}, - { "2", "Apply", NULL, run_select_device, NULL }, + { "1", "Device list", NULL, run_ua_device_foreach_added, g_selected_device_idx}, + { "2", "Apply", NULL, uat_select_device, NULL }, { NULL, NULL, }, }; |