Skip to main content
AMETA.1
Visitor II
October 27, 2021
Question

hidSetDeviceDiscoverable returns BLE_STATUS_INVALID_ADV_FLAGS why ?

  • October 27, 2021
  • 0 replies
  • 535 views

Hey Team, iv had some issues trying to modify the BLE_HID_Peripheral example.

Iv modified the report descriptor and can confirm it works on another BLE ic.

The only things iv changed outside the report descriptor are just the config_hid function.

At hidSetDeviceDiscoverable it returns BLE_STATUS_INVALID_ADV_FLAGS

"  * @brief The discoverability flags in the advertising data are not coherent

 *     with the discoverability mode set in the advertising configuration"

but to my understanding here the hiddevice_init sets that up

//################################################
			//TEST
//###############################################
uint8_t Configure_HidPeripheral(void) 
{
 uint8_t ret;
 batteryService_Type battery;
 devInfService_Type devInf;
 hidService_Type hid;
 connParam_Type connParam;
 
 /* HID Peripheral Init */
 connParam.interval_min = 9;
 connParam.interval_max = 10;
 connParam.slave_latency = 0;
 connParam.timeout_multiplier = 300;
 /**
 * @brief Initializes the HID Device with Peripheral Role and
 * sets the public address.
 * @param IO_Capability Sets the device IO capabilities. Possible value are:
 * - IO_CAP_DISPLAY_ONLY
 * - IO_CAP_DISPLAY_YES_NO
 * - KEYBOARD_ONLY
 * - IO_CAP_NO_INPUT_NO_OUTPUT
 * - IO_CAP_KEYBOARD_DISPLAY
 * @param connParam Connection parameter to send to the
 * HID Host after bonding/service discovery
 * @param dev_name_len Device name length
 * @param dev_name Device name
 * @param identity_address_type The type of own adress. It must be one between
 * @ref PUBLIC_ADDR or @ref STATIC_RANDOM_ADDR.
 * @retval Status of the call.
 */
 ret = hidDevice_Init(IO_CAP_DISPLAY_ONLY, connParam, sizeof(dev_name), dev_name, STATIC_RANDOM_ADDR);
 if (ret != BLE_STATUS_SUCCESS) {
 PRINTF("Error in hidDevice_Init() 0x%02x\n", ret);
 return ret;
 }
 
 /* Set the HID Peripheral Security */
 /**
 * @brief Configures the device for LE Security Mode 1 and either Security Level 2 or 3
 * To set the Security Level 2 the MITM mode param shall be equal to FALSE, all the other params are ignored.
 * To set the Security Level 3 the MITM mode param shall be equal to TRUE, the other params shall be used to
 * signal if the device uses a fixed PIN or not.
 * @param MITM_Mode MITM mode. TRUE to set the security level 3, FALSE to set the security level 2
 * @param fixedPinUsed TRUE to use a fixed PIN, FALSE otherwise. If the MITM_Mode param is FALSE, this param is ignored
 * @param fixedPinValue PIN value
 * @retval Status of the call.
 */
 ret = hidSetDeviceSecurty(TRUE, TRUE, 123456);
 if (ret != BLE_STATUS_SUCCESS) {
 PRINTF("Error in hidSetDeviceSecurty() 0x%02x\n", ret);
 return ret;
 }
 
 /* Set the HID Idle Timeout */
 hidSetIdleTimeout(IDLE_CONNECTION_TIMEOUT);
 
 /* Set the TX Power */
 ret = aci_hal_set_tx_power_level(0, 24);
 if (ret != BLE_STATUS_SUCCESS) {
 PRINTF("Error with aci_hal_set_tx_power_level() 0x%02x\n", ret);
 return ret;
 }
 
 /**** Setup the GATT Database ****/
 
 /* Battery Service */
 battery.inReportMap = FALSE;
 
 /* Device Information Service */
 memcpy(devInf.manufacName, "ST Micro", 8);
 memcpy(devInf.modelNumber, "0001", 4);
 memcpy(devInf.fwRevision, "0630", 4);
 memcpy(devInf.swRevision, "0001", 4);
 devInf.pnpID[0] = 0x01;
 devInf.pnpID[1] = 0x30;
 devInf.pnpID[2] = 0x00;
 devInf.pnpID[3] = 0xfc;
 devInf.pnpID[4] = 0x00;
 devInf.pnpID[5] = 0xec;
 devInf.pnpID[6] = 0x00;
 
 
 /* HID Service */
 //hid = hid_param;
 
 
 hid.bootSupport 							= FALSE;			// no boot support
 hid.reportSupport					 		= FALSE;			// i would guess it would support a report characteristic
 hid.num_reports 							= NUM_REPORTS; // What defines the amount of reports characteristics ? (is it referring to byte allocation for the report ?)
 hid.reportReferenceDesc 					= reportReferenceDesc;
 hid.reportReferenceDesc[0].ID 			= REPORT_ID;
 hid.reportReferenceDesc[0].type 			= INPUT_REPORT;
 hid.reportReferenceDesc[1].ID 			= REPORT_ID;
 hid.reportReferenceDesc[1].type 			= OUTPUT_REPORT;
 hid.isBootDevKeyboard 					= FALSE;
 hid.isBootDevMouse 						= FALSE;
 hid.externalReportEnabled 				= FALSE; // not sure was 0
 hid.includedServiceEnabled 				= FALSE;
 hid.informationCharac[0] 					= 0x01;
 hid.informationCharac[1] 					= 0x01;
 hid.informationCharac[2] 					= 0;
 hid.informationCharac[3] 					= 0x01;
 
 hid.reportDescLen = sizeof(reportDesc);		 /** Report Descriptor length */
 hid.reportDesc = reportDesc;						/** Report Descriptor */
 
 
 
 //#########################
 	 	//adds all services
// Adds the Primary service and the characteristics associated
// * for the battery, device information and hid services.
 //#########################
 ret = hidAddServices(&battery, &devInf, &hid);
 if (ret != BLE_STATUS_SUCCESS) {
 PRINTF("Error in hidAddServices() 0x%02x\n for &battery ", ret);
 return ret;
 }
 
 //#########################
 	 	//discoverable
 //#########################
 /* Set the HID Peripheral device discoverable */
 /**
 * @brief Starts the peripheral device discoverable mode. This mode is ended
 * when either the upper layer issues a command to terminate the procedure
 * using the command hidTerminateDiscoverableMode() or the
 * timeout happens (timeout value is 180 s).
 * @param mode Discoverable mode to use:
 * - LIMITED_DISCOVERABLE_MODE
 * - GENERAL_DISCOVERABLE_MODE
 * @param nameLen Local name length. Max 20
 * @param name Local name value
 * @retval Status of the
 */
 ret = hidSetDeviceDiscoverable(LIMITED_DISCOVERABLE_MODE, sizeof(dev_name), dev_name);
 if (ret != BLE_STATUS_SUCCESS) {
 PRINTF("Error in hidSetDeviceDiscoverable() 0x%02x\n", ret);
 return ret;
 }
 
 PRINTF("HID gamepad Configured\n");
 
 BSP_LED_Off(BSP_LED1);
 
 /* Button Init */
 BSP_PB_Init(USER_BUTTON, BUTTON_MODE_EXTI);
 
 return BLE_STATUS_SUCCESS;
}

