Add API to get access list 92/17892/4 accepted/tizen_common accepted/tizen_ivi_panda accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable tizen_3.0.2015.q2_common tizen_ivi_panda accepted/tizen/common/20150210.094816 accepted/tizen/ivi/panda/20140403.015053 accepted/tizen/mobile/20150210.015425 accepted/tizen/mobile/20150211.014838 accepted/tizen/tv/20150210.080015 accepted/tizen/tv/20150212.064337 accepted/tizen/wearable/20150212.102636 accepted/tizen/wearable/20150212.122637 submit/accepted/tizen_ivi_panda/20150209.183016 submit/tizen/20150209.015140 submit/tizen/20150209.183108 submit/tizen_ivi_panda/20140403.011848
authorJiung Yu <jiung.yu@samsung.com>
Wed, 12 Mar 2014 05:44:40 +0000 (14:44 +0900)
committerJiung Yu <jiung.yu@samsung.com>
Fri, 14 Mar 2014 04:53:38 +0000 (13:53 +0900)
Change-Id: Ie2187bea651cf9f24e66c738cad25cda9a515883
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
include/wifi-direct-internal.h
include/wifi-direct.h
src/wifi-direct-client-proxy.c
src/wifi-direct-utils.c

index ad76139..9c5649a 100644 (file)
@@ -146,6 +146,7 @@ typedef enum
        WIFI_DIRECT_CMD_GET_DISPLAY_PORT,
        WIFI_DIRECT_CMD_GET_DISPLAY_TYPE,
 
+       WIFI_DIRECT_CMD_GET_ACCESS_LIST,
        WIFI_DIRECT_CMD_ADD_TO_ACCESS_LIST,
        WIFI_DIRECT_CMD_DEL_FROM_ACCESS_LIST,
 
@@ -205,6 +206,17 @@ typedef struct
 
 
 /**
+ * Wi-Fi Direct buffer structure to store access list for IPC
+ */
+typedef struct
+{
+       bool allowed;
+       char device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1];
+       unsigned char mac_address[6];
+} wfd_access_list_info_s;
+
+
+/**
  * Wi-Fi Direct buffer structure to store result of peer discovery for IPC
  */
 typedef struct
