123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- #include "bcomdef.h"
- #include "OSAL.h"
- #include "linkdb.h"
- #include "att.h"
- #include "gatt.h"
- #include "gatt_uuid.h"
- #include "gattservapp.h"
- #include "gapbondmgr.h"
- #include "simplekeys.h"
- #define SERVAPP_NUM_ATTR_SUPPORTED 5
- CONST uint8 skServUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(SK_SERV_UUID), HI_UINT16(SK_SERV_UUID)
- };
- CONST uint8 keyPressedUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(SK_KEYPRESSED_UUID), HI_UINT16(SK_KEYPRESSED_UUID)
- };
- static CONST gattAttrType_t skService = { ATT_BT_UUID_SIZE, skServUUID };
- static uint8 skCharProps = GATT_PROP_NOTIFY;
- static uint8 skKeyPressed = 0;
- static gattCharCfg_t skConfig[GATT_MAX_NUM_CONN];
- static uint8 skCharUserDesp[16] = "Key Press State\0";
- static gattAttribute_t simplekeysAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
- {
-
- {
- { ATT_BT_UUID_SIZE, primaryServiceUUID },
- GATT_PERMIT_READ,
- 0,
- (uint8 *)&skService
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &skCharProps
- },
-
- {
- { ATT_BT_UUID_SIZE, keyPressedUUID },
- 0,
- 0,
- &skKeyPressed
- },
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_WRITE,
- 0,
- (uint8 *)skConfig
- },
-
- {
- { ATT_BT_UUID_SIZE, charUserDescUUID },
- GATT_PERMIT_READ,
- 0,
- skCharUserDesp
- },
- };
- static uint8 sk_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen );
- static bStatus_t sk_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset );
- static void sk_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
- CONST gattServiceCBs_t skCBs =
- {
- sk_ReadAttrCB,
- sk_WriteAttrCB,
- NULL
- };
- bStatus_t SK_AddService( uint32 services )
- {
- uint8 status = SUCCESS;
-
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, skConfig );
-
- VOID linkDB_Register( sk_HandleConnStatusCB );
-
-
- if ( services & SK_SERVICE )
- {
-
- status = GATTServApp_RegisterService( simplekeysAttrTbl,
- GATT_NUM_ATTRS( simplekeysAttrTbl ),
- &skCBs );
- }
- return ( status );
- }
- bStatus_t SK_SetParameter( uint8 param, uint8 len, void *pValue )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- case SK_KEY_ATTR:
- if ( len == sizeof ( uint8 ) )
- {
- skKeyPressed = *((uint8*)pValue);
-
-
- GATTServApp_ProcessCharCfg( skConfig, &skKeyPressed, FALSE,
- simplekeysAttrTbl, GATT_NUM_ATTRS( simplekeysAttrTbl ),
- INVALID_TASK_ID );
- }
- else
- {
- ret = bleInvalidRange;
- }
- break;
-
- default:
- ret = INVALIDPARAMETER;
- break;
- }
-
- return ( ret );
- }
- bStatus_t SK_GetParameter( uint8 param, void *pValue )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- case SK_KEY_ATTR:
- *((uint8*)pValue) = skKeyPressed;
- break;
-
- default:
- ret = INVALIDPARAMETER;
- break;
- }
-
- return ( ret );
- }
- static uint8 sk_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
- {
- bStatus_t status = SUCCESS;
-
-
- if ( offset > 0 )
- {
- return ( ATT_ERR_ATTR_NOT_LONG );
- }
-
- if ( pAttr->type.len == ATT_BT_UUID_SIZE )
- {
-
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
- switch ( uuid )
- {
-
-
-
-
- case SK_KEYPRESSED_UUID:
- *pLen = 1;
- pValue[0] = *pAttr->pValue;
- break;
- default:
-
- *pLen = 0;
- status = ATT_ERR_ATTR_NOT_FOUND;
- break;
- }
- }
- else
- {
-
- *pLen = 0;
- status = ATT_ERR_INVALID_HANDLE;
- }
- return ( status );
- }
- static bStatus_t sk_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset )
- {
- bStatus_t status = SUCCESS;
- 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 );
- break;
-
- default:
-
- status = ATT_ERR_ATTR_NOT_FOUND;
- break;
- }
- }
- else
- {
-
- status = ATT_ERR_INVALID_HANDLE;
- }
- return ( status );
- }
- static void sk_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
- {
-
- if ( connHandle != LOOPBACK_CONNHANDLE )
- {
-
- if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED ) ||
- ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
- ( !linkDB_Up( connHandle ) ) ) )
- {
- GATTServApp_InitCharCfg( connHandle, skConfig );
- }
- }
- }
|