//***************************************************************************** // //! recvfrom //! //! @param[in] sd socket handle //! @param[out] buf Points to the buffer where the message should be stored //! @param[in] len Specifies the length in bytes of the buffer pointed to //! by the buffer argument. //! @param[in] flags Specifies the type of message reception. //! On this version, this parameter is not supported. //! @param[in] from pointer to an address structure indicating the source //! address: sockaddr. On this version only AF_INET is //! supported. //! @param[in] fromlen source address tructure size //! //! @return Return the number of bytes received, or -1 if an error //! occurred //! //! @brief read data from socket //! function receives a message from a connection-mode or //! connectionless-mode socket. Note that raw sockets are not //! supported. //! //! @sa recv //! //! @Note On this version, only blocking mode is supported. // //***************************************************************************** int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen) { int index = 0; int ret; OS_semaphore_post(g_select_sleep_semaphore); //wakeup select thread if needed for (index = 0; index < MAX_NUM_OF_SOCKETS; index++){ if (g_sockets[index].sd == sd){ /* wait for data to become available */ OS_semaphore_pend(g_sockets[index].sd_semaphore, e_WAIT_FOREVER); } } OS_semaphore_pend(g_select_sleep_semaphore, e_WAIT_FOREVER); //suspend select thread until waiting for more data if (g_wlan_stopped){ //if wlan_stop then return return -1; } /* Call the original recv knowing there is available data and it's a non-blocking call */ OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_recvfrom(sd, buf, len, flags, from, fromlen); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
static void sfos_signal_result(s32_t res) { OS_mutex_lock(&sfos.sig_mutex); sfos.sig_res = res; sfos.state = FS_OP_IDLE; OS_cond_broadcast(&sfos.cond); OS_mutex_unlock(&sfos.sig_mutex); }
s32_t SFOS_erase(u32_t addr, u32_t size) { s32_t res; OS_mutex_lock(&sfos.lock); sfos.args[0] = addr; sfos.args[1] = size; res = sfos_exe(SFOS_OP_ERASE); OS_mutex_unlock(&sfos.lock); return res; }
long wlan_set_event_mask(unsigned long ulMask) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_set_event_mask(ulMask); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
//***************************************************************************** // //! wlan_ioctl_del_profile //! //! @param index number of profile to delete //! //! @return On success, zero is returned. On error, -1 is returned //! //! @brief Delete WLAN profile //! //! @Note In order to delete all stored profile, set index to 255. //! //! @sa wlan_add_profile // //***************************************************************************** long wlan_ioctl_del_profile(unsigned long ulIndex) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_ioctl_del_profile(ulIndex); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_disconnect() { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_disconnect(); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_connect(char *ssid, long ssid_len) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_connect(ssid, ssid_len); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_ioctl_statusget(void) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_ioctl_statusget(); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
//***************************************************************************** // //! wlan_smart_config_start //! //! @param algoEncryptedFlag indicates whether the information is encrypted //! //! @return On success, zero is returned. On error, -1 is returned //! //! @brief Start to acquire device profile. The device acquire its own //! profile, if profile message is found. The acquired AP information //! is stored in CC3000 EEPROM only in case AES128 encryption is used. //! In case AES128 encryption is not used, a profile is created by //! CC3000 internally. //! //! @Note An asynchronous event - Smart Config Done will be generated as soon //! as the process finishes successfully. //! //! @sa wlan_smart_config_set_prefix , wlan_smart_config_stop // //***************************************************************************** long wlan_smart_config_start(unsigned long algoEncryptedFlag) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_smart_config_start(algoEncryptedFlag); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
//***************************************************************************** // //! wlan_smart_config_stop //! //! @param algoEncryptedFlag indicates whether the information is encrypted //! //! @return On success, zero is returned. On error, -1 is returned //! //! @brief Stop the acquire profile procedure //! //! @sa wlan_smart_config_start , wlan_smart_config_set_prefix // //***************************************************************************** long wlan_smart_config_stop(void) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_smart_config_stop(); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
s32_t SFOS_read(u32_t addr, u32_t size, u8_t *dst) { s32_t res; OS_mutex_lock(&sfos.lock); sfos.args[0] = addr; sfos.args[1] = size; sfos.args[2] = (u32_t)dst; res = sfos_exe(SFOS_OP_READ); OS_mutex_unlock(&sfos.lock); return res; }
s32_t SFOS_write(u32_t addr, u32_t size, u8_t *src) { s32_t res; OS_mutex_lock(&sfos.lock); sfos.args[0] = addr; sfos.args[1] = size; sfos.args[2] = (u32_t)src; res = sfos_exe(SFOS_OP_WRITE); OS_mutex_unlock(&sfos.lock); return res; }
long wlan_smart_config_process() { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_smart_config_process(); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
//***************************************************************************** // //! wlan_smart_config_set_prefix //! //! @param newPrefix 3 bytes identify the SSID prefix for the Smart Config. //! //! @return On success, zero is returned. On error, -1 is returned //! //! @brief Configure station ssid prefix. The prefix is used internally //! in CC3000. It should always be TTT. //! //! @Note The prefix is stored in CC3000 NVMEM //! //! @sa wlan_smart_config_start , wlan_smart_config_stop // //***************************************************************************** long wlan_smart_config_set_prefix(char* cNewPrefix) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_smart_config_set_prefix(cNewPrefix); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int select(long nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_select(nfds, readsds, writesds, exceptsds, timeout); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int getsockopt(long sd, long level, long optname, void *optval, socklen_t *optlen) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_getsockopt(sd, level, optname, optval, optlen); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int send(long sd, const void *buf, long len, long flags) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_send(sd, buf, len, flags); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len, unsigned char *bssid, unsigned char *key, long key_len) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_connect(ulSecType, ssid, ssid_len, bssid, key, key_len); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, unsigned char *ucResults) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_ioctl_get_scan_results(ulScanTimeout, ucResults); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long connect(long sd, const sockaddr *addr, long addrlen) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_connect(sd, addr, addrlen); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long listen(long sd, long backlog) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_listen(sd, backlog); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int gethostbyname(char * hostname, unsigned short usNameLen, unsigned long* out_ip_addr) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_gethostbyname(hostname, usNameLen, out_ip_addr); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_mdnsAdvertiser(mdnsEnabled, deviceServiceName, deviceServiceNameLength); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
static s32_t sfos_exe(enum sfos_op op) { s32_t res; OS_mutex_lock(&sfos.sig_mutex); sfos.state = op; TASK_run(sfos.kernel_task, op, sfos.args); while (sfos.state != FS_OP_IDLE) { OS_cond_wait(&sfos.cond, &sfos.sig_mutex); } res = sfos.sig_res; OS_mutex_unlock(&sfos.sig_mutex); return res; }
int sendto(long sd, const void *buf, long len, long flags, const sockaddr *to, socklen_t tolen) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_sendto(sd, buf, len, flags, to, tolen); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int socket(long domain, long type, long protocol) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_socket(domain, type, protocol); /*if the value is not error then add to our array for later reference */ if (-1 != ret) find_add_next_free_socket(ret); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, unsigned long ulShouldUseFastConnect, unsigned long ulUseProfiles) { long ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_wlan_ioctl_set_connection_policy(should_connect_to_open_ap,\ ulShouldUseFastConnect,\ ulUseProfiles); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
long wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime, unsigned long uiMaxDwellTime, unsigned long uiNumOfProbeRequests, unsigned long uiChannelMask, long iRSSIThreshold, unsigned long uiSNRThreshold, unsigned long uiDefaultTxPower, unsigned long *aiIntervalList) { unsigned long uiRes; OS_mutex_lock(g_main_mutex, &mtx_key); uiRes = c_wlan_ioctl_set_scan_params(uiEnable, uiMinDwellTime, uiMaxDwellTime,\ uiNumOfProbeRequests, uiChannelMask, iRSSIThreshold,\ uiSNRThreshold, uiDefaultTxPower, aiIntervalList); OS_mutex_unlock(g_main_mutex, mtx_key); return (uiRes); }
void wlan_start(unsigned short usPatchesAvailableAtHost) { OS_mutex_lock(g_main_mutex, &mtx_key); s_thread_params params = {0}; int index = 0; for(index = 0; index < MAX_NUM_OF_SOCKETS; index++){ g_sockets[index].sd = -1; g_sockets[index].status = SOC_NOT_INITED; if (NULL == g_sockets[index].sd_semaphore) OS_semaphore_create(&g_sockets[index].sd_semaphore, "SockSem", 0); } if (NULL == g_accept_semaphore) OS_semaphore_create(&g_accept_semaphore, "AcceptSem", 0); if (NULL == g_select_sleep_semaphore) OS_semaphore_create(&g_select_sleep_semaphore, "SelectSleepSem", 0); /**/ c_wlan_start(usPatchesAvailableAtHost); g_wlan_stopped = 0; g_should_poll_accept = 0; g_accept_socket = -1; if (NULL == g_select_thread){ /* Thread not created yet */ /* Fill Thread Params */ strncpy(params.thread_name, "SelectThread", strlen("SelectThread")); params.p_stack_start = NULL; /* TBD - Mandatory in Thread-X */ params.p_entry_function = SelectThread; *(sInt32 *)params.p_func_params = 0; params.stack_size = 512; params.priority = 3; if (e_SUCCESS != OS_thread_create(&g_select_thread, ¶ms)) { OS_mutex_unlock(g_main_mutex, mtx_key); /* Error */ } } OS_mutex_unlock(g_main_mutex, mtx_key); }
long closesocket(long sd) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_closesocket(sd); /* remove from our array if no error */ if (0 == ret){ find_clear_socket(sd); /* if this is a listeningsocket then reset the global variable pointing to it*/ if (sd == g_accept_socket) g_accept_socket = -1; } OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }