void _sl_HandleAsync_PingResponse(void *pVoidBuf) { _PingReportResponse_t *pMsgArgs = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); SlPingReport_t pingReport; if(pPingCallBackFunc) { CopyPingResultsToReport(pMsgArgs,&pingReport); pPingCallBackFunc(&pingReport); } else { OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp); if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) { memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t)); OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); } OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); } return; }
DRESULT sflash_disk_init (void) { _i32 fileHandle; SlFsFileInfo_t FsFileInfo; if (!sflash_init_done) { // Allocate space for the block cache ASSERT ((sflash_block_cache = mem_Malloc(SFLASH_BLOCK_SIZE)) != NULL); sflash_init_done = true; sflash_prblock = UINT32_MAX; sflash_cache_is_dirty = false; // In order too speed up booting, check the last block, if exists, then // it means that the file system has been already created print_block_name (SFLASH_BLOCK_COUNT - 1); sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); if (!sl_FsGetInfo(sflash_block_name, 0, &FsFileInfo)) { sl_LockObjUnlock (&wlan_LockObj); return RES_OK; } sl_LockObjUnlock (&wlan_LockObj); // Proceed to format the memory for (int i = 0; i < SFLASH_BLOCK_COUNT; i++) { print_block_name (i); sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); // Create the block file if it doesn't exist if (sl_FsGetInfo(sflash_block_name, 0, &FsFileInfo) != 0) { if (!sl_FsOpen(sflash_block_name, FS_MODE_OPEN_CREATE(SFLASH_BLOCK_SIZE, 0), NULL, &fileHandle)) { sl_FsClose(fileHandle, NULL, NULL, 0); sl_LockObjUnlock (&wlan_LockObj); memset(sflash_block_cache, 0xFF, SFLASH_BLOCK_SIZE); if (!sflash_access(FS_MODE_OPEN_WRITE, sl_FsWrite)) { return RES_ERROR; } } else { // Unexpected failure while creating the file sl_LockObjUnlock (&wlan_LockObj); return RES_ERROR; } } sl_LockObjUnlock (&wlan_LockObj); } } return RES_OK; }
void wlan_stop (uint32_t timeout) { wlan_servers_stop(); #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); #endif sl_Stop(timeout); wlan_clear_data(); wlan_obj.mode = -1; }
void modusocket_close_all_user_sockets (void) { sl_LockObjLock (&modusocket_LockObj, SL_OS_WAIT_FOREVER); for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) { if (modusocket_sockets[i].sd >= 0 && modusocket_sockets[i].user) { sl_Close(modusocket_sockets[i].sd); modusocket_sockets[i].sd = -1; } } sl_LockObjUnlock (&modusocket_LockObj); }
void modusocket_socket_delete (int16_t sd) { sl_LockObjLock (&modusocket_LockObj, SL_OS_WAIT_FOREVER); for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) { if (modusocket_sockets[i].sd == sd) { modusocket_sockets[i].sd = -1; break; } } sl_LockObjUnlock (&modusocket_LockObj); }
void modusocket_socket_add (int16_t sd, bool user) { sl_LockObjLock (&modusocket_LockObj, SL_OS_WAIT_FOREVER); for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) { if (modusocket_sockets[i].sd < 0) { modusocket_sockets[i].sd = sd; modusocket_sockets[i].user = user; break; } } sl_LockObjUnlock (&modusocket_LockObj); }
void updater_finnish (void) { _i32 fhandle; if (updater_data.fhandle > 0) { sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); // close the file being updated sl_FsClose(updater_data.fhandle, NULL, NULL, 0); #ifdef WIPY // if we still have an image pending for verification, leave the boot info as it is if (!strncmp(IMG_PREFIX, updater_data.path, strlen(IMG_PREFIX)) && sBootInfo.Status != IMG_STATUS_CHECK) { #else if (!strncmp(IMG_PREFIX, updater_data.path, strlen(IMG_PREFIX))) { #endif #ifdef DEBUG if (!sl_FsOpen((unsigned char *)IMG_BOOT_INFO, FS_MODE_OPEN_READ, NULL, &fhandle)) { ASSERT (sizeof(sBootInfo_t) == sl_FsRead(fhandle, 0, (unsigned char *)&sBootInfo, sizeof(sBootInfo_t))); sl_FsClose(fhandle, 0, 0, 0); #endif // open the boot info file for writing ASSERT (sl_FsOpen((unsigned char *)IMG_BOOT_INFO, FS_MODE_OPEN_WRITE, NULL, &fhandle) == 0); #ifdef DEBUG } else { // the boot info file doesn't exist yet _u32 BootInfoCreateFlag = _FS_FILE_OPEN_FLAG_COMMIT | _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ; ASSERT (sl_FsOpen ((unsigned char *)IMG_BOOT_INFO, FS_MODE_OPEN_CREATE((2 * sizeof(sBootInfo_t)), BootInfoCreateFlag), NULL, &fhandle) == 0); } #endif // save the new boot info #ifdef WIPY sBootInfo.PrevImg = sBootInfo.ActiveImg; if (sBootInfo.ActiveImg == IMG_ACT_UPDATE1) { sBootInfo.ActiveImg = IMG_ACT_UPDATE2; } else { sBootInfo.ActiveImg = IMG_ACT_UPDATE1; } // the launchxl doesn't have enough flash space for 2 user updates #else sBootInfo.PrevImg = IMG_ACT_FACTORY; sBootInfo.ActiveImg = IMG_ACT_UPDATE1; #endif sBootInfo.Status = IMG_STATUS_CHECK; ASSERT (sizeof(sBootInfo_t) == sl_FsWrite(fhandle, 0, (unsigned char *)&sBootInfo, sizeof(sBootInfo_t))); sl_FsClose(fhandle, 0, 0, 0); } sl_LockObjUnlock (&wlan_LockObj); updater_data.fhandle = -1; } sl_LockObjUnlock (&updater_LockObj); }
bool updater_write (uint8_t *buf, uint32_t len) { bool result = false; sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); if (len == sl_FsWrite(updater_data.fhandle, updater_data.foffset, buf, len)) { updater_data.foffset += len; result = true; } sl_LockObjUnlock (&wlan_LockObj); return result; }
int sl_Start(const void* pIfHdl, char* pDevName, const P_INIT_CALLBACK pInitCallBack) { int pObjIdx = MAX_CONCURRENT_ACTIONS; InitComplete_t AsyncRsp; /* callback init */ _SlDrvDriverCBInit(); /* open the interface: usually SPI or UART */ if (NULL == pIfHdl) { g_pCB->FD = sl_IfOpen(pDevName, 0); } else { g_pCB->FD = (_SlFd_t)pIfHdl; } /* Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(START_STOP_ID, SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&AsyncRsp; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); if( g_pCB->FD >= 0) { sl_DeviceDisable(); sl_IfRegIntHdlr((SL_P_EVENT_HANDLER)_SlDrvRxIrqHandler, NULL); sl_DeviceEnable(); if (NULL != pInitCallBack) { g_pCB->pInitCallback = pInitCallBack; } else { OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); /*release Pool Object*/ _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex); return GetStartResponseConvert(AsyncRsp.Status); } } return (int)g_pCB->FD; }
STATIC void wlan_reenable (SlWlanMode_t mode) { // stop and start again #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); #endif sl_Stop(SL_STOP_TIMEOUT); wlan_clear_data(); wlan_obj.mode = sl_Start(0, 0, 0); #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjUnlock (&wlan_LockObj); #endif ASSERT (wlan_obj.mode == mode); }
void _sl_HandleAsync_Stop(void *pVoidBuf) { _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp); OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t)); OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); return; }
int sl_Stop(unsigned short timeout) { int RetVal=0; _SlStopMsg_u Msg; _BasicResponse_t AsyncRsp; int pObjIdx = MAX_CONCURRENT_ACTIONS; /* if timeout is 0 the shutdown is forced immediately */ if( 0 == timeout ) { sl_IfRegIntHdlr(NULL, NULL); sl_DeviceDisable(); RetVal = sl_IfClose(g_pCB->FD); } else { /* let the device make the shutdown using the defined timeout */ Msg.Cmd.Timeout = timeout; /* Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(START_STOP_ID,SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&AsyncRsp; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlStopCmdCtrl, &Msg, NULL)); if(SL_OS_RET_CODE_OK == (int)Msg.Rsp.status) { OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); Msg.Rsp.status = AsyncRsp.status; RetVal = Msg.Rsp.status; } _SlDrvReleasePoolObj(pObjIdx); sl_IfRegIntHdlr(NULL, NULL); sl_DeviceDisable(); sl_IfClose(g_pCB->FD); } _SlDrvDriverCBDeinit(); return RetVal; }
int sl_NetAppDnsGetHostByName(char * hostname, unsigned short usNameLen, unsigned long* out_ip_addr,unsigned char family) { _SlGetHostByNameMsg_u Msg; _SlCmdExt_t ExtCtrl; _GetHostByNameAsyncResponse_u AsyncRsp; UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS; ExtCtrl.TxPayloadLen = usNameLen; ExtCtrl.RxPayloadLen = 0; ExtCtrl.pTxPayload = (UINT8 *)hostname; ExtCtrl.pRxPayload = 0; Msg.Cmd.Len = usNameLen; Msg.Cmd.family = family; /*Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(GETHOSYBYNAME_ID,SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&AsyncRsp; /*set bit to indicate IPv6 address is expected */ if (SL_AF_INET6 == family) { g_pCB->ObjPool[pObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; } OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByNameCtrl, &Msg, &ExtCtrl)); if(SL_RET_CODE_OK == Msg.Rsp.status) { OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); Msg.Rsp.status = AsyncRsp.IpV4.status; if(SL_OS_RET_CODE_OK == (int)Msg.Rsp.status) { sl_Memcpy((char *)out_ip_addr, (char *)&AsyncRsp.IpV4.ip0, (SL_AF_INET == family) ? SL_IPV4_ADDRESS_SIZE : SL_IPV6_ADDRESS_SIZE); } } _SlDrvReleasePoolObj(pObjIdx); return Msg.Rsp.status; }
void _sl_HandleAsync_Accept(void *pVoidBuf) { _SocketAddrResponse_u *pMsgArgs = (_SocketAddrResponse_u *)_SL_RESP_ARGS_START(pVoidBuf); OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); VERIFY_PROTOCOL(( pMsgArgs->IpV4.sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS); VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs,sizeof(_SocketAddrResponse_u)); OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); return; }
static bool sflash_access (_u32 mode, _i32 (* sl_FsFunction)(_i32 FileHdl, _u32 Offset, _u8* pData, _u32 Len)) { _i32 fileHandle; bool retval = false; // wlan must be enabled in order to access the serial flash sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); if (0 == sl_FsOpen(sflash_block_name, mode, NULL, &fileHandle)) { if (SFLASH_BLOCK_SIZE == sl_FsFunction (fileHandle, 0, sflash_block_cache, SFLASH_BLOCK_SIZE)) { retval = true; } sl_FsClose (fileHandle, NULL, NULL, 0); } sl_LockObjUnlock (&wlan_LockObj); return retval; }
void _sl_HandleAsync_Connect(void *pVoidBuf) { _SocketResponse_t *pMsgArgs = (_SocketResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); VERIFY_PROTOCOL((pMsgArgs->sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS); VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->sd = pMsgArgs->sd; ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->statusOrLen = pMsgArgs->statusOrLen; OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); return; }
bool updater_start (void) { _u32 AccessModeAndMaxSize = FS_MODE_OPEN_WRITE; SlFsFileInfo_t FsFileInfo; bool result = false; sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); if (0 != sl_FsGetInfo((_u8 *)updater_data.path, 0, &FsFileInfo)) { // file doesn't exist, create it AccessModeAndMaxSize = FS_MODE_OPEN_CREATE(updater_data.fsize, 0); } if (!sl_FsOpen((_u8 *)updater_data.path, AccessModeAndMaxSize, NULL, &updater_data.fhandle)) { updater_data.foffset = 0; result = true; } sl_LockObjUnlock (&wlan_LockObj); return result; }
bool updater_check_path (void *path) { sl_LockObjLock (&updater_LockObj, SL_OS_WAIT_FOREVER); if (!strcmp(UPDATER_IMG_PATH, path)) { updater_data.fsize = IMG_SIZE; updater_data.path = IMG_UPDATE1; // the launchxl doesn't have enough flash space for 2 user update images #ifdef WIPY // check which one should be the next active image _i32 fhandle; if (!sl_FsOpen((unsigned char *)IMG_BOOT_INFO, FS_MODE_OPEN_READ, NULL, &fhandle)) { ASSERT (sizeof(sBootInfo_t) == sl_FsRead(fhandle, 0, (unsigned char *)&sBootInfo, sizeof(sBootInfo_t))); sl_FsClose(fhandle, 0, 0, 0); // if we still have an image pending for verification, keep overwriting it if ((sBootInfo.Status == IMG_STATUS_CHECK && sBootInfo.ActiveImg == IMG_ACT_UPDATE2) || (sBootInfo.ActiveImg == IMG_ACT_UPDATE1 && sBootInfo.Status != IMG_STATUS_CHECK)) { updater_data.path = IMG_UPDATE2; } } #endif } else if (!strcmp(UPDATER_SRVPACK_PATH, path)) { updater_data.path = IMG_SRVPACK; updater_data.fsize = SRVPACK_SIZE; } else if (!strcmp(UPDATER_SIGN_PATH, path)) { updater_data.path = SRVPACK_SIGN; updater_data.fsize = SIGN_SIZE; } else if (!strcmp(UPDATER_CA_PATH, path)) { updater_data.path = CA_FILE; updater_data.fsize = CA_KEY_SIZE; } else if (!strcmp(UPDATER_CERT_PATH, path)) { updater_data.path = CERT_FILE; updater_data.fsize = CA_KEY_SIZE; } else if (!strcmp(UPDATER_KEY_PATH, path)) { updater_data.path = KEY_FILE; updater_data.fsize = CA_KEY_SIZE; } else { sl_LockObjUnlock (&updater_LockObj); return false; } return true; }
/***************************************************************************** _sl_HandleAsync_InitComplete - handles init complete signalling to a waiting object ****************************************************************************/ void _sl_HandleAsync_InitComplete(void *pVoidBuf) { InitComplete_t *pMsgArgs = (InitComplete_t *)_SL_RESP_ARGS_START(pVoidBuf); OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); if(g_pCB->pInitCallback) { g_pCB->pInitCallback(GetStartResponseConvert(pMsgArgs->Status)); } else { memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(InitComplete_t)); OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); } OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); if(g_pCB->pInitCallback) { _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex); } }
_i16 _SlInternalSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags) { _i16 Res = 0; _SlInternalSpawnEntry_t* pSpawnEntry; if (NULL == pEntry) { Res = -1; } else { sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER); pSpawnEntry = g_SlInternalSpawnCB.pFree; g_SlInternalSpawnCB.pFree = pSpawnEntry->pNext; pSpawnEntry->pEntry = pEntry; pSpawnEntry->pValue = pValue; pSpawnEntry->pNext = NULL; if (NULL == g_SlInternalSpawnCB.pWaitForExe) { g_SlInternalSpawnCB.pWaitForExe = pSpawnEntry; g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry; } else { g_SlInternalSpawnCB.pLastInWaitList->pNext = pSpawnEntry; g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry; } sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); /* this sync is called after releasing the lock object to avoid unnecessary context switches */ sl_SyncObjSignal(&g_SlInternalSpawnCB.SyncObj); } return Res; }
void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf) { _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); /*IPv6 */ if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) { memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t)); } /*IPv4 */ else { memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t)); } OSI_RET_OK_CHECK(sl_SyncObjSignal(&(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj))); OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); return; }
int sl_Select(int nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout) { _SlSelectMsg_u Msg; _SelectAsyncResponse_t AsyncRsp; UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS; Msg.Cmd.nfds = nfds; Msg.Cmd.readFdsCount = 0; Msg.Cmd.writeFdsCount = 0; Msg.Cmd.readFds = 0; Msg.Cmd.writeFds = 0; if( readsds ) { Msg.Cmd.readFds = (UINT16)readsds->fd_array[0]; } if( writesds ) { Msg.Cmd.writeFds = (UINT16)writesds->fd_array[0]; } if( NULL == timeout ) { Msg.Cmd.tv_sec = 0xffff; Msg.Cmd.tv_usec = 0xffff; } else { if( 0xffff <= timeout->tv_sec ) { Msg.Cmd.tv_sec = 0xffff; } else { Msg.Cmd.tv_sec = (UINT16)timeout->tv_sec; } timeout->tv_usec = timeout->tv_usec >> 10; /* convert to milliseconds */ if( 0xffff <= timeout->tv_usec ) { Msg.Cmd.tv_usec = 0xffff; } else { Msg.Cmd.tv_usec = (UINT16)timeout->tv_usec; } } /* Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(SELECT_ID, SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&AsyncRsp; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); /* send the command */ VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSelectCmdCtrl, &Msg, NULL)); if(SL_OS_RET_CODE_OK == (int)Msg.Rsp.status) { OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); Msg.Rsp.status = AsyncRsp.status; if( ((int)Msg.Rsp.status) >= 0 ) { if( readsds ) { readsds->fd_array[0] = AsyncRsp.readFds; } if( writesds ) { writesds->fd_array[0] = AsyncRsp.writeFds; } } } _SlDrvReleasePoolObj(pObjIdx); return (int)Msg.Rsp.status; }
int sl_Accept(int sd, SlSockAddr_t *addr, SlSocklen_t *addrlen) { _SlSockAcceptMsg_u Msg; _SlReturnVal_t RetVal; _SocketAddrResponse_u AsyncRsp; UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS; Msg.Cmd.sd = sd; Msg.Cmd.family = (sizeof(SlSockAddrIn_t) == *addrlen) ? SL_AF_INET : SL_AF_INET6; /* Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(ACCEPT_ID, sd & BSD_SOCKET_ID_MASK); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&AsyncRsp; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); /* send the command */ VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlAcceptCmdCtrl, &Msg, NULL)); VERIFY_PROTOCOL(Msg.Rsp.sd == sd); RetVal = Msg.Rsp.statusOrLen; if(SL_OS_RET_CODE_OK == RetVal) { /* wait for async and get Data Read parameters */ OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); VERIFY_PROTOCOL(AsyncRsp.IpV4.sd == sd); RetVal = AsyncRsp.IpV4.statusOrLen; if( (NULL != addr) && (NULL != addrlen) ) { #if 0 /* Kept for backup */ _sl_ParseAddress(&AsyncRsp, addr, addrlen); #else addr->sa_family = AsyncRsp.IpV4.family; if(SL_AF_INET == addr->sa_family) { if( *addrlen == sizeof( SlSockAddrIn_t ) ) { ((SlSockAddrIn_t *)addr)->sin_port = AsyncRsp.IpV4.port; ((SlSockAddrIn_t *)addr)->sin_addr.s_addr = AsyncRsp.IpV4.address; } else { *addrlen = 0; } } else if (SL_AF_INET6_EUI_48 == addr->sa_family ) { if( *addrlen == sizeof( SlSockAddrIn6_t ) ) { ((SlSockAddrIn6_t *)addr)->sin6_port = AsyncRsp.IpV6EUI48.port ; /* will be called from here and from _sl_BuildAddress*/ sl_Memcpy(((SlSockAddrIn6_t *)addr)->sin6_addr._S6_un._S6_u8, AsyncRsp.IpV6EUI48.address, 6); } else { *addrlen = 0; } } #ifdef SL_SUPPORT_IPV6 else { if( *addrlen == sizeof( sockaddr_in6 ) ) { ((sockaddr_in6 *)addr)->sin6_port = AsyncRsp.IpV6.port ; sl_Memcpy(((sockaddr_in6 *)addr)->sin6_addr._S6_un._S6_u32, AsyncRsp.IpV6.address, 16); } else { *addrlen = 0; } } #endif #endif } } _SlDrvReleasePoolObj(pObjIdx); return (int)RetVal; }
int sl_Connect(int sd, const SlSockAddr_t *addr, int addrlen) { _SlSockConnectMsg_u Msg; _SlReturnVal_t RetVal; _SlCmdCtrl_t CmdCtrl = {0, 0, sizeof(_SocketResponse_t)}; _SocketResponse_t AsyncRsp; UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS; switch(addr->sa_family) { case SL_AF_INET : CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT; CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t); break; case SL_AF_INET6_EUI_48: CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6; CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t); break; #ifdef SL_SUPPORT_IPV6 case AF_INET6: CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6; CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t); break; #endif case SL_AF_RF : default: return SL_RET_CODE_INVALID_INPUT; } Msg.Cmd.IpV4.lenOrPadding = 0; Msg.Cmd.IpV4.sd = sd; _sl_BuildAddress(addr, addrlen, &Msg.Cmd); /* Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(CONNECT_ID, sd & BSD_SOCKET_ID_MASK); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&AsyncRsp; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); /* send the command */ VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL)); VERIFY_PROTOCOL(Msg.Rsp.sd == sd) RetVal = Msg.Rsp.statusOrLen; if(SL_RET_CODE_OK == RetVal) { /* wait for async and get Data Read parameters */ OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); VERIFY_PROTOCOL(AsyncRsp.sd == sd); RetVal = AsyncRsp.statusOrLen; } _SlDrvReleasePoolObj(pObjIdx); return RetVal; }
int sl_NetAppPingStart(SlPingStartCommand_t* pPingParams,unsigned char family,SlPingReport_t *pReport,const P_SL_DEV_PING_CALLBACK pPingCallback) { _SlCmdCtrl_t CmdCtrl = {0, sizeof(_PingStartCommand_t), sizeof(_BasicResponse_t)}; _SlPingStartMsg_u Msg; _PingReportResponse_t PingRsp; UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS; if( 0 == pPingParams->Ip ) // stop any ongoing ping { return _SlDrvBasicCmd(SL_OPCODE_NETAPP_PINGSTOP); } if(SL_AF_INET == family) { CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART; memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV4_ADDRESS_SIZE); } else { CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART_V6; memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV6_ADDRESS_SIZE); } Msg.Cmd.pingIntervalTime = pPingParams->PingIntervalTime; Msg.Cmd.PingSize = pPingParams->PingSize; Msg.Cmd.pingRequestTimeout = pPingParams->PingRequestTimeout; Msg.Cmd.totalNumberOfAttempts = pPingParams->TotalNumberOfAttempts; Msg.Cmd.flags = pPingParams->Flags; if( pPingCallback ) { pPingCallBackFunc = pPingCallback; } else { /*Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(PING_ID,SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); /* async response handler for non callback mode */ g_pCB->ObjPool[pObjIdx].pRespArgs = (UINT8 *)&PingRsp; pPingCallBackFunc = NULL; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); } VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL)); /*send the command*/ if(CMD_PING_TEST_RUNNING == (int)Msg.Rsp.status || CMD_PING_TEST_STOPPED == (int)Msg.Rsp.status ) { /* block waiting for results if no callback function is used */ if( NULL == pPingCallback ) { OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); if( SL_OS_RET_CODE_OK == (int)PingRsp.status ) { CopyPingResultsToReport(&PingRsp,pReport); } _SlDrvReleasePoolObj(pObjIdx); } } else { /* ping failure, no async response */ if( NULL == pPingCallback ) { _SlDrvReleasePoolObj(pObjIdx); } } return Msg.Rsp.status; }
long sl_NetAppDnsGetHostByService(char *pServiceName, /* string containing all (or only part): name + subtype + service */ unsigned char ServiceLen, unsigned char Family, /* 4-IPv4 , 16-IPv6 */ unsigned long pAddr[], unsigned long *pPort, unsigned short *pTextLen, /* in: max len , out: actual len */ char *pText ) { _SlGetHostByServiceMsg_u Msg; _SlCmdExt_t CmdExt ; _GetHostByServiceAsyncResponse_t AsyncRsp; UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS; /* Note: 1. The return's attributes are belonged to first service that is found. It can be other services with the same service name will response to the query. The results of these responses are saved in the peer cache of the NWP, and should be read by another API. 2. Text length can be 120 bytes only - not more It is because of constraints in the NWP on the buffer that is allocated for the Async event. 3.The API waits to Async event by blocking. It means that the API is finished only after an Async event is sent by the NWP. 4.No rolling option!!! - only PTR type is sent. */ /*build the attribute part of the command. It contains the constant parameters of the command */ Msg.Cmd.ServiceLen = ServiceLen; Msg.Cmd.AddrLen = Family; /*Build the payload part of the command Copy the service name and text to one buffer.*/ CmdExt.TxPayloadLen = ServiceLen; CmdExt.RxPayloadLen = 0; CmdExt.pTxPayload = (UINT8 *)pServiceName; CmdExt.pRxPayload = NULL; /*set pointers to the output parameters (the returned parameters). This pointers are belonged to local struct that is set to global Async response parameter. It is done in order not to run more than one sl_DnsGetHostByService at the same time. The API should be run only if global parameter is pointed to NULL. */ AsyncRsp.out_pText = pText; AsyncRsp.inout_TextLen = (unsigned short*)pTextLen; AsyncRsp.out_pPort = pPort; AsyncRsp.out_pAddr = (unsigned long *)pAddr; /*Use Obj to issue the command, if not available try later */ pObjIdx = _SlDrvWaitForPoolObj(GETHOSYBYSERVICE_ID,SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == pObjIdx) { return SL_POOL_IS_EMPTY; } OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); g_pCB->ObjPool[pObjIdx].pRespArgs = (void *)&AsyncRsp; OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); /* set bit to indicate IPv6 address is expected */ if (SL_AF_INET6 == Family) { g_pCB->ObjPool[pObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; } /* Send the command */ VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByServiceCtrl, &Msg, &CmdExt)); /* If the immediate reponse is O.K. than wait for aSYNC event response. */ if(SL_RET_CODE_OK == Msg.Rsp.status) { OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); /* If we are - it means that Async event was sent. The results are copied in the Async handle return functions */ Msg.Rsp.status = AsyncRsp.Status; } _SlDrvReleasePoolObj(pObjIdx); return Msg.Rsp.status; }
void _SlInternalSpawnTaskEntry() { _i16 i; _SlInternalSpawnEntry_t* pEntry; _u8 LastEntry; /* create and lock the locking object. lock in order to avoid race condition on the first creation */ sl_LockObjCreate(&g_SlInternalSpawnCB.LockObj,"SlSpawnProtect"); sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_NO_WAIT); /* create and clear the sync object */ sl_SyncObjCreate(&g_SlInternalSpawnCB.SyncObj,"SlSpawnSync"); sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_NO_WAIT); g_SlInternalSpawnCB.pFree = &g_SlInternalSpawnCB.SpawnEntries[0]; g_SlInternalSpawnCB.pWaitForExe = NULL; g_SlInternalSpawnCB.pLastInWaitList = NULL; /* create the link list between the entries */ for (i=0 ; i<_SL_MAX_INTERNAL_SPAWN_ENTRIES - 1 ; i++) { g_SlInternalSpawnCB.SpawnEntries[i].pNext = &g_SlInternalSpawnCB.SpawnEntries[i+1]; g_SlInternalSpawnCB.SpawnEntries[i].pEntry = NULL; } g_SlInternalSpawnCB.SpawnEntries[i].pNext = NULL; sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); /* here we ready to execute entries */ while (TRUE) { sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_WAIT_FOREVER); /* go over all entries that already waiting for execution */ LastEntry = FALSE; do { /* get entry to execute */ sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER); pEntry = g_SlInternalSpawnCB.pWaitForExe; if ( NULL == pEntry ) { sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); break; } g_SlInternalSpawnCB.pWaitForExe = pEntry->pNext; if (pEntry == g_SlInternalSpawnCB.pLastInWaitList) { g_SlInternalSpawnCB.pLastInWaitList = NULL; LastEntry = TRUE; } sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); /* pEntry could be null in case that the sync was already set by some of the entries during execution of earlier entry */ if (NULL != pEntry) { pEntry->pEntry(pEntry->pValue); /* free the entry */ sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER); pEntry->pNext = g_SlInternalSpawnCB.pFree; g_SlInternalSpawnCB.pFree = pEntry; if (NULL != g_SlInternalSpawnCB.pWaitForExe) { /* new entry received meanwhile */ LastEntry = FALSE; } sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); } }while (!LastEntry); } }