Main:

int main(void)
{
 uint8_t ret;
 
 /* System initialization function */
 if (SystemInit(SYSCLK_64M, BLE_SYSCLK_32M) != SUCCESS) 
 {
 /* Error during system clock configuration take appropriate action */
 while(1);
 } 
 /* Configure IOs for pwer save modes */
 BSP_IO_Init();
 
 /* Configure I/O communication channel */
 BSP_COM_Init(BSP_COM_RxDataUserCb);
 
 /* BlueNRG-LP stack init */
 
 /* Application demo Led Init 
 BSP_LED1 = Sensor configuration led 
 BSP_LED3 = Connection led
 */
 BSP_LED_Init(BSP_LED1);
 BSP_LED_Init(BSP_LED2); // Led on when not sleeping
 BSP_LED_Init(BSP_LED3);
 BSP_LED_On(BSP_LED1);
 BSP_LED_On(BSP_LED2);
 BSP_LED_Off(BSP_LED3);
 
 
 /* Clock Init */
 Clock_Init();
 
 ModulesInit(); 
 
 /* Set HID Service params */
 //setDefaultHidParams();
 /* Configure HID Peripheral and put the device in discoverable mode */
 ret = Configure_HidPeripheral();
 if (ret != BLE_STATUS_SUCCESS) {
 PRINTF("Error in configure_hid_peripheral() 0x%02x\n", ret);
 }
 
 while(1) {
 
 ModulesTick();
 
 /* Application Tick */
 APP_Tick();
 
 /* Device Power Save Management Procedures */
 //DevicePowerSaveProcedure();
 }
}

This topic has been closed for replies.