hsp_hs.c (5611a760af48d1ce1beea59c7908be73bd2393f1) | hsp_hs.c (f8fbdce0c5067e7e7edd3a29934b1f9b79c8ff2d) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 124 unchanged lines hidden (view full) --- 133 134static void emit_event_audio_connected(uint8_t status, uint16_t handle){ 135 if (!hsp_hs_callback) return; 136 uint8_t event[6]; 137 event[0] = HCI_EVENT_HSP_META; 138 event[1] = sizeof(event) - 2; 139 event[2] = HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE; 140 event[3] = status; | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 124 unchanged lines hidden (view full) --- 133 134static void emit_event_audio_connected(uint8_t status, uint16_t handle){ 135 if (!hsp_hs_callback) return; 136 uint8_t event[6]; 137 event[0] = HCI_EVENT_HSP_META; 138 event[1] = sizeof(event) - 2; 139 event[2] = HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE; 140 event[3] = status; |
141 bt_store_16(event, 4, handle); | 141 little_endian_store_16(event, 4, handle); |
142 (*hsp_hs_callback)(event, sizeof(event)); 143} 144 145// remote audio volume control 146// AG +VGM=13 [0..15] ; HS AT+VGM=6 | AG OK 147 148static int hsp_hs_send_str_over_rfcomm(uint16_t cid, const char * command){ 149 if (!rfcomm_can_send_packet_now(rfcomm_cid)) return 1; --- 289 unchanged lines hidden (view full) --- 439 // inform about pin code request 440 printf("Pin code request - using '0000'\n\r"); 441 bt_flip_addr(event_addr, &packet[2]); 442 hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000"); 443 break; 444 case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:{ 445 int index = 2; 446 uint8_t status = packet[index++]; | 142 (*hsp_hs_callback)(event, sizeof(event)); 143} 144 145// remote audio volume control 146// AG +VGM=13 [0..15] ; HS AT+VGM=6 | AG OK 147 148static int hsp_hs_send_str_over_rfcomm(uint16_t cid, const char * command){ 149 if (!rfcomm_can_send_packet_now(rfcomm_cid)) return 1; --- 289 unchanged lines hidden (view full) --- 439 // inform about pin code request 440 printf("Pin code request - using '0000'\n\r"); 441 bt_flip_addr(event_addr, &packet[2]); 442 hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000"); 443 break; 444 case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:{ 445 int index = 2; 446 uint8_t status = packet[index++]; |
447 sco_handle = READ_BT_16(packet, index); | 447 sco_handle = little_endian_read_16(packet, index); |
448 index+=2; 449 bd_addr_t address; 450 memcpy(address, &packet[index], 6); 451 index+=6; 452 uint8_t link_type = packet[index++]; 453 uint8_t transmission_interval = packet[index++]; // measured in slots 454 uint8_t retransmission_interval = packet[index++];// measured in slots | 448 index+=2; 449 bd_addr_t address; 450 memcpy(address, &packet[index], 6); 451 index+=6; 452 uint8_t link_type = packet[index++]; 453 uint8_t transmission_interval = packet[index++]; // measured in slots 454 uint8_t retransmission_interval = packet[index++];// measured in slots |
455 uint16_t rx_packet_length = READ_BT_16(packet, index); // measured in bytes | 455 uint16_t rx_packet_length = little_endian_read_16(packet, index); // measured in bytes |
456 index+=2; | 456 index+=2; |
457 uint16_t tx_packet_length = READ_BT_16(packet, index); // measured in bytes | 457 uint16_t tx_packet_length = little_endian_read_16(packet, index); // measured in bytes |
458 index+=2; 459 uint8_t air_mode = packet[index]; 460 461 if (status != 0){ 462 log_error("(e)SCO Connection failed, status %u", status); 463 emit_event_audio_connected(status, sco_handle); 464 break; 465 } --- 29 unchanged lines hidden (view full) --- 495 break; 496 } 497 498 case RFCOMM_EVENT_INCOMING_CONNECTION: 499 // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) 500 if (hsp_state != HSP_IDLE) return; 501 502 bt_flip_addr(event_addr, &packet[2]); | 458 index+=2; 459 uint8_t air_mode = packet[index]; 460 461 if (status != 0){ 462 log_error("(e)SCO Connection failed, status %u", status); 463 emit_event_audio_connected(status, sco_handle); 464 break; 465 } --- 29 unchanged lines hidden (view full) --- 495 break; 496 } 497 498 case RFCOMM_EVENT_INCOMING_CONNECTION: 499 // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) 500 if (hsp_state != HSP_IDLE) return; 501 502 bt_flip_addr(event_addr, &packet[2]); |
503 rfcomm_cid = READ_BT_16(packet, 9); | 503 rfcomm_cid = little_endian_read_16(packet, 9); |
504 printf("RFCOMM channel %u requested for %s\n", packet[8], bd_addr_to_str(event_addr)); 505 rfcomm_accept_connection(rfcomm_cid); 506 507 hsp_state = HSP_W4_RFCOMM_CONNECTED; 508 break; 509 510 case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE: 511 printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE packet_handler type %u, packet[0] %x\n", packet_type, packet[0]); 512 // data: event(8), len(8), status (8), address (48), handle(16), server channel(8), rfcomm_cid(16), max frame size(16) 513 if (packet[2]) { 514 printf("RFCOMM channel open failed, status %u\n", packet[2]); 515 hsp_hs_reset_state(); 516 emit_event(HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE, packet[2]); 517 hs_outgoing_connection = 0; 518 } else { 519 // data: event(8) , len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16) | 504 printf("RFCOMM channel %u requested for %s\n", packet[8], bd_addr_to_str(event_addr)); 505 rfcomm_accept_connection(rfcomm_cid); 506 507 hsp_state = HSP_W4_RFCOMM_CONNECTED; 508 break; 509 510 case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE: 511 printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE packet_handler type %u, packet[0] %x\n", packet_type, packet[0]); 512 // data: event(8), len(8), status (8), address (48), handle(16), server channel(8), rfcomm_cid(16), max frame size(16) 513 if (packet[2]) { 514 printf("RFCOMM channel open failed, status %u\n", packet[2]); 515 hsp_hs_reset_state(); 516 emit_event(HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE, packet[2]); 517 hs_outgoing_connection = 0; 518 } else { 519 // data: event(8) , len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16) |
520 rfcomm_handle = READ_BT_16(packet, 9); 521 rfcomm_cid = READ_BT_16(packet, 12); 522 mtu = READ_BT_16(packet, 14); | 520 rfcomm_handle = little_endian_read_16(packet, 9); 521 rfcomm_cid = little_endian_read_16(packet, 12); 522 mtu = little_endian_read_16(packet, 14); |
523 printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_cid, mtu); 524 525 if (hs_outgoing_connection){ 526 hs_outgoing_connection = 0; 527 hs_send_button_press = 1; 528 } 529 530 switch (hsp_state){ --- 14 unchanged lines hidden (view full) --- 545 hsp_hs_callback(packet, size); 546 break; 547 548 case HCI_EVENT_DISCONNECTION_COMPLETE: 549 printf("HCI_EVENT_DISCONNECTION_COMPLETE \n"); 550 // if (hsp_state != HSP_W4_SCO_DISCONNECTED){ 551 // printf("received gap disconnect in wrong hsp state\n"); 552 // } | 523 printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_cid, mtu); 524 525 if (hs_outgoing_connection){ 526 hs_outgoing_connection = 0; 527 hs_send_button_press = 1; 528 } 529 530 switch (hsp_state){ --- 14 unchanged lines hidden (view full) --- 545 hsp_hs_callback(packet, size); 546 break; 547 548 case HCI_EVENT_DISCONNECTION_COMPLETE: 549 printf("HCI_EVENT_DISCONNECTION_COMPLETE \n"); 550 // if (hsp_state != HSP_W4_SCO_DISCONNECTED){ 551 // printf("received gap disconnect in wrong hsp state\n"); 552 // } |
553 handle = READ_BT_16(packet,3); | 553 handle = little_endian_read_16(packet,3); |
554 if (handle == sco_handle){ 555 sco_handle = 0; 556 hsp_state = HSP_W2_DISCONNECT_RFCOMM; 557 printf(" HSP_W2_DISCONNECT_RFCOMM\n"); 558 break; 559 } 560 break; 561 case RFCOMM_EVENT_CHANNEL_CLOSED: --- 42 unchanged lines hidden --- | 554 if (handle == sco_handle){ 555 sco_handle = 0; 556 hsp_state = HSP_W2_DISCONNECT_RFCOMM; 557 printf(" HSP_W2_DISCONNECT_RFCOMM\n"); 558 break; 559 } 560 break; 561 case RFCOMM_EVENT_CHANNEL_CLOSED: --- 42 unchanged lines hidden --- |