*/
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. */
/**
+ * 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.
/**
* \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.
*
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:
}
}
+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)
{