/********************************************************************* * @fn proxReporter_ReadAttrCB * * @brief Read an attribute. * * @param * * @return Success or Failure */ static uint8 proxReporter_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen ) { uint16 uuid; bStatus_t status = SUCCESS; // Make sure it's not a blob operation if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); } if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { // 16-bit UUID 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 types for reads case PROXIMITY_ALERT_LEVEL_UUID: case PROXIMITY_TX_PWR_LEVEL_UUID: *pLen = 1; pValue[0] = *pAttr->pValue; break; default: // Should never get here! *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { //128-bit UUID *pLen = 0; status = ATT_ERR_INVALID_HANDLE; } return ( status ); }
/********************************************************************* * @fn zclPartition_ConvertOtaToNative_TransferPartitionedFrame * * @brief Helper function used to process an incoming TransferPartionFrame * command. * * @param pCmd - (output) the converted command * @param buf - pointer to incoming frame (just after ZCL header) * @param buflen - length of buffer (ZCL payload) * * @return ZStatus_t */ ZStatus_t zclPartition_ConvertOtaToNative_TransferPartitionedFrame( zclCmdTransferPartitionedFrame_t *pCmd, uint8 *buf, uint8 buflen ) { uint8 offset; pCmd->fragmentationOptions = buf[0]; if ( pCmd->fragmentationOptions & ZCL_PARTITION_OPTIONS_INDICATOR_16BIT ) { pCmd->partitionIndicator = BUILD_UINT16( buf[1], buf[2] ); offset = 3; } else { pCmd->partitionIndicator = buf[1]; offset = 2; } pCmd->frameLen = buf[offset++]; pCmd->pFrame = &buf[offset]; return ( ZSuccess ); }
/********************************************************************* * @fn temp_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 temp_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset ) { bStatus_t status = ATT_ERR_ATTR_NOT_FOUND; if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { 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 (GATTServApp_ReadCharCfg(connHandle, valueConfigCoordinates) & GATT_CLIENT_CFG_NOTIFY) { iDoTurnOnTemp(); } else { iDoTurnOffTemp(); } break; case TEMP_UUID: if (len != sizeof(struct temp_ts)) { return ATT_ERR_INVALID_VALUE_SIZE; } recorder_set_read_base_ts((struct calendar *)(pValue + sizeof(struct temp))); status = SUCCESS; break; case TEMP_TIME_UUID: if (len != sizeof(struct calendar)) { return ATT_ERR_INVALID_VALUE_SIZE; } recorder_set_calendar_time((struct calendar *)pValue); status = SUCCESS; break; default: status = ATT_ERR_ATTR_NOT_FOUND; } } return ( status ); }
/********************************************************************* * @fn battReadAttrCB * * @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 method - type of read message * * @return SUCCESS, blePending or Failure */ static bStatus_t battReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen, uint8 method ) { bStatus_t status = SUCCESS; // Make sure it's not a blob operation (no attributes in the profile are long) if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); } uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1] ); // Measure battery level if reading level if ( uuid == BATT_LEVEL_UUID ) { uint8 level; level = battMeasure(); // If level has gone down if (level < battLevel) { // Update level battLevel = level; } *pLen = 1; pValue[0] = battLevel; } else if ( uuid == GATT_REPORT_REF_UUID ) { *pLen = HID_REPORT_REF_LEN; osal_memcpy( pValue, pAttr->pValue, HID_REPORT_REF_LEN ); } else { status = ATT_ERR_ATTR_NOT_FOUND; } return ( status ); }
/********************************************************************* * @fn sk_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 sk_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen ) { bStatus_t status = SUCCESS; // 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 this type for reads // simple keys characteristic does not have read permissions, but because it // can be sent as a notification, it must be included here case SK_KEYPRESSED_UUID: *pLen = 1; pValue[0] = *pAttr->pValue; break; default: // Should never get here! *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { // 128-bit UUID *pLen = 0; status = ATT_ERR_INVALID_HANDLE; } return ( status ); }
void get_dev_info( uint8 *buf ) { // 0x05 mac short_addr type // 1 8 2 1 == 12 bytes // 0 1 2 3 4 5 6 7 8 9 10 11 uint16 short_addr; uint8 type; uint8 ieeeAddr[9]; uint8 i; type = buf[11]; short_addr = BUILD_UINT16( buf[9], buf[10]); for(i=0;i<8;i++) { ieeeAddr[i] = buf[i+1]; } }
/*************************************************************************************************** * @fn MT_UtilSrcMatchCheckSrcAddr * * @brief Check if a short or extended address is in the source address table. * * @param pBuf - Buffer contains the data * * @return void ***************************************************************************************************/ void MT_UtilSrcMatchCheckSrcAddr (uint8 *pBuf) { uint8 cmdId; uint8 retArray[2]; /* Parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; #if 0 /* Unsupported */ uint16 panID; zAddrType_t devAddr; /* Address mode */ devAddr.addrMode = *pBuf++; /* Address based on the address mode */ MT_UtilSpi2Addr( &devAddr, pBuf); pBuf += Z_EXTADDR_LEN; /* PanID */ panID = BUILD_UINT16( pBuf[0] , pBuf[1] ); /* Call the routine */ retArray[1] = ZMacSrcMatchCheckSrcAddr (&devAddr, panID); /* Return failure if the index is invalid */ if (retArray[1] == ZMacSrcMatchInvalidIndex ) { retArray[0] = ZFailure; } else { retArray[0] = ZSuccess; } #else retArray[0] = ZMacUnsupported; retArray[1] = ZMacSrcMatchInvalidIndex; #endif /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 2, retArray ); }
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { uint16 flashTime; switch ( pkt->clusterId ) { case SAMPLEAPP_PERIODIC_CLUSTERID: f=pkt->cmd.Data[0];//检测其panid,记录在参数f里面。 if(State_data[f]=='0'){State_data[f]='1';}//将其状态置为在线 // HalUARTWrite(0, State_data,3); //十六进制发给PC机 // HalUARTWrite(0, "\n",1); break; case SAMPLEAPP_FLASH_CLUSTERID: flashTime = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[2] ); HalLedBlink( HAL_LED_4, 4, 50, (flashTime / 4) ); break; } }
/*************************************************************************************************** * @fn MT_AfInterPanCtl * * @brief Process the AF Inter Pan control command. * * @param pBuf - pointer to the received buffer * * @return none ***************************************************************************************************/ static void MT_AfInterPanCtl(uint8 *pBuf) { uint8 cmd, rtrn; uint16 panId; endPointDesc_t *pEP; cmd = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; switch (*pBuf++) // Inter-pan request parameter. { case InterPanClr: rtrn = StubAPS_SetIntraPanChannel(); // Switch channel back to the NIB channel. break; case InterPanSet: rtrn = StubAPS_SetInterPanChannel(*pBuf); // Set channel for inter-pan communication. break; case InterPanReg: if ((pEP = afFindEndPointDesc(*pBuf))) { StubAPS_RegisterApp(pEP); rtrn = SUCCESS; } else { rtrn = FAILURE; } break; case InterPanChk: panId = BUILD_UINT16(pBuf[0], pBuf[1]); rtrn = (StubAPS_InterPan(panId, pBuf[2])) ? ZSuccess : ZFailure; break; default: rtrn = afStatus_INVALID_PARAMETER; break; } MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_AF), cmd, 1, &rtrn); }
/********************************************************************* * @fn GATTServApp_ProcessCCCWriteReq * * @brief Process the client characteristic configuration * write request for a given client. * * @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 validCfg - valid configuration * * @return Success or Failure */ bStatus_t GATTServApp_ProcessCCCWriteReq( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 len, uint16 offset, uint16 validCfg ) { bStatus_t status = SUCCESS; // Validate the value if ( offset == 0 ) { if ( len == 2 ) { uint16 value = BUILD_UINT16( pValue[0], pValue[1] ); // Validate characteristic configuration bit field if ( ( value & ~validCfg ) == 0 ) // indicate and/or notify { // Write the value if it's changed if ( GATTServApp_ReadCharCfg( connHandle, GATT_CCC_TBL(pAttr->pValue) ) != value ) { status = GATTServApp_WriteCharCfg( connHandle, GATT_CCC_TBL(pAttr->pValue), value ); } } else { status = ATT_ERR_INVALID_VALUE; } } else { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } return ( status ); }
/********************************************************************* * @fn findMeTarget_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 * @param method - type of read message * * @return SUCCESS, blePending or Failure */ static bStatus_t findMeTarget_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen, uint8 method ) { bStatus_t status = SUCCESS; // 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_PRIMARY_SERVICE_UUID" or "GATT_CHARACTER_UUID" cases; // gattserverapp handles those types for reads case ALERT_LEVEL_UUID: *pLen = 1; pValue[0] = *pAttr->pValue; 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 *pLen = 0; status = ATT_ERR_INVALID_HANDLE; } return ( status ); }
/********************************************************************* * @fn glucose_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 glucose_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen ) { bStatus_t status = SUCCESS; // Require security for all characteristics if ( linkDB_Encrypted( connHandle ) == FALSE ) { return ATT_ERR_INSUFFICIENT_ENCRYPT; } // 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 types for reads case GLUCOSE_FEATURE_UUID: *pLen = 2; pValue[0] = LO_UINT16( glucoseFeature ); pValue[1] = HI_UINT16( glucoseFeature ); break; default: // Should never get here! (characteristics 3 and 4 do not have read permissions) *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; } } return ( status ); }
/*************************************************************************************************** * @fn MT_NlmeJoinRequest * * @brief Join Request * * @param pBuf - pointer to the received buffer * * @return void ***************************************************************************************************/ void MT_NlmeJoinRequest(uint8 *pBuf) { uint8 retValue = ZFailure; uint8 dummyExPANID[Z_EXTADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint16 panID; uint8 cmdId; networkDesc_t *pNwkDesc; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; panID = BUILD_UINT16(pBuf[0], pBuf[1]); if((pNwkDesc = nwk_getNetworkDesc(dummyExPANID,panID, pBuf[2])) != NULL ) { if (pNwkDesc->chosenRouter == INVALID_NODE_ADDR ) { retValue = ZNwkNotPermitted; } else { retValue = NLME_JoinRequest( dummyExPANID, panID, pBuf[2], pBuf[3], pNwkDesc->chosenRouter, pNwkDesc->chosenRouterDepth ); } } else { retValue = ZNwkNotPermitted; } if ( pBuf[3] & CAPINFO_RCVR_ON_IDLE ) { /* The receiver is on, turn network layer polling off. */ NLME_SetPollRate( 0 ); NLME_SetQueuedPollRate( 0 ); NLME_SetResponseRate( 0 ); } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue); }
/********************************************************************* * @fn bloodPressure_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 bloodPressure_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 ) { case BLOODPRESSURE_FEATURE_UUID: { *pLen = 2; pValue[0] = 0; pValue[1] = 0; } break; default: // Should never get here! (characteristics 3 and 4 do not have read permissions) *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; } } return ( status ); }
/********************************************************************* * @fn bat_ReadAttrCB * * @brief Read an attribute. * * * @return Success or Failure */ static uint8 bat_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen ) { bStatus_t status = SUCCESS; // Make sure it's not a blob operation (no attributes in the profile are long if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); } // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { switch ( uuid ) { // No need for "GATT_SERVICE_UUID" case; // gattserverapp handles those types for reads case BATTERY_LEVEL_UUID: case BATTERY_STATE_UUID: *pLen = 1; pValue[0] = *pAttr->pValue; break; default: // Should never get here! *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { //128-bit UUID *pLen = 0; status = ATT_ERR_INVALID_HANDLE; } return ( status ); }
/** * @fn battReadAttrCB * * @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 battReadAttrCB(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen) { bStatus_t status = SUCCESS; uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]); // Make sure it's not a blob operation (no attributes in the profile are long) if (offset > 0) { return (ATT_ERR_ATTR_NOT_LONG); } // Measure battery level if reading level if (uuid == BATT_LEVEL_UUID) { *pLen = 1; pValue[0] = battLevel; } else { status = ATT_ERR_ATTR_NOT_FOUND; } return (status); }
static void dev_opera(uint8*buf) { uint8 dev_cnt; //device count uint16 dev_addr; // device 地址 uint8 opera_bit; uint8 stop_bit; uint8 i,j; i = 0; j = 0; //0x01 0x?? ff ff xx ff ff xx ff ff xx dev_cnt = buf[1]; for(i=0;i<dev_cnt;i++) { stop_bit = 2+i*3; dev_addr = BUILD_UINT16(buf[stop_bit], buf[ stop_bit + 1]); opera_bit = stop_bit+2; } }
/********************************************************************* * @fn StubNWK_ParseMsg * * @brief Call this function to parse an incoming Stub NWK frame. * * @param buf - pointer incoming message buffer * @param bufLength - length of incoming message * @param snff - pointer Frame Format Parameters * * @return pointer to network packet, NULL if error */ static void StubNWK_ParseMsg( uint8 *buf, uint8 bufLength, NLDE_FrameFormat_t *snff ) { uint16 fc; osal_memset( snff, 0, sizeof(NLDE_FrameFormat_t) ); snff->bufLength = bufLength; // get the frame control fc = BUILD_UINT16( buf[NWK_HDR_FRAME_CTRL_LSB], buf[NWK_HDR_FRAME_CTRL_MSB] ); // parse the frame control NLDE_ParseFrameControl( fc, snff ); snff->hdrLen = STUB_NWK_HDR_LEN; // Stub NWK payload snff->nsdu = buf + snff->hdrLen; snff->nsduLength = snff->bufLength - snff->hdrLen; } /* StubNWK_ParseMsg */
/*************************************************************************************************** * @fn MT_SysOsalNVLength * * @brief Attempt to get the length to an NV item * * @param uint8 pData - pointer to the data * * @return None ***************************************************************************************************/ void MT_SysOsalNVLength(uint8 *pBuf) { uint16 nvId; uint16 nvLen; uint8 rsp[2]; /* Skip over RPC header */ pBuf += MT_RPC_FRAME_HDR_SZ; /* Get the ID */ nvId = BUILD_UINT16(pBuf[0], pBuf[1]); /* Attempt to get NV item length */ nvLen = osal_nv_item_len( nvId ); rsp[0] = LO_UINT16( nvLen ); rsp[1] = HI_UINT16( nvLen ); /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), MT_SYS_OSAL_NV_LENGTH, 2, rsp); }
/*************************************************************************************************** * @fn MT_NlmeRouteDiscoveryRequest * * @brief Route Discovery Request * * @param pBuf - pointer to the received buffer * * @return void ***************************************************************************************************/ void MT_NlmeRouteDiscoveryRequest(uint8 *pBuf) { uint8 retValue = ZFailure; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; if ( ZSTACK_ROUTER_BUILD ) { retValue = NLME_RouteDiscoveryRequest(BUILD_UINT16(pBuf[0], pBuf[1]), pBuf[2], pBuf[3]); } else { retValue = ZUnsupportedMode; } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue); }
/****************************************************************************** * @fn modbus_multi_write */ void modbus_multi_write( uint8 *data_buffer, uint8 len) { uint8 address; address = BUILD_UINT16( data_buffer[3], data_buffer[2]); if( address == MODBUS_SECURITY_KEY_START) { if(data_buffer[6]>=32) { for(uint8 i=0; i<16; i++) { // osal_memcpy(defaultKey, data_buffer[7+i*2], 1); defaultKey[i] = data_buffer[7+i*2]; zgPreconfigKeyInit( TRUE ); // Initialize NV items for all Keys: NWK, APS, TCLK and Master ZDSecMgrInitNVKeyTables( TRUE ); } } } }
/********************************************************************* * @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 zclElectricalMeasurement_ProcessInCmd_GetMeasurementProfileRsp * * @brief Process in the received Electrical Measurement Get Measurement Profile Response cmd * * @param pInMsg - pointer to the incoming message * @param pCBs - pointer to the application callbacks * * @return ZStatus_t */ static ZStatus_t zclElectricalMeasurement_ProcessInCmd_GetMeasurementProfileRsp( zclIncoming_t *pInMsg, zclElectricalMeasurement_AppCallbacks_t *pCBs ) { uint8 i; uint8 offset; uint16 calculatedIntervalSize; zclElectricalMeasurementGetMeasurementProfileRsp_t cmd; ZStatus_t status; if ( pCBs->pfnElectricalMeasurement_GetMeasurementProfileRsp ) { // determine size of intervals by subtracting size of startTime, status, // profileIntervalPeriod, numberOfIntervalsDelivered, and attributeID from message length calculatedIntervalSize = pInMsg->pDataLen - 9; cmd.pIntervals = zcl_mem_alloc( calculatedIntervalSize ); if ( !cmd.pIntervals ) { return ( ZMemError ); // no memory, return failure } cmd.startTime = BUILD_UINT32( pInMsg->pData[0], pInMsg->pData[1], pInMsg->pData[2], pInMsg->pData[3] ); cmd.status = pInMsg->pData[4]; cmd.profileIntervalPeriod = pInMsg->pData[5]; cmd.numberOfIntervalsDelivered = pInMsg->pData[6]; cmd.attributeID = BUILD_UINT16( pInMsg->pData[7], pInMsg->pData[8] ); offset = 9; for ( i = 0; i < calculatedIntervalSize; i++ ) { cmd.pIntervals[i] = pInMsg->pData[offset++]; } status = ( pCBs->pfnElectricalMeasurement_GetMeasurementProfileRsp( &cmd ) ); zcl_mem_free( cmd.pIntervals ); return status; } return ( ZFailure ); }
/** * SNP_getGapParam * */ uint8_t SNP_getGapParam(snpGetGapParamReq_t* pReq) { uint8_t status; //Move part of the simple peripheral init back here if((pReq->paramId != TGAP_AUTH_TASK_ID) && (pReq->value < TGAP_PARAMID_MAX)) { uint16_t value; value = GAP_GetParamValue(pReq->paramId); pReq->value = BUILD_UINT16( LO_UINT16(value), HI_UINT16(value)); } if(pReq->value != 0xFFFF) { status = SNP_SUCCESS; } else { status = SNP_INVALID_PARAMS; } return status; }
/*************************************************************************************************** * @fn MT_UtilzclGeneral_KeyEstablish_InitiateKeyEstablishment * * @brief Proxy the zclGeneral_KeyEstablish_InitiateKeyEstablishment() function. * * @param pBuf - pointer to the received buffer * * @return void ***************************************************************************************************/ static void MT_UtilzclGeneral_KeyEstablish_InitiateKeyEstablishment(uint8 *pBuf) { afAddrType_t partnerAddr; uint8 cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; partnerAddr.panId = 0; // Not an inter-pan message. partnerAddr.endPoint = pBuf[2]; partnerAddr.addrMode = (afAddrMode_t)pBuf[3]; if (afAddr64Bit == partnerAddr.addrMode) { (void)osal_memcpy(partnerAddr.addr.extAddr, pBuf+4, Z_EXTADDR_LEN); } else { partnerAddr.addr.shortAddr = BUILD_UINT16(pBuf[4], pBuf[5]); } zcl_key_establish_task_id = pBuf[0]; *pBuf = zclGeneral_KeyEstablish_InitiateKeyEstablishment(MT_TaskID, &partnerAddr, pBuf[1]); MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, pBuf); }
/*************************************************************************************************** * @fn MT_SysOsalNVWrite * * @brief * * @param uint8 pData - pointer to the data * * @return None ***************************************************************************************************/ void MT_SysOsalNVWrite(uint8 *pBuf) { uint16 nvId; uint8 nvItemLen=0, nvItemOffset=0; uint8 rtrn; /* Skip over RPC header */ pBuf += MT_RPC_FRAME_HDR_SZ; /* Get the ID */ nvId = BUILD_UINT16(pBuf[0], pBuf[1]); /* Get the offset */ nvItemOffset = pBuf[2]; /* Get the length */ nvItemLen = pBuf[3]; pBuf += 4; /* Default to ZFailure */ rtrn = ZFailure; /* Set the Z-Globals value of this NV item. */ zgSetItem( nvId, (uint16)nvItemLen, pBuf ); if ((osal_nv_write(nvId, (uint16)nvItemOffset, (uint16)nvItemLen, pBuf)) == ZSUCCESS) { if (nvId == ZCD_NV_EXTADDR) { rtrn = ZMacSetReq(ZMacExtAddr, pBuf); } else { rtrn = ZSuccess; } } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), MT_SYS_OSAL_NV_WRITE, 1, &rtrn); }
/********************************************************************* * @fn zclElectricalMeasurement_ProcessInCmd_GetProfileInfoRsp * * @brief Process in the received Electrical Measurement Get Profile Info Response cmd * * @param pInMsg - pointer to the incoming message * @param pCBs - pointer to the application callbacks * * @return ZStatus_t */ static ZStatus_t zclElectricalMeasurement_ProcessInCmd_GetProfileInfoRsp( zclIncoming_t *pInMsg, zclElectricalMeasurement_AppCallbacks_t *pCBs ) { uint8 i; uint8 offset; uint16 calculatedArraySize; zclElectricalMeasurementGetProfileInfoRsp_t cmd; ZStatus_t status; if ( pCBs->pfnElectricalMeasurement_GetProfileInfoRsp ) { // calculate size of variable array calculatedArraySize = pInMsg->pDataLen - 3; // variable array - 3 bytes of fixed variables cmd.pListOfAttributes = zcl_mem_alloc( calculatedArraySize ); if ( !cmd.pListOfAttributes ) { return ( ZMemError ); // no memory, return failure } cmd.profileCount = pInMsg->pData[0]; cmd.profileIntervalPeriod = pInMsg->pData[1]; cmd.maxNumberOfIntervals = pInMsg->pData[2]; cmd.numberOfAttributes = calculatedArraySize / sizeof( uint16 ); offset = 3; for ( i = 0; i < cmd.numberOfAttributes; i++ ) { cmd.pListOfAttributes[i] = BUILD_UINT16( pInMsg->pData[offset], pInMsg->pData[offset + 1] ); offset += 2; } status = ( pCBs->pfnElectricalMeasurement_GetProfileInfoRsp( &cmd ) ); zcl_mem_free( cmd.pListOfAttributes ); return status; } return ( ZFailure ); }
/********************************************************************* * @fn glucoseConfigGattMsg() * * @brief Handle GATT messages for characteristic configuration. * * @param state - Discovery state. * @param pMsg - GATT message. * * @return New configuration state. */ uint8_t glucoseConfigGattMsg(uint8_t state, gattMsgEvent_t *pMsg) { if ((pMsg->method == ATT_READ_RSP || pMsg->method == ATT_WRITE_RSP) && (pMsg->hdr.status == SUCCESS)) { // Process response switch (glucoseConfigList[state]) { case HDL_GLUCOSE_MEAS_CCCD: break; case HDL_GLUCOSE_CONTEXT_CCCD: break; case HDL_GLUCOSE_CTL_PNT_CCCD: break; case HDL_GLUCOSE_FEATURE: glucoseFeatures = BUILD_UINT16(pMsg->msg.readRsp.pValue[0], pMsg->msg.readRsp.pValue[1]); break; case HDL_DEVINFO_SYSTEM_ID: break; case HDL_DEVINFO_MANUFACTURER_NAME: break; case HDL_DEVINFO_MODEL_NUM: break; default: break; } } return glucoseConfigNext(state + 1); }
/* * @fn uartServ1_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 * * @return Success or Failure */ static bStatus_t uartServ1_WriteAttrCB(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset) { bStatus_t status = SUCCESS; dmsg(("\033[40;31m0xFFE9 (Write)\033[0m\n")); // 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 UARTSERV1_CHAR_UUID: osal_memcpy(pAttr->pValue, pValue, len); if (uartServ1_AppCBs) { uartServ1_AppCBs(UARTSERV1_CHAR); } break; default: // should never get here! (characteristic 2 do not have write permissions) dmsg(("err\n")); status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { // 128-bit UUID status = ATT_ERR_INVALID_HANDLE; } return (status); }
/*************************************************************************************************** * @fn MT_SysOsalStartTimer * * @brief * * @param uint8 pData - pointer to the data * * @return None ***************************************************************************************************/ void MT_SysOsalStartTimer(uint8 *pBuf) { uint16 eventId; uint8 retValue = ZFailure; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; if (*pBuf <= 3) { eventId = (uint16) MT_SysOsalEventId[*pBuf]; retValue = osal_start_timerEx(MT_TaskID, eventId, BUILD_UINT16(pBuf[1], pBuf[2])); } else { retValue = ZInvalidParameter; } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), cmdId, 1, &retValue); }