@@ -531,6 +531,11 @@ static inline void isr_radio_state_tx(void)
531531 }
532532
533533 radio_tmr_end_capture ();
534+
535+ #if defined(CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_RSSI )
536+ radio_rssi_measure ();
537+ #endif /* CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_RSSI */
538+
534539 break ;
535540
536541 case ROLE_OBS :
@@ -578,6 +583,37 @@ static inline void isr_radio_state_tx(void)
578583 }
579584}
580585
586+ #if defined(CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY )
587+ static u32_t isr_rx_adv_sr_report (struct pdu_adv * pdu_adv_rx , u8_t rssi_ready )
588+ {
589+ struct radio_pdu_node_rx * radio_pdu_node_rx ;
590+ struct pdu_adv * pdu_adv ;
591+ u8_t pdu_len ;
592+
593+ radio_pdu_node_rx = packet_rx_reserve_get (3 );
594+ if (radio_pdu_node_rx == 0 ) {
595+ return 1 ;
596+ }
597+
598+ /* Prepare the report (scan req) */
599+ radio_pdu_node_rx -> hdr .handle = 0xffff ;
600+ radio_pdu_node_rx -> hdr .type = NODE_RX_TYPE_SCAN_REQ ;
601+
602+ /* Make a copy of PDU into Rx node (as the received PDU is in the
603+ * scratch buffer), and save the RSSI value.
604+ */
605+ pdu_adv = (struct pdu_adv * )radio_pdu_node_rx -> pdu_data ;
606+ pdu_len = offsetof(struct pdu_adv , payload ) + pdu_adv_rx -> len ;
607+ memcpy (pdu_adv , pdu_adv_rx , pdu_len );
608+ ((u8_t * )pdu_adv )[pdu_len ] =
609+ (rssi_ready ) ? (radio_rssi_get () & 0x7f ) : 0x7f ;
610+
611+ packet_rx_enqueue ();
612+
613+ return 0 ;
614+ }
615+ #endif /* CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY */
616+
581617static inline u32_t isr_rx_adv (u8_t devmatch_ok , u8_t irkmatch_ok ,
582618 u8_t irkmatch_id , u8_t rssi_ready )
583619{
@@ -591,13 +627,22 @@ static inline u32_t isr_rx_adv(u8_t devmatch_ok, u8_t irkmatch_ok,
591627 (((_radio .advertiser .filter_policy & 0x01 ) == 0 ) ||
592628 (devmatch_ok ) || (irkmatch_ok )) &&
593629 (1 /** @todo own addr match check */ )) {
630+
631+ #if defined(CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY )
632+ u32_t err ;
633+
634+ /* Generate the scan request event */
635+ err = isr_rx_adv_sr_report (pdu_adv , rssi_ready );
636+ if (err ) {
637+ /* Scan Response will not be transmitted */
638+ return err ;
639+ }
640+ #endif /* CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY */
641+
594642 _radio .state = STATE_CLOSE ;
595643
596644 radio_switch_complete_and_disable ();
597645
598- /* TODO use rssi_ready to generate proprietary scan_req event */
599- ARG_UNUSED (rssi_ready );
600-
601646 /* use the latest scan data, if any */
602647 if (_radio .advertiser .scan_data .first != _radio .
603648 advertiser .scan_data .last ) {
@@ -829,6 +874,31 @@ static inline u32_t isr_rx_adv(u8_t devmatch_ok, u8_t irkmatch_ok,
829874 return 1 ;
830875}
831876
877+ static u32_t isr_rx_obs_report (u8_t rssi_ready )
878+ {
879+ struct radio_pdu_node_rx * radio_pdu_node_rx ;
880+ struct pdu_adv * pdu_adv_rx ;
881+
882+ radio_pdu_node_rx = packet_rx_reserve_get (3 );
883+ if (radio_pdu_node_rx == 0 ) {
884+ return 1 ;
885+ }
886+
887+ /* Prepare the report (adv or scan resp) */
888+ radio_pdu_node_rx -> hdr .handle = 0xffff ;
889+ radio_pdu_node_rx -> hdr .type = NODE_RX_TYPE_REPORT ;
890+
891+ /* save the RSSI value */
892+ pdu_adv_rx = (struct pdu_adv * )radio_pdu_node_rx -> pdu_data ;
893+ ((u8_t * )pdu_adv_rx )[offsetof(struct pdu_adv , payload ) +
894+ pdu_adv_rx -> len ] =
895+ (rssi_ready ) ? (radio_rssi_get () & 0x7f ) : 0x7f ;
896+
897+ packet_rx_enqueue ();
898+
899+ return 0 ;
900+ }
901+
832902static inline u32_t isr_rx_obs (u8_t irkmatch_id , u8_t rssi_ready )
833903{
834904 struct pdu_adv * pdu_adv_rx ;
@@ -1084,23 +1154,14 @@ static inline u32_t isr_rx_obs(u8_t irkmatch_id, u8_t rssi_ready)
10841154 (pdu_adv_rx -> type == PDU_ADV_TYPE_SCAN_IND )) &&
10851155 (_radio .observer .scan_type != 0 ) &&
10861156 (_radio .observer .conn == 0 )) {
1087- struct radio_pdu_node_rx * radio_pdu_node_rx ;
10881157 struct pdu_adv * pdu_adv_tx ;
1089-
1090- radio_pdu_node_rx = packet_rx_reserve_get (3 );
1091- if (radio_pdu_node_rx == 0 ) {
1092- return 1 ;
1093- }
1094-
1095- /* save the RSSI value */
1096- ((u8_t * )pdu_adv_rx )[offsetof(struct pdu_adv , payload ) +
1097- pdu_adv_rx -> len ] =
1098- (rssi_ready ) ? (radio_rssi_get () & 0x7F ) : 0x7F ;
1158+ u32_t err ;
10991159
11001160 /* save the adv packet */
1101- radio_pdu_node_rx -> hdr .handle = 0xffff ;
1102- radio_pdu_node_rx -> hdr .type = NODE_RX_TYPE_REPORT ;
1103- packet_rx_enqueue ();
1161+ err = isr_rx_obs_report (rssi_ready );
1162+ if (err ) {
1163+ return err ;
1164+ }
11041165
11051166 /* prepare the scan request packet */
11061167 pdu_adv_tx = (struct pdu_adv * )radio_pkt_scratch_get ();
@@ -1143,22 +1204,13 @@ static inline u32_t isr_rx_obs(u8_t irkmatch_id, u8_t rssi_ready)
11431204 ((pdu_adv_rx -> type == PDU_ADV_TYPE_SCAN_RSP ) &&
11441205 (_radio .observer .scan_state != 0 ))) &&
11451206 (pdu_adv_rx -> len != 0 ) && (!_radio .observer .conn )) {
1146- struct radio_pdu_node_rx * radio_pdu_node_rx ;
1147-
1148- radio_pdu_node_rx = packet_rx_reserve_get (3 );
1149- if (radio_pdu_node_rx == 0 ) {
1150- return 1 ;
1151- }
1152-
1153- /* save the RSSI value */
1154- ((u8_t * )pdu_adv_rx )[offsetof(struct pdu_adv , payload ) +
1155- pdu_adv_rx -> len ] =
1156- (rssi_ready ) ? (radio_rssi_get () & 0x7f ) : 0x7f ;
1207+ u32_t err ;
11571208
11581209 /* save the scan response packet */
1159- radio_pdu_node_rx -> hdr .handle = 0xffff ;
1160- radio_pdu_node_rx -> hdr .type = NODE_RX_TYPE_REPORT ;
1161- packet_rx_enqueue ();
1210+ err = isr_rx_obs_report (rssi_ready );
1211+ if (err ) {
1212+ return err ;
1213+ }
11621214 }
11631215 /* invalid PDU */
11641216 else {
@@ -8196,6 +8248,11 @@ void radio_rx_dequeue(void)
81968248 switch (radio_pdu_node_rx -> hdr .type ) {
81978249 case NODE_RX_TYPE_DC_PDU :
81988250 case NODE_RX_TYPE_REPORT :
8251+
8252+ #if defined(CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY )
8253+ case NODE_RX_TYPE_SCAN_REQ :
8254+ #endif /* CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY */
8255+
81998256 case NODE_RX_TYPE_CONNECTION :
82008257 case NODE_RX_TYPE_CONN_UPDATE :
82018258 case NODE_RX_TYPE_ENC_REFRESH :
@@ -8250,6 +8307,11 @@ void radio_rx_mem_release(struct radio_pdu_node_rx **radio_pdu_node_rx)
82508307 switch (_radio_pdu_node_rx_free -> hdr .type ) {
82518308 case NODE_RX_TYPE_DC_PDU :
82528309 case NODE_RX_TYPE_REPORT :
8310+
8311+ #if defined(CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY )
8312+ case NODE_RX_TYPE_SCAN_REQ :
8313+ #endif /* CONFIG_BLUETOOTH_CONTROLLER_SCAN_REQ_NOTIFY */
8314+
82538315 case NODE_RX_TYPE_CONNECTION :
82548316 case NODE_RX_TYPE_CONN_UPDATE :
82558317 case NODE_RX_TYPE_ENC_REFRESH :
0 commit comments