123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698 |
- #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 "AudioGATTprofile.h"
- #include "log.h"
- #include "common.h"
- #include "peripheral.h"
- #include "hidkbd.h"
- #define SERVAPP_NUM_ATTR_SUPPORTED 8
-
- #define AUDIO_BASE_UUID_128( uuid ) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, \
- 0x00, 0x40, 0x51, 0x04, LO_UINT16( uuid ), HI_UINT16( uuid ), 0x00, 0xF0
- uint8 char1Tx_length=0;
- uint8 char2Tx_length=0;
- CONST uint8 AudioProfileServUUID[ATT_UUID_SIZE] =
- {
- AUDIO_BASE_UUID_128(AUDIOPROFILE_SERV_UUID)
- };
- CONST uint8 AudioProfilechar1UUID[ATT_UUID_SIZE] =
- {
- AUDIO_BASE_UUID_128(AUDIOPROFILE_CHAR1_UUID)
- };
- CONST uint8 AudioProfilechar2UUID[ATT_UUID_SIZE] =
- {
- AUDIO_BASE_UUID_128(AUDIOPROFILE_CHAR2_UUID)
- };
- static AudioProfileCBs_t *AudioProfile_AppCBs = NULL;
- static CONST gattAttrType_t AudioProfileService = { ATT_UUID_SIZE, AudioProfileServUUID };
- static uint8 AudioProfileChar1Props = GATT_PROP_NOTIFY|GATT_PROP_READ;
- uint8 AudioProfileChar1[AUDIOPROFILE_CHAR1_LEN];
-
-
-
-
- static gattCharCfg_t AudioProfileChar1Config[GATT_MAX_NUM_CONN];
- static uint8 AudioProfileChar2Props = GATT_PROP_NOTIFY|GATT_PROP_READ;
- uint8 AudioProfileChar2[AUDIOPROFILE_CHAR2_LEN];
- static gattCharCfg_t AudioProfileChar2Config[GATT_MAX_NUM_CONN];
- static gattAttribute_t AudioProfileAttrTbl[] =
- {
-
- {
- { ATT_BT_UUID_SIZE, primaryServiceUUID },
- GATT_PERMIT_READ,
- 0,
- (uint8 *)&AudioProfileService
- },
-
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &AudioProfileChar1Props
- },
-
- {
- { ATT_UUID_SIZE, AudioProfilechar1UUID },
- GATT_PERMIT_READ | GATT_PERMIT_WRITE,
- 0,
- (uint8 *)&AudioProfileChar1
- },
-
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_WRITE,
- 0,
- (uint8 *)AudioProfileChar1Config
- },
-
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &AudioProfileChar2Props
- },
-
- {
- { ATT_UUID_SIZE, AudioProfilechar2UUID },
- GATT_PERMIT_READ,
- 0,
- AudioProfileChar2
- },
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_WRITE,
- 0,
- (uint8 *)AudioProfileChar2Config
- },
-
-
-
-
-
-
-
- };
- static uint8 AudioProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen );
- static bStatus_t AudioProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset );
- static void AudioProfile_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
- CONST gattServiceCBs_t AudioProfileCBs =
- {
- AudioProfile_ReadAttrCB,
- AudioProfile_WriteAttrCB,
- NULL
- };
- bStatus_t AudioProfile_AddService( uint32 services )
- {
- uint8 status = SUCCESS;
-
-
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, AudioProfileChar1Config );
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, AudioProfileChar2Config );
-
-
- VOID linkDB_Register(AudioProfile_HandleConnStatusCB );
-
- if ( services & AUDIOPROFILE_SERVICE )
- {
-
- status = GATTServApp_RegisterService( AudioProfileAttrTbl,
- GATT_NUM_ATTRS( AudioProfileAttrTbl ),
- &AudioProfileCBs );
- }
-
- return ( status );
- }
- bStatus_t AudioProfile_RegisterAppCBs( AudioProfileCBs_t *appCallbacks )
- {
- if ( appCallbacks )
- {
- AudioProfile_AppCBs = appCallbacks;
-
- return ( SUCCESS );
- }
- else
- {
- return ( bleAlreadyInRequestedMode );
- }
- }
-
- bStatus_t AudioProfile_SetParameter( uint8 param, uint8 len, void *value )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- case AUDIOPROFILE_CHAR1:
- if ( len >0)
- {
- VOID osal_memcpy( AudioProfileChar1, value, len );
- char1Tx_length=len;
-
- ret=GATTServApp_ProcessCharCfg( AudioProfileChar1Config, AudioProfileChar1, FALSE,
- AudioProfileAttrTbl, GATT_NUM_ATTRS( AudioProfileAttrTbl ),
- INVALID_TASK_ID );
- if(ret!=SUCCESS)
- {
-
- }
-
- }
- else
- {
- ret = bleInvalidRange;
- }
- break;
- case AUDIOPROFILE_CHAR2:
- if ( len >0)
- {
- VOID osal_memcpy( AudioProfileChar2, value, len );
- char2Tx_length=len;
-
- ret=GATTServApp_ProcessCharCfg( AudioProfileChar2Config, AudioProfileChar2, FALSE,
- AudioProfileAttrTbl, GATT_NUM_ATTRS( AudioProfileAttrTbl ),
- INVALID_TASK_ID );
- if(ret!=SUCCESS)
- {
-
- }
- }
- else
- {
- ret = bleInvalidRange;
- }
- break;
-
- default:
- ret = INVALIDPARAMETER;
- break;
- }
-
- return ( ret );
- }
- bStatus_t AudioProfile_GetParameter( uint8 param, void *value )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
-
- default:
- ret = INVALIDPARAMETER;
- break;
- }
-
- return ( ret );
- }
- static uint8 AudioProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
- {
- bStatus_t status = SUCCESS;
-
-
- if ( gattPermitAuthorRead( pAttr->permissions ) )
- {
-
- return ( ATT_ERR_INSUFFICIENT_AUTHOR );
- }
-
-
- if ( offset > 0 )
- {
- return ( ATT_ERR_ATTR_NOT_LONG );
- }
-
- if ( pAttr->type.len == ATT_BT_UUID_SIZE||pAttr->type.len == ATT_UUID_SIZE )
- {
-
- AudioProfile_Read(connHandle,pAttr,pValue,pLen,offset,maxLen);
- }
-
-
- return ( status );
- }
- static bStatus_t AudioProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset )
- {
- bStatus_t status = SUCCESS;
- uint8 notifyApp = 0xFF;
-
-
- if ( gattPermitAuthorWrite( pAttr->permissions ) )
- {
-
- return ( ATT_ERR_INSUFFICIENT_AUTHOR );
- }
-
- 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 ( status == SUCCESS )
- {
-
- if(pAttr->handle==AudioProfileAttrTbl[3].handle)
- {
- LOG("audio start cmd enable\n\r");
- }
- else if(pAttr->handle==AudioProfileAttrTbl[6].handle)
- {
- LOG("audio data transf enable\n\r");
-
-
-
-
- }
- }
-
- break;
-
- default:
-
- status = ATT_ERR_ATTR_NOT_FOUND;
- break;
- }
- }
- else
- {
-
- status = ATT_ERR_INVALID_HANDLE;
- }
-
-
- if ( (notifyApp != 0xFF ) && AudioProfile_AppCBs && AudioProfile_AppCBs->pfnAudioProfileChange )
- {
- AudioProfile_AppCBs->pfnAudioProfileChange( notifyApp );
- }
-
- return ( status );
- }
- static void AudioProfile_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, AudioProfileChar1Config );
- GATTServApp_InitCharCfg( connHandle, AudioProfileChar2Config );
- }
- }
- }
- bStatus_t AudioProfile_Notify( uint8 param, uint8 len, void *value )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- case AUDIOPROFILE_CHAR2:
- VOID osal_memcpy( AudioProfileChar2, value, len );
- GATTServApp_ProcessCharCfg( AudioProfileChar2Config, AudioProfileChar2, FALSE,
- AudioProfileAttrTbl, GATT_NUM_ATTRS( AudioProfileAttrTbl ),
- INVALID_TASK_ID );
- break;
-
- default:
- ret = INVALIDPARAMETER;
- break;
- }
-
- return ( ret );
- }
- bStatus_t AudioProfile_Write( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset )
- {
- bStatus_t status = SUCCESS;
-
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
-
- switch(uuid){
- case AUDIOPROFILE_CHAR1_UUID:
- if ( offset != 0 )
- {
- status = ATT_ERR_ATTR_NOT_LONG;
- }
-
- if ( status == SUCCESS ){
- uint8 *pCurValue = (uint8 *)pAttr->pValue;
- VOID osal_memcpy( pCurValue, pValue, len );
-
-
- }
- break;
-
- 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;
- }
- return status;
- }
- bStatus_t AudioProfile_Read( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
- {
- bStatus_t status = SUCCESS;
- if(pAttr->type.len == ATT_BT_UUID_SIZE)
- {
-
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
- LOG("16 uuid:%X\n\r",uuid);
- switch ( uuid )
- {
- case AUDIOPROFILE_CHAR1_UUID:
- *pLen = char1Tx_length;
- VOID osal_memcpy( pValue, pAttr->pValue, *pLen );
- break;
- case AUDIOPROFILE_CHAR2_UUID:
- *pLen=char2Tx_length;
- VOID osal_memcpy( pValue, pAttr->pValue, *pLen );
- break;
-
- default:
-
- *pLen = 0;
- status = ATT_ERR_ATTR_NOT_FOUND;
- LOG("uuid not find\n\r");
- break;
-
-
- }
- }
- else
- {
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[12], pAttr->type.uuid[13]);
-
- switch ( uuid )
- {
- case AUDIOPROFILE_CHAR1_UUID:
- *pLen = char1Tx_length;
- VOID osal_memcpy( pValue, pAttr->pValue, *pLen );
- break;
- case AUDIOPROFILE_CHAR2_UUID:
- *pLen=char2Tx_length;
- VOID osal_memcpy( pValue, pAttr->pValue, *pLen );
- break;
-
- default:
-
- *pLen = 0;
- status = ATT_ERR_ATTR_NOT_FOUND;
- LOG("uuid not find\n\r");
- break;
-
-
- }
- }
-
-
- return status;
- }
|