Skip to content

Commit cb47366

Browse files
committed
control the init / running phase to detect error in the Rx EVT
Signed-off-by: Francois Ramu <[email protected]>
1 parent 38c0c7c commit cb47366

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/utility/HCISharedMemTransport.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static uint8_t bd_addr_udn[6];
6363
static bool phase_bd_addr = false;
6464
static bool phase_tx_power = false;
6565
static bool phase_reset = false;
66+
static bool phase_running = false;
6667

6768
HCISharedMemTransportClass::HCISharedMemTransportClass(BLEChip_t ble_chip) :
6869
_ble_chip(ble_chip)
@@ -99,13 +100,20 @@ static void evt_received(TL_EvtPacket_t *hcievt)
99100
#endif /* PRINT_HCI_DATA */
100101
#endif /* DEBUG */
101102

103+
if (phase_running == false) {
102104
/* check the Rx event of complete the previous bd_addr opcode 0xfc0c */
103105
if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) &&
104106
(hcievt->evtserial.evt.payload[0] == 0x01) &&
105107
(hcievt->evtserial.evt.payload[1] == 0x0C) &&
106108
(hcievt->evtserial.evt.payload[2] == 0xFC)) {
107-
phase_bd_addr = true;
109+
phase_bd_addr = true;
108110
/* rx data is no more useful */
111+
if (hcievt->evtserial.evt.payload[3] != 0) {
112+
#if defined(DEBUG)
113+
printf("Error: wrong BD Addr\r\n");
114+
#endif /* DEBUG */
115+
return;
116+
}
109117
break;
110118
}
111119
/* check the Rx event of complete the previous tx power opcode 0xFC0F */
@@ -115,16 +123,31 @@ static void evt_received(TL_EvtPacket_t *hcievt)
115123
(hcievt->evtserial.evt.payload[2] == 0xFC)) {
116124
phase_tx_power = true;
117125
/* rx data is no more useful */
126+
if (hcievt->evtserial.evt.payload[3] != 0) {
127+
#if defined(DEBUG)
128+
printf("Error: wrong Tx power\r\n");
129+
#endif /* DEBUG */
130+
return;
131+
}
118132
break;
119133
}
120-
121134
/* check if the reset phase is in progress (opcode is 0x0C03) */
122135
if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) &&
123136
(hcievt->evtserial.evt.payload[0] == 0x01) &&
124137
(hcievt->evtserial.evt.payload[1] == 0x03) &&
125138
(hcievt->evtserial.evt.payload[2] == 0x0C)) {
126139
phase_reset = true;
140+
if (hcievt->evtserial.evt.payload[3] != 0) {
141+
#if defined(DEBUG)
142+
printf("Error: wrong reset\r\n");
143+
#endif /* DEBUG */
144+
return;
145+
}
146+
}
147+
if ((phase_bd_addr == true) && (phase_bd_addr == true) && (phase_reset == true)) {
148+
phase_running = true;
127149
}
150+
}
128151
__disable_irq();
129152
/* store received data in the _rxbuff buffer */
130153
len = hcievt->evtserial.evt.plen + TL_EVT_HDR_SIZE;
@@ -623,7 +646,7 @@ static int bt_ipm_set_addr(void)
623646

624647
/* now wait for the corresponding Rx event */
625648
while (!phase_bd_addr);
626-
phase_bd_addr = false; /* this sequence is now complete */
649+
/* this sequence is now complete */
627650

628651
return 1; /* success */
629652
} else {
@@ -652,7 +675,7 @@ static int bt_ipm_set_power(void)
652675

653676
/* now wait for the corresponding Rx event */
654677
while (!phase_tx_power);
655-
phase_tx_power = false; /* this sequence is now complete */
678+
/* this sequence is now complete */
656679

657680
return 1; /* success */
658681
}

0 commit comments

Comments
 (0)