streamline hci_transport interface: only have single send_packet(type,data,size)

This commit is contained in:
matthias.ringwald 2010-08-16 17:23:22 +00:00
parent 4c744e2140
commit 622d0de9a0
5 changed files with 21 additions and 57 deletions

View File

@ -185,7 +185,7 @@ int hci_send_acl_packet(uint8_t *packet, int size){
// log_dbg("hci_send_acl_packet - handle %u, sent %u\n", connection->con_handle, connection->num_acl_packets_sent); // log_dbg("hci_send_acl_packet - handle %u, sent %u\n", connection->con_handle, connection->num_acl_packets_sent);
// send packet - ignore errors // send packet - ignore errors
hci_stack.hci_transport->send_acl_packet(packet, size); hci_stack.hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
return 0; return 0;
} }
@ -517,7 +517,7 @@ void hci_run(){
uint8_t * cmd = (*hci_stack.control->next_command)(hci_stack.config); uint8_t * cmd = (*hci_stack.control->next_command)(hci_stack.config);
if (cmd) { if (cmd) {
int size = 3 + cmd[2]; int size = 3 + cmd[2];
hci_stack.hci_transport->send_cmd_packet(cmd, size); hci_stack.hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, cmd, size);
hci_stack.substate = 0; // more init commands hci_stack.substate = 0; // more init commands
break; break;
} }
@ -586,7 +586,7 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
// set state = SENT_DISCONNECT // set state = SENT_DISCONNECT
hci_stack.num_cmd_packets--; hci_stack.num_cmd_packets--;
return hci_stack.hci_transport->send_cmd_packet(packet, size); return hci_stack.hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size);
} }
/** /**

View File

@ -46,8 +46,7 @@
typedef struct { typedef struct {
int (*open)(void *transport_config); int (*open)(void *transport_config);
int (*close)(); int (*close)();
int (*send_cmd_packet)(uint8_t *packet, int size); int (*send_packet)(uint8_t packet_type, uint8_t *packet, int size);
int (*send_acl_packet)(uint8_t *packet, int size);
void (*register_packet_handler)(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)); void (*register_packet_handler)(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
const char * (*get_transport_name)(); const char * (*get_transport_name)();
} hci_transport_t; } hci_transport_t;

View File

@ -188,35 +188,12 @@ static int h4_close(){
return 0; return 0;
} }
static int h4_send_cmd_packet(uint8_t *packet, int size){ static int h4_send_packet(uint8_t packet_type, uint8_t * packet, int size){
if (hci_transport_h4->ds == NULL) return -1; if (hci_transport_h4->ds == NULL) return -1;
if (hci_transport_h4->ds->fd == 0) return -1; if (hci_transport_h4->ds->fd == 0) return -1;
char *data = (char*) packet;
char packet_type = HCI_COMMAND_DATA_PACKET;
hci_dump_packet( (uint8_t) packet_type, 0, packet, size); hci_dump_packet( (uint8_t) packet_type, 0, packet, size);
write(hci_transport_h4->ds->fd, &packet_type, 1); write(hci_transport_h4->ds->fd, &packet_type, 1);
while (size > 0) {
int bytes_written = write(hci_transport_h4->ds->fd, data, size);
if (bytes_written < 0) {
return bytes_written;
}
data += bytes_written;
size -= bytes_written;
}
return 0;
}
static int h4_send_acl_packet(uint8_t *packet, int size){
if (hci_transport_h4->ds->fd == 0) return -1;
char *data = (char*) packet; char *data = (char*) packet;
char packet_type = HCI_ACL_DATA_PACKET;
hci_dump_packet( (uint8_t) packet_type, 0, packet, size);
write(hci_transport_h4->ds->fd, &packet_type, 1);
while (size > 0) { while (size > 0) {
int bytes_written = write(hci_transport_h4->ds->fd, data, size); int bytes_written = write(hci_transport_h4->ds->fd, data, size);
if (bytes_written < 0) { if (bytes_written < 0) {
@ -316,8 +293,7 @@ hci_transport_t * hci_transport_h4_instance() {
hci_transport_h4->ds = NULL; hci_transport_h4->ds = NULL;
hci_transport_h4->transport.open = h4_open; hci_transport_h4->transport.open = h4_open;
hci_transport_h4->transport.close = h4_close; hci_transport_h4->transport.close = h4_close;
hci_transport_h4->transport.send_cmd_packet = h4_send_cmd_packet; hci_transport_h4->transport.send_packet = h4_send_packet;
hci_transport_h4->transport.send_acl_packet = h4_send_acl_packet;
hci_transport_h4->transport.register_packet_handler = h4_register_packet_handler; hci_transport_h4->transport.register_packet_handler = h4_register_packet_handler;
hci_transport_h4->transport.get_transport_name = h4_get_transport_name; hci_transport_h4->transport.get_transport_name = h4_get_transport_name;
} }

View File

@ -168,31 +168,10 @@ static int h5_close(){
return 0; return 0;
} }
static int h5_send_cmd_packet(uint8_t *packet, int size){ static int h5_send_packet(uint8_t packet_type, uint8_t *packet, int size){
if (hci_transport_h5->ds == NULL) return -1; if (hci_transport_h5->ds == NULL) return -1;
if (hci_transport_h5->ds->fd == 0) return -1; if (hci_transport_h5->ds->fd == 0) return -1;
char *data = (char*) packet; char *data = (char*) packet;
char packet_type = HCI_COMMAND_DATA_PACKET;
hci_dump_packet( (uint8_t) packet_type, 0, packet, size);
write(hci_transport_h5->ds->fd, &packet_type, 1);
while (size > 0) {
int bytes_written = write(hci_transport_h5->ds->fd, data, size);
if (bytes_written < 0) {
return bytes_written;
}
data += bytes_written;
size -= bytes_written;
}
return 0;
}
static int h5_send_acl_packet(uint8_t *packet, int size){
if (hci_transport_h5->ds->fd == 0) return -1;
char *data = (char*) packet;
char packet_type = HCI_ACL_DATA_PACKET;
hci_dump_packet( (uint8_t) packet_type, 0, packet, size); hci_dump_packet( (uint8_t) packet_type, 0, packet, size);
@ -318,9 +297,8 @@ hci_transport_t * hci_transport_h5_instance() {
hci_transport_h5->ds = NULL; hci_transport_h5->ds = NULL;
hci_transport_h5->transport.open = h5_open; hci_transport_h5->transport.open = h5_open;
hci_transport_h5->transport.close = h5_close; hci_transport_h5->transport.close = h5_close;
hci_transport_h5->transport.send_cmd_packet = h5_send_cmd_packet; hci_transport_h5->transport.send_packet = h5_send_packet;
hci_transport_h5->transport.send_acl_packet = h5_send_acl_packet; hci_transport_h5->transport.register_packet_handler = h5_register_event_packet_handler;
hci_transport_h5->transport.register_packet_handler = h5_register_event_packet_handler;
hci_transport_h5->transport.get_transport_name = h5_get_transport_name; hci_transport_h5->transport.get_transport_name = h5_get_transport_name;
} }
return (hci_transport_t *) hci_transport_h5; return (hci_transport_t *) hci_transport_h5;

View File

@ -373,6 +373,17 @@ static int usb_send_acl_packet(uint8_t *packet, int size){
return 0; return 0;
} }
static int usb_send_packet(uint8_t packet_type, uint8_8 * packet, int size){
switch (packet_type){
case HCI_COMMAND_DATA_PACKET:
return usb_send_cmd_packet(packet, size);
case HCI_ACL_DATA_PACKET:
return usb_send_acl_packet(packet, size);
default:
return -1;
}
}
static void usb_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, int size)){ static void usb_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, int size)){
event_packet_handler = handler; event_packet_handler = handler;
} }