Catch scan request on KW45

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Catch scan request on KW45

623 次查看
Liwa
Contributor I

Hello,

I'm working on on a KW45 based board, I'm working on BLE ADV, I want to test if a scan request is reveived, then I will send the ADV data with the scan response, but i could not find a way to check if a scan request is received or not, here is my code : 

 

typedef struct advState_tag{
    bool_t      advOn;
}advState_t;
/* Adv State */
static advState_t  mAdvState;

/*! *********************************************************************************
* \brief        Handles BLE Advertising callback from host stack.
*
* \param[in]    pAdvertisingEvent    Pointer to gapAdvertisingEvent_t.
********************************************************************************** */
static void BleApp_AdvertisingCallback (gapAdvertisingEvent_t* pAdvertisingEvent)
{
    switch (pAdvertisingEvent->eventType)
    {
        case gAdvertisingStateChanged_c:
        {
            mAdvState.advOn = !mAdvState.advOn;

            if(mAdvState.advOn)
            {
            }
            else
            {
            }
        }
        break;

        case gAdvertisingCommandFailed_c:
        {
        }
        break;

        default:
        {
            ; /* For MISRA Compliance */
        }
        break;
    }
}


static void vBleSensitivityMeasurement( uint32_t channelId )
{
	/* Set New Lowpower Constraint on Advertising start request */
	( void )PWR_SetLowPowerModeConstraint(PWR_WFI);

	/** (!) */
	OSA_vidTaskSleep(10);

    Controller_SetTxPowerLevel(ADV_POWER_DBM, channelId);

	/*LED ON*/
	GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_ON);

	BluetoothLEHost_StartAdvertising(&RADIATION_strAdvertisingData, BleApp_AdvertisingCallback, NULL);

	OSA_vidTaskSleep(ADV_DURATION_MS); // TODO change 3000 with ADV_DURATION_MS

	Gap_StopAdvertising();

	GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_OFF);

    // Wait for the tester's response
    bool scanRequestReceived = true;// WaitForScanRequest(); // TODO Implement this function

    if (scanRequestReceived) {
        // Scan request received
        // Turn off the LED and send a SCAN Response
        GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_OFF);
//        BluetoothLEHost_SendScanResponse(/* scan response data */);
    } else {
        // Scan request not received
        // Light the LED for 500ms
        GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_ON);
        OSA_vidTaskSleep(500);
    }
0 项奖励
回复
3 回复数

572 次查看
EduardoZamora
NXP TechSupport
NXP TechSupport

Hello @Liwa

Hope you are doing well.

You could try adding the gExtScanNotification_c event as a case in the BleApp_AdvertisingCallback function. This event indicates that a SCAN_REQ PDU has been received by an extended advertiser.

Also, it is important to consider that the Scan Type must be set as Active Scanning on the Scanner device, so this device can send Scan Requests to the advertiser.

Once the event occurs, you can get this information in gapAdvertisingEvent_t.eventData.scanNotification:

EduardoZamora_0-1708703990773.png

Regards,
Eduardo.

0 项奖励
回复

567 次查看
Liwa
Contributor I

Hello @EduardoZamora ,

Thank you for your response, just to be sure this is how I should send the scan response is that it ? by advertising with new ADV scan resp data ? 

static void BleApp_AdvertisingCallback (gapAdvertisingEvent_t* pAdvertisingEvent)
{
    switch (pAdvertisingEvent->eventType)
    {
        case gAdvertisingStateChanged_c:
        {
            mAdvState.advOn = !mAdvState.advOn;

            if(mAdvState.advOn)
            {
            	 asm("nop");
            }
            else
            {
            	 asm("nop");
            }
        }
        break;

        case gAdvertisingCommandFailed_c:
        {
        	 asm("nop");
			GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_OFF);
			OSA_vidTaskSleep(500);
        }
        break;

        case gExtScanNotification_c:
        {
        	GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_OFF);

			static gapAdStructure_t RADIATION_scanResponseStruct[1] = {
																		  {
																			.adType = gAdShortenedLocalName_c,
																			.length = 12,
																			.aData = (uint8_t*)"DEVICE_NAME"
																		  }
																		};

			gapScanResponseData_t RADIATION_gAppScanRspData = {NumberOfElements(RADIATION_scanResponseStruct),
														  (void *)RADIATION_scanResponseStruct};

			appAdvertisingParams_t RADIATION_strAdvertisingData = {
																	  .pGapAdvParams = &RADIATION_strGapAdvParams,
																	  .pGapAdvData = &RADIATION_gAppAdvertisingData,
																	  .pScanResponseData = &RADIATION_gAppScanRspData
																   };

			BluetoothLEHost_StartAdvertising(&RADIATION_strAdvertisingData, NULL, NULL);
        }
        break;

        default:
        {
            ; /* For MISRA Compliance */
        }
        break;
    }
}


static void vBleSensitivityMeasurement( uint32_t channelId )
{

	/* Set New Lowpower Constraint on Advertising start request */
	( void )PWR_SetLowPowerModeConstraint(PWR_WFI);

	/** (!) */
	OSA_vidTaskSleep(10);

    Controller_SetTxPowerLevel(ADV_POWER_DBM, channelId);

	/*LED ON*/
	GPIO_PinWrite(DIAG_LED_GPIO, DIAG_LED_PIN, DIAG_LED_ON);

	BluetoothLEHost_StartAdvertising(&RADIATION_strAdvertisingData, BleApp_AdvertisingCallback, NULL);

	OSA_vidTaskSleep(ADV_DURATION_MS);

	Gap_StopAdvertising();
}

 

0 项奖励
回复

557 次查看
EduardoZamora
NXP TechSupport
NXP TechSupport

Hello,

gapAdStructure_t can be defined as static const gapAdStructure_t scanResponseStruct[1]. Both gapAdStructure_t and gapScanResponseData_t structures can be defined in source/app_config.c file.

Please, test you application under these modifications and let me know your findings.

Regards,
Eduardo.

0 项奖励
回复