/********************************************************************* * @fn OADTarget_rejectImage * * @brief Reject the Image identified by the OAD manager, send back * active image version, length and UID to manager. * * @param connHandle - connection message was received on. * @param pImgHdr - pointer to the img_hdr_t data to send. * * @return None. */ static void OADTarget_rejectImage(uint16_t connHandle, img_hdr_t *pImgHdr) { uint16_t value = GATTServApp_ReadCharCfg(connHandle, oadImgIdentifyConfig); // If notifications enabled if (value & GATT_CLIENT_CFG_NOTIFY) { attHandleValueNoti_t noti; noti.pValue = GATT_bm_alloc(connHandle, ATT_HANDLE_VALUE_NOTI, 8, NULL); if (noti.pValue != NULL) { gattAttribute_t *pAttr = GATTServApp_FindAttr(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), oadCharVals+OAD_CHAR_IMG_IDENTIFY); noti.handle = pAttr->handle; noti.len = OAD_IMG_HDR_SIZE; noti.pValue[0] = LO_UINT16(pImgHdr->ver); noti.pValue[1] = HI_UINT16(pImgHdr->ver); noti.pValue[2] = LO_UINT16(pImgHdr->len); noti.pValue[3] = HI_UINT16(pImgHdr->len); (void)memcpy(noti.pValue+4, pImgHdr->uid, sizeof(pImgHdr->uid)); if (GATT_Notification(connHandle, ¬i, FALSE) != SUCCESS) { GATT_bm_free((gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI); } } } }
/********************************************************************* * @fn OADTarget_getNextBlockReq * * @brief Process the Request for next image block. * * @param connHandle - connection message was received on * @param blkNum - block number to request from OAD Manager. * * @return None */ static void OADTarget_getNextBlockReq(uint16_t connHandle, uint16_t blkNum) { uint16_t value = GATTServApp_ReadCharCfg(connHandle, oadImgBlockConfig); // If notifications enabled if (value & GATT_CLIENT_CFG_NOTIFY) { attHandleValueNoti_t noti; noti.pValue = GATT_bm_alloc(connHandle, ATT_HANDLE_VALUE_NOTI, 2, NULL); if (noti.pValue != NULL) { gattAttribute_t *pAttr = GATTServApp_FindAttr(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), oadCharVals+OAD_CHAR_IMG_BLOCK); noti.handle = pAttr->handle; noti.len = 2; noti.pValue[0] = LO_UINT16(blkNum); noti.pValue[1] = HI_UINT16(blkNum); if (GATT_Notification(connHandle, ¬i, FALSE) != SUCCESS) { GATT_bm_free((gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI); } } } }
/********************************************************************* * @fn simpleProfile_ProcessCharCfg * * @brief Process Client Charateristic Configuration change. * * @param charCfgTbl - characteristic configuration table * @param pValue - pointer to attribute value * @param authenticated - whether an authenticated link is required * * @return none */ static void simpleProfile_ProcessCharCfg( gattCharCfg_t *charCfgTbl, uint8 *pValue, uint8 authenticated ) { for ( uint8 i = 0; i < GATT_MAX_NUM_CONN; i++ ) { gattCharCfg_t *pItem = &(charCfgTbl[i]); if ( ( pItem->connHandle != INVALID_CONNHANDLE ) && ( pItem->value != GATT_CFG_NO_OPERATION ) ) { gattAttribute_t *pAttr; // Find the characteristic value attribute pAttr = GATTServApp_FindAttr( simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ), pValue ); if ( pAttr != NULL ) { attHandleValueNoti_t noti; // If the attribute value is longer than (ATT_MTU - 3) octets, then // only the first (ATT_MTU - 3) octets of this attributes value can // be sent in a notification. if ( simpleProfile_ReadAttrCB( pItem->connHandle, pAttr, noti.value, ¬i.len, 0, (ATT_MTU_SIZE-3) ) == SUCCESS ) { noti.handle = pAttr->handle; if ( pItem->value & GATT_CLIENT_CFG_NOTIFY ) { VOID GATT_Notification( pItem->connHandle, ¬i, authenticated ); } } } } } // for }
/********************************************************************* * @fn HidMouse_SetParameter * * @brief Set a Simple Profile parameter. * * @param param - Profile parameter ID * @param len - length of data to right * @param value - pointer to data to write. This is dependent on * the parameter ID and WILL be cast to the appropriate * data type (example: data type of uint16 will be cast to * uint16 pointer). * * @return bStatus_t */ bStatus_t HidMouse_SetParameter(uint8 param, uint8 len, void *value) { bStatus_t ret = SUCCESS; const uint8 MOUSE_LEN = 4; switch (param) { case HIDMOUSE_DATA: if (len == MOUSE_LEN) { memcpy(hidMouseData, value, MOUSE_LEN); // Send notification if enabled if ((hidMouseDataCharConfig == GATT_CLIENT_CFG_NOTIFY) && (hidMouseConnHandle != INVALID_CONNHANDLE)) { gattAttribute_t *attr; // Find the characteristic value attribute attr = GATTServApp_FindAttr(hidMouseAttrTbl, GATT_NUM_ATTRS(hidMouseAttrTbl), hidMouseData); if (attr != NULL) { attHandleValueNoti_t notify; // Send the notification notify.handle = attr->handle; notify.len = MOUSE_LEN; memcpy(notify.value, hidMouseData, MOUSE_LEN); ret = GATT_Notification(hidMouseConnHandle, ¬ify, FALSE); } } } else { ret = bleInvalidRange; } break; default: ret = INVALIDPARAMETER; break; } return (ret); }
/********************************************************************* * @fn GATTServApp_ProcessCharCfg * * @brief Process Client Characteristic Configuration change. * * @param charCfgTbl - characteristic configuration table. * @param pValue - pointer to attribute value. * @param authenticated - whether an authenticated link is required. * @param attrTbl - attribute table. * @param numAttrs - number of attributes in attribute table. * @param taskId - task to be notified of confirmation. * @param pfnReadAttrCB - read callback function pointer. * * @return Success or Failure */ bStatus_t GATTServApp_ProcessCharCfg( gattCharCfg_t *charCfgTbl, uint8 *pValue, uint8 authenticated, gattAttribute_t *attrTbl, uint16 numAttrs, uint8 taskId, pfnGATTReadAttrCB_t pfnReadAttrCB ) { uint8 i; bStatus_t status = SUCCESS; // Verify input parameters if ( ( charCfgTbl == NULL ) || ( pValue == NULL ) || ( attrTbl == NULL ) || ( pfnReadAttrCB == NULL ) ) { return ( INVALIDPARAMETER ); } for ( i = 0; i < linkDBNumConns; i++ ) { gattCharCfg_t *pItem = &(charCfgTbl[i]); if ( ( pItem->connHandle != INVALID_CONNHANDLE ) && ( pItem->value != GATT_CFG_NO_OPERATION ) ) { gattAttribute_t *pAttr; // Find the characteristic value attribute pAttr = GATTServApp_FindAttr( attrTbl, numAttrs, pValue ); if ( pAttr != NULL ) { if ( pItem->value & GATT_CLIENT_CFG_NOTIFY ) { status |= gattServApp_SendNotiInd( pItem->connHandle, GATT_CLIENT_CFG_NOTIFY, authenticated, pAttr, taskId, pfnReadAttrCB ); } if ( pItem->value & GATT_CLIENT_CFG_INDICATE ) { status |= gattServApp_SendNotiInd( pItem->connHandle, GATT_CLIENT_CFG_INDICATE, authenticated, pAttr, taskId, pfnReadAttrCB ); } } } } // for return ( status ); }
/********************************************************************* * @fn oadImgIdentifyReq * * @brief Process the Image Identify Request. * * @param connHandle - connection message was received on * @param pImgHdr - Pointer to the img_hdr_t data to send. * * @return None */ static void oadImgBlockReq(uint16 connHandle, uint16 blkNum) { uint16 value = GATTServApp_ReadCharCfg( connHandle, oadImgBlockConfig ); // If notifications enabled if ( value & GATT_CLIENT_CFG_NOTIFY ) { attHandleValueNoti_t noti; gattAttribute_t *pAttr = GATTServApp_FindAttr(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), oadCharVals+OAD_CHAR_IMG_BLOCK); noti.handle = pAttr->handle; noti.len = 2; noti.value[0] = LO_UINT16(blkNum); noti.value[1] = HI_UINT16(blkNum); VOID GATT_Notification(connHandle, ¬i, FALSE); } }
/********************************************************************* * @fn oadImgIdentifyReq * * @brief Process the Image Identify Request. * * @param connHandle - connection message was received on * @param pImgHdr - Pointer to the img_hdr_t data to send. * * @return None */ static void oadImgIdentifyReq(uint16 connHandle, img_hdr_t *pImgHdr) { uint16 value = GATTServApp_ReadCharCfg( connHandle, oadImgIdentifyConfig ); // If notifications enabled if ( value & GATT_CLIENT_CFG_NOTIFY ) { attHandleValueNoti_t noti; gattAttribute_t *pAttr = GATTServApp_FindAttr(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), oadCharVals+OAD_CHAR_IMG_IDENTIFY); noti.handle = pAttr->handle; noti.len = OAD_IMG_HDR_SIZE; noti.value[0] = LO_UINT16(pImgHdr->ver); noti.value[1] = HI_UINT16(pImgHdr->ver); noti.value[2] = LO_UINT16(pImgHdr->len); noti.value[3] = HI_UINT16(pImgHdr->len); (void)osal_memcpy(noti.value+4, pImgHdr->uid, sizeof(pImgHdr->uid)); VOID GATT_Notification(connHandle, ¬i, FALSE); } }