1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432 |
- #include "OSAL.h"
- #include "gatt.h"
- #include "hci.h"
- #include "gapgattserver.h"
- #include "gattservapp.h"
- #include "gatt_uuid.h"
- #include "gatt_profile_uuid.h"
- #include "linkdb.h"
- #include "peripheral.h"
- #include "gapbondmgr.h"
- #include "devinfoservice.h"
- #include "battservice.h"
- #include "scanparamservice.h"
- #include "hiddev.h"
- #include "hidkbd.h"
- #include "hidkbdservice.h"
- #include "log.h"
- #define DEFAULT_BATT_PERIOD 15000
- #define DEFAULT_SCAN_PARAM_NOTIFY_TEST TRUE
- #define HID_INITIAL_ADV_INT_MIN 48
- #define HID_INITIAL_ADV_INT_MAX 80
- #define HID_HIGH_ADV_INT_MIN 32
- #define HID_HIGH_ADV_INT_MAX 48
- #define HID_LOW_ADV_INT_MIN 1600
- #define HID_LOW_ADV_INT_MAX 1600
- #define HID_INITIAL_ADV_TIMEOUT 60
- #define HID_HIGH_ADV_TIMEOUT 5
- #define HID_LOW_ADV_TIMEOUT 0
- #define START_DEVICE_EVT 0x0001
- #define BATT_PERIODIC_EVT 0x0002
- #define HID_IDLE_EVT 0x0004
- #define HID_SEND_REPORT_EVT 0x0008
- #define reportQEmpty() ( firstQIdx == lastQIdx )
- #define HID_DEV_DATA_LEN 8
- #ifdef HID_DEV_RPT_QUEUE_LEN
- #define HID_DEV_REPORT_Q_SIZE (HID_DEV_RPT_QUEUE_LEN+1)
- #else
- #define HID_DEV_REPORT_Q_SIZE (10+1)
- #endif
- typedef struct
- {
- uint8 id;
- uint8 type;
- uint8 len;
- uint8 data[HID_DEV_DATA_LEN];
- } hidDevReport_t;
- uint8 hidDevTaskId;
- extern hidRptMap_t hidRptMap[];
- gaprole_States_t hidDevGapState = GAPROLE_INIT;
- static uint8 hidDevConnSecure = FALSE;
- uint16 gapConnHandle;
- static uint8 hidDevPairingStarted = FALSE;
- static uint8 pairingStatus = SUCCESS;
- static hidRptMap_t *pHidDevRptTbl;
- static uint8 hidDevRptTblLen;
- static hidDevCB_t *pHidDevCB;
- static hidDevCfg_t *pHidDevCfg;
- static uint8 updateConnParams = TRUE;
- static uint8 firstQIdx = 0;
- static uint8 lastQIdx = 0;
- static hidDevReport_t hidDevReportQ[HID_DEV_REPORT_Q_SIZE];
- static attHandleValueNoti_t lastNoti = { 0 };
- static void hidDev_ProcessOSALMsg( osal_event_hdr_t *pMsg );
- static void hidDevProcessGattMsg( gattMsgEvent_t *pMsg );
- static void hidDevDisconnected( void );
- static void hidDevGapStateCB( gaprole_States_t newState );
- static void hidDevPairStateCB( uint16 connHandle, uint8 state, uint8 status );
- static void hidDevPasscodeCB( uint8 *deviceAddr, uint16 connectionHandle,
- uint8 uiInputs, uint8 uiOutputs );
- void hidDevBattCB( uint8 event );
- void hidDevScanParamCB( uint8 event );
- static void hidDevBattPeriodicTask( void );
- static hidRptMap_t *hidDevRptByHandle( uint16 handle );
- static hidRptMap_t *hidDevRptById( uint8 id, uint8 type );
- static hidRptMap_t *hidDevRptByCccdHandle( uint16 handle );
- static void hidDevEnqueueReport( uint8 id, uint8 type, uint8 len, uint8 *pData );
- static hidDevReport_t *hidDevDequeueReport( void );
- static void hidDevSendReport( uint8 id, uint8 type, uint8 len, uint8 *pData );
- static void hidDevHighAdvertising( void );
- static void hidDevLowAdvertising( void );
- static void hidDevInitialAdvertising( void );
- static uint8 hidDevBondCount( void );
- static void hidDevStartIdleTimer( void );
- static void hidDevStopIdleTimer( void );
- static void HidDev_scanParamCB(uint8_t event);
- static gapRolesCBs_t hidDev_PeripheralCBs =
- {
- hidDevGapStateCB,
- NULL
- };
- static const gapBondCBs_t hidDevBondCB =
- {
- hidDevPasscodeCB,
- hidDevPairStateCB
- };
- void HidDev_Init( uint8 task_id )
- {
- hidDevTaskId = task_id;
-
- {
- uint8 syncWL = FALSE;
-
-
-
-
- VOID GAPBondMgr_SetParameter( GAPBOND_AUTO_SYNC_WL, sizeof( uint8 ), &syncWL );
- }
-
- GGS_AddService( GATT_ALL_SERVICES );
- GATTServApp_AddService( GATT_ALL_SERVICES );
- DevInfo_AddService( );
- Batt_AddService();
- ScanParam_AddService();
-
- Batt_Register(NULL);
-
-
- ScanParam_Register(HidDev_scanParamCB);
-
-
-
-
- osal_set_event( hidDevTaskId, START_DEVICE_EVT );
- }
- uint16 HidDev_ProcessEvent( uint8 task_id, uint16 events )
- {
- VOID task_id;
- LOG("%s\n",__FUNCTION__);
- if ( events & SYS_EVENT_MSG )
- {
- uint8 *pMsg;
- if ( (pMsg = osal_msg_receive( hidDevTaskId )) != NULL )
- {
- hidDev_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
-
- VOID osal_msg_deallocate( pMsg );
- }
-
- return (events ^ SYS_EVENT_MSG);
- }
- if ( events & START_DEVICE_EVT )
- {
-
- VOID GAPRole_StartDevice( &hidDev_PeripheralCBs );
-
- GAPBondMgr_Register( (gapBondCBs_t *) &hidDevBondCB );
- GAPBondMgr_SetParameter(GAPBOND_ERASE_ALLBONDS,0,NULL);
- LOG("start Device EVT\n\r");
-
- return ( events ^ START_DEVICE_EVT );
- }
- if ( events & HID_IDLE_EVT )
- {
- if ( hidDevGapState == GAPROLE_CONNECTED )
- {
-
- if ( hidDevPairingStarted )
- {
- hidDevStartIdleTimer();
- LOG("hidDevStartIdleTimer \n\r");
- }
-
- else
- {
- GAPRole_TerminateConnection();
- }
- }
- return ( events ^ HID_IDLE_EVT );
- }
- if ( events & BATT_PERIODIC_EVT )
- {
-
- hidDevBattPeriodicTask();
- return ( events ^ BATT_PERIODIC_EVT );
- }
- if ( events & HID_SEND_REPORT_EVT )
- {
-
- if ( hidDevConnSecure )
- {
- LOG("Send Hid Report\n\r");
- hidDevReport_t *pReport = hidDevDequeueReport();
- if ( pReport != NULL )
- {
-
- hidDevSendReport( pReport->id, pReport->type, pReport->len, pReport->data );
- }
- return ( reportQEmpty() ? events ^ HID_SEND_REPORT_EVT : events );
- }
- return ( events ^ HID_SEND_REPORT_EVT );
- }
- return 0;
- }
- void HidDev_Register( hidDevCfg_t *pCfg, hidDevCB_t *pCBs )
- {
- pHidDevCB = pCBs;
- pHidDevCfg = pCfg;
- }
- void HidDev_RegisterReports( uint8 numReports, hidRptMap_t *pRpt )
- {
- pHidDevRptTbl = pRpt;
- hidDevRptTblLen = numReports;
- }
- void HidDev_Report( uint8 id, uint8 type, uint8 len, uint8*pData )
- {
-
- if ( hidDevGapState == GAPROLE_CONNECTED )
- {
-
- if ( hidDevConnSecure )
- {
-
- if ( reportQEmpty() )
- {
-
- hidDevSendReport( id, type, len, pData );
-
- LOG("send key action\n\r");
- return;
- }
- }
- }
-
- else if ( hidDevGapState != GAPROLE_ADVERTISING )
- {
-
- if ( hidDevBondCount() > 0 )
- {
-
- hidDevHighAdvertising();
- }
-
- else
- {
-
- hidDevInitialAdvertising();
- }
- }
-
- hidDevEnqueueReport( id, type, len, pData );
- }
- void HidDev_Close( void )
- {
- uint8 param;
-
- if ( hidDevGapState == GAPROLE_CONNECTED )
- {
- GAPRole_TerminateConnection();
- }
-
- else
- {
- param = FALSE;
- GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), ¶m );
- }
- }
- bStatus_t HidDev_SetParameter( uint8 param, uint8 len, void *pValue )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- case HIDDEV_ERASE_ALLBONDS:
- if ( len == 0 )
- {
-
- if ( osal_isbufset( lastNoti.value, 0x00, lastNoti.len ) == FALSE )
- {
-
-
- osal_memset( lastNoti.value, 0x00, lastNoti.len );
- GATT_Notification( gapConnHandle, &lastNoti, FALSE );
- }
-
- if ( hidDevGapState == GAPROLE_CONNECTED )
- {
- GAPRole_TerminateConnection();
- }
-
- firstQIdx = lastQIdx = 0;
-
- GAPBondMgr_SetParameter( GAPBOND_ERASE_ALLBONDS, 0, NULL );
- }
- else
- {
- ret = bleInvalidRange;
- }
- break;
- default:
- ret = INVALIDPARAMETER;
- break;
- }
- return ( ret );
- }
- bStatus_t HidDev_GetParameter( uint8 param, void *pValue )
- {
- bStatus_t ret = SUCCESS;
- switch ( param )
- {
- default:
- ret = INVALIDPARAMETER;
- break;
- }
- return ( ret );
- }
- void HidDev_PasscodeRsp( uint8 status, uint32 passcode )
- {
-
- GAPBondMgr_PasscodeRsp( gapConnHandle, status, passcode );
- }
- uint8 HidDev_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
- {
- bStatus_t status = SUCCESS;
- hidRptMap_t *pRpt;
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
-
- if ( offset > 0 && uuid != REPORT_MAP_UUID )
- {
- return ( ATT_ERR_ATTR_NOT_LONG );
- }
- if ( uuid == REPORT_UUID ||
- uuid == BOOT_KEY_INPUT_UUID ||
- uuid == BOOT_KEY_OUTPUT_UUID ||
- uuid == BOOT_MOUSE_INPUT_UUID )
- {
-
- if ( (pRpt = hidDevRptByHandle(pAttr->handle)) != NULL )
- {
-
- status = (*pHidDevCB->reportCB)( pRpt->id, pRpt->type, uuid,
- HID_DEV_OPER_READ, pLen, pValue );
- }
- else
- {
- *pLen = 0;
- }
- }
- else if ( uuid == REPORT_MAP_UUID )
- {
-
- if ( offset >= hidReportMapLen )
- {
- status = ATT_ERR_INVALID_OFFSET;
- }
- else
- {
-
- *pLen = MIN( maxLen, (hidReportMapLen - offset) );
-
- osal_memcpy( pValue, pAttr->pValue + offset, *pLen );
- }
- }
- else if ( uuid == HID_INFORMATION_UUID )
- {
- *pLen = HID_INFORMATION_LEN;
- osal_memcpy( pValue, pAttr->pValue, HID_INFORMATION_LEN );
- }
- else if ( uuid == GATT_REPORT_REF_UUID )
- {
- *pLen = HID_REPORT_REF_LEN;
- osal_memcpy( pValue, pAttr->pValue, HID_REPORT_REF_LEN );
- }
- else if ( uuid == PROTOCOL_MODE_UUID )
- {
- *pLen = HID_PROTOCOL_MODE_LEN;
- pValue[0] = pAttr->pValue[0];
- }
- else if ( uuid == GATT_EXT_REPORT_REF_UUID )
- {
- *pLen = HID_EXT_REPORT_REF_LEN;
- osal_memcpy( pValue, pAttr->pValue, HID_EXT_REPORT_REF_LEN );
- }
-
- if ( status == SUCCESS )
- {
- hidDevStartIdleTimer();
- }
- return ( status );
- }
- bStatus_t HidDev_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
- uint8 *pValue, uint8 len, uint16 offset )
- {
- bStatus_t status = SUCCESS;
- hidRptMap_t *pRpt;
-
- if ( offset > 0 )
- {
- return ( ATT_ERR_ATTR_NOT_LONG );
- }
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
- if ( uuid == REPORT_UUID ||
- uuid == BOOT_KEY_OUTPUT_UUID )
- {
-
- if ((pRpt = hidDevRptByHandle(pAttr->handle)) != NULL)
- {
-
- status = (*pHidDevCB->reportCB)( pRpt->id, pRpt->type, uuid,
- HID_DEV_OPER_WRITE, &len, pValue );
- }
- }
- else if ( uuid == HID_CTRL_PT_UUID )
- {
-
- if ( len == 1 )
- {
- if ( pValue[0] == HID_CMD_SUSPEND || pValue[0] == HID_CMD_EXIT_SUSPEND )
- {
-
- (*pHidDevCB->evtCB)( (pValue[0] == HID_CMD_SUSPEND) ?
- HID_DEV_SUSPEND_EVT : HID_DEV_EXIT_SUSPEND_EVT );
- }
- 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 );
- if ( status == SUCCESS )
- {
- uint16 charCfg = BUILD_UINT16( pValue[0], pValue[1] );
-
- if ( (pRpt = hidDevRptByCccdHandle(pAttr->handle)) != NULL )
- {
-
- if(hidRptMap[5].cccdHandle==pRpt->cccdHandle)
- {
- LOG("Audio cfg%4X\n\r",charCfg);
- }
-
- (*pHidDevCB->reportCB)( pRpt->id, pRpt->type, uuid,
- (charCfg == GATT_CLIENT_CFG_NOTIFY) ?
- HID_DEV_OPER_ENABLE : HID_DEV_OPER_DISABLE,
- &len, pValue );
- }
- }
- }
- else if ( uuid == PROTOCOL_MODE_UUID )
- {
- if ( len == HID_PROTOCOL_MODE_LEN )
- {
- if ( pValue[0] == HID_PROTOCOL_MODE_BOOT ||
- pValue[0] == HID_PROTOCOL_MODE_REPORT )
- {
- pAttr->pValue[0] = pValue[0];
-
- (*pHidDevCB->evtCB)( (pValue[0] == HID_PROTOCOL_MODE_BOOT) ?
- HID_DEV_SET_BOOT_EVT : HID_DEV_SET_REPORT_EVT );
- }
- else
- {
- status = ATT_ERR_INVALID_VALUE;
- }
- }
- else
- {
- status = ATT_ERR_INVALID_VALUE_SIZE;
- }
- }
-
- if (status == SUCCESS)
- {
- hidDevStartIdleTimer();
- }
- return ( status );
- }
- static void hidDev_ProcessOSALMsg( osal_event_hdr_t *pMsg )
- {
- switch ( pMsg->event )
- {
- case GATT_MSG_EVENT:
- hidDevProcessGattMsg( (gattMsgEvent_t *) pMsg );
- break;
- default:
- break;
- }
- }
- static void hidDevProcessGattMsg( gattMsgEvent_t *pMsg )
- {
- }
- static void hidDevHandleConnStatusCB( uint16 connHandle, uint8 changeType )
- {
- uint8 i;
- hidRptMap_t *p = pHidDevRptTbl;
- uint16 retHandle;
- gattAttribute_t *pAttr;
-
- if ( connHandle != LOOPBACK_CONNHANDLE )
- {
- if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED ) ||
- ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
- ( !linkDB_Up( connHandle ) ) ) )
- {
- for ( i = hidDevRptTblLen; i > 0; i--, p++ )
- {
- if ( p->cccdHandle != 0 )
- {
- if ( (pAttr = GATT_FindHandle(p->cccdHandle, &retHandle)) != NULL )
- {
- GATTServApp_InitCharCfg( connHandle, (gattCharCfg_t *) pAttr->pValue );
- }
- }
- }
- }
- }
- }
- static void hidDevDisconnected( void )
- {
-
- hidDevStopIdleTimer();
-
- Batt_HandleConnStatusCB( gapConnHandle, LINKDB_STATUS_UPDATE_REMOVED );
-
- hidDevHandleConnStatusCB( gapConnHandle, LINKDB_STATUS_UPDATE_REMOVED );
-
- hidDevConnSecure = FALSE;
- hidProtocolMode = HID_PROTOCOL_MODE_REPORT;
- hidDevPairingStarted = FALSE;
-
- osal_memset( &lastNoti, 0, sizeof( attHandleValueNoti_t ) );
-
- if ( ( hidDevBondCount() > 0 ) &&
- ( pHidDevCfg->hidFlags & HID_FLAGS_NORMALLY_CONNECTABLE ) )
- {
- hidDevLowAdvertising();
- }
- }
- void hidDevGapStateCB( gaprole_States_t newState )
- {
- LOG("%s, %d\n",__FUNCTION__, newState);
-
- if ( newState == GAPROLE_CONNECTED )
- {
-
- GAPRole_GetParameter( GAPROLE_CONNHANDLE, &gapConnHandle );
-
- hidDevConnSecure = FALSE;
-
- uint8 param = FALSE;
- GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), ¶m );
- uint8 peerAddress[B_ADDR_LEN];
- GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress);
- LOG("Master Mac:%02X,%02X,%02X,%02X,%02X,%02X\n\r",peerAddress[5],peerAddress[4],peerAddress[3],peerAddress[2],peerAddress[1],peerAddress[0]);
-
-
-
- hidDevStartIdleTimer();
- }
-
- else if ( hidDevGapState == GAPROLE_CONNECTED &&
- newState != GAPROLE_CONNECTED )
- {
-
- hidDevDisconnected();
- updateConnParams = TRUE;
- if ( pairingStatus == SMP_PAIRING_FAILED_CONFIRM_VALUE )
- {
-
- hidDevInitialAdvertising();
- pairingStatus = SUCCESS;
- }
- }
-
- else if ( newState == GAPROLE_STARTED )
- {
-
- }
- hidDevGapState = newState;
- }
- static void hidDevPairStateCB( uint16 connHandle, uint8 state, uint8 status )
- {
- if ( state == GAPBOND_PAIRING_STATE_STARTED )
- {
- hidDevPairingStarted = TRUE;
- }
- else if ( state == GAPBOND_PAIRING_STATE_COMPLETE )
- {
- hidDevPairingStarted = FALSE;
- if ( status == SUCCESS )
- {
- hidDevConnSecure = TRUE;
- LOG("Pair Success\n\r");
-
- }
- else
- {
- LOG("Pair Fail\n\r");
- }
- pairingStatus = status;
- }
- else if ( state == GAPBOND_PAIRING_STATE_BONDED )
- {
- if ( status == SUCCESS )
- {
- hidDevConnSecure = TRUE;
- }
- }
- if ( !reportQEmpty() && hidDevConnSecure )
- {
- LOG("Set Send Report EVENT\n\r");
-
- osal_set_event( hidDevTaskId, HID_SEND_REPORT_EVT );
- }
- }
- void hidDevPasscodeCB( uint8 *deviceAddr, uint16 connectionHandle,
- uint8 uiInputs, uint8 uiOutputs )
- {
- if ( pHidDevCB && pHidDevCB->passcodeCB )
- {
-
- (*pHidDevCB->passcodeCB)( deviceAddr, connectionHandle, uiInputs, uiOutputs );
- }
- else
- {
-
- GAPBondMgr_PasscodeRsp( connectionHandle, SUCCESS, 0 );
- }
- }
- void hidDevBattCB( uint8 event )
- {
- if ( event == BATT_LEVEL_NOTI_ENABLED )
- {
-
- if ( hidDevGapState == GAPROLE_CONNECTED )
- {
- osal_start_timerEx( hidDevTaskId, BATT_PERIODIC_EVT, DEFAULT_BATT_PERIOD );
- }
- }
- else if ( event == BATT_LEVEL_NOTI_DISABLED )
- {
-
- osal_stop_timerEx( hidDevTaskId, BATT_PERIODIC_EVT );
- }
- }
- void hidDevScanParamCB( uint8 event )
- {
- }
- static void hidDevBattPeriodicTask( void )
- {
- if ( hidDevGapState == GAPROLE_CONNECTED )
- {
-
- Batt_MeasLevel( );
-
- osal_start_timerEx( hidDevTaskId, BATT_PERIODIC_EVT, DEFAULT_BATT_PERIOD );
- }
- }
- static hidRptMap_t *hidDevRptByHandle( uint16 handle )
- {
- uint8 i;
- hidRptMap_t *p = pHidDevRptTbl;
- for ( i = hidDevRptTblLen; i > 0; i--, p++ )
- {
- if ( p->handle == handle && p->mode == hidProtocolMode)
- {
- return p;
- }
- }
- return NULL;
- }
- static hidRptMap_t *hidDevRptByCccdHandle( uint16 handle )
- {
- uint8 i;
- hidRptMap_t *p = pHidDevRptTbl;
- for ( i = hidDevRptTblLen; i > 0; i--, p++ )
- {
- if ( p->cccdHandle == handle)
- {
- if(i==HID_VOICE_START_IN_CCCD_IDX)
- {
- LOG("Voice Notify Enable!!!!!\n\r");
- }
- return p;
- }
- }
- return NULL;
- }
- static hidRptMap_t *hidDevRptById( uint8 id, uint8 type )
- {
- uint8 i;
- hidRptMap_t *p = pHidDevRptTbl;
- for ( i = hidDevRptTblLen; i > 0; i--, p++ )
- {
- if ( p->id == id && p->type == type && p->mode == hidProtocolMode )
- {
- return p;
- }
- }
- return NULL;
- }
- static void hidDevSendReport( uint8 id, uint8 type, uint8 len, uint8 *pData )
- {
- hidRptMap_t *pRpt;
- gattAttribute_t *pAttr;
- uint16 retHandle;
- LOG("%s\n",__FUNCTION__);
-
- if ( (pRpt = hidDevRptById(id, type)) != NULL )
- {
-
- if ( (pAttr = GATT_FindHandle(pRpt->cccdHandle, &retHandle)) != NULL )
- {
- uint16 value;
- value = GATTServApp_ReadCharCfg( gapConnHandle, (gattCharCfg_t *) pAttr->pValue );
- if ( value & GATT_CLIENT_CFG_NOTIFY )
- {
-
-
- if ( updateConnParams )
- {
- GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_REQ, sizeof( uint8 ), &updateConnParams );
- updateConnParams = FALSE;
- }
-
- lastNoti.handle = pRpt->handle;
- lastNoti.len = len;
- osal_memcpy(lastNoti.value, pData, len);
- GATT_Notification( gapConnHandle, &lastNoti, FALSE );
-
- hidDevStartIdleTimer();
- }
- else
- {
- LOG("notify fail\n\r");
- }
- }
- }
- }
- static void hidDevEnqueueReport( uint8 id, uint8 type, uint8 len, uint8 *pData )
- {
-
- if ( hidDevBondCount() > 0 )
- {
-
- lastQIdx = ( lastQIdx + 1 ) % HID_DEV_REPORT_Q_SIZE;
- if ( lastQIdx == firstQIdx )
- {
-
- firstQIdx = ( firstQIdx + 1 ) % HID_DEV_REPORT_Q_SIZE;
- }
-
- hidDevReportQ[lastQIdx].id = id;
- hidDevReportQ[lastQIdx].type = type;
- hidDevReportQ[lastQIdx].len = len;
- osal_memcpy( hidDevReportQ[lastQIdx].data, pData, len );
- if ( hidDevConnSecure )
- {
-
- osal_set_event( hidDevTaskId, HID_SEND_REPORT_EVT );
- }
- }
- }
- static hidDevReport_t *hidDevDequeueReport( void )
- {
- if ( reportQEmpty() )
- {
- return NULL;
- }
-
- firstQIdx = ( firstQIdx + 1 ) % HID_DEV_REPORT_Q_SIZE;
- return ( &(hidDevReportQ[firstQIdx]) );
- }
- static void hidDevHighAdvertising( void )
- {
- uint8 param;
- VOID GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, HID_HIGH_ADV_INT_MIN );
- VOID GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, HID_HIGH_ADV_INT_MAX );
- VOID GAP_SetParamValue( TGAP_LIM_ADV_TIMEOUT, HID_HIGH_ADV_TIMEOUT );
-
- param = GAP_FILTER_POLICY_WHITE;
- VOID GAPRole_SetParameter( GAPROLE_ADV_FILTER_POLICY, sizeof( uint8 ), ¶m );
- param = TRUE;
- GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), ¶m );
- }
- static void hidDevLowAdvertising( void )
- {
- uint8 param;
- VOID GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, HID_LOW_ADV_INT_MIN );
- VOID GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, HID_LOW_ADV_INT_MAX );
- VOID GAP_SetParamValue( TGAP_LIM_ADV_TIMEOUT, HID_LOW_ADV_TIMEOUT );
-
- param = GAP_FILTER_POLICY_ALL;
- VOID GAPRole_SetParameter( GAPROLE_ADV_FILTER_POLICY, sizeof( uint8 ), ¶m );
- param = TRUE;
- VOID GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), ¶m );
- }
- static void hidDevInitialAdvertising( void )
- {
- uint8 param;
- VOID GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, HID_INITIAL_ADV_INT_MIN );
- VOID GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, HID_INITIAL_ADV_INT_MAX );
- VOID GAP_SetParamValue( TGAP_LIM_ADV_TIMEOUT, HID_INITIAL_ADV_TIMEOUT );
-
- param = GAP_FILTER_POLICY_ALL;
- VOID GAPRole_SetParameter( GAPROLE_ADV_FILTER_POLICY, sizeof( uint8 ), ¶m );
- param = TRUE;
- VOID GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), ¶m );
- }
- static uint8 hidDevBondCount( void )
- {
- uint8 bondCnt = 0;
- VOID GAPBondMgr_GetParameter( GAPBOND_BOND_COUNT, &bondCnt );
- return ( bondCnt );
- }
- static void hidDevStartIdleTimer( void )
- {
- if ( pHidDevCfg->idleTimeout > 0 )
- {
- osal_start_timerEx( hidDevTaskId, HID_IDLE_EVT, pHidDevCfg->idleTimeout );
- }
- }
- static void hidDevStopIdleTimer( void )
- {
- osal_stop_timerEx( hidDevTaskId, HID_IDLE_EVT );
- }
- static void HidDev_scanParamCB(uint8_t event)
- {
-
- }
|