123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- #include "bcomdef.h"
- #include "OSAL.h"
- #include "att.h"
- #include "gatt.h"
- #include "gatt_uuid.h"
- #include "gatt_profile_uuid.h"
- #include "linkdb.h"
- #include "gattservapp.h"
- #include "hidkbdservice.h"
- #include "peripheral.h"
- #include "hiddev.h"
- #include "battservice.h"
- CONST uint8 hidServUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(HID_SERV_UUID), HI_UINT16(HID_SERV_UUID)
- };
- CONST uint8 hidBootKeyInputUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(BOOT_KEY_INPUT_UUID), HI_UINT16(BOOT_KEY_INPUT_UUID)
- };
- CONST uint8 hidBootMouseInputUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(BOOT_MOUSE_INPUT_UUID), HI_UINT16(BOOT_MOUSE_INPUT_UUID)
- };
- CONST uint8 hidBootKeyOutputUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(BOOT_KEY_OUTPUT_UUID), HI_UINT16(BOOT_KEY_OUTPUT_UUID)
- };
- CONST uint8 hidInfoUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(HID_INFORMATION_UUID), HI_UINT16(HID_INFORMATION_UUID)
- };
- CONST uint8 hidReportMapUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(REPORT_MAP_UUID), HI_UINT16(REPORT_MAP_UUID)
- };
- CONST uint8 hidControlPointUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(HID_CTRL_PT_UUID), HI_UINT16(HID_CTRL_PT_UUID)
- };
- CONST uint8 hidReportUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(REPORT_UUID), HI_UINT16(REPORT_UUID)
- };
- CONST uint8 hidProtocolModeUUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(PROTOCOL_MODE_UUID), HI_UINT16(PROTOCOL_MODE_UUID)
- };
- static CONST uint8 hidInfo[HID_INFORMATION_LEN] =
- {
- LO_UINT16(0x0111), HI_UINT16(0x0111),
- 0x00,
- HID_KBD_FLAGS
- };
- static CONST uint8 hidReportMap[] =
- {
- 0x05, 0x01,
- 0x09, 0x06,
- 0xA1, 0x01,
-
- 0x05, 0x07,
- 0x19, 0xE0,
- 0x29, 0xE7,
- 0x15, 0x00,
- 0x25, 0x01,
-
-
- 0x75, 0x01,
- 0x95, 0x08,
- 0x81, 0x02,
-
-
- 0x95, 0x01,
- 0x75, 0x08,
- 0x81, 0x01,
-
-
- 0x95, 0x05,
- 0x75, 0x01,
- 0x05, 0x08,
- 0x19, 0x01,
- 0x29, 0x05,
- 0x91, 0x02,
-
-
- 0x95, 0x01,
- 0x75, 0x03,
- 0x91, 0x01,
-
-
- 0x95, 0x06,
- 0x75, 0x08,
- 0x15, 0x00,
- 0x25, 0x65,
- 0x05, 0x07,
- 0x19, 0x00,
- 0x29, 0x65,
- 0x81, 0x00,
-
- 0xC0
- };
- uint8 hidReportMapLen = sizeof(hidReportMap);
- static hidRptMap_t hidRptMap[HID_NUM_REPORTS];
- static CONST gattAttrType_t hidService = { ATT_BT_UUID_SIZE, hidServUUID };
- static uint16 include = GATT_INVALID_HANDLE;
- static uint8 hidInfoProps = GATT_PROP_READ;
- static uint8 hidReportMapProps = GATT_PROP_READ;
- static uint8 hidExtReportRefDesc[ATT_BT_UUID_SIZE] =
- { LO_UINT16(BATT_LEVEL_UUID), HI_UINT16(BATT_LEVEL_UUID) };
- static uint8 hidControlPointProps = GATT_PROP_WRITE_NO_RSP;
- static uint8 hidControlPoint;
- static uint8 hidProtocolModeProps = GATT_PROP_READ | GATT_PROP_WRITE_NO_RSP;
- uint8 hidProtocolMode = HID_PROTOCOL_MODE_REPORT;
- static uint8 hidReportKeyInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
- static uint8 hidReportKeyIn;
- static gattCharCfg_t hidReportKeyInClientCharCfg[GATT_MAX_NUM_CONN];
- static uint8 hidReportRefKeyIn[HID_REPORT_REF_LEN] =
- { HID_RPT_ID_KEY_IN, HID_REPORT_TYPE_INPUT };
- static uint8 hidReportLedOutProps = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP;
- static uint8 hidReportLedOut;
- static uint8 hidReportRefLedOut[HID_REPORT_REF_LEN] =
- { HID_RPT_ID_LED_OUT, HID_REPORT_TYPE_OUTPUT };
- static uint8 hidReportBootKeyInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
- static uint8 hidReportBootKeyIn;
- static gattCharCfg_t hidReportBootKeyInClientCharCfg[GATT_MAX_NUM_CONN];
- static uint8 hidReportBootKeyOutProps = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP;
- static uint8 hidReportBootKeyOut;
- static uint8 hidReportBootMouseInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
- static uint8 hidReportBootMouseIn;
- static gattCharCfg_t hidReportBootMouseInClientCharCfg[GATT_MAX_NUM_CONN];
- static uint8 hidReportFeatureProps = GATT_PROP_READ | GATT_PROP_WRITE;
- static uint8 hidReportFeature;
- static uint8 hidReportRefFeature[HID_REPORT_REF_LEN] =
- { HID_RPT_ID_FEATURE, HID_REPORT_TYPE_FEATURE };
- static gattAttribute_t hidAttrTbl[] =
- {
-
- {
- { ATT_BT_UUID_SIZE, primaryServiceUUID },
- GATT_PERMIT_READ,
- 0,
- (uint8 *) &hidService
- },
-
- {
- { ATT_BT_UUID_SIZE, includeUUID },
- GATT_PERMIT_READ,
- 0,
- (uint8 *)&include
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidInfoProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidInfoUUID },
- GATT_PERMIT_ENCRYPT_READ,
- 0,
- (uint8 *) hidInfo
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidControlPointProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidControlPointUUID },
- GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- &hidControlPoint
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidProtocolModeProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidProtocolModeUUID },
- GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- &hidProtocolMode
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportMapProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidReportMapUUID },
- GATT_PERMIT_ENCRYPT_READ,
- 0,
- (uint8 *) hidReportMap
- },
-
- {
- { ATT_BT_UUID_SIZE, extReportRefUUID },
- GATT_PERMIT_READ,
- 0,
- hidExtReportRefDesc
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportKeyInProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidReportUUID },
- GATT_PERMIT_ENCRYPT_READ,
- 0,
- &hidReportKeyIn
- },
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- (uint8 *) &hidReportKeyInClientCharCfg
- },
-
- {
- { ATT_BT_UUID_SIZE, reportRefUUID },
- GATT_PERMIT_READ,
- 0,
- hidReportRefKeyIn
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportLedOutProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidReportUUID },
- GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- &hidReportLedOut
- },
-
- {
- { ATT_BT_UUID_SIZE, reportRefUUID },
- GATT_PERMIT_READ,
- 0,
- hidReportRefLedOut
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportBootKeyInProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidBootKeyInputUUID },
- GATT_PERMIT_ENCRYPT_READ,
- 0,
- &hidReportBootKeyIn
- },
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- (uint8 *) &hidReportBootKeyInClientCharCfg
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportBootKeyOutProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidBootKeyOutputUUID },
- GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- &hidReportBootKeyOut
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportBootMouseInProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidBootMouseInputUUID },
- GATT_PERMIT_ENCRYPT_READ,
- 0,
- &hidReportBootMouseIn
- },
-
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- (uint8 *) &hidReportBootMouseInClientCharCfg
- },
-
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &hidReportFeatureProps
- },
-
- {
- { ATT_BT_UUID_SIZE, hidReportUUID},
- GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
- 0,
- &hidReportFeature
- },
-
- {
- { ATT_BT_UUID_SIZE, reportRefUUID },
- GATT_PERMIT_READ,
- 0,
- hidReportRefFeature
- },
- };
- enum
- {
- HID_SERVICE_IDX,
- HID_INCLUDED_SERVICE_IDX,
- HID_INFO_DECL_IDX,
- HID_INFO_IDX,
- HID_CONTROL_POINT_DECL_IDX,
- HID_CONTROL_POINT_IDX,
- HID_PROTOCOL_MODE_DECL_IDX,
- HID_PROTOCOL_MODE_IDX,
- HID_REPORT_MAP_DECL_IDX,
- HID_REPORT_MAP_IDX,
- HID_EXT_REPORT_REF_DESC_IDX,
- HID_REPORT_KEY_IN_DECL_IDX,
- HID_REPORT_KEY_IN_IDX,
- HID_REPORT_KEY_IN_CCCD_IDX,
- HID_REPORT_REF_KEY_IN_IDX,
- HID_REPORT_LED_OUT_DECL_IDX,
- HID_REPORT_LED_OUT_IDX,
- HID_REPORT_REF_LED_OUT_IDX,
- HID_BOOT_KEY_IN_DECL_IDX,
- HID_BOOT_KEY_IN_IDX,
- HID_BOOT_KEY_IN_CCCD_IDX,
- HID_BOOT_KEY_OUT_DECL_IDX,
- HID_BOOT_KEY_OUT_IDX,
- HID_BOOT_MOUSE_IN_DECL_IDX,
- HID_BOOT_MOUSE_IN_IDX,
- HID_BOOT_MOUSE_IN_CCCD_IDX,
- HID_FEATURE_DECL_IDX,
- HID_FEATURE_IDX,
- HID_REPORT_REF_FEATURE_IDX
- };
- CONST gattServiceCBs_t hidKbdCBs =
- {
- HidDev_ReadAttrCB,
- HidDev_WriteAttrCB,
- NULL
- };
- bStatus_t HidKbd_AddService( void )
- {
- uint8 status = SUCCESS;
-
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootMouseInClientCharCfg );
-
- status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ), &hidKbdCBs );
-
- Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
- &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );
-
-
-
- hidRptMap[0].id = hidReportRefKeyIn[0];
- hidRptMap[0].type = hidReportRefKeyIn[1];
- hidRptMap[0].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
- hidRptMap[0].cccdHandle = hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX].handle;
- hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;
-
- hidRptMap[1].id = hidReportRefLedOut[0];
- hidRptMap[1].type = hidReportRefLedOut[1];
- hidRptMap[1].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
- hidRptMap[1].cccdHandle = 0;
- hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;
-
-
- hidRptMap[2].id = hidReportRefKeyIn[0];
- hidRptMap[2].type = hidReportRefKeyIn[1];
- hidRptMap[2].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
- hidRptMap[2].cccdHandle = hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX].handle;
- hidRptMap[2].mode = HID_PROTOCOL_MODE_BOOT;
-
-
- hidRptMap[3].id = hidReportRefLedOut[0];
- hidRptMap[3].type = hidReportRefLedOut[1];
- hidRptMap[3].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
- hidRptMap[3].cccdHandle = 0;
- hidRptMap[3].mode = HID_PROTOCOL_MODE_BOOT;
-
- hidRptMap[4].id = HID_RPT_ID_MOUSE_IN;
- hidRptMap[4].type = HID_REPORT_TYPE_INPUT;
- hidRptMap[4].handle = hidAttrTbl[HID_BOOT_MOUSE_IN_IDX].handle;
- hidRptMap[4].cccdHandle = hidAttrTbl[HID_BOOT_MOUSE_IN_CCCD_IDX].handle;
- hidRptMap[4].mode = HID_PROTOCOL_MODE_BOOT;
-
- hidRptMap[5].id = hidReportRefFeature[0];
- hidRptMap[5].type = hidReportRefFeature[1];
- hidRptMap[5].handle = hidAttrTbl[HID_FEATURE_IDX].handle;
- hidRptMap[5].cccdHandle = 0;
- hidRptMap[5].mode = HID_PROTOCOL_MODE_REPORT;
-
- VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[6]) );
-
- HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );
- return ( status );
- }
- uint8 HidKbd_SetParameter( uint8 id, uint8 type, uint16 uuid, uint8 len, void *pValue )
- {
- bStatus_t ret = SUCCESS;
- switch ( uuid )
- {
- case REPORT_UUID:
- if ( type == HID_REPORT_TYPE_OUTPUT )
- {
- if ( len == 1 )
- {
- hidReportLedOut = *((uint8 *)pValue);
- }
- else
- {
- ret = ATT_ERR_INVALID_VALUE_SIZE;
- }
- }
- else if ( type == HID_REPORT_TYPE_FEATURE )
- {
- if ( len == 1 )
- {
- hidReportFeature = *((uint8 *)pValue);
- }
- else
- {
- ret = ATT_ERR_INVALID_VALUE_SIZE;
- }
- }
- else
- {
- ret = ATT_ERR_ATTR_NOT_FOUND;
- }
- break;
- case BOOT_KEY_OUTPUT_UUID:
- if ( len == 1 )
- {
- hidReportBootKeyOut = *((uint8 *)pValue);
- }
- else
- {
- ret = ATT_ERR_INVALID_VALUE_SIZE;
- }
- break;
- default:
-
- break;
- }
- return ( ret );
- }
- uint8 HidKbd_GetParameter( uint8 id, uint8 type, uint16 uuid, uint8 *pLen, void *pValue )
- {
- switch ( uuid )
- {
- case REPORT_UUID:
- if ( type == HID_REPORT_TYPE_OUTPUT )
- {
- *((uint8 *)pValue) = hidReportLedOut;
- *pLen = 1;
- }
- else if ( type == HID_REPORT_TYPE_FEATURE )
- {
- *((uint8 *)pValue) = hidReportFeature;
- *pLen = 1;
- }
- else
- {
- *pLen = 0;
- }
- break;
- case BOOT_KEY_OUTPUT_UUID:
- *((uint8 *)pValue) = hidReportBootKeyOut;
- *pLen = 1;
- break;
- default:
- *pLen = 0;
- break;
- }
- return ( SUCCESS );
- }
|