mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-15 23:42:52 +00:00
move hci event handling into hci.c
This commit is contained in:
parent
16833f0a4e
commit
22909952ea
22
src/hci.c
22
src/hci.c
@ -89,7 +89,21 @@ static void dummy_handler(uint8_t *packet, int size){
|
|||||||
static void acl_handler(uint8_t *packet, int size){
|
static void acl_handler(uint8_t *packet, int size){
|
||||||
hci_stack.acl_packet_handler(packet, size);
|
hci_stack.acl_packet_handler(packet, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_handler(uint8_t *packet, int size){
|
static void event_handler(uint8_t *packet, int size){
|
||||||
|
|
||||||
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_reset) ) {
|
||||||
|
// reset done, write page timeout
|
||||||
|
hci_send_cmd(&hci_write_page_timeout, 0x6000); // ca. 15 sec
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_page_timeout) ) {
|
||||||
|
uint8_t micro_packet = 100;
|
||||||
|
hci_stack.event_packet_handler(µ_packet, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hci_stack.event_packet_handler(packet, size);
|
hci_stack.event_packet_handler(packet, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +132,7 @@ void hci_init(hci_transport_t *transport, void *config){
|
|||||||
transport->register_acl_packet_handler( acl_handler);
|
transport->register_acl_packet_handler( acl_handler);
|
||||||
|
|
||||||
// open low-level device
|
// open low-level device
|
||||||
transport->open(&config);
|
transport->open(config);
|
||||||
|
|
||||||
// open unix socket
|
// open unix socket
|
||||||
|
|
||||||
@ -134,6 +148,11 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hci_run(){
|
void hci_run(){
|
||||||
|
|
||||||
|
// send hci reset
|
||||||
|
hci_send_cmd(&hci_reset);
|
||||||
|
|
||||||
|
#if 0
|
||||||
while (1) {
|
while (1) {
|
||||||
// construct file descriptor set to wait for
|
// construct file descriptor set to wait for
|
||||||
// select
|
// select
|
||||||
@ -141,6 +160,7 @@ void hci_run(){
|
|||||||
// for each ready file in FD - call handle_data
|
// for each ready file in FD - call handle_data
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
// #define STORE_BT_16( buffer, pos, value ) { buffer[pos] = (value) & 0xff; buffer[pos+1] = (value) >> 8; }
|
// #define STORE_BT_16( buffer, pos, value ) { buffer[pos] = (value) & 0xff; buffer[pos+1] = (value) >> 8; }
|
||||||
|
|
||||||
|
#define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == 0x0e && READ_BT_16(event,3) == cmd.opcode)
|
||||||
|
|
||||||
// packet headers
|
// packet headers
|
||||||
#define HCI_CMD_DATA_PKT_HDR 0x03
|
#define HCI_CMD_DATA_PKT_HDR 0x03
|
||||||
#define HCI_ACL_DATA_PKT_HDR 0x04
|
#define HCI_ACL_DATA_PKT_HDR 0x04
|
||||||
|
@ -43,6 +43,7 @@ static int h4_open(void *transport_config){
|
|||||||
fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY);
|
fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror("init_serialport: Unable to open port ");
|
perror("init_serialport: Unable to open port ");
|
||||||
|
perror(hci_uart_config->device_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
src/main.c
25
src/main.c
@ -22,33 +22,26 @@ static hci_uart_config_t config;
|
|||||||
hci_con_handle_t con_handle= 0;
|
hci_con_handle_t con_handle= 0;
|
||||||
uint16_t dest_cid;
|
uint16_t dest_cid;
|
||||||
|
|
||||||
#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
|
||||||
hci_send_cmd(&hci_host_buffer_size, 400, 255, 1, 0, 0);
|
hci_send_cmd(&hci_host_buffer_size, 400, 255, 1, 0, 0);
|
||||||
// reset done, send inq
|
// reset done, send inq
|
||||||
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, 0x03, 0xc9, 0x3d, 0x77, 0x43 };
|
||||||
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9};
|
// 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) ) {
|
|
||||||
// reset done, write page timeout
|
// bt stack activated, set authentication enabled
|
||||||
hci_send_cmd(&hci_write_page_timeout, 0x6000); // ca. 15 sec
|
if (packet[0] == 100) {
|
||||||
}
|
|
||||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_page_timeout) ) {
|
|
||||||
// reset done, write page timeout
|
|
||||||
hci_send_cmd(&hci_write_authentication_enable, 1);
|
hci_send_cmd(&hci_write_authentication_enable, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_host_buffer_size) ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) {
|
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) {
|
||||||
// hci_host_buffer_size done, send connect
|
// hci_write_authentication_enable done, send connect
|
||||||
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
|
// link key request
|
||||||
@ -136,12 +129,12 @@ int main (int argc, const char * argv[]) {
|
|||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
|
|
||||||
|
// go!
|
||||||
|
hci_run();
|
||||||
|
|
||||||
// get fd for select call
|
// get fd for select call
|
||||||
int transport_fd = transport->get_fd();
|
int transport_fd = transport->get_fd();
|
||||||
|
|
||||||
// send hci reset
|
|
||||||
hci_send_cmd(&hci_reset);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
fd_set descriptors;
|
fd_set descriptors;
|
||||||
FD_ZERO(&descriptors);
|
FD_ZERO(&descriptors);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user