/*********************************************************************
 * @fn      HidKbM_AddService
 *
 * @brief   Initializes the HID Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t HidKbM_AddService( void )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportMouseInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportCCInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootMouseInClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ), &hidKbdMsCBs );

  // Set up included service
  Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
                     &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );

  // Construct map of reports to characteristic handles
  // Each report is uniquely identified via its ID and type

  // Mouse input report
  hidRptMap[0].id = hidReportRefMouseIn[0];
  hidRptMap[0].type = hidReportRefMouseIn[1];
  hidRptMap[0].handle = hidAttrTbl[HID_REPORT_MOUSE_IN_IDX].handle;
  hidRptMap[0].cccdHandle = hidAttrTbl[HID_REPORT_MOUSE_IN_CCCD_IDX].handle;
  hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;

  // Key input report
  hidRptMap[1].id = hidReportRefKeyIn[0];
  hidRptMap[1].type = hidReportRefKeyIn[1];
  hidRptMap[1].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
  hidRptMap[1].cccdHandle = hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX].handle;
  hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;

  // Consumer Control input report
  hidRptMap[2].id = hidReportRefCCIn[0];
  hidRptMap[2].type = hidReportRefCCIn[1];
  hidRptMap[2].handle = hidAttrTbl[HID_REPORT_CC_IN_IDX].handle;
  hidRptMap[2].cccdHandle = hidAttrTbl[HID_REPORT_CC_IN_CCCD_IDX].handle;
  hidRptMap[2].mode = HID_PROTOCOL_MODE_REPORT;

  // LED output report
  hidRptMap[3].id = hidReportRefLedOut[0];
  hidRptMap[3].type = hidReportRefLedOut[1];
  hidRptMap[3].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
  hidRptMap[3].cccdHandle = 0;
  hidRptMap[3].mode = HID_PROTOCOL_MODE_REPORT;

  // Boot keyboard input report
  // Use same ID and type as key input report
  hidRptMap[4].id = hidReportRefKeyIn[0];
  hidRptMap[4].type = hidReportRefKeyIn[1];
  hidRptMap[4].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
  hidRptMap[4].cccdHandle = hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX].handle;
  hidRptMap[4].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot keyboard output report
  // Use same ID and type as LED output report
  hidRptMap[5].id = hidReportRefLedOut[0];
  hidRptMap[5].type = hidReportRefLedOut[1];
  hidRptMap[5].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
  hidRptMap[5].cccdHandle = 0;
  hidRptMap[5].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot mouse input report
  hidRptMap[6].id = HID_RPT_ID_MOUSE_IN;
  hidRptMap[6].type = HID_REPORT_TYPE_INPUT;
  hidRptMap[6].handle = hidAttrTbl[HID_BOOT_MOUSE_IN_IDX].handle;
  hidRptMap[6].cccdHandle = hidAttrTbl[HID_BOOT_MOUSE_IN_CCCD_IDX].handle;
  hidRptMap[6].mode = HID_PROTOCOL_MODE_BOOT;

  // Feature report
  hidRptMap[7].id = hidReportRefFeature[0];
  hidRptMap[7].type = hidReportRefFeature[1];
  hidRptMap[7].handle = hidAttrTbl[HID_FEATURE_IDX].handle;
  hidRptMap[7].cccdHandle = 0;
  hidRptMap[7].mode = HID_PROTOCOL_MODE_REPORT;

  // Battery level input report
  VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[8]) );

  // Setup report ID map
  HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );

  return ( status );
}
Example #2
0
/*********************************************************************
 * @fn      HidKbd_AddService
 *
 * @brief   Initializes the HID Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t HidKbd_AddService( void )
{
  uint8 status;

  // Allocate Client Charateristic Configuration tables.
  hidReportKeyInClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                 linkDBNumConns);
  
  if (hidReportKeyInClientCharCfg == NULL)
  {
    return ( bleMemAllocError );
  }
  
  hidReportBootKeyInClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                     linkDBNumConns);
  
  if (hidReportBootKeyInClientCharCfg == NULL)
  {
    osal_mem_free(hidReportKeyInClientCharCfg);
    
    return ( bleMemAllocError );
  }
  
  hidReportBootMouseInClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                       linkDBNumConns);
  if (hidReportBootMouseInClientCharCfg == NULL)
  {     
    osal_mem_free(hidReportKeyInClientCharCfg);
    
    osal_mem_free(hidReportBootKeyInClientCharCfg);
    
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootMouseInClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ),
                                        GATT_MAX_ENCRYPT_KEY_SIZE, &hidKbdCBs );

  // Set up included service
  Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
                     &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );

  // Construct map of reports to characteristic handles
  // Each report is uniquely identified via its ID and type

  // Key input report
  hidRptMap[0].id = hidReportRefKeyIn[0];
  hidRptMap[0].type = hidReportRefKeyIn[1];
  hidRptMap[0].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
  hidRptMap[0].pCccdAttr = &hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX];
  hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;

  // LED output report
  hidRptMap[1].id = hidReportRefLedOut[0];
  hidRptMap[1].type = hidReportRefLedOut[1];
  hidRptMap[1].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
  hidRptMap[1].pCccdAttr = NULL;
  hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;

  // Boot keyboard input report
  // Use same ID and type as key input report
  hidRptMap[2].id = hidReportRefKeyIn[0];
  hidRptMap[2].type = hidReportRefKeyIn[1];
  hidRptMap[2].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
  hidRptMap[2].pCccdAttr = &hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX];
  hidRptMap[2].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot keyboard output report
  // Use same ID and type as LED output report
  hidRptMap[3].id = hidReportRefLedOut[0];
  hidRptMap[3].type = hidReportRefLedOut[1];
  hidRptMap[3].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
  hidRptMap[3].pCccdAttr = NULL;
  hidRptMap[3].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot mouse input report
  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].pCccdAttr = &hidAttrTbl[HID_BOOT_MOUSE_IN_CCCD_IDX];
  hidRptMap[4].mode = HID_PROTOCOL_MODE_BOOT;

  // Feature report
  hidRptMap[5].id = hidReportRefFeature[0];
  hidRptMap[5].type = hidReportRefFeature[1];
  hidRptMap[5].handle = hidAttrTbl[HID_FEATURE_IDX].handle;
  hidRptMap[5].pCccdAttr = NULL;
  hidRptMap[5].mode = HID_PROTOCOL_MODE_REPORT;

  // Battery level input report
  VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[6]) );

  // Setup report ID map
  HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );

  return ( status );
}