Skip to content

Commit 52a5492

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

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 bool phase_bd_addr = false;
6363
static bool phase_tx_power = false;
6464
static bool phase_reset = false;
6565
static bool phase_cnx = 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,17 +123,32 @@ 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+
}
127146
}
128147

148+
if ((phase_bd_addr == true) && (phase_bd_addr == true) && (phase_reset == true)) {
149+
phase_running = true;
150+
}
151+
}
129152
/* check if the connection phase is up (event code is 0x3E) */
130153
if ((hcievt->evtserial.evt.evtcode == 0x3E)) {
131154
phase_cnx = true;
@@ -633,7 +656,7 @@ static int bt_ipm_set_addr(void)
633656

634657
/* now wait for the corresponding Rx event */
635658
while (!phase_bd_addr);
636-
phase_bd_addr = false; /* this sequence is now complete */
659+
/* this sequence is now complete */
637660

638661
return 1; /* success */
639662
} else {
@@ -662,7 +685,7 @@ static int bt_ipm_set_power(void)
662685

663686
/* now wait for the corresponding Rx event */
664687
while (!phase_tx_power);
665-
phase_tx_power = false; /* this sequence is now complete */
688+
/* this sequence is now complete */
666689

667690
return 1; /* success */
668691
}

0 commit comments

Comments
 (0)