123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- #include "bcomdef.h"
- #include "OSAL.h"
- #include "att.h"
- #include "gatt.h"
- #include "gatt_uuid.h"
- #include "gattservapp.h"
- #include "gatt_profile_uuid.h"
- #include "gapbondmgr.h"
- #include "linkdb.h"
- #include "scanparamservice.h"
- CONST uint8 scanParamServUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(SCAN_PARAM_SERV_UUID), HI_UINT16(SCAN_PARAM_SERV_UUID)
- };
- CONST uint8 scanIntervalWindowUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(SCAN_INTERVAL_WINDOW_UUID), HI_UINT16(SCAN_INTERVAL_WINDOW_UUID)
- };
- CONST uint8 scanParamRefreshUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(SCAN_REFRESH_UUID), HI_UINT16(SCAN_REFRESH_UUID)
- };
- static scanParamServiceCB_t scanParamServiceCB;
- static CONST gattAttrType_t scanParamService = { ATT_BT_UUID_SIZE, scanParamServUUID };
- static uint8 scanIntervalWindowProps = GATT_PROP_WRITE_NO_RSP;
- static uint8 scanIntervalWindow[SCAN_INTERVAL_WINDOW_CHAR_LEN];
- static uint8 scanParamRefreshProps = GATT_PROP_NOTIFY;
- static uint8 scanParamRefresh[SCAN_PARAM_REFRESH_LEN];
- static gattCharCfg_t scanParamRefreshClientCharCfg[GATT_MAX_NUM_CONN];
- static gattAttribute_t scanParamAttrTbl[] =
- {
-
- {
- { ATT_BT_UUID_SIZE, primaryServiceUUID },
- GATT_PERMIT_READ,
- 0,
- (uint8 *)&scanParamService
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &scanIntervalWindowProps
- },
-
- {
- { ATT_BT_UUID_SIZE, scanIntervalWindowUUID },
- GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- scanIntervalWindow
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &scanParamRefreshProps
- },
-
- {
- { ATT_BT_UUID_SIZE, scanParamRefreshUUID },
- 0,
- 0,
- scanParamRefresh
- },
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- (uint8 *) &scanParamRefreshClientCharCfg
- }
- };
- enum
- {
- SCAN_PARAM_SERVICE_IDX,
- SCAN_PARAM_INTERVAL_DECL_IDX,
- SCAN_PARAM_INTERVAL_IDX,
- SCAN_PARAM_REFRESH_DECL_IDX,
- SCAN_PARAM_REFRESH_IDX,
- SCAN_PARAM_REFRESH_CCCD_IDX
- };
- static bStatus_t scanParamWriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset );
- static uint8 scanParamReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen );
- CONST gattServiceCBs_t scanParamCBs =
- {
- scanParamReadAttrCB,
- scanParamWriteAttrCB,
- NULL
- };
- bStatus_t ScanParam_AddService( void )
- {
- uint8 status = SUCCESS;
-
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, scanParamRefreshClientCharCfg );
-
- status = GATTServApp_RegisterService( scanParamAttrTbl, GATT_NUM_ATTRS( scanParamAttrTbl ),
- &scanParamCBs );
- return ( status );
- }
- extern void ScanParam_Register( scanParamServiceCB_t pfnServiceCB )
- {
- scanParamServiceCB = pfnServiceCB;
- }
- bStatus_t ScanParam_SetParameter( uint8 param, uint8 len, void *value )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- default:
- ret = INVALIDPARAMETER;
- break;
- }
- return ( ret );
- }
- bStatus_t ScanParam_GetParameter( uint8 param, void *value )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- case SCAN_PARAM_PARAM_INTERVAL:
- *((uint16*)value) = BUILD_UINT16(scanIntervalWindow[0],
- scanIntervalWindow[1]);
- break;
- case SCAN_PARAM_PARAM_WINDOW:
- *((uint16*)value) = BUILD_UINT16(scanIntervalWindow[2],
- scanIntervalWindow[3]);
- break;
- default:
- ret = INVALIDPARAMETER;
- break;
- }
- return ( ret );
- }
- void ScanParam_RefreshNotify( uint16 connHandle )
- {
- attHandleValueNoti_t noti;
- uint16 value;
- value = GATTServApp_ReadCharCfg( connHandle, scanParamRefreshClientCharCfg );
- if ( value & GATT_CLIENT_CFG_NOTIFY )
- {
-
- noti.handle = scanParamAttrTbl[SCAN_PARAM_REFRESH_CCCD_IDX].handle;
- noti.len = SCAN_PARAM_REFRESH_LEN;
- noti.value[0] = SCAN_PARAM_REFRESH_REQ;
- GATT_Notification( connHandle, ¬i, FALSE );
- }
- }
- static uint8 scanParamReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
- {
- bStatus_t status = SUCCESS;
- return ( status );
- }
- static bStatus_t scanParamWriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset )
- {
- bStatus_t status = SUCCESS;
-
- if ( offset > 0 )
- {
- return ( ATT_ERR_ATTR_NOT_LONG );
- }
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
-
- if ( uuid == SCAN_INTERVAL_WINDOW_UUID )
- {
- if ( len == SCAN_INTERVAL_WINDOW_CHAR_LEN )
- {
- uint16 interval = BUILD_UINT16( pValue[0], pValue[1] );
- uint16 window = BUILD_UINT16( pValue[0], pValue[1] );
-
- if ( window <= interval )
- {
- osal_memcpy( pAttr->pValue, pValue, len );
- (*scanParamServiceCB)( SCAN_INTERVAL_WINDOW_SET );
- }
- else
- {
- status = ATT_ERR_INVALID_VALUE;
- }
- }
- else
- {
- status = ATT_ERR_INVALID_VALUE_SIZE;
- }
- }
- else 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;
- }
- return ( status );
- }
- void ScanParam_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, scanParamRefreshClientCharCfg );
- }
- }
- }
|