/********************************************************************* * @fn hidappFindHIDRemote * * @brief Search Scan Response data for a "HID AdvRemote" * * @param pData - received advertising data * @param dataLen - advertising data length * * @return TRUE if found, false otherwise */ static uint8 hidappFindHIDRemote( uint8* pData, uint8 length ) { static uint8 remoteName[] = { 'H', 'I', 'D', ' ', 'A', 'd', 'v', 'R', 'e', 'm', 'o', 't', 'e' }; // move pointer to the start of the scan response data. pData += 2; // adjust length as well length -= 2; return osal_memcmp( remoteName, pData, length ); }
/****************************************************************************** * @fn APSME_IsLinkKeyValid * * @brief Verifies if Link Key in NV has been set. * * @param extAddr - [in] EXT address * * @return TRUE - Link Key has been established * FALSE - Link Key in NV has default value. */ uint8 APSME_IsLinkKeyValid(uint8* extAddr) { APSME_LinkKeyData_t *pKeyData = NULL; uint8 nullKey[SEC_KEY_LEN]; uint8 status = FALSE; uint8 ret; // initialize default vealue to compare to osal_memset(nullKey, 0x00, SEC_KEY_LEN); pKeyData = (APSME_LinkKeyData_t *)osal_mem_alloc(sizeof(APSME_LinkKeyData_t)); if (pKeyData != NULL) { ret = zapUtilReq(MT_UTIL_APSME_LINK_KEY_DATA_GET, extAddr, (uint8 *)pKeyData); if (ret == SUCCESS) { // if stored key is different than default value, then a key has been established if (!osal_memcmp(pKeyData, nullKey, SEC_KEY_LEN)) { status = TRUE; } } } return status; }
static void ClientWriteValue(void){ attWriteReq_t req; //one write last one seconds the most //WD_KICK(); if(TRUE == osal_memcmp(mac_buffer[send_record], mac_buffer[send_record+1] ,MAC_LEN)) //check if it is the last value to send CharSendingFlag =0; if(send_record <= Buffer_Top) osal_memcpy(req.value, mac_buffer[send_record++], BLEChar.len); else return; req.len = BLEChar.len; req.handle = BLEChar.handle; req.sig = 0; req.cmd = 0; uint8 result_value_send; if(result_value_send = GATT_WriteCharValue(CurrentConnectionInfo.Handle, &req, MasterSlaveSwitchTaskID )) LCDPrintText("send error",result_value_send,PRINT_VALUE); }
/********************************************************************* * @fn macSrcMatchCheckSrcAddr * * @brief Check if a short or extended address is in the source address * table. * This function shall not be called from ISR. It is not thread * safe. * * @param addr - a pointer to sAddr_t which contains addrMode * and a union of a short 16-bit MAC address or an extended * 64-bit MAC address to be checked in the source address * table. * @param panID - the device PAN ID. It is only used when the addr is * using short address * @return uint8 - index of the entry in the table. Return * MAC_SRCMATCH_INVALID_INDEX (0xFF) if address not found. */ static uint8 macSrcMatchCheckSrcAddr ( sAddr_t *addr, uint16 panID ) { uint8 index; uint8 *pAddr; uint8 entrySize; uint8 indexUsed; uint8 indexSize; uint8 entry[MAC_SRCMATCH_SHORT_ENTRY_SIZE]; uint8 ramEntry[MAC_SRCMATCH_EXT_ENTRY_SIZE]; uint24 enable; /* Currently, shadow memory is not supported to optimize SPI traffic. */ if( addr->addrMode == SADDR_MODE_SHORT ) { entry[0] = LO_UINT16( panID ); /* Little Endian for the radio RAM */ entry[1] = HI_UINT16( panID ); entry[2] = LO_UINT16( addr->addr.shortAddr ); entry[3] = HI_UINT16( addr->addr.shortAddr ); pAddr = entry; entrySize = MAC_SRCMATCH_SHORT_ENTRY_SIZE; indexSize = 1; enable = MAC_RADIO_SRC_MATCH_GET_SHORTADDR_EN(); } else { pAddr = addr->addr.extAddr; entrySize = MAC_SRCMATCH_EXT_ENTRY_SIZE; indexSize = 2; enable = MAC_RADIO_SRC_MATCH_GET_EXTADDR_EN(); } for( index = 0; index < MAC_SRCMATCH_SHORT_MAX_NUM_ENTRIES; index += indexSize ) { /* Check if the entry is enabled */ if( macSrcMatchCheckEnableBit( index, enable ) == FALSE ) { continue; } indexUsed = index / indexSize; /* Compare the short address or extended address */ MAC_RADIO_SRC_MATCH_TABLE_READ( ( indexUsed * entrySize ), ramEntry, entrySize ); if( osal_memcmp( pAddr, ramEntry, entrySize ) == TRUE ) { /* Match found */ return indexUsed; } } return MAC_SRCMATCH_INVALID_INDEX; }
/************************************************************************************************** * @fn znpBasicCfg * * @brief Process the Conglomerate Basic Configuration command. * * input parameters * * @param pBuf - Pointer to the MT buffer containing the conglomerated configuration. * * output parameters * * None. * * @return None. */ static void znpBasicCfg(uint8 *pBuf) { uint32 t32 = osal_build_uint32( &pBuf[0], 4 ); if (MT_PeriodicMsgRate != t32) { MT_PeriodicMsgRate = t32; (void)osal_start_reload_timer(MT_TaskID, MT_PERIODIC_MSG_EVENT, t32); } t32 = osal_build_uint32( &pBuf[4], 4 ); if (osal_memcmp(&zgDefaultChannelList, &t32, 4) == FALSE) { (void)osal_nv_write(ZCD_NV_CHANLIST, 0, 4, &t32); } uint16 t16 = osal_build_uint16( &pBuf[8] ); if (osal_memcmp(&zgConfigPANID, &t16, 2) == FALSE) { (void)osal_nv_write(ZCD_NV_PANID, 0, 2, &t16); } if (zgDeviceLogicalType != pBuf[10]) { (void)osal_nv_write(ZCD_NV_LOGICAL_TYPE, 0, 1, pBuf+10); } if (pBuf[11] & MT_ZNP_CMD_DISC_RESET_NWK) { pBuf[0] = ZCD_STARTOPT_DEFAULT_NETWORK_STATE; (void)osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, 1, pBuf); #if defined CC2531ZNP SystemResetSoft(); #else SystemReset(); #endif } else if (pBuf[11] & MT_ZNP_CMD_DISC_ZDO_START) { if (devState == DEV_HOLD) { ZDOInitDevice(0); } } }
/********************************************************************* * @fn oadWriteAttrCB * * @brief Validate and Write attribute data * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be written * @param len - length of data * @param offset - offset of the first octet to be written * @param method - type of write message * * @return SUCCESS, blePending or Failure */ static bStatus_t oadWriteAttrCB(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset, uint8 method) { bStatus_t status = SUCCESS; if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); if ( uuid == GATT_CLIENT_CHAR_CFG_UUID) { status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY ); } else { status = ATT_ERR_ATTR_NOT_FOUND; // Should never get here! } } else { // 128-bit UUID if (osal_memcmp(pAttr->type.uuid, oadCharUUID[OAD_CHAR_IMG_IDENTIFY], ATT_UUID_SIZE)) { status = oadImgIdentifyWrite( connHandle, pValue ); } else if (osal_memcmp(pAttr->type.uuid, oadCharUUID[OAD_CHAR_IMG_BLOCK], ATT_UUID_SIZE)) { status = oadImgBlockWrite( connHandle, pValue ); } else { status = ATT_ERR_ATTR_NOT_FOUND; // Should never get here! } } return status; }
/********************************************************************* * @fn oadManagerFindServUUID * * @brief Find the OAD Service UUID in an advertiser's service UUID list. * * @return TRUE if service UUID found */ static bool oadManagerFindServUUID( uint8 *pData, uint8 dataLen ) { uint8 adLen; uint8 adType; uint8 *pEnd; pEnd = pData + dataLen - 1; // While end of data not reached while ( pData < pEnd ) { // Get length of next AD item adLen = *pData++; if ( adLen > 0 ) { adType = *pData; if ( adType == GAP_ADTYPE_128BIT_MORE || adType == GAP_ADTYPE_128BIT_COMPLETE ) { pData++; adLen--; while ((adLen >= ATT_UUID_SIZE) && (pData < pEnd)) // For each UUID in list. { uint8 oadServUUID[ATT_UUID_SIZE] = { TI_BASE_UUID_128( OAD_SERVICE_UUID ) }; if (osal_memcmp(pData, oadServUUID, ATT_UUID_SIZE)) // Check for match. { return TRUE; // Match found } // Go to next pData += ATT_UUID_SIZE; adLen -= ATT_UUID_SIZE; } // Handle possible erroneous extra byte in UUID list if ( adLen == 1 ) { pData++; } } else // Go to next item { pData += adLen; } } } return FALSE; // Match not found }
/************************************************************************************************** * @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; } }
// << Wayne >> << dBCmd Service >> ++ void dBCommand_Service(uint8 *pCmd) { if(osal_memcmp( pCmd, DBCMD_COMFIRM_TICKET, DBCMD_COMFIRM_TICKET_LEN)) { repeatCmdSendData("s,et,01,cfm,0005,e",18); // << Wayne >> << Exchanging Take >> ++ dbExchangeCounter++; // << Wayne >> << Exchanging Take >> -- UART_SEND_STRING(pCmd,19); #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Confirm", HAL_LCD_LINE_6 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } else if(osal_memcmp( pCmd, DBCMD_READ_EXCHANGE_NUMBER, DBCMD_READ_EXCHANGE_NUMBER_LEN)) { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "ReadCounter", HAL_LCD_LINE_6 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) num2Str_Max4L( &pCmd[12], dbExchangeCounter, 4); UART_SEND_DEBUG_MSG( pCmd, 18 ); repeatCmdSendData(pCmd,18); } }
/************************************************************************************************** * @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; } }
// FIXME: currently only device name void custom_init(void) { uint8 buf[CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN]; uint8 idx = 0; HalFlashRead(CUSTOM_DN_PAGE_IDX, CUSTOM_DN_MGIC_OFFSET, buf, (CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN)); if (osal_memcmp(buf, dn_magic, CUSTOM_DN_MAGIC_LEN) != TRUE) { HalFlashErase(CUSTOM_DN_PAGE_IDX); for (idx = 0; idx < (CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN); idx++) { buf[idx] = 0; } osal_memcpy(buf, dn_magic, CUSTOM_DN_MAGIC_LEN); osal_memcpy((buf + CUSTOM_DN_MAGIC_LEN), dn_default, 3); HalFlashWrite((((uint32)CUSTOM_DN_PAGE_IDX * (uint32)2048 + CUSTOM_DN_MGIC_OFFSET) / 4), buf, (CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN) / 4); } }
bool MacBufferSearch(uint8 *value){ if(Buffer_Top<BUFFER_LEN){ for(uint8 i=0; i<Buffer_Top; ++i) if(TRUE == osal_memcmp(mac_buffer[i],value,MAC_LEN)) return(FALSE); // the buffer contains this value,so throw it, else continue; return(TRUE); //the buffer do not contains this value, } else return(FALSE); //the buffer has no area }
/********************************************************************* * @fn gapBondMgrFindAddr * * @brief Look through the bonding NV entries to find an address. * * @param pDevAddr - device address to look for * * @return index to empty bonding (0 - (GAP_BONDINGS_MAX-1), * GAP_BONDINGS_MAX if no empty entries */ static uint8 gapBondMgrFindAddr( uint8 *pDevAddr ) { // Item doesn't exist, so create all the items for ( uint8 idx = 0; idx < GAP_BONDINGS_MAX; idx++ ) { gapBondRec_t bondRec; // Bond record work place // Read in NV Main Bond Record and compare public address if ( (osal_snv_read( mainRecordNvID(idx), sizeof ( gapBondRec_t ), &bondRec ) == SUCCESS) && (osal_memcmp( bondRec.publicAddr, pDevAddr, B_ADDR_LEN )) ) { return ( idx ); // Found it } } return ( GAP_BONDINGS_MAX ); }
// Input buffer at least 21 bytes (couting tailing zero) void custom_get_dn(uint8 *dn) { uint8 buf[CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN]; uint8 idx = 0; HalFlashRead(CUSTOM_DN_PAGE_IDX, CUSTOM_DN_MGIC_OFFSET, buf, (CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN)); if (osal_memcmp(buf, dn_magic, CUSTOM_DN_MAGIC_LEN) == TRUE) { for (idx = CUSTOM_DN_MAGIC_LEN; idx < (CUSTOM_DN_MAGIC_LEN + CUSTOM_DN_LEN); idx++) { dn[idx - CUSTOM_DN_MAGIC_LEN] = buf[idx]; } dn[CUSTOM_DN_LEN] = 0; } else { dn[0] = 'i'; dn[1] = 'D'; dn[2] = 'o'; dn[3] = 0; } }
/********************************************************************* * @fn verifyWordM * * @brief verify the written word. * * @param pg - A valid NV Flash page. * @param offset - A valid offset into the page. * @param pBuf - Pointer to source buffer. * @param cnt - Number of 4-byte blocks to verify. * * @return none */ static void verifyWordM( uint8 pg, uint16 offset, uint8 *pBuf, osalSnvLen_t cnt ) { uint8 tmp[OSAL_NV_WORD_SIZE]; while (cnt--) { // Reading byte per byte will reduce code size but will slow down // and not sure it will meet the timing requirements. HalFlashRead(pg, offset, tmp, OSAL_NV_WORD_SIZE); if (FALSE == osal_memcmp(tmp, pBuf, OSAL_NV_WORD_SIZE)) { failF = TRUE; return; } offset += OSAL_NV_WORD_SIZE; pBuf += OSAL_NV_WORD_SIZE; } }
/********************************************************************* * @fn softCmdGapStateCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void softCmdGapStateCB( gaprole_States_t newState ) { // if connected if (newState == GAPROLE_CONNECTED) { linkDBItem_t *pItem; // Get connection handle GAPRole_GetParameter( GAPROLE_CONNHANDLE, &softCmdConnHandle ); // Get peer bd address if ( (pItem = linkDB_Find( softCmdConnHandle )) != NULL) { // If connected to device without bond do service discovery if ( !osal_memcmp( pItem->addr, softCmdBondedAddr, B_ADDR_LEN ) ) { softCmdDiscoveryCmpl = FALSE; } // Initiate service discovery if necessary if ( softCmdDiscoveryCmpl == FALSE ) { osal_start_timerEx( softCmdTaskId, START_DISCOVERY_EVT, DEFAULT_DISCOVERY_DELAY ); } } } // if disconnected else if (softCmdGapState == GAPROLE_CONNECTED && newState != GAPROLE_CONNECTED) { softCmdDisconnected(); // reset client characteristic configuration descriptors uint16 param = GATT_CFG_NO_OPERATION; Batt_SetParameter(BATT_PARAM_LVL_ST_CHAR_CFG, sizeof(uint16), (uint8 *) ¶m); } softCmdGapState = newState; }
INT32 stp_dbg_dmp_out (MTKSTP_DBG_T *stp_dbg, CHAR *buf, INT32 *len) { INT32 remaining = 0; osal_lock_unsleepable_lock(&(stp_dbg->logsys->lock)); if (stp_dbg->logsys->size > 0){ osal_memcmp(buf, &(stp_dbg->logsys->queue[stp_dbg->logsys->out].buffer[0]), stp_dbg->logsys->queue[stp_dbg->logsys->out].len); (*len) = stp_dbg->logsys->queue[stp_dbg->logsys->out].len; stp_dbg->logsys->out = (stp_dbg->logsys->out >= (STP_DBG_LOG_ENTRY_NUM - 1))?(0):(stp_dbg->logsys->out + 1); stp_dbg->logsys->size--; STP_DBG_DBG_FUNC("logsys size = %d, out = %d\n", stp_dbg->logsys->size, stp_dbg->logsys->out); } else { STP_DBG_LOUD_FUNC("logsys EMPTY!\n"); } remaining = (stp_dbg->logsys->size == 0)?(0):(1); osal_unlock_unsleepable_lock(&(stp_dbg->logsys->lock)); return remaining; }
/********************************************************************* * @fn simpleBLEAddDeviceInfo * * @brief Add a device to the device discovery result list * * @return none */ static void simpleBLEAddDeviceInfo( uint8 *pAddr, uint8 addrType ) { uint8 i; // If result count not at max if ( simpleBLEScanRes < DEFAULT_MAX_SCAN_RES ) { // Check if device is already in scan results for ( i = 0; i < simpleBLEScanRes; i++ ) { if ( osal_memcmp( pAddr, simpleBLEDevList[i].addr , B_ADDR_LEN ) ) { return; } } // Add addr to scan result list osal_memcpy( simpleBLEDevList[simpleBLEScanRes].addr, pAddr, B_ADDR_LEN ); simpleBLEDevList[simpleBLEScanRes].addrType = addrType; // Increment scan result count simpleBLEScanRes++; } }
/********************************************************************* * @fn simpleProfile_ReadAttrCB * * @brief Read an attribute. * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be read * @param pLen - length of data to be read * @param offset - offset of the first octet to be read * @param maxLen - maximum length of data to be read * * @return Success or Failure */ static uint8 biscuit_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen ) { bStatus_t status = SUCCESS; // If attribute permissions require authorization to read, return error if ( gattPermitAuthorRead( pAttr->permissions ) ) { // Insufficient authorization return ( ATT_ERR_INSUFFICIENT_AUTHOR ); } // Make sure it's not a blob operation (no attributes in the profile are long) if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); } if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); switch ( uuid ) { // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases; // gattserverapp handles those reads // characteristics 1 and 2 have read permissions // characteritisc 3 does not have read permissions; therefore it is not // included here // characteristic 4 does not have read permissions, but because it // can be sent as a notification, it is included here case VENDOR_NAME_CHAR_UUID: *pLen = VENDOR_NAME_SIZE; VOID osal_memcpy( pValue, pAttr->pValue, VENDOR_NAME_SIZE); break; case TX_DATA_CHAR_UUID: case RESET_WRITE_CHAR_UUID: *pLen = 1; pValue[0] = *pAttr->pValue; break; case LIB_VER_CHAR_UUID: *pLen = 2; VOID osal_memcpy( pValue, pAttr->pValue, 2 ); break; default: // Should never get here! (characteristics 3 and 4 do not have read permissions) *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { // 128-bit UUID const uint8 uuid[ATT_UUID_SIZE] = { UUID_BASE_TAIL, LO_UINT16(pAttr->type.uuid[0]), pAttr->type.uuid[1], UUID_BASE_HEAD }; // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases; // gattserverapp handles those reads // characteristics 1 and 2 have read permissions // characteritisc 3 does not have read permissions; therefore it is not // included here // characteristic 4 does not have read permissions, but because it // can be sent as a notification, it is included here if ( osal_memcmp(pAttr->type.uuid, txDataCharUUID, ATT_UUID_SIZE) ) { *pLen = bLen; VOID osal_memcpy( pValue, pAttr->pValue, bLen ); } else if (osal_memcmp(pAttr->type.uuid, vendorNameCharUUID, ATT_UUID_SIZE)) { *pLen = 13; VOID osal_memcpy( pValue, pAttr->pValue, 13 ); } else if (osal_memcmp(pAttr->type.uuid, libVerCharUUID, ATT_UUID_SIZE)) { *pLen = 2; VOID osal_memcpy( pValue, pAttr->pValue, 2 ); } else { // Should never get here! (characteristics 3 and 4 do not have read permissions) *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; } } return ( status ); }
/********************************************************************* * @fn txrx_ReadAttrCB * * @brief Read an attribute. * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be read * @param pLen - length of data to be read * @param offset - offset of the first octet to be read * @param maxLen - maximum length of data to be read * * @return Success or Failure */ static uint8 txrx_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen ) { bStatus_t status = SUCCESS; // If attribute permissions require authorization to read, return error if ( gattPermitAuthorRead( pAttr->permissions ) ) { // Insufficient authorization return ( ATT_ERR_INSUFFICIENT_AUTHOR ); } // Make sure it's not a blob operation (no attributes in the profile are long) if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); } if ( pAttr->type.len == ATT_UUID_SIZE ) { if ( osal_memcmp(pAttr->type.uuid, txDataCharUUID, ATT_UUID_SIZE) ) { *pLen = txDataLen; VOID osal_memcpy( pValue, pAttr->pValue, txDataLen ); } else if ( osal_memcmp(pAttr->type.uuid, BaudrateCharUUID, ATT_UUID_SIZE) ) { //*pLen = 1; //VOID osal_memcpy( pValue, pAttr->pValue, 1 ); switch(Baudrate) { case 0: //9600 { *pLen = 9; uint8 *str = "BAUD_9600"; VOID osal_memcpy( pValue, str, 9 ); break; } case 1: //19200 { *pLen = 10; uint8 *str = "BAUD_19200"; VOID osal_memcpy( pValue, str, 10 ); break; } case 2: //38400 { *pLen = 10; uint8 *str = "BAUD_38400"; VOID osal_memcpy( pValue, str, 10 ); break; } case 3: //57600 { *pLen = 10; uint8 *str = "BAUD_57600"; VOID osal_memcpy( pValue, str, 10 ); break; } case 4: //115200 { *pLen = 11; uint8 *str = "BAUD_115200"; VOID osal_memcpy( pValue, str, 11 ); break; } default: break; } } else if ( osal_memcmp(pAttr->type.uuid, DevNameCharUUID, ATT_UUID_SIZE) ) { *pLen = DevNameLen; VOID osal_memcpy( pValue, pAttr->pValue, DevNameLen ); } else if ( osal_memcmp(pAttr->type.uuid, VersionCharUUID, ATT_UUID_SIZE) ) { *pLen = VersionLen; VOID osal_memcpy( pValue, pAttr->pValue, VersionLen ); } else if ( osal_memcmp(pAttr->type.uuid, TxPowerCharUUID, ATT_UUID_SIZE) ) { switch(TxPower) { case 0: //-23dbm { *pLen = 7; uint8 *str = "-23 dBm"; VOID osal_memcpy( pValue, str, 7 ); break; } case 1: //-6dbm { *pLen = 6; uint8 *str = "-6 dBm"; VOID osal_memcpy( pValue, str, 6 ); break; } case 2: //0dbm { *pLen = 5; uint8 *str = "0 dBm"; VOID osal_memcpy( pValue, str, 5 ); break; } case 3: //+4dbm { *pLen = 6; uint8 *str = "+4 dBm"; VOID osal_memcpy( pValue, str, 6 ); break; } default: break; } } else { // Should never get here! *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; } } return ( status ); }
/********************************************************************* * @fn iBeacon_WriteAttrCB * * @brief Validate attribute data prior to a write operation * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be written * @param len - length of data * @param offset - offset of the first octet to be written * @param complete - whether this is the last packet * @param oper - whether to validate and/or write attribute value * * @return Success or Failure */ static bStatus_t iBeacon_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset ) { bStatus_t status = SUCCESS; uint8 notifyApp = 0xFF; // If attribute permissions require authorization to write, return error if ( gattPermitAuthorWrite( pAttr->permissions ) ) { // Insufficient authorization return ( ATT_ERR_INSUFFICIENT_AUTHOR ); } if ( pAttr->type.len == ATT_BT_UUID_SIZE ) // 16-bit UUID { // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); switch ( uuid ) { case IBEACON_CHAR1_UUID: case IBEACON_CHAR2_UUID: case IBEACON_CHAR3_UUID: case IBEACON_CHAR4_UUID: case IBEACON_CHAR5_UUID: case IBEACON_CHAR6_UUID: case IBEACON_CHAR7_UUID: //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len != 1 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; if ( pAttr->pValue == iBeaconChar1 ) { notifyApp = IBEACON_CHAR1; } else if ( pAttr->pValue == iBeaconChar2 ) { notifyApp = IBEACON_CHAR2; } else if ( pAttr->pValue == iBeaconChar3 ) { notifyApp = IBEACON_CHAR3; } else if ( pAttr->pValue == iBeaconChar4 ) { notifyApp = IBEACON_CHAR4; } else if ( pAttr->pValue == iBeaconChar5 ) { notifyApp = IBEACON_CHAR5; } else if ( pAttr->pValue == iBeaconChar6 ) { notifyApp = IBEACON_CHAR6; } else if ( pAttr->pValue == iBeaconChar7 ) { notifyApp = IBEACON_CHAR7; } } break; case GATT_CLIENT_CHAR_CFG_UUID: status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY ); break; default: // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; break; } } else // 128-bit UUID { if (osal_memcmp(pAttr->type.uuid, iBeaconChar1UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR1_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; osal_memcpy(pCurValue, pValue, IBEACON_CHAR1_LEN); if ( pAttr->pValue == iBeaconChar1 ) notifyApp = IBEACON_CHAR1; } } else if (osal_memcmp(pAttr->type.uuid, iBeaconChar2UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR2_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; pCurValue[0] = pValue[0]; pCurValue[1] = pValue[1]; if ( pAttr->pValue == iBeaconChar2 ) notifyApp = IBEACON_CHAR2; } } else if (osal_memcmp(pAttr->type.uuid, iBeaconChar3UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR3_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; pCurValue[0] = pValue[0]; pCurValue[1] = pValue[1]; if ( pAttr->pValue == iBeaconChar3 ) notifyApp = IBEACON_CHAR3; } } else if (osal_memcmp(pAttr->type.uuid, iBeaconChar4UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR4_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } int8 newValue = (int8)pValue[0]; if(newValue > 0.0 || newValue < -100.0) { status = ATT_ERR_UNSUPPORTED_GRP_TYPE; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; if ( pAttr->pValue == iBeaconChar4 ) notifyApp = IBEACON_CHAR4; } } else if (osal_memcmp(pAttr->type.uuid, iBeaconChar5UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR5_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } if(pValue[0] != 0x00 && pValue[0] != 0x01) { status = ATT_ERR_UNSUPPORTED_GRP_TYPE; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; pCurValue[0] = pValue[0]; if ( pAttr->pValue == iBeaconChar5 ) notifyApp = IBEACON_CHAR5; } } else if (osal_memcmp(pAttr->type.uuid, iBeaconChar6UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR6_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } uint16 adv = pValue[0] * 256 + pValue[1]; if(adv > 10000 || adv < 100) { status = ATT_ERR_UNSUPPORTED_GRP_TYPE; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; pCurValue[0] = pValue[0]; pCurValue[1] = pValue[1]; if ( pAttr->pValue == iBeaconChar6 ) notifyApp = IBEACON_CHAR6; } } else if (osal_memcmp(pAttr->type.uuid, iBeaconChar7UUID, ATT_UUID_SIZE) ) { if (offset == 0) { if (len != IBEACON_CHAR7_LEN) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } if(pValue[0] != 0x00 && pValue[0] != 0x01 && pValue[0] != 0x02 && pValue[0] != 0x03) { status = ATT_ERR_UNSUPPORTED_GRP_TYPE; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; pCurValue[0] = pValue[0]; if ( pAttr->pValue == iBeaconChar7 ) notifyApp = IBEACON_CHAR7; } } else { status = ATT_ERR_INVALID_HANDLE; } } // If a charactersitic value changed then callback function to notify application of change if ( (notifyApp != 0xFF ) && iBeacon_AppCBs && iBeacon_AppCBs->pfn_iBeaconChange ) { iBeacon_AppCBs->pfn_iBeaconChange( notifyApp ); } return ( status ); }
/********************************************************************* * @fn txrx_WriteAttrCB * * @brief Validate attribute data prior to a write operation * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be written * @param len - length of data * @param offset - offset of the first octet to be written * @param complete - whether this is the last packet * @param oper - whether to validate and/or write attribute value * * @return Success or Failure */ static bStatus_t txrx_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset ) { bStatus_t status = SUCCESS; uint8 notifyApp = 0xFF; // If attribute permissions require authorization to write, return error if ( gattPermitAuthorWrite( pAttr->permissions ) ) { // Insufficient authorization return ( ATT_ERR_INSUFFICIENT_AUTHOR ); } if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); switch ( uuid ) { case GATT_CLIENT_CHAR_CFG_UUID: status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY ); if (status == SUCCESS) { uint16 charCfg = BUILD_UINT16( pValue[0], pValue[1] ); txrxService_AppCBs->pfnTXRXServiceChange( (charCfg == GATT_CFG_NO_OPERATION) ? TXRX_RX_NOTI_DISABLED : TXRX_RX_NOTI_ENABLED ); } break; default: // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; break; } } else // 128-bit { if ( osal_memcmp(pAttr->type.uuid, rxDataCharUUID, ATT_UUID_SIZE) ) { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len > 20 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; osal_memcpy(pCurValue, pValue, len); rxDataLen = len; notifyApp = TXRX_RX_DATA_READY; } } else if ( osal_memcmp(pAttr->type.uuid, BaudrateCharUUID, ATT_UUID_SIZE) ) { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len != 1 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } if(*pValue > 4) { status = ATT_ERR_INVALID_VALUE; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; osal_memcpy(pCurValue, pValue, len); notifyApp = BAUDRATE_SET; } } else if ( osal_memcmp(pAttr->type.uuid, DevNameCharUUID, ATT_UUID_SIZE) ) { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len > 20 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; osal_memcpy(pCurValue, pValue, len); DevNameLen = len; notifyApp = DEV_NAME_CHANGED; } } else if ( osal_memcmp(pAttr->type.uuid, TxPowerCharUUID, ATT_UUID_SIZE) ) { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len != 1 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } if(*pValue > 3) { status = ATT_ERR_INVALID_VALUE; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; osal_memcpy(pCurValue, pValue, len); notifyApp = TX_POWER_CHANGED; } } else { // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; } } // If a charactersitic value changed then callback function to notify application of change if ( (notifyApp != 0xFF ) && txrxService_AppCBs && txrxService_AppCBs->pfnTXRXServiceChange ) { txrxService_AppCBs->pfnTXRXServiceChange( notifyApp ); } return ( status ); }
/********************************************************************* * @fn hidappPairStateCB * * @brief Notification from the Bond Manager on pairing state. * * @param connHandle - the connection handle this bonding event occured for. * @param state - new bonding state * @param status - success of failure of bonding * * @return none */ static void hidappPairStateCB( uint16 connHandle, uint8 state, uint8 status ) { switch( state ) { case GAPBOND_PAIRING_STATE_BONDED: if ( status == SUCCESS ) { // Enter a GAP Bond manager Paired state gapBondMgrState = PAIRED_BONDED_STATE; //Check if this is the same address as a previous connection if ( osal_memcmp( remoteHandles.lastRemoteAddr, remoteAddr, B_ADDR_LEN ) == TRUE ) { serviceChangeHandle = remoteHandles.svcChangeHandle; // Check if there has been a service change or if this is a newly connected device if ( ( remoteHandles.mouseCharHandle == GATT_INVALID_HANDLE ) || ( remoteHandles.keyCharHandle == GATT_INVALID_HANDLE ) || ( remoteHandles.consumerCtrlCharHandle == GATT_INVALID_HANDLE ) || ( serviceChange == CHANGE_OCCURED ) ) { // Do we know the service change handle yet? if (serviceChangeHandle == GATT_INVALID_HANDLE ) { // Begin dicovery of GATT Service Changed characteristic serviceToDiscover = GATT_SERVICE_UUID; } else { // Begin discovery of HID service serviceToDiscover = HID_SERVICE_UUID; } // We must perform service discovery again, something might have changed. // Begin Service Discovery hidappDiscoverService( connHandle, serviceToDiscover ); serviceDiscComplete = FALSE; } else { // No change, restore handle info. // bonding indicates that we probably already enabled all these characteristics. easy fix if not. serviceDiscComplete = TRUE; mouseCharHandle = remoteHandles.mouseCharHandle; keyCharHandle = remoteHandles.keyCharHandle; consumerCtrlCharHandle = remoteHandles.consumerCtrlCharHandle; mouseCCCHandle = remoteHandles.mouseCCCHandle; keyCCCHandle = remoteHandles.keyCCCHandle; consumerCtrlCCCHandle = remoteHandles.consumerCtrlCCCHandle; } } else if ( osal_isbufset( remoteHandles.lastRemoteAddr, 0x00, B_ADDR_LEN ) == TRUE ) { // lastRemoteAddr is all 0's, which means the device was bonded before // it was power-cycled, and that we probably already enabled all CCCDs. // So, we only need to find out attribute report handles. enableCCCDs = FALSE; // Begin Service Discovery of HID Service to find out report handles serviceToDiscover = HID_SERVICE_UUID; hidappDiscoverService( connHandle, HID_SERVICE_UUID ); } } break; case GAPBOND_PAIRING_STATE_COMPLETE: if ( status == SUCCESS ) { // Enter a GAP Bond manager Paired state gapBondMgrState = PAIRED_BONDED_STATE; // Begin Service Discovery of GATT Service serviceToDiscover = GATT_SERVICE_UUID; hidappDiscoverService( connHandle, GATT_SERVICE_UUID ); } break; default: break; } }
/********************************************************************* * @fn gapProfileStateCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void peripheralStateNotificationCB( gaprole_States_t newState ) { // if connected if ( newState == GAPROLE_CONNECTED ) { linkDBItem_t *pItem; HalLedSet ( HAL_LED_1, HAL_LED_MODE_OFF ); // Get connection handle GAPRole_GetParameter( GAPROLE_CONNHANDLE, &gapConnHandle ); // Get peer bd address if ( (pItem = linkDB_Find( gapConnHandle )) != NULL) { // If connected to device without bond do service discovery if ( !osal_memcmp( pItem->addr, timeAppBondedAddr, B_ADDR_LEN ) ) { timeAppDiscoveryCmpl = FALSE; } else { timeAppDiscoveryCmpl = TRUE; } // if this was last connection address don't do discovery if(osal_memcmp( pItem->addr, lastConnAddr, B_ADDR_LEN )) { timeAppDiscoveryCmpl = TRUE; connectedToLastAddress = true; } else { //save the last connected address osal_memcpy(lastConnAddr, pItem->addr, B_ADDR_LEN ); } // Initiate service discovery if necessary if ( timeAppDiscoveryCmpl == FALSE ) { // osal_start_timerEx( bloodPressureTaskId, BP_START_DISCOVERY_EVT, DEFAULT_DISCOVERY_DELAY ); } } } // if disconnected else if ( gapProfileState == GAPROLE_CONNECTED && newState != GAPROLE_CONNECTED ) { timeAppDisconnected(); //always stop intermediate timer osal_stop_timerEx( bloodPressureTaskId, BP_TIMER_CUFF_EVT ); // stop disconnect timer osal_stop_timerEx( bloodPressureTaskId, BP_DISCONNECT_PERIOD ); } // if started else if ( newState == GAPROLE_STARTED ) { // Initialize time clock display //timeAppClockInit(); } gapProfileState = newState; updateUI(); }
//static void peripheralStateNotificationCB( gaprole_States_t newState ) static void peripheralStateNotificationCB( gaprole_States_t* newState ) { // if connected if ( *newState == GAPROLE_CONNECTED ) { linkDBItem_t *pItem; // Get connection handle GAPRole_GetParameter( GAPROLE_CONNHANDLE, &gapConnHandle ); // Get peer bd address if ( (pItem = linkDB_Find( gapConnHandle )) != NULL) { // If connected to device without bond do service discovery if ( !osal_memcmp( pItem->addr, timeAppBondedAddr, B_ADDR_LEN ) ) { timeAppDiscoveryCmpl = FALSE; } else { timeAppDiscoveryCmpl = TRUE; } // if this was last connection address don't do discovery if(osal_memcmp( pItem->addr, lastConnAddr, B_ADDR_LEN )) { timeAppDiscoveryCmpl = TRUE; connectedToLastAddress = true; } else { //save the last connected address osal_memcpy(lastConnAddr, pItem->addr, B_ADDR_LEN ); } // Initiate service discovery if necessary if ( timeAppDiscoveryCmpl == FALSE ) { osal_start_timerEx( thermometerTaskId, TH_START_DISCOVERY_EVT, DEFAULT_DISCOVERY_DELAY ); } //on connection initiate disconnect timer in 20 seconds osal_start_timerEx( thermometerTaskId, TH_DISCONNECT_EVT, 20000 ); } } // if disconnected else if ( gapProfileState == GAPROLE_CONNECTED && *newState != GAPROLE_CONNECTED ) { timeAppDisconnected(); //always stop intermediate timer osal_stop_timerEx( thermometerTaskId, TH_PERIODIC_IMEAS_EVT ); } // if started else if ( *newState == GAPROLE_STARTED ) { // Initialize time clock timeAppClockInit(); } gapProfileState = *newState; updateUI(); }
INT32 _stp_dbg_parser_assert_str(CHAR *str, ENUM_ASSERT_INFO_PARSER_TYPE type) { char *pStr = NULL; char *pDtr = NULL; char *pTemp = NULL; char *pTemp2 = NULL; char tempBuf[64] = {0}; UINT32 len = 0; char *parser_sub_string[] = { "<ASSERT> ", "id=", "isr=", "irq=", "rc=" }; if (!str) { STP_DBG_ERR_FUNC("NULL string source\n"); return -1; } if (!g_stp_dbg_cpupcr) { STP_DBG_ERR_FUNC("NULL pointer\n"); return -2; } pStr = str; STP_DBG_DBG_FUNC("source infor:%s\n", pStr); switch (type) { case STP_DBG_ASSERT_INFO: pDtr = osal_strstr(pStr, parser_sub_string[type]); if (NULL != pDtr) { pDtr += osal_strlen(parser_sub_string[type]); pTemp = osal_strchr(pDtr, ' '); } else { STP_DBG_ERR_FUNC("parser str is NULL,substring(%s)\n", parser_sub_string[type]); return -3; } len = pTemp - pDtr; osal_memcpy(&g_stp_dbg_cpupcr->assert_info[0], "assert@", osal_strlen("assert@")); osal_memcpy(&g_stp_dbg_cpupcr->assert_info[osal_strlen("assert@")], pDtr, len); g_stp_dbg_cpupcr->assert_info[osal_strlen("assert@") + len] = '_'; pTemp = osal_strchr(pDtr, '#'); pTemp += 1; pTemp2 = osal_strchr(pTemp, ' '); osal_memcpy(&g_stp_dbg_cpupcr->assert_info[osal_strlen("assert@") + len + 1], pTemp, pTemp2 - pTemp); g_stp_dbg_cpupcr->assert_info[osal_strlen("assert@") + len + 1 + pTemp2 - pTemp] = '\0'; STP_DBG_INFO_FUNC("assert info:%s\n", &g_stp_dbg_cpupcr->assert_info[0]); break; case STP_DBG_FW_TASK_ID: pDtr = osal_strstr(pStr, parser_sub_string[type]); if (NULL != pDtr) { pDtr += osal_strlen(parser_sub_string[type]); pTemp = osal_strchr(pDtr, ' '); } else { STP_DBG_ERR_FUNC("parser str is NULL,substring(%s)\n", parser_sub_string[type]); return -3; } len = pTemp - pDtr; osal_memcpy(&tempBuf[0], pDtr, len); tempBuf[len] = '\0'; g_stp_dbg_cpupcr->fwTaskId = osal_strtol(tempBuf, NULL, 16); STP_DBG_INFO_FUNC("fw task id :%x\n", (UINT32)osal_strtol(tempBuf, NULL, 16)); break; case STP_DBG_FW_ISR: pDtr = osal_strstr(pStr, parser_sub_string[type]); if (NULL != pDtr) { pDtr += osal_strlen(parser_sub_string[type]); pTemp = osal_strchr(pDtr, ','); } else { STP_DBG_ERR_FUNC("parser str is NULL,substring(%s)\n", parser_sub_string[type]); return -3; } len = pTemp - pDtr; osal_memcpy(&tempBuf[0], pDtr, len); tempBuf[len] = '\0'; g_stp_dbg_cpupcr->fwIsr = osal_strtol(tempBuf, NULL, 16); STP_DBG_INFO_FUNC("fw isr str:%x\n", (UINT32)osal_strtol(tempBuf, NULL, 16)); break; case STP_DBG_FW_IRQ: pDtr = osal_strstr(pStr, parser_sub_string[type]); if (NULL != pDtr) { pDtr += osal_strlen(parser_sub_string[type]); pTemp = osal_strchr(pDtr, ','); } else { STP_DBG_ERR_FUNC("parser str is NULL,substring(%s)\n", parser_sub_string[type]); return -3; } len = pTemp - pDtr; osal_memcpy(&tempBuf[0], pDtr, len); tempBuf[len] = '\0'; g_stp_dbg_cpupcr->fwRrq = osal_strtol(tempBuf, NULL, 16); STP_DBG_INFO_FUNC("fw irq value:%x\n", (UINT32)osal_strtol(tempBuf, NULL, 16)); break; case STP_DBG_ASSERT_TYPE: pDtr = osal_strstr(pStr, parser_sub_string[type]); if (NULL != pDtr) { pDtr += osal_strlen(parser_sub_string[type]); pTemp = osal_strchr(pDtr, ','); } else { STP_DBG_ERR_FUNC("parser str is NULL,substring(%s)\n", parser_sub_string[type]); return -3; } len = pTemp - pDtr; osal_memcpy(&tempBuf[0], pDtr, len); tempBuf[len] = '\0'; if (0 == osal_memcmp(tempBuf, "*", len)) { osal_memcpy(&g_stp_dbg_cpupcr->assert_type[0], "general assert", osal_strlen("general assert")); } if (0 == osal_memcmp(tempBuf, "Watch Dog Timeout", len)) { osal_memcpy(&g_stp_dbg_cpupcr->assert_type[0], "wdt", osal_strlen("wdt")); } if (0 == osal_memcmp(tempBuf, "RB_FULL", osal_strlen("RB_FULL"))) { osal_memcpy(&g_stp_dbg_cpupcr->assert_type[0], tempBuf, len); pDtr = osal_strstr(&g_stp_dbg_cpupcr->assert_type[0], "RB_FULL("); if (NULL != pDtr) { pDtr += osal_strlen("RB_FULL("); pTemp = osal_strchr(pDtr, ')'); } else { STP_DBG_ERR_FUNC("parser str is NULL,substring(RB_FULL()\n"); return -4; } len = pTemp - pDtr; osal_memcpy(&tempBuf[0], pDtr, len); tempBuf[len] = '\0'; g_stp_dbg_cpupcr->fwTaskId = osal_strtol(tempBuf, NULL, 16); STP_DBG_INFO_FUNC("update fw task id :%x\n", (UINT32)osal_strtol(tempBuf, NULL, 16)); } STP_DBG_INFO_FUNC("fw asert type:%s\n", g_stp_dbg_cpupcr->assert_type); break; default: STP_DBG_ERR_FUNC("unknow parser type\n"); break; } return 0; }
/********************************************************************* * @fn timeAppGapStateCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void timeAppGapStateCB( gaprole_States_t newState ) { // if connected if ( newState == GAPROLE_CONNECTED ) { linkDBItem_t *pItem; // Get connection handle GAPRole_GetParameter( GAPROLE_CONNHANDLE, &timeAppConnHandle ); // Get peer bd address if ( (pItem = linkDB_Find( timeAppConnHandle )) != NULL) { // If connected to device without bond do service discovery if ( !osal_memcmp( pItem->addr, timeAppBondedAddr, B_ADDR_LEN ) ) { timeAppDiscoveryCmpl = FALSE; } // Initiate service discovery if necessary if ( timeAppDiscoveryCmpl == FALSE ) { osal_start_timerEx( timeAppTaskId, START_DISCOVERY_EVT, DEFAULT_DISCOVERY_DELAY ); } // Perform configuration of characteristics on connection setup else { timeAppConfigState = timeAppConfigNext( TIMEAPP_CONFIG_CONN_START ); } } LCD_WRITE_STRING( "Connected", HAL_LCD_LINE_1 ); LCD_WRITE_STRING( "", HAL_LCD_LINE_2 ); } // if disconnected else if ( timeAppGapState == GAPROLE_CONNECTED && newState != GAPROLE_CONNECTED ) { uint8 advState = TRUE; timeAppDisconnected(); if ( newState == GAPROLE_WAITING_AFTER_TIMEOUT ) { // link loss timeout-- use fast advertising GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_FAST_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_FAST_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_FAST_ADV_DURATION ); } else { // Else use slow advertising GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_SLOW_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_SLOW_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_SLOW_ADV_DURATION ); } // Enable advertising GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advState ); LCD_WRITE_STRING( "Disconnected", HAL_LCD_LINE_1 ); LCD_WRITE_STRING( "", HAL_LCD_LINE_2 ); } // if advertising stopped else if ( timeAppGapState == GAPROLE_ADVERTISING && newState == GAPROLE_WAITING ) { // if advertising stopped by user if ( timeAppAdvCancelled ) { timeAppAdvCancelled = FALSE; } // if fast advertising switch to slow else if ( GAP_GetParamValue( TGAP_GEN_DISC_ADV_INT_MIN ) == DEFAULT_FAST_ADV_INTERVAL ) { uint8 advState = TRUE; GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_SLOW_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_SLOW_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_SLOW_ADV_DURATION ); GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advState ); } } // if started else if ( newState == GAPROLE_STARTED ) { #ifndef CC2540_MINIDK uint8 bdAddr[B_ADDR_LEN]; GAPRole_GetParameter( GAPROLE_BD_ADDR, &bdAddr ); LCD_WRITE_STRING( "Time App", HAL_LCD_LINE_1 ); LCD_WRITE_STRING( bdAddr2Str( bdAddr ), HAL_LCD_LINE_2 ); #endif // Initialize time clock after writing first two lines of LCD timeAppClockInit(); } timeAppGapState = newState; }
INT32 stp_dbg_cpupcr_infor_format(UINT8 **buf, UINT32 *str_len) { UINT32 len = 0; UINT32 i = 0; if (!g_stp_dbg_cpupcr) { STP_DBG_ERR_FUNC("NULL pointer\n"); return -1; } /*format common information about issue*/ len = osal_sprintf(*buf, "<main>\n\t"); len += osal_sprintf(*buf + len, "<chipid>\n\t\tMT%x\n\t</chipid>\n\t", g_stp_dbg_cpupcr->chipId); len += osal_sprintf(*buf + len, "<version>\n\t\t"); len += osal_sprintf(*buf + len, "<rom>%s</rom>\n\t\t", g_stp_dbg_cpupcr->romVer); if (!(osal_memcmp(g_stp_dbg_cpupcr->branchVer, "ALPS", STP_PATCH_BRANCH_SZIE))) { len += osal_sprintf(*buf + len, "<branch>Internal Dev</branch>\n\t\t", g_stp_dbg_cpupcr->branchVer); } else { len += osal_sprintf(*buf + len, "<branch>W%sMP</branch>\n\t\t", g_stp_dbg_cpupcr->branchVer); } len += osal_sprintf(*buf + len, "<patch>%s</patch>\n\t\t", g_stp_dbg_cpupcr->patchVer); if (!g_stp_dbg_cpupcr->wifiVer[0]) { len += osal_sprintf(*buf + len, "<wifi>NULL</wifi>\n\t"); } else { len += osal_sprintf(*buf + len, "<wifi>%s</wifi>\n\t", g_stp_dbg_cpupcr->wifiVer); } len += osal_sprintf(*buf + len, "</version>\n\t"); /*format issue information: no ack, assert*/ len += osal_sprintf(*buf + len, "<issue>\n\t\t<classification>\n\t\t\t"); if ((STP_FW_NOACK_ISSUE == g_stp_dbg_cpupcr->issue_type) || (STP_DBG_PROC_TEST == g_stp_dbg_cpupcr->issue_type) || (STP_FW_WARM_RST_ISSUE == g_stp_dbg_cpupcr->issue_type)) { len += osal_sprintf(*buf + len, "%s\n\t\t</classification>\n\t\t<rc>\n\t\t\t", g_stp_dbg_cpupcr->assert_info); len += osal_sprintf(*buf + len, "NULL\n\t\t</rc>\n\t</issue>\n\t"); len += osal_sprintf(*buf + len, "<hint>\n\t\t<time_align>NULL</time_align>\n\t\t"); len += osal_sprintf(*buf + len, "<host>NULL</host>\n\t\t"); len += osal_sprintf(*buf + len, "<client>\n\t\t\t<task>%s</task>\n\t\t\t", _stp_dbg_id_to_task(g_stp_dbg_cpupcr->fwTaskId)); len += osal_sprintf(*buf + len, "<irqx>IRQ_0x%x</irqx>\n\t\t\t", g_stp_dbg_cpupcr->fwRrq); len += osal_sprintf(*buf + len, "<isr>0x%x</isr>\n\t\t\t", g_stp_dbg_cpupcr->fwIsr); } else if ((STP_FW_ASSERT_ISSUE == g_stp_dbg_cpupcr->issue_type)) { len += osal_sprintf(*buf + len, "%s\n\t\t</classification>\n\t\t<rc>\n\t\t\t", g_stp_dbg_cpupcr->assert_info); len += osal_sprintf(*buf + len, "%s\n\t\t</rc>\n\t</issue>\n\t", g_stp_dbg_cpupcr->assert_type); len += osal_sprintf(*buf + len, "<hint>\n\t\t<time_align>NULL</time_align>\n\t\t"); len += osal_sprintf(*buf + len, "<host>NULL</host>\n\t\t"); len += osal_sprintf(*buf + len, "<client>\n\t\t\t<task>%s</task>\n\t\t\t", _stp_dbg_id_to_task(g_stp_dbg_cpupcr->fwTaskId)); len += osal_sprintf(*buf + len, "<irqx>IRQ_0x%x</irqx>\n\t\t\t", g_stp_dbg_cpupcr->fwRrq); len += osal_sprintf(*buf + len, "<isr>0x%x</isr>\n\t\t\t", g_stp_dbg_cpupcr->fwIsr); } else { len += osal_sprintf(*buf + len, "NULL\n\t\t</classification>\n\t\t<rc>\n\t\t\t"); len += osal_sprintf(*buf + len, "NULL\n\t\t</rc>\n\t</issue>\n\t"); len += osal_sprintf(*buf + len, "<hint>\n\t\t<time_align>NULL</time_align>\n\t\t"); len += osal_sprintf(*buf + len, "<host>NULL</host>\n\t\t"); len += osal_sprintf(*buf + len, "<client>\n\t\t\t<task>NULL</task>\n\t\t\t"); len += osal_sprintf(*buf + len, "<irqx>NULL</irqx>\n\t\t\t"); len += osal_sprintf(*buf + len, "<isr>NULL</isr>\n\t\t\t"); } len += osal_sprintf(*buf + len, "<pctrace>"); STP_DBG_INFO_FUNC("stp-dbg:sub len1 for debug(%d)\n", len); if (!g_stp_dbg_cpupcr->count) { len += osal_sprintf(*buf + len, "NULL"); } else { for (i = 0; i < g_stp_dbg_cpupcr->count; i++) { len += osal_sprintf(*buf + len, "%08x,", g_stp_dbg_cpupcr->buffer[i]); } } STP_DBG_INFO_FUNC("stp-dbg:sub len2 for debug(%d)\n", len); len += osal_sprintf(*buf + len, "</pctrace>\n\t\t\t"); len += osal_sprintf(*buf + len, "<extension>NULL</extension>\n\t\t</client>\n\t</hint>\n</main>\n"); STP_DBG_INFO_FUNC("buffer len[%d]\n", len); //STP_DBG_INFO_FUNC("Format infor:\n%s\n",*buf); *str_len = len; osal_memset(&g_stp_dbg_cpupcr->buffer[0], 0, STP_DBG_CPUPCR_NUM); g_stp_dbg_cpupcr->count = 0; return 0; }
/************************************************************************************************ * @fn simpleBLECentralProcessGATTMsg * * @brief Process GATT messages * * @return none ************************************************************************************************/ void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg ){ switch(pMsg->method){ case ATT_READ_RSP:{ uint8 valueRead = pMsg->msg.readRsp.value[0]; LCDPrintText("Read rsp:",valueRead,PRINT_VALUE); //GAPCentralRole_TerminateLink( connHandle ); break; } case ATT_WRITE_RSP:{ if(CharSendingFlag ==1){ //to filt out the last rep message! Z_DelayMS(50); ClientWriteValue(); } break; } case ATT_FIND_BY_TYPE_VALUE_RSP:{ if(pMsg->msg.findByTypeValueRsp.numInfo > 0 ){ //LCDPrintText("Found group h",0,PRINT_STRING); HandleRangeStart = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle; //Found attribute handle HandleRangeEnd = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle; //Group end handle } if(pMsg->hdr.status == bleProcedureComplete) if( HandleRangeEnd != 0 ){ attReadByTypeReq_t req; req.startHandle = HandleRangeStart; req.endHandle = HandleRangeEnd; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(BLEChar.uuid); req.type.uuid[1] = HI_UINT16(BLEChar.uuid); uint8 return_status; //LCDPrintText("seach attrib h",0,PRINT_STRING); if(return_status = GATT_ReadUsingCharUUID(CurrentConnectionInfo.Handle, &req, MasterSlaveSwitchTaskID ))// Discover characteristic LCDPrintText("ReadUsingChar error",return_status,PRINT_VALUE); } else LCDPrintText("Handle range error",1,PRINT_STRING); break; } case ATT_READ_BY_TYPE_RSP:{ if(pMsg->msg.readByTypeRsp.numPairs > 0 ){ uint16 temp_handle = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0], pMsg->msg.readByTypeRsp.dataList[1] ); if((temp_handle == BLEChar.handle) && (BLEChar.handle != 0)) {CharHandleSearchFlag = 0; //HalLcdWriteStringValue("HANDLE SA",temp_handle,10,HAL_LCD_LINE_5); } else {BLEChar.handle= temp_handle; //HalLcdWriteStringValue("HANDLE DE",temp_handle,10,HAL_LCD_LINE_6); } } if(pMsg->hdr.status == bleProcedureComplete) if(BLEChar.handle != 0){ ClientWriteValue(); CharSendingFlag =1; //LCDPrintText("finished attrib h",0,PRINT_STRING); } else LCDPrintText("Handle value error",1,PRINT_STRING); break; } case ATT_HANDLE_VALUE_NOTI:{ //one transfer last 1s the most ,otherwise watchdog will reset the device //WD_KICK(); if(pMsg->msg.handleValueNoti.len != MAC_LEN){ LCDPrintText("error noti lenth:",pMsg->msg.handleValueNoti.len,PRINT_VALUE); break; } osal_memcpy(mac_buffer[Buffer_Top],pMsg->msg.handleValueNoti.value,pMsg->msg.handleValueNoti.len); if(TRUE == osal_memcmp(mac_buffer[Buffer_Top], mac_buffer[Buffer_Top+1] ,MAC_LEN)){ GAPCentralRole_TerminateLink( CurrentConnectionInfo.Handle ); uint32 timeout_value = 50; //osal_start_timerEx(MasterSlaveSwitchTaskID, CHECH_LINK_EVT, timeout_value); break; }//wait for conn timeout if(TRUE == MacBufferSearch(mac_buffer[Buffer_Top])){ //LCDPrintText("valid value:",mac_buffer[Buffer_Top][0],PRINT_VALUE); Buffer_Top++; } else osal_memset(mac_buffer[Buffer_Top], 0, MAC_LEN); break; } case ATT_ERROR_RSP:{ if(pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ){ uint8 status = pMsg->msg.errorRsp.errCode; LCDPrintText("Read Error",status,PRINT_VALUE); } else if(pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ){ uint8 status = pMsg->msg.errorRsp.errCode; LCDPrintText("Write Error",status,PRINT_VALUE); } else if(pMsg->msg.errorRsp.reqOpcode == ATT_FIND_BY_TYPE_VALUE_REQ) LCDPrintText("service find error",1,PRINT_STRING); else if(pMsg->msg.errorRsp.reqOpcode == ATT_READ_BY_TYPE_REQ) LCDPrintText("charac find error",1,PRINT_STRING); break; } default: LCDPrintText("unknow gatt message",1,PRINT_STRING); break; } }
/********************************************************************* * @fn simpleProfile_WriteAttrCB * * @brief Validate attribute data prior to a write operation * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be written * @param len - length of data * @param offset - offset of the first octet to be written * @param complete - whether this is the last packet * @param oper - whether to validate and/or write attribute value * * @return Success or Failure */ static bStatus_t biscuit_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset ) { bStatus_t status = SUCCESS; uint8 notifyApp = 0xFF; // If attribute permissions require authorization to write, return error if ( gattPermitAuthorWrite( pAttr->permissions ) ) { // Insufficient authorization return ( ATT_ERR_INSUFFICIENT_AUTHOR ); } if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); switch ( uuid ) { case VENDOR_NAME_CHAR_UUID: case RX_DATA_CHAR_UUID: //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len != 1 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; // if( pAttr->pValue == &vendorNameCharValue ) { notifyApp = VENDOR_NAME_CHAR; } // else { notifyApp = RX_DATA_CHAR; } } break; case GATT_CLIENT_CHAR_CFG_UUID: status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY ); break; default: // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { // 128-bit UUID const uint8 uuid[ATT_UUID_SIZE] = { UUID_BASE_TAIL, LO_UINT16(pAttr->type.uuid[0]), pAttr->type.uuid[1], UUID_BASE_HEAD }; if ( osal_memcmp(pAttr->type.uuid, rxDataCharUUID, ATT_UUID_SIZE) ) { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len > 20 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { // uint8 *pCurValue = (uint8 *)pAttr->pValue; // *pCurValue = pValue[0]; HalUARTWrite(HAL_UART_PORT_0, pValue, len); notifyApp = RX_DATA_CHAR; } else { // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; } } else if ( osal_memcmp(pAttr->type.uuid, resetWriteCharUUID, ATT_UUID_SIZE) ) // UUID 0004 { resetWriteChar = 1; } else if ( osal_memcmp(uuid, vendorNameCharUUID, ATT_UUID_SIZE) ) { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { if ( len != 1 ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; // if( pAttr->pValue == &vendorNameCharValue ) //char 1 or 3? { notifyApp = VENDOR_NAME_CHAR; } // else { notifyApp = RX_DATA_CHAR; } } else { // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; } } } // If a charactersitic value changed then callback function to notify application of change if ( (notifyApp != 0xFF ) && biscuitProfile_AppCBs && biscuitProfile_AppCBs->pfnBiscuitProfileChange ) { biscuitProfile_AppCBs->pfnBiscuitProfileChange( notifyApp ); } return ( status ); }