mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-10 06:40:23 +00:00
test code to simulate remote name with invalid UTF-8 name
This commit is contained in:
parent
add0749a90
commit
2277459341
@ -40,6 +40,7 @@
|
||||
#include <fcntl.h> /* File control definitions */
|
||||
#include <unistd.h> /* UNIX standard function definitions */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hci.h"
|
||||
#include "hci_transport_h4.h"
|
||||
@ -75,6 +76,30 @@ static int read_pos;
|
||||
// static uint8_t hci_event_buffer[255+2]; // maximal payload + 2 bytes header
|
||||
static uint8_t hci_packet[400]; // bigger than largest packet
|
||||
|
||||
#ifdef TEST_LONG_INVALID_REMOTE_NAME
|
||||
// test event with remote name of 255 bytes length
|
||||
const uint8_t remoteNameEvent[] = { 0x07, 0xFF, 0x00, 0xC4, 0xC6, 0x65, 0x5A, 0x12, 0x00, 0x4D, 0x69,
|
||||
0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0xAE, 0x20, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65,
|
||||
0x73, 0x73, 0x20, 0x4E, 0x6F, 0x74, 0x65, 0x62, 0x6F, 0x6F, 0x6B, 0x20, 0x50, 0x72, 0x65,
|
||||
0x73, 0x65, 0x6E, 0x74, 0x65, 0x72, 0x20, 0x4D, 0x6F, 0x75, 0x73, 0x65, 0x20, 0x38, 0x30,
|
||||
0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
const int remoteNameEventSize = sizeof(remoteNameEvent);
|
||||
#endif
|
||||
|
||||
|
||||
// prototypes
|
||||
static int h4_open(void *transport_config){
|
||||
hci_uart_config = (hci_uart_config_t*) transport_config;
|
||||
@ -228,6 +253,7 @@ static int h4_process(struct data_source *ds) {
|
||||
|
||||
// act
|
||||
switch (h4_state) {
|
||||
|
||||
case H4_W4_PACKET_TYPE:
|
||||
if (hci_packet[0] == HCI_EVENT_PACKET){
|
||||
read_pos = 0;
|
||||
@ -243,24 +269,35 @@ static int h4_process(struct data_source *ds) {
|
||||
bytes_to_read = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case H4_W4_EVENT_HEADER:
|
||||
bytes_to_read = hci_packet[1];
|
||||
h4_state = H4_W4_EVENT_PAYLOAD;
|
||||
break;
|
||||
|
||||
case H4_W4_EVENT_PAYLOAD:
|
||||
|
||||
#ifdef TEST_LONG_INVALID_REMOTE_NAME
|
||||
if (hci_packet[0] == HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE){
|
||||
hci_packet[1] = remoteNameEvent[1];
|
||||
memcpy( &hci_packet[9], &remoteNameEvent[9], remoteNameEventSize);
|
||||
read_pos = remoteNameEventSize;
|
||||
}
|
||||
#endif
|
||||
hci_dump_packet( HCI_EVENT_PACKET, 1, hci_packet, read_pos);
|
||||
event_packet_handler(hci_packet, read_pos);
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
bytes_to_read = 1;
|
||||
break;
|
||||
|
||||
case H4_W4_ACL_HEADER:
|
||||
bytes_to_read = READ_BT_16( hci_packet, 2);
|
||||
h4_state = H4_W4_ACL_PAYLOAD;
|
||||
break;
|
||||
|
||||
case H4_W4_ACL_PAYLOAD:
|
||||
hci_dump_packet( HCI_ACL_DATA_PACKET, 1, hci_packet, read_pos);
|
||||
|
||||
acl_packet_handler(hci_packet, read_pos);
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user