/* Internal cleanup function. */ static int wps_cleanup(void) { int ret; #ifdef CONFIG_P2P ret = os_mutex_delete(&wps.p2p_session); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete mutex.\r\n"); return -WM_FAIL; } ret = os_queue_delete(&wps.peer_event_queue); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete queue.\r\n"); return -WM_FAIL; } ret = os_queue_delete(&wps.event_queue); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete queue.\r\n"); return -WM_FAIL; } if (!auto_go) { ret = os_thread_delete(&p2p_scan_thread); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete thread.\r\n"); return -WM_FAIL; } } #endif ret = os_queue_delete(&wps.cmd_queue); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete queue.\r\n"); return -WM_FAIL; } ret = os_queue_delete(&wps.data_queue); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete queue.\r\n"); return -WM_FAIL; } ret = os_thread_delete(&wps_main_thread); if (ret != WM_SUCCESS) { WPS_LOG("Warning: failed to delete thread.\r\n"); return -WM_FAIL; } return WM_SUCCESS; }
/** * @brief Destroy the provided mutex * * Call this function to destroy the mutex * * @param IoT_Mutex_t - pointer to the mutex to be destroyed * @return IoT_Error_t - error code indicating result of operation */ IoT_Error_t aws_iot_thread_mutex_destroy(IoT_Mutex_t *pMutex) { if (os_mutex_delete(&pMutex->lock) != WM_SUCCESS) { return MUTEX_LOCK_ERROR; } return AWS_SUCCESS; }
/** * @brief C main entry function * @param argc number of arguments * @param argv A pointer to arguments array * @return WPS_STATUS_SUCCESS--success, otherwise--fail */ int wps_start(struct wps_config *wps_conf) { int ret; WPS_DATA *wps_s = (WPS_DATA *) &wps_global; #ifdef CONFIG_WPA2_ENTP WPA_SM *wpa_sm_s = (WPA_SM *) &wpa_sm; #endif if (wps.initialized == true) return -WM_FAIL; local_wcc = wps_conf; memset((void *)&wps, 0, sizeof(wps)); #ifdef CONFIG_P2P wps.peer_event_queue_data = wps_peer_event_queue_data; wps.event_queue_data = wps_event_queue_data; #endif wps.cmd_queue_data = wps_cmd_queue_data; wps.data_queue_data = wps_data_queue_data; wps.cb = local_wcc->wps_callback; #ifdef CONFIG_P2P /* WFD data initiliazation */ memset(&wps_s->wfd_data, 0, sizeof(WFD_DATA)); wps_s->wfd_data.dev_index = -1; wps_s->wfd_data.dev_found = -1; ret = os_mutex_create(&wps.p2p_session, "p2p_session", OS_MUTEX_INHERIT); if (ret != WM_SUCCESS) { WPS_LOG("Error: Failed to create " "p2p session mutex: %d\r\n", ret); goto fail; } ret = os_queue_create(&wps.event_queue, "wps_event_queue", sizeof(struct wfd_wlan_event), &wps.event_queue_data); if (ret != WM_SUCCESS) { WPS_LOG ("Error: Failed to create wps event queue: %d\r\n", ret); goto fail; } ret = os_queue_create(&wps.peer_event_queue, "wps_peer_event_queue", sizeof(struct wfd_wlan_event), &wps.peer_event_queue_data); if (ret != WM_SUCCESS) { WPS_LOG ("Error: Failed to create wps peer " "event queue: %d\r\n", ret); goto fail; } ret = wifi_register_wfd_event_queue(&wps.peer_event_queue); if (ret) { WPS_LOG("Error: unable to register peer " "event queue %d\r\n", ret); os_queue_delete(&wps.peer_event_queue); goto fail; } #endif ret = os_queue_create(&wps.cmd_queue, "wps_cmd_queue", sizeof(struct wps_command **), &wps.cmd_queue_data); if (ret != WM_SUCCESS) { WPS_LOG("Error: Failed to create wps cmd queue: %d\r\n", ret); goto fail; } ret = os_queue_create(&wps.data_queue, "wps_message_queue", sizeof(struct wps_msg), &wps.data_queue_data); if (ret != WM_SUCCESS) { WPS_LOG ("Error: Failed to create wps message queue: %d\r\n", ret); goto fail; } #ifdef CONFIG_CYASSL ctaocrypt_lib_init(); #endif wps.initialized = true; memset(wps_s->ifname, 0, IFNAMSIZ + 1); #ifdef CONFIG_P2P if (local_wcc->role == WFD_ROLE) strncpy(wps_s->ifname, "wfd0", IFNAMSIZ); else if (local_wcc->role == WPS_REGISTRAR) strncpy(wps_s->ifname, "uap0", IFNAMSIZ); else #endif strncpy(wps_s->ifname, "mlan0", IFNAMSIZ); gpwps_info_initialized = false; ret = wps_private_info_allocate(&gpwps_info); wps_printf(DEBUG_INIT, "Initializing interface '%s'", wps_s->ifname); #ifdef CONFIG_P2P if (local_wcc->role == WFD_ROLE) { if (auto_go) wps_s->bss_type = BSS_TYPE_UAP; else wps_s->bss_type = BSS_TYPE_STA; } else if (local_wcc->role == WPS_REGISTRAR) wps_s->bss_type = BSS_TYPE_UAP; else wps_s->bss_type = BSS_TYPE_STA; gpwps_info->discovery_role = WPS_ENROLLEE; #else wps_s->bss_type = BSS_TYPE_STA; #endif /* * 1. Initialize L2 packet interface for receiving EAP packet. * 2. Get L2 MAC address and store to application global structure */ if (wps_loop_init(wps_s) != 0) { wps_printf(MSG_ERROR, "ERROR - Fail to initialize layer 2 socket !\n"); wps_stop(); goto fail; } #ifdef CONFIG_WPA2_ENTP memset(wpa_sm_s, 0, sizeof(WPA_SM)); wpa_sm_s->pairwise_cipher = WPA_CIPHER_CCMP; wpa_sm_s->group_cipher = WPA_CIPHER_CCMP; wpa_sm_s->proto = WPA_PROTO_RSN; wpa_sm_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X; wpa_sm_s->renew_snonce = 1; memcpy(wpa_sm_s->own_addr, wps_s->l2->my_mac_addr, ETH_ALEN); #endif #ifdef CONFIG_P2P ret = os_thread_create(&wps_main_thread, "p2p", wps_main, 0, &wps_stack, OS_PRIO_3); if (ret != WM_SUCCESS) { WPS_LOG("Error: Failed to create p2p thread: %d\r\n", ret); goto fail; } if (!auto_go) { ret = os_thread_create(&p2p_scan_thread, "p2p_scan", wps_peer_event_receive, 0, &p2p_scan_stack, OS_PRIO_3); if (ret != WM_SUCCESS) { WPS_LOG("Error: Failed to create p2p_scan" " thread: %d\r\n", ret); goto fail; } } #else ret = os_thread_create(&wps_main_thread, "wps", wps_main, 0, &wps_stack, OS_PRIO_3); if (ret != WM_SUCCESS) { WPS_LOG("Error: Failed to create wps thread: %d\r\n", ret); goto fail; } #endif return WM_SUCCESS; fail: if (wps_main_thread) os_thread_delete(&wps_main_thread); if (wps.cmd_queue) os_queue_delete(&wps.cmd_queue); if (wps.data_queue) os_queue_delete(&wps.data_queue); #ifdef CONFIG_P2P if (wps.p2p_session) os_mutex_delete(&wps.p2p_session); if (wps.peer_event_queue) os_queue_delete(&wps.peer_event_queue); if (wps.event_queue) os_queue_delete(&wps.event_queue); #endif return -WM_FAIL; }