index c67f02f..d611348 100644 (file)
@@ -236,6 +236,18 @@ typedef enum
  */
 typedef struct
 {
+       int allowed;            /** Is device allowed**/
+       char *device_name;      /** Null-terminated device friendly name. */
+       char *mac_address;      /** Device's P2P Device Address */
+} wifi_direct_access_list_info_s;
+
+
+/**
+ * @struct wifi_direct_discovered_peer_info_s
+ * Wi-Fi Direct buffer structure to store result of peer discovery
+ */
+typedef struct
+{
        char *device_name;  /** Null-terminated device friendly name. */
        char *mac_address;  /** Device's P2P Device Address */
        char *interface_address;  /** Device's P2P Interface Address. Valid only if device is a P2P GO. */
@@ -1019,6 +1031,90 @@ int wifi_direct_cancel_discovery(void);
 
 
 /**
+ * access list notification callback function type. \n
+ *
+ * @param device The device that is in access list.
+ * @param user_data The user data passed from the foreach function.
+ * @return @c true to continue with the next iteration of the loop,
+ * \n @c false to break out of the loop.
+ *
+ * @pre wifi_direct_get_access_list() will invoke this function.
+ *
+ * @see wifi_direct_get_access_list()
+ *
+ */
+typedef bool(*wifi_direct_access_list_cb)      (wifi_direct_access_list_info_s *device, void *user_data);
+
+/*****************************************************************************************/
+/* wifi_direct_get_access_list API function prototype
+ * int wifi_direct_get_access_list(wifi_direct_discovered_peer_cb, void* user_data)
+ */
+/**
+ * \brief This API shall get the information of all devices in access list. \n
+ *
+ * @param callback The callback function to invoke.
+ * @param user_data The user data passed from the foreach function.
+ *
+ * \see wifi_direct_discovered_peer_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ *  None
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * bool _cb_access_list_impl(wifi_direct_access_list_info_s* device, void* user_data)
+ * {
+ *     struct appdata* ad = (struct appdata*) user_data;
+ *
+ *     if(NULL != device)
+ *     {
+ *             memcpy(&ad->access_list[ad->access_list_count], device, sizeof(wifi_direct_access_list_info_s));
+               ad->access_list_count++;
+ *     }
+ *
+ *     return true;    // continue with the next iteration of the loop
+ * }
+ *
+ *
+ * void foo()
+ * {
+ *     int result;
+ *
+ *     ad->access_list = NULL;
+ *     ad->access_list_count = 0;
+ *     result = wifi_direct_get_access_list(_cb_access_list_impl, (void*)ad);
+ *
+ *     if(result == WIFI_DIRECT_ERROR_NONE)......... // get access list is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_access_list(wifi_direct_access_list_cb callback,
+                                                                                               void *user_data);
+
+
+/**
  * discorverd peers notification callback function type. \n
  *
  * @param peer The discovered peer information.
@@ -3138,6 +3234,7 @@ int wifi_direct_add_to_access_list(const char *mac_address, bool allow);
 /**
  * \brief This API shall add device to list to automatically allow or deny connection request. \n
  * @param mac_address              device mac address to delete from list.
+ *                                                                               if 00:00:00:00:00:00, reset list
  *
  * \see wifi_direct_add_to_access_list.
  *
index f7ba1d4..ae3f480 100644 (file)
@@ -431,6 +431,8 @@ char *__wfd_client_print_cmd(wifi_direct_cmd_e cmd)
                return "WIFI_DIRECT_CMD_GET_DISPLAY_PORT";
        case WIFI_DIRECT_CMD_GET_DISPLAY_TYPE:
                return "WIFI_DIRECT_CMD_GET_DISPLAY_TYPE";
+       case WIFI_DIRECT_CMD_GET_ACCESS_LIST:
+               return "WIFI_DIRECT_CMD_GET_ACCESS_LIST";
        case WIFI_DIRECT_CMD_ADD_TO_ACCESS_LIST:
                return "WIFI_DIRECT_CMD_ADD_TO_ACCESS_LIST";
        case WIFI_DIRECT_CMD_DEL_FROM_ACCESS_LIST:
@@ -1388,6 +1390,122 @@ static char **get_service_list(char *services, unsigned int *count)
         }
 }
 
+int wifi_direct_get_access_list(wifi_direct_access_list_cb cb,
+                                                                                               void *user_data)
+{
+       __WDC_LOG_FUNC_START__;
+       wifi_direct_client_info_s *client_info = __wfd_get_control();
+       wifi_direct_client_request_s req;
+       wifi_direct_client_response_s rsp;
+       int res = WIFI_DIRECT_ERROR_NONE;
+       int i;
+
+       if ((client_info->is_registered == false) ||
+                       (client_info->client_id == WFD_INVALID_ID)) {
+               WDC_LOGE("Client is NOT registered");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+       }
+
+       if (!cb) {
+               WDC_LOGE("NULL Param [callback]!");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+       }
+
+       memset(&req, 0, sizeof(wifi_direct_client_request_s));
+       memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+       req.cmd = WIFI_DIRECT_CMD_GET_ACCESS_LIST;
+       req.client_id = client_info->client_id;
+
+       pthread_mutex_lock(&g_client_info.mutex);
+       res = __wfd_client_write_socket(client_info->sync_sockfd, &req, sizeof(wifi_direct_client_request_s));
+       if (res != WIFI_DIRECT_ERROR_NONE) {
+               WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res));
+               __wfd_reset_control();
+               pthread_mutex_unlock(&g_client_info.mutex);
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+       }
+       WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd));
+
+       res = __wfd_client_read_socket(client_info->sync_sockfd, &rsp, sizeof(wifi_direct_client_response_s));
+       if (res <= 0) {
+               WDC_LOGE("Failed to read socket [%d]", res);
+               __wfd_reset_control();
+               pthread_mutex_unlock(&g_client_info.mutex);
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+       } else {
+               if (rsp.cmd != req.cmd) {
+                       WDC_LOGE("Invalid resp [%d]", rsp.cmd);
+                       pthread_mutex_unlock(&g_client_info.mutex);
+                       __WDC_LOG_FUNC_END__;
+                       return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+               }
+
+               if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+                       WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result));
+                       pthread_mutex_unlock(&g_client_info.mutex);
+                       __WDC_LOG_FUNC_END__;
+                       return rsp.result;
+               }
+       }
+
+       int num = rsp.param1;
+       wfd_access_list_info_s *buff = NULL;
+
+       WDC_LOGD("Num of access list = %d", num);
+
+       if (num > 0) {
+               buff = (wfd_access_list_info_s*) calloc(num, sizeof (wfd_access_list_info_s));
+               if (!buff) {
+                       WDC_LOGE("Failed to alloc memory");
+                       pthread_mutex_unlock(&g_client_info.mutex);
+                       return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+               }
+
+               res = __wfd_client_read_socket(client_info->sync_sockfd, (char*) buff,
+                                                               num * sizeof(wfd_access_list_info_s));
+               pthread_mutex_unlock(&g_client_info.mutex);
+               if (res <= 0) {
+                       free(buff);
+                       WDC_LOGE("Failed to read socket");
+                       __wfd_reset_control();
+                       return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+               }
+
+               WDC_LOGD("wifi_direct_get_access_list() SUCCESS");
+
+               wifi_direct_access_list_info_s access_list;
+
+               for (i = 0; i < num; i++) {
+                       memset(&access_list, 0, sizeof(wifi_direct_access_list_info_s));
+                       access_list.device_name = strdup(buff[i].device_name);
+                       access_list.mac_address = (char*) calloc(1, MACSTR_LEN);
+                       snprintf(access_list.mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address));
+                       access_list.allowed = buff[i].allowed;
+
+                       if (!cb(&access_list, user_data))
+                               i = num;
+
+                       if (access_list.device_name)
+                               free(access_list.device_name);
+                       if (access_list.mac_address)
+                               free(access_list.mac_address);
+               }
+
+               if (buff)
+                       free(buff);
+       } else {
+               pthread_mutex_unlock(&g_client_info.mutex);
+       }
+
+       __WDC_LOG_FUNC_END__;
+       return WIFI_DIRECT_ERROR_NONE;
+}
+
 int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb,
                                                                                                void *user_data)
 {
index b6c2e30..daa0cbb 100644 (file)
@@ -41,7 +41,6 @@ char *wfd_print_state(wifi_direct_state_e s)
        case WIFI_DIRECT_STATE_DEACTIVATED:
                return "DEACTIVATED";
                break;
-
        case WIFI_DIRECT_STATE_DEACTIVATING:
                return "DEACTIVATING";
                break;