mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
authenticate using pin code
This commit is contained in:
parent
ea6387df26
commit
3091b266fe
38
src/hci.c
38
src/hci.c
@ -17,7 +17,17 @@
|
|||||||
#define OGF_CONTROLLER_BASEBAND 0x03
|
#define OGF_CONTROLLER_BASEBAND 0x03
|
||||||
|
|
||||||
hci_cmd_t hci_inquiry = {
|
hci_cmd_t hci_inquiry = {
|
||||||
OPCODE(OGF_LINK_CONTROL, 0x01), "311" // LAP, Inquiry length, Num_responses
|
OPCODE(OGF_LINK_CONTROL, 0x01), "311"
|
||||||
|
// LAP, Inquiry length, Num_responses
|
||||||
|
};
|
||||||
|
|
||||||
|
hci_cmd_t hci_link_key_request_negative_reply = {
|
||||||
|
OPCODE(OGF_LINK_CONTROL, 0x0c), "B"
|
||||||
|
};
|
||||||
|
|
||||||
|
hci_cmd_t hci_pin_code_request_reply = {
|
||||||
|
OPCODE(OGF_LINK_CONTROL, 0x0d), "B1P"
|
||||||
|
// BD_ADDR, pin length, PIN: c-string
|
||||||
};
|
};
|
||||||
|
|
||||||
hci_cmd_t hci_reset = {
|
hci_cmd_t hci_reset = {
|
||||||
@ -34,6 +44,11 @@ hci_cmd_t hci_write_page_timeout = {
|
|||||||
// Page_Timeout * 0.625 ms
|
// Page_Timeout * 0.625 ms
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hci_cmd_t hci_write_authentication_enable = {
|
||||||
|
OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1"
|
||||||
|
// Authentication_Enable
|
||||||
|
};
|
||||||
|
|
||||||
hci_cmd_t hci_host_buffer_size = {
|
hci_cmd_t hci_host_buffer_size = {
|
||||||
OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122"
|
OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122"
|
||||||
// Host_ACL_Data_Packet_Length:, Host_Synchronous_Data_Packet_Length:, Host_Total_Num_ACL_Data_Packets:, Host_Total_Num_Synchronous_Data_Packets:
|
// Host_ACL_Data_Packet_Length:, Host_Synchronous_Data_Packet_Length:, Host_Total_Num_ACL_Data_Packets:, Host_Total_Num_Synchronous_Data_Packets:
|
||||||
@ -100,7 +115,7 @@ int hci_send_cmd(hci_cmd_t *cmd, ...){
|
|||||||
const char *format = cmd->format;
|
const char *format = cmd->format;
|
||||||
uint16_t word;
|
uint16_t word;
|
||||||
uint32_t longword;
|
uint32_t longword;
|
||||||
uint8_t * bt_addr;
|
uint8_t * ptr;
|
||||||
while (*format) {
|
while (*format) {
|
||||||
switch(*format) {
|
switch(*format) {
|
||||||
case '1': // 8 bit value
|
case '1': // 8 bit value
|
||||||
@ -126,13 +141,18 @@ int hci_send_cmd(hci_cmd_t *cmd, ...){
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'B': // bt-addr
|
case 'B': // bt-addr
|
||||||
bt_addr = va_arg(argptr, uint8_t *);
|
ptr = va_arg(argptr, uint8_t *);
|
||||||
hci_cmd_buffer[pos++] = bt_addr[5];
|
hci_cmd_buffer[pos++] = ptr[5];
|
||||||
hci_cmd_buffer[pos++] = bt_addr[4];
|
hci_cmd_buffer[pos++] = ptr[4];
|
||||||
hci_cmd_buffer[pos++] = bt_addr[3];
|
hci_cmd_buffer[pos++] = ptr[3];
|
||||||
hci_cmd_buffer[pos++] = bt_addr[2];
|
hci_cmd_buffer[pos++] = ptr[2];
|
||||||
hci_cmd_buffer[pos++] = bt_addr[1];
|
hci_cmd_buffer[pos++] = ptr[1];
|
||||||
hci_cmd_buffer[pos++] = bt_addr[0];
|
hci_cmd_buffer[pos++] = ptr[0];
|
||||||
|
break;
|
||||||
|
case 'P': // c string passed as pascal string with leading 1-byte len
|
||||||
|
ptr = va_arg(argptr, uint8_t *);
|
||||||
|
memcpy(&hci_cmd_buffer[pos], ptr, 16);
|
||||||
|
pos += 16;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -66,9 +66,12 @@ void hexdump(uint8_t *data, int size);
|
|||||||
int hci_send_cmd(hci_cmd_t *cmd, ...);
|
int hci_send_cmd(hci_cmd_t *cmd, ...);
|
||||||
|
|
||||||
extern hci_cmd_t hci_inquiry;
|
extern hci_cmd_t hci_inquiry;
|
||||||
|
extern hci_cmd_t hci_link_key_request_negative_reply;
|
||||||
|
extern hci_cmd_t hci_pin_code_request_reply;
|
||||||
extern hci_cmd_t hci_reset;
|
extern hci_cmd_t hci_reset;
|
||||||
extern hci_cmd_t hci_create_connection;
|
extern hci_cmd_t hci_create_connection;
|
||||||
extern hci_cmd_t hci_host_buffer_size;
|
extern hci_cmd_t hci_host_buffer_size;
|
||||||
|
extern hci_cmd_t hci_write_authentication_enable;
|
||||||
extern hci_cmd_t hci_write_page_timeout;
|
extern hci_cmd_t hci_write_page_timeout;
|
||||||
|
|
||||||
#define HCI_INQUIRY_LAP 0x9E8B33L // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC)
|
#define HCI_INQUIRY_LAP 0x9E8B33L // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC)
|
||||||
|
23
src/main.c
23
src/main.c
@ -18,7 +18,7 @@
|
|||||||
static hci_transport_t * transport;
|
static hci_transport_t * transport;
|
||||||
static hci_uart_config_t config;
|
static hci_uart_config_t config;
|
||||||
|
|
||||||
#define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == 0x0e && READ_BT_16(event,2) == cmd.opcode)
|
#define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == 0x0e && READ_BT_16(event,3) == cmd.opcode)
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// reset done, send host buffer size
|
// reset done, send host buffer size
|
||||||
@ -27,21 +27,34 @@ hci_send_cmd(&hci_host_buffer_size, 400, 255, 1, 0, 0);
|
|||||||
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
|
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
|
||||||
#endif
|
#endif
|
||||||
void event_handler(uint8_t *packet, int size){
|
void event_handler(uint8_t *packet, int size){
|
||||||
|
bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 };
|
||||||
|
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9};
|
||||||
|
|
||||||
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
|
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
|
||||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_reset) ) {
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_reset) ) {
|
||||||
// reset done, write page timeout
|
// reset done, write page timeout
|
||||||
hci_send_cmd(&hci_write_page_timeout, 0x6000); // ca. 15 sec
|
hci_send_cmd(&hci_write_page_timeout, 0x6000); // ca. 15 sec
|
||||||
}
|
}
|
||||||
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_page_timeout) ) {
|
||||||
|
// reset done, write page timeout
|
||||||
|
hci_send_cmd(&hci_write_authentication_enable, 1);
|
||||||
|
}
|
||||||
|
|
||||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_host_buffer_size) ) {
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_host_buffer_size) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_page_timeout) ) {
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) {
|
||||||
// hci_host_buffer_size done, send connect
|
// hci_host_buffer_size done, send connect
|
||||||
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 };
|
|
||||||
bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9};
|
|
||||||
hci_send_cmd(&hci_create_connection, &addr, 0x18, 0, 0, 0, 0);
|
hci_send_cmd(&hci_create_connection, &addr, 0x18, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
// link key request
|
||||||
|
if (packet[0] == 0x17){
|
||||||
|
hci_send_cmd(&hci_link_key_request_negative_reply, &addr);
|
||||||
|
}
|
||||||
|
// pin code request
|
||||||
|
if (packet[0] == 0x16){
|
||||||
|
hci_send_cmd(&hci_pin_code_request_reply, &addr, 4, "1234");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user