/********************************************************************* * @fn zllSampleLight_SceneStoreCB * * @brief Callback from the ZCL General Cluster Library when * it received a Scene Store Request Command for * this application. * Stores current attributes in the scene's extension fields. * Extension field sets = * {{Cluster ID 1, length 1, {extension field set 1}}, {{Cluster ID 2, * length 2, {extension field set 2}}, ...} * * @param pReq - pointer to a request holding scene data * * @return TRUE if extField is filled out, FALSE if not filled * and there is no need to save the scene */ static uint8 zllSampleLight_SceneStoreCB( zclSceneReq_t *pReq ) { uint8 *pExt; pReq->scene->extLen = SAMPLELIGHT_SCENE_EXT_FIELD_SIZE; pExt = pReq->scene->extField; // Build an extension field for On/Off cluster *pExt++ = LO_UINT16( ZCL_CLUSTER_ID_GEN_ON_OFF ); *pExt++ = HI_UINT16( ZCL_CLUSTER_ID_GEN_ON_OFF ); *pExt++ = sizeof(zllSampleLight_OnOff); // length // Store the value of onOff attribute *pExt++ = zllSampleLight_OnOff; #ifdef ZCL_LEVEL_CTRL // Build an extension field for Level Control cluster *pExt++ = LO_UINT16( ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL ); *pExt++ = HI_UINT16( ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL ); *pExt++ = sizeof(zclLevel_CurrentLevel); // length // Store the value of currentLevel attribute *pExt++ = zclLevel_CurrentLevel; #endif //ZCL_LEVEL_CTRL #ifdef ZCL_COLOR_CTRL // Build an extension field for Color Control cluster *pExt++ = LO_UINT16( ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL ); *pExt++ = HI_UINT16( ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL ); *pExt++ = COLOR_SCN_X_Y_ATTRS_SIZE + COLOR_SCN_HUE_SAT_ATTRS_SIZE + COLOR_SCN_LOOP_ATTRS_SIZE; // length // Restored color mode is determined by whether stored currentX, currentY values are 0. if ( zclColor_ColorMode == COLOR_MODE_CURRENT_X_Y ) { *pExt++ = LO_UINT16( zclColor_CurrentX ); *pExt++ = HI_UINT16( zclColor_CurrentX ); *pExt++ = LO_UINT16( zclColor_CurrentY ); *pExt++ = HI_UINT16( zclColor_CurrentY ); pExt += COLOR_SCN_HUE_SAT_ATTRS_SIZE + COLOR_SCN_LOOP_ATTRS_SIZE; // ignore other parameters } else { // nullify currentX and currentY to mark hue/sat color mode osal_memset( pExt, 0x00, COLOR_SCN_X_Y_ATTRS_SIZE ); pExt += COLOR_SCN_X_Y_ATTRS_SIZE; *pExt++ = LO_UINT16( zclColor_EnhancedCurrentHue ); *pExt++ = HI_UINT16( zclColor_EnhancedCurrentHue ); *pExt++ = zclColor_CurrentSaturation; *pExt++ = zclColor_ColorLoopActive; *pExt++ = zclColor_ColorLoopDirection; *pExt++ = LO_UINT16( zclColor_ColorLoopTime ); *pExt++ = HI_UINT16( zclColor_ColorLoopTime ); } #endif //ZCL_COLOR_CTRL // Add more clusters here return ( TRUE ); }
/*************************************************************************************************** * @fn MT_UtilBindAddEntry * * @brief Add Binding Entry into Local Table. * * @param pBuf - pointer to the received buffer * * @return void ***************************************************************************************************/ static void MT_UtilBindAddEntry(uint8 *pBuf) { uint8 srcEp; zAddrType_t dstAddr; uint8 dstEp; uint8 numClusterIds; uint16 *clusterIds; uint8 buf[sizeof(BindingEntry_t)]; uint8 cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; // Initialize the return buffer osal_memset( buf, 0xFF, sizeof(BindingEntry_t) ); buf[2] = 0xFE; // set the default value of INVALID_NODE_ADDR buf[3] = 0xFF; // set the default value of INVALID_NODE_ADDR srcEp = *pBuf++; // Destination Address mode dstAddr.addrMode = *pBuf++; // Destination Address if ( dstAddr.addrMode == Addr64Bit ) { uint8 *ptr; // Use this additional pointer because *pBuf is incremented later for both cases ptr = pBuf; osal_cpyExtAddr( dstAddr.addr.extAddr, ptr ); } else { dstAddr.addr.shortAddr = BUILD_UINT16( pBuf[0], pBuf[1] ); } // The short address occupies LSB two bytes pBuf += Z_EXTADDR_LEN; // DstEPInt dstEp = *pBuf++; numClusterIds = *pBuf++; if ( numClusterIds > 0 ) { // copy list of clusters clusterIds = (uint16 *)osal_mem_alloc( numClusterIds * sizeof(uint16) ); osal_memcpy( clusterIds, pBuf, numClusterIds * sizeof(uint16)); if ( clusterIds != NULL ) { // The response to MT interface has to be pack into buf packBindEntry_t( buf, bindAddEntry( srcEp, &dstAddr, dstEp, numClusterIds, clusterIds )); osal_mem_free( clusterIds ); } } MT_BuildAndSendZToolResponse( ( (uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL ), cmdId, sizeof(BindingEntry_t), buf ); }
/********************************************************************* * @fn Wechat_Init * * @brief Initialization function for the BLE wechat App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param none * * @return none */ uint8 Wechat_Init( void ) { uint8 stat = SUCCESS; osal_memset( wechatStoreAuth, 0, (sizeof(attHandleValueInd_t) * WECHAT_AUTH_STORE_MAX) ); Wechat_state_reset(); stat = Wechat_get_md5(); return stat; }
/********************************************************************* * @fn timeAppDiscStart() * * @brief Start service discovery. * * * @return New discovery state. */ uint8 timeAppDiscStart( void ) { // Clear handle cache osal_memset( timeAppHdlCache, 0, sizeof(timeAppHdlCache) ); // Start discovery with first service return timeAppDiscGattMsg( DISC_CURR_TIME_START, NULL ); }
/********************************************************************* * @fn glucoseDiscStart() * * @brief Start service discovery. * * * @return New discovery state. */ uint8 glucoseDiscStart( void ) { // Clear handle cache osal_memset( glucoseHdlCache, 0, sizeof(glucoseHdlCache) ); // Start discovery with first service return glucoseDiscGattMsg( DISC_GLUCOSE_START, NULL ); }
/********************************************************************* * @fn softCmdDiscStart() * * @brief Start service discovery. * * * @return New discovery state. */ static uint8 softCmdDiscStart( void ) { // Clear handle cache osal_memset( softCmdHdlCache, 0, sizeof(softCmdHdlCache) ); // Start discovery with first service return softCmdDiscGenCtrl( DISC_GEN_CTRL_START, NULL ); }
/********************************************************************* * @fn osal_mem_free * * @brief Implementation of the de-allocator functionality. * * @param ptr - pointer to the memory to free. * * @return void */ void osal_mem_free( void *ptr ) { osalMemHdr_t *currHdr; halIntState_t intState; #if ( OSALMEM_GUARD ) // Try to protect against premature use by HAL / OSAL. if ( ready != OSALMEM_READY ) { osal_mem_init(); } #endif HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts. OSALMEM_ASSERT( ptr ); currHdr = (osalMemHdr_t *)ptr - 1; // Has this block already been freed? OSALMEM_ASSERT( *currHdr & OSALMEM_IN_USE ); *currHdr &= ~OSALMEM_IN_USE; #if ( OSALMEM_PROFILER ) { uint16 size = *currHdr; byte idx; for ( idx = 0; idx < OSALMEM_PROMAX; idx++ ) { if ( size <= proCnt[idx] ) { break; } } proCur[idx]--; } #endif #if ( OSALMEM_METRICS ) memAlo -= *currHdr; blkFree++; #endif if ( ff1 > currHdr ) { ff1 = currHdr; } #if ( OSALMEM_PROFILER ) osal_memset( (byte *)currHdr+HDRSZ, OSALMEM_REIN, (*currHdr - HDRSZ) ); #endif HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts. }
/************************************************************************************************** * @fn znpTestRF * * @brief This function initializes and checks the ZNP RF Test Mode NV items. It is designed * to be invoked before/instead of MAC radio initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. */ void znpTestRF(void) { uint8 rfTestParms[4] = { 0, 0, 0, 0 }; if ((SUCCESS != osal_nv_item_init(ZNP_NV_RF_TEST_PARMS, 4, rfTestParms)) || (SUCCESS != osal_nv_read(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms)) || (rfTestParms[0] == 0)) { return; } // Settings from SmartRF Studio MDMCTRL0 = 0x85; RXCTRL = 0x3F; FSCTRL = 0x5A; FSCAL1 = 0x2B; AGCCTRL1 = 0x11; ADCTEST0 = 0x10; ADCTEST1 = 0x0E; ADCTEST2 = 0x03; FRMCTRL0 = 0x43; FRMCTRL1 = 0x00; MAC_RADIO_RXTX_OFF(); MAC_RADIO_SET_CHANNEL(rfTestParms[1]); MAC_RADIO_SET_TX_POWER(rfTestParms[2]); TX_PWR_TONE_SET(rfTestParms[3]); switch (rfTestParms[0]) { case 1: // Rx promiscuous mode. MAC_RADIO_RX_ON(); break; case 2: // Un-modulated Tx. TX_PWR_MOD__SET(1); // no break; case 3: // Modulated Tx. // Modulated is default register setting, so no special action. // Now turn on Tx power for either mod or un-modulated Tx test. MAC_RADIO_TX_ON(); break; default: // Not expected. break; } // Clear the RF test mode. (void)osal_memset(rfTestParms, 0, 4); (void)osal_nv_write(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms); while (1); // Spin in RF test mode until a hard reset. }
void lock_init(void) { uint8 read_tmp[6] = {0}; uint8 use_lock_times[2] = {0}; uint8 ret8; osal_memset(read_tmp, '0', sizeof(read_tmp)); ret8 = osal_snv_write(admin_flash_start_addr, sizeof(read_tmp), read_tmp); if(ret8 == NV_OPER_FAILED) return; osal_memset(read_tmp, '1', sizeof(read_tmp)); ret8 = osal_snv_write(user_flash_start_addr, sizeof(read_tmp), read_tmp); if(ret8 == NV_OPER_FAILED) return; osal_memcpy(read_tmp, ssid, 6); ret8 = osal_snv_write(ssid_flash_start_addr, sizeof(read_tmp), read_tmp); if(ret8 == NV_OPER_FAILED) return; osal_memcpy(scanRspData + 2, read_tmp, 6); osal_memcpy(attDeviceName, read_tmp, 6); GAP_UpdateAdvertisingData( simpleBLEPeripheral_TaskID, FALSE, sizeof( scanRspData ), scanRspData ); GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName ); osal_memset(read_tmp, '0', sizeof(read_tmp)); ret8 = osal_snv_write(dead_date_flash_start_addr, sizeof(read_tmp), read_tmp); if(ret8 == NV_OPER_FAILED) return; osal_memset(read_tmp, '0', sizeof(read_tmp)); ret8 = osal_snv_write(carlock_id_flash_start_addr, sizeof(read_tmp), read_tmp); if(ret8 == NV_OPER_FAILED) return; osal_memset(use_lock_times, 0, sizeof(use_lock_times)); ret8 = osal_snv_write(use_lock_times_start_addr, sizeof(use_lock_times), use_lock_times); if(ret8 == NV_OPER_FAILED) return; HAL_SYSTEM_RESET();//reset }
/********************************************************************* * @fn zclCCServer_SendLeaveReq * * @brief Send out a Leave Request command. * * @param void * * @return ZStatus_t */ static ZStatus_t zclCCServer_SendLeaveReq( void ) { NLME_LeaveReq_t leaveReq; // Set every field to 0 osal_memset( &leaveReq, 0, sizeof( NLME_LeaveReq_t ) ); // Send out our leave return ( NLME_LeaveReq( &leaveReq ) ); }
/********************************************************************* * @fn zdo_MTCB_MgmtRtgRspCB() * * @brief * * Called to send MT callback response for Management Network * Discover response * * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtRtgRspCB( uint16 SrcAddr, byte Status, byte RtgCount, byte StartIndex, byte RtgListCount, rtgItem_t *pList ) { byte *msgPtr; byte *msg; byte len; byte x; /*Allocate a message of size equivalent to the corresponding SPI message (plus a couple of bytes for MT use)so that the same buffer can be sent by MT to the test tool by simply setting the header bytes.*/ /*In order to allocate the message , we need to know the length and this has to be calculated before we allocate the message*/ len = 2 + 1 + 1 + 1 + 1 + (ZDP_RTG_DISCRIPTOR_SIZE * ZDO_MAX_RTG_ITEMS); // SrcAddr + Status + RtgCount + StartIndex + RtgListCount // + (maximum entries * size of struct) msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { msg = msgPtr; //Fill up the data bytes *msg++ = HI_UINT16( SrcAddr ); *msg++ = LO_UINT16( SrcAddr ); *msg++ = Status; *msg++ = RtgCount; *msg++ = StartIndex; *msg++ = RtgListCount; osal_memset( msg, 0, (ZDP_RTG_DISCRIPTOR_SIZE * ZDO_MAX_RTG_ITEMS) ); for ( x = 0; x < ZDO_MAX_RTG_ITEMS; x++ ) { if ( x < RtgListCount ) { *msg++ = HI_UINT16( pList->dstAddress ); *msg++ = LO_UINT16( pList->dstAddress ); *msg++ = HI_UINT16( pList->nextHopAddress ); *msg++ = LO_UINT16( pList->nextHopAddress ); *msg++ = pList->status; pList++; } } MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_RTG_RSP, len, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn Thermometer_Init * * @brief Initialization function for the Thermometer App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void Thermometer_Init(uint8 task_id) { struct ther_info *ti = &ther_info; osal_memset(ti, 0, sizeof(struct ther_info)); ti->task_id = task_id; ti->power_mode = PM_ACTIVE; osal_set_event(ti->task_id, TH_POWER_ON_EVT); }
/************************************************************************************************** * @fn AddrMgrExtAddrSet * * @brief Set destination address to source address or empty{0x00}. * * input parameters * * @param dstExtAddr - Pointer to the buffer to which to copy. * @param srcExtAddr - Pointer to the buffer from which to copy. * * output parameters * * @param dstExtAddr - Pointer to the buffer to which to copy. * * @return None. ************************************************************************************************** */ void AddrMgrExtAddrSet(uint8 *dstExtAddr, uint8 *srcExtAddr) { if ( srcExtAddr != NULL ) { osal_cpyExtAddr( dstExtAddr, srcExtAddr ); } else { osal_memset( dstExtAddr, 0x00, Z_EXTADDR_LEN ); } }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); Hal_Init(taskID++); // HAL should be a higher priority than any ZNP task. zapInit(taskID++); // ZAP APP should be the highest priority ZNP task. pulseAppInit(taskID); //MHMS registers endpoint and other initialization stuff }
static INT32 _stp_dbg_disable (MTKSTP_DBG_T *stp_dbg) { osal_lock_unsleepable_lock(&(stp_dbg->logsys->lock)); stp_dbg->pkt_trace_no = 0; /* [FIXME][George] DANGEROUS CODING to MEMSET A STRUCTURE in a NON-INIT * or a NON-DEINIT CONTEXT!!! */ #if 0 osal_memset(stp_dbg->logsys,0,osal_sizeof(MTKSTP_LOG_SYS_T)); #else osal_memset(&stp_dbg->logsys->queue[0], 0x0, sizeof(stp_dbg->logsys->queue)); stp_dbg->logsys->size = 0; stp_dbg->logsys->in = 0; stp_dbg->logsys->out = 0; #endif stp_dbg->is_enable = 0; osal_unlock_unsleepable_lock(&(stp_dbg->logsys->lock)); return 0; }
/********************************************************************* * @fn zclCCServer_UseStartupParameters * * @brief Set the network parameters to the current Startup Parameters. * * @param none * * @return none */ static void zclCCServer_UseStartupParameters( void ) { if ( zclCCServer_StartUpControl == CC_STARTUP_CONTROL_OPTION_1 ) { uint8 networkKey[SEC_KEY_LEN]; // Form the Commissioning network and become the Coordinator for that network // Required attributes: Extended PAN ID osal_nv_write( ZCD_NV_EXTENDED_PAN_ID, 0, Z_EXTADDR_LEN, zclCCServer_ExtendedPanId ); osal_nv_write( ZCD_NV_APS_USE_EXT_PANID, 0, Z_EXTADDR_LEN, zclCCServer_ExtendedPanId ); // Optional attributes: PAN ID, Channel Mask, Network Manager Address, // Network Key, Network Key Type (only KEY_TYPE_NWK is currently supported), // and Trust Center Address (which is used with Preconfigured Link Key). osal_nv_write( ZCD_NV_PANID, 0, sizeof( zclCCServer_PanId ), &zclCCServer_PanId ); osal_nv_write( ZCD_NV_CHANLIST, 0, sizeof( zclCCServer_ChannelMask ), &zclCCServer_ChannelMask ); osal_nv_write( ZCD_NV_NWKMGR_ADDR, 0, sizeof( zclCCServer_NwkManagerAddr ), &zclCCServer_NwkManagerAddr ); osal_nv_read( ZCD_NV_SAS_CURR_NWK_KEY, 0, SEC_KEY_LEN, networkKey ); if ( !nullKey( networkKey ) ) { // Save the Network Key as the Pre-Configured Key in NV osal_nv_write( ZCD_NV_PRECFGKEY, 0, SEC_KEY_LEN, networkKey ); // Clear copy of key in RAM osal_memset( networkKey, 0x00, SEC_KEY_LEN ); } } else if ( zclCCServer_StartUpControl == CC_STARTUP_CONTROL_OPTION_3 ) { // Join the Commissioning network // Required attributes: none // Optional attributes: Extended PAN ID, Channel Mask, and // Preconfigured Link Key osal_nv_write( ZCD_NV_EXTENDED_PAN_ID, 0, Z_EXTADDR_LEN, zclCCServer_ExtendedPanId ); osal_nv_write( ZCD_NV_CHANLIST, 0, sizeof( zclCCServer_ChannelMask ), &zclCCServer_ChannelMask ); zclCCServer_SavePreconfigLinkKey(); } }
/********************************************************************* * @fn zllSampleBridge_InitLinkedTargets() * * @brief Initialize linked targets and controlled groups lists in NV. * * @param none * * @return none */ static void zllSampleBridge_InitLinkedTargets( void ) { uint8 i; osal_memset( &linkedTargets, 0xFF, sizeof(linkedTargets)); zll_ItemInit( ZCD_NV_ZLL_BRIDGE_LINK_TARGETS, sizeof(zllBridgeLinkedTargetList_t), &linkedTargets ); linkedAddrNum = 0; for (i = 0; i < MAX_LINKED_TARGETS; i++ ) { if ( linkedTargets.arr[i].Addr != 0xFFFF ) { linkedAddrNum++; } } if ( linkedAddrNum < MAX_LINKED_TARGETS ) { linkedAddrNextIdx = linkedAddrNum; } // init controlled groups list osal_memset( &controlledGroups, 0x00, sizeof(controlledGroups)); zll_ItemInit( ZCD_NV_ZLL_BRIDGE_CTRL_GROUPS, sizeof(zllBridgeControlledGroupsList_t), &controlledGroups ); }
INT32 wmt_idc_deinit(VOID) { INT32 iRet; iRet = mtk_conn_md_bridge_unreg(gWmtIdcInfo.iit.src_mod_id); if (iRet) WMT_ERR_FUNC("mtk_conn_md_bridge_unreg fail(%d)\n", iRet); osal_memset(&gWmtIdcInfo, 0, osal_sizeof(gWmtIdcInfo)); return 0; }
void ther_buzzer_init(unsigned char task_id) { struct ther_buzzer *b = &buzzer; print(LOG_INFO, MODULE "buzzer init\n"); osal_memset(b, 0, sizeof(struct ther_buzzer)); b->task_id = task_id; P1_BUZZER_PIN = 1; }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); Hal_Init(taskID++); // HAL should be a higher priority than any ZNP task. zapInit(taskID++); // ZAP APP should be the highest priority ZNP task. zcl_Init( taskID++ ); ipd_Init( taskID ); }
/********************************************************************* * @fn WechatSendStoredAuth * * @brief Send a stored measurement indication. An incoming indication * confirmation will trigger the next pending stored measurement. * * @return none */ void WechatSendStoredAuth(void) { // We connected to this peer before so send any stored measurements if (wechatStoreStartIndex != wechatStoreIndex) { attHandleValueInd_t *pStoreInd = &wechatStoreAuth[wechatStoreStartIndex]; #if 0 NPI_Printf("\r\n##send %d[%d] wechat data: ", wechatStoreStartIndex, pStoreInd->len); for(uint8 i=0;i> pStoreInd->len;++i) { NPI_Printf(" %x", pStoreInd->pValue[i]); } NPI_Printf("\r\n"); #endif // Send wechat auth - can fail if not connected or CCC not enabled bStatus_t status = Wechat_Indicate( gapConnHandle, pStoreInd, simpleBLEPeripheral_TaskID ); // If sucess, increment the counters and the indication confirmation // will trigger the next indication if there are more pending. if (status == SUCCESS) { // Clear out this Meas indication. VOID osal_memset( pStoreInd, 0, sizeof(attHandleValueInd_t) ); wechatStoreStartIndex ++; // Wrap around buffer if (wechatStoreStartIndex > WECHAT_AUTH_STORE_MAX) { wechatStoreStartIndex = 0; } //osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD ); } else { //osal_stop_timerEx( simpleBLEPeripheral_TaskID, WECHAT_CCC_UPDATE_EVT); NPI_Printf("Send %d failed %d \r\n", wechatStoreStartIndex, status); //osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD ); } } else { //NPI_Printf("wechat send end\r\n"); wechatStoreIndex=0; wechatStoreStartIndex=0; osal_stop_timerEx( simpleBLEPeripheral_TaskID, WECHAT_CCC_UPDATE_EVT); } }
/********************************************************************* * @fn gapBondMgrEraseBonding * * @brief Write all 0xFF's to the complete bonding record * * @param idx - bonding index * * @return SUCCESS if successful. * Otherwise, NV_OPER_FAILED for failure. */ static bStatus_t gapBondMgrEraseBonding( uint8 idx ) { bStatus_t ret; gapBondRec_t bondRec; gapBondLTK_t ltk; VOID osal_memset( &bondRec, 0xFF, sizeof ( gapBondRec_t ) ); VOID osal_memset( <k, 0xFF, sizeof ( gapBondLTK_t ) ); // Write out FF's over the entire bond entry. ret = osal_snv_write( mainRecordNvID(idx), sizeof ( gapBondRec_t ), &bondRec ); ret |= osal_snv_write( localLTKNvID(idx), sizeof ( gapBondLTK_t ), <k ); ret |= osal_snv_write( devLTKNvID(idx), sizeof ( gapBondLTK_t ), <k ); ret |= osal_snv_write( devIRKNvID(idx), KEYLEN, ltk.LTK ); ret |= osal_snv_write( devCSRKNvID(idx), KEYLEN, ltk.LTK ); ret |= osal_snv_write( devSignCounterNvID(idx), sizeof ( uint32 ), ltk.LTK ); // Update the GAP Privacy Flag Properties gapBondSetupPrivFlag(); return ( ret ); }
P_OSAL_OP _stp_btm_get_free_op(MTKSTP_BTM_T *stp_btm) { P_OSAL_OP pOp; if (stp_btm) { pOp = _stp_btm_get_op(stp_btm, &stp_btm->rFreeOpQ); if (pOp) osal_memset(&pOp->op, 0, sizeof(pOp->op)); return pOp; } else return NULL; }
/********************************************************************* * @fn zclCCServer_SavePreconfigLinkKey * * @brief Save the Pre-Configured Link Key. * * @param void * * @return ZStatus_t */ static void zclCCServer_SavePreconfigLinkKey( void ) { APSME_TCLinkKey_t *pKeyData; pKeyData = (APSME_TCLinkKey_t *)osal_mem_alloc( sizeof( APSME_TCLinkKey_t ) ); if (pKeyData != NULL) { // Making sure data is cleared for every key all the time osal_memset( pKeyData, 0x00, sizeof( APSME_TCLinkKey_t ) ); osal_memset( pKeyData->extAddr, 0xFF, Z_EXTADDR_LEN ); osal_nv_read( ZCD_NV_SAS_CURR_PRECFG_LINK_KEY, 0, SEC_KEY_LEN, pKeyData->key ); // Save the Pre-Configured Link Key as the default TC Link Key the in NV osal_nv_write( ZCD_NV_TCLK_TABLE_START, 0, sizeof( APSME_TCLinkKey_t ), pKeyData ); // Clear copy of key in RAM osal_memset( pKeyData, 0x00, sizeof( APSME_TCLinkKey_t ) ); osal_mem_free( pKeyData ); } }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); VOID osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); /* LL Task */ LL_Init( taskID++ ); /* Hal Task */ Hal_Init( taskID++ ); /* HCI Task */ HCI_Init( taskID++ ); #if defined ( OSAL_CBTIMER_NUM_TASKS ) /* Callback Timer Tasks */ osal_CbTimerInit( taskID ); taskID += OSAL_CBTIMER_NUM_TASKS; #endif /* L2CAP Task */ L2CAP_Init( taskID++ ); /* GAP Task */ GAP_Init( taskID++ ); /* SM Task */ SM_Init( taskID++ ); /* GATT Task */ GATT_Init( taskID++ ); #if !defined ( GATT_DB_OFF_CHIP ) /* GATT Server App Task */ GATTServApp_Init( taskID++ ); #if defined ( GATT_TEST ) /* GATT Test Task */ GATTTest_Init( taskID++ ); #endif #endif // GATT_DB_OFF_CHIP #if defined ( GAP_BOND_MGR ) GAPBondMgr_Init( taskID++ ); #endif /* HCI Extension GAP Task */ HCI_EXT_App_Init( taskID ); }
/************************************************************************************************** * @fn AddrMgrExtAddrLookup * * @brief Lookup EXT address using the NWK address. * * input parameters * * @param nwkAddr - [in] NWK address * * output parameters * * @param extAddr - [out] EXT address * * @return uint8 - success(TRUE:FALSE) ************************************************************************************************** */ uint8 AddrMgrExtAddrLookup(uint16 nwkAddr, uint8* extAddr) { uint8 args[2] = { LO_UINT16(nwkAddr), HI_UINT16(nwkAddr) }; if (SUCCESS == zapUtilReq(MT_UTIL_ADDRMGR_NWK_ADDR_LOOKUP, extAddr, args)) { return ((osal_memcmp(nullAddr, extAddr, Z_EXTADDR_LEN)) ? FALSE : TRUE); } else { (void)osal_memset(extAddr, 0, Z_EXTADDR_LEN); return FALSE; } }
/************************************************************************************************** * @fn AddrMgrEntryLookupNwk * * @brief Lookup entry based on NWK address. * * input parameters * * @param entry * ::nwkAddr - [in] NWK address * * output parameters * * @param entry * ::extAddr - [out] EXT address * * @return uint8 - success(TRUE:FALSE) ************************************************************************************************** */ uint8 AddrMgrEntryLookupNwk(AddrMgrEntry_t* entry) { uint8 args[2] = { LO_UINT16(entry->nwkAddr), HI_UINT16(entry->nwkAddr) }; if (SUCCESS == zapUtilReq(MT_UTIL_ADDRMGR_NWK_ADDR_LOOKUP, entry->extAddr, args)) { return ((osal_memcmp(nullAddr, entry->extAddr, Z_EXTADDR_LEN)) ? FALSE : TRUE); } else { (void)osal_memset(entry->extAddr, 0, Z_EXTADDR_LEN); return FALSE; } }
/********************************************************************* * @fn BindSetDefaultNV * * @brief Write the defaults to NV * * @param none * * @return none */ void BindSetDefaultNV( void ) { BindingEntry_t bind; bindTableIndex_t x; // Initialize a binding record osal_memset( &bind, 0xFF, sizeof ( BindingEntry_t ) ); for ( x = 0; x < gNWK_MAX_BINDING_ENTRIES; x++ ) { // Over write each binding record with an "empty" record osal_nv_write_ex( ZCD_NV_EX_BINDING_TABLE, x, 0, NV_BIND_REC_SIZE, &bind ); } }
/* wcn_core_dump_init - create core dump sys * @ timeout - core dump time out value * * Return object pointer if success, else NULL */ P_WCN_CORE_DUMP_T wcn_core_dump_init(UINT32 timeout) { #define KBYTES (1024*sizeof(char)) #define L1_BUF_SIZE (32*KBYTES) #define L2_BUF_SIZE (512*KBYTES) P_WCN_CORE_DUMP_T core_dmp = NULL; core_dmp = (P_WCN_CORE_DUMP_T)osal_malloc(sizeof(WCN_CORE_DUMP_T)); if (!core_dmp) { STP_DBG_ERR_FUNC("alloc mem failed!\n"); goto fail; } osal_memset(core_dmp, 0, sizeof(WCN_CORE_DUMP_T)); core_dmp->compressor = wcn_compressor_init("core_dump_compressor", L1_BUF_SIZE, L2_BUF_SIZE); if (!core_dmp->compressor) { STP_DBG_ERR_FUNC("create compressor failed!\n"); goto fail; } wcn_compressor_reset(core_dmp->compressor, 1, GZIP); core_dmp->dmp_timer.timeoutHandler = core_dump_timeout_handler; core_dmp->dmp_timer.timeroutHandlerData = (ULONG)core_dmp; osal_timer_create(&core_dmp->dmp_timer); core_dmp->timeout = timeout; osal_sleepable_lock_init(&core_dmp->dmp_lock); core_dmp->sm = CORE_DUMP_INIT; STP_DBG_INFO_FUNC("create coredump object OK!\n"); return core_dmp; fail: if (core_dmp && core_dmp->compressor) { wcn_compressor_deinit(core_dmp->compressor); core_dmp->compressor = NULL; } if (core_dmp) { osal_free(core_dmp); } osal_sleepable_lock_deinit(&core_dmp->dmp_lock); return NULL; }
/********************************************************************* * @fn resetCharacteristicValue * * @brief Initialize a characteristic value to zero * * @param servID - service ID (UUID) * * @param paramID - parameter ID of the value is to be cleared * * @param vakue - value to initialise with * * @param paramLen - length of the parameter * * @return none */ static void resetCharacteristicValue(uint16 servUuid, uint8 paramID, uint8 value, uint8 paramLen) { uint8* pData = osal_mem_alloc(paramLen); if (pData == NULL) { return; } osal_memset(pData,value,paramLen); switch(servUuid) { case IRTEMPERATURE_SERV_UUID: IRTemp_SetParameter( paramID, paramLen, pData); break; case ACCELEROMETER_SERV_UUID: Accel_SetParameter( paramID, paramLen, pData); break; case MAGNETOMETER_SERV_UUID: Magnetometer_SetParameter( paramID, paramLen, pData); break; case HUMIDITY_SERV_UUID: Humidity_SetParameter( paramID, paramLen, pData); break; case BAROMETER_SERV_UUID: Barometer_SetParameter( paramID, paramLen, pData); break; case GYROSCOPE_SERV_UUID: Gyro_SetParameter( paramID, paramLen, pData); break; // VB case BED_SERV_UUID: Bed_SetParameter( paramID, paramLen, pData); break; default: // Should not get here break; } osal_mem_free(pData); }