Merge branch 'master' into ble-api-cleanup

This commit is contained in:
Matthias Ringwald 2016-01-08 23:14:07 +01:00
commit 74386ee04d
23 changed files with 3975 additions and 128 deletions

View File

@ -77,6 +77,7 @@ Chipsets | Status
TI CC256x, WL183x | complete incl. eHCIll support (chipset-cc256x)
CSR 8811, 8510 | H4 only (chipset-csr)
STM STLC2500D | working, no support for custom deep sleep management (chipset-stlc2500d)
TC35661 | working, BLE patches missing (chipset-tc3566x)
EM 9301 | used on Arduino Shield (chipset-em9301)
CSR USB Dongles | complete
Broadcom USB Dongles | complete

View File

@ -0,0 +1,121 @@
/*
* Copyright (C) 2015 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
/*
* bt_control_tc3566x.c
*
* Adapter to use Toshiba TC3566x-based chipsets with BTstack
*
* Supports:
* - Set BD ADDR
* - Set baud rate
*/
#include "btstack-config.h"
#include "bt_control_tc3566x.h"
#include <stddef.h> /* NULL */
#include <stdio.h>
#include <string.h> /* memcpy */
#include "hci.h"
#include "debug.h"
// should go to some common place
#define OPCODE(ogf, ocf) (ocf | ogf << 10)
static const uint8_t baudrate_command[] = { 0x08, 0xfc, 0x11, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x14, 0x42, 0xff, 0x10, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// baud rate command for tc3566x
static int tc35661_baudrate_cmd(void * config, uint32_t baudrate, uint8_t *hci_cmd_buffer){
uint16_t div1 = 0;
uint8_t div2 = 0;
switch (baudrate) {
case 115200:
div1 = 0x001A;
div2 = 0x60;
break;
case 230400:
div1 = 0x000D;
div2 = 0x60;
break;
case 460800:
div1 = 0x0005;
div2 = 0xA0;
break;
case 921600:
div1 = 0x0003;
div2 = 0x70;
break;
default:
log_error("tc3566x_baudrate_cmd baudrate %u not supported", baudrate);
return 1;
}
memcpy(hci_cmd_buffer, baudrate_command, sizeof(baudrate_command));
bt_store_16(hci_cmd_buffer, 13, div1);
hci_cmd_buffer[15] = div2;
return 0;
}
static int tc3566x_set_bd_addr_cmd(void * config, bd_addr_t addr, uint8_t *hci_cmd_buffer){
// OGF 0x04 - Informational Parameters, OCF 0x10
hci_cmd_buffer[0] = 0x13;
hci_cmd_buffer[1] = 0x10;
hci_cmd_buffer[2] = 0x06;
bt_flip_addr(&hci_cmd_buffer[3], addr);
return 0;
}
// MARK: const structs
static const bt_control_t bt_control_tc3566x = {
NULL, // on
NULL, // off
NULL, // sleep
NULL, // wake
NULL, // valid
NULL, // name
tc35661_baudrate_cmd, // baudrate_cmd
NULL, // next_cmd
NULL, // register_for_power_notifications
NULL, // hw_error
tc3566x_set_bd_addr_cmd, // set_bd_addr_cmd
};
// MARK: public API
bt_control_t *bt_control_tc3566x_instance(void){
return (bt_control_t*) &bt_control_tc3566x;
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2015 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
/*
* bt_control_tc3566x.c
*
* Adapter to use Toshiba TC3566x-based chipsets with BTstack
*
* Supports:
* - Set BD ADDR
* - Set baud rate
*/
#ifndef __BT_CONTROL_TC3566x_H
#define __BT_CONTROL_TC3566x_H
#if defined __cplusplus
extern "C" {
#endif
#include "bt_control.h"
bt_control_t *bt_control_tc3566x_instance(void);
#if defined __cplusplus
}
#endif
#endif // __BT_CONTROL_TC3566x_H

View File

@ -105,7 +105,7 @@ static libusb_device_handle * handle;
#define ASYNC_BUFFERS 2
#define AYSNC_POLLING_INTERVAL_MS 1
#define NUM_ISO_PACKETS 4
#define NUM_ISO_PACKETS 16
#define SCO_PACKET_SIZE 49
static struct libusb_transfer *command_out_transfer;

26
platforms/posix-tc35661/.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
ancs_client
ancs_client.h
ble_central_test
ble_peripheral
ble_peripheral_sm_minimal
bnep_test
classic_test
gap_dedicated_bonding
gap_inquiry
gap_inquiry_and_bond
gatt_battery_query
gatt_browser
hsp_ag_test
hsp_hs_test
l2cap_test
profile.h
sdp_bnep_query
sdp_general_query
sdp_rfcomm_query
spp_and_le_counter
spp_and_le_counter.h
spp_counter
spp_streamer
led_counter
le_counter
le_counter.h

View File

@ -0,0 +1,29 @@
# Makefile for libusb based examples
BTSTACK_ROOT = ../..
POSIX_ROOT= ${BTSTACK_ROOT}/platforms/posix
CORE += main.c stdin_support.c bt_control_tc3566x.c
COMMON += hci_transport_h4.c run_loop_posix.c remote_device_db_fs.c
include ${BTSTACK_ROOT}/example/embedded/Makefile.inc
CFLAGS += -I$(BTSTACK_ROOT)/chipset-tc3566x
# CC = gcc-fsf-4.9
CFLAGS += -g -Wall
# CFLAGS += -Werror
VPATH += ${BTSTACK_ROOT}/platforms/posix/src
VPATH += ${BTSTACK_ROOT}/chipset-tc3566x
# Command Line examples require porting to win32, so only build on other unix-ish hosts
ifneq ($(OS),Windows_NT)
EXAMPLES += ${EXAMPLES_CLI}
CFLAGS += -I${POSIX_ROOT}/src
endif
# no BLE here
EXAMPLES:= $(filter-out ${EXAMPLES_USING_LE},$(EXAMPLES))
all: ${BTSTACK_ROOT}/include/btstack/version.h ${EXAMPLES}

View File

@ -0,0 +1,24 @@
// config.h created by configure for BTstack Tue Jun 4 23:10:20 CEST 2013
#ifndef __BTSTACK_CONFIG
#define __BTSTACK_CONFIG
// #define HAVE_BLE
#define USE_POSIX_RUN_LOOP
#define HAVE_SDP
#define HAVE_RFCOMM
#define REMOTE_DEVICE_DB remote_device_db_iphone
#define HAVE_SO_NOSIGPIPE
#define HAVE_TIME
#define HAVE_MALLOC
#define HAVE_BZERO
#define SDP_DES_DUMP
#define ENABLE_LOG_INFO
#define ENABLE_LOG_ERROR
#define HCI_INCOMING_PRE_BUFFER_SIZE 14 // sizeof benep heade, avoid memcpy
#define HCI_ACL_PAYLOAD_SIZE (1691 + 4)
#define HAVE_HCI_DUMP
#define SDP_DES_DUMP
#endif

View File

@ -0,0 +1,118 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
// *****************************************************************************
//
// minimal setup for HCI code
//
// *****************************************************************************
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "btstack-config.h"
#include <btstack/run_loop.h>
#include "debug.h"
#include "btstack_memory.h"
#include "hci.h"
#include "hci_dump.h"
#include "stdin_support.h"
#include "bt_control_tc3566x.h"
int btstack_main(int argc, const char * argv[]);
static hci_uart_config_t hci_uart_config = {
NULL,
115200,
921600, // main baudrate: set to higher standard values if needed e.g. 460800
};
static void sigint_handler(int param){
#ifndef _WIN32
// reset anyway
btstack_stdin_reset();
#endif
log_info(" <= SIGINT received, shutting down..\n");
hci_power_control(HCI_POWER_OFF);
hci_close();
log_info("Good bye, see you.\n");
exit(0);
}
static int led_state = 0;
void hal_led_toggle(void){
led_state = 1 - led_state;
printf("LED State %u\n", led_state);
}
int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
// pick serial port
hci_uart_config.device_name = "/dev/tty.usbserial-A701Z5Q3";
// init HCI
hci_transport_t * transport = hci_transport_h4_instance();
bt_control_t * control = bt_control_tc3566x_instance();
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs;
hci_init(transport, (void*) &hci_uart_config, control, remote_db);
// handle CTRL-c
signal(SIGINT, sigint_handler);
// setup app
btstack_main(argc, argv);
// go
run_loop_execute();
return 0;
}

View File

@ -130,8 +130,8 @@ const char * hfp_ag_feature(int index){
}
int send_str_over_rfcomm(uint16_t cid, char * command){
log_info("HFP_TX %s", command);
if (!rfcomm_can_send_packet_now(cid)) return 1;
log_info("HFP_TX %s", command);
int err = rfcomm_send_internal(cid, (uint8_t*) command, strlen(command));
if (err){
log_error("rfcomm_send_internal -> error 0x%02x \n", err);

View File

@ -275,7 +275,7 @@ typedef enum {
HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG,
HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF,
HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF,
HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF,
HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF
} hfp_ag_call_event_t;
@ -404,14 +404,14 @@ typedef enum {
} hfp_hf_query_operator_state_t;
typedef enum {
HFP_LINK_SETTINGS_D0 = 0,
HFP_LINK_SETTINGS_D1,
HFP_LINK_SETTINGS_S1,
HFP_LINK_SETTINGS_S2,
HFP_LINK_SETTINGS_S3,
HFP_LINK_SETTINGS_S4,
HFP_LINK_SETTINGS_T1,
HFP_LINK_SETTINGS_T2
HFP_LINK_SETTINGS_D0 = 0,
HFP_LINK_SETTINGS_D1,
HFP_LINK_SETTINGS_S1,
HFP_LINK_SETTINGS_S2,
HFP_LINK_SETTINGS_S3,
HFP_LINK_SETTINGS_S4,
HFP_LINK_SETTINGS_T1,
HFP_LINK_SETTINGS_T2
} hfp_link_setttings_t;
typedef enum{

View File

@ -59,6 +59,7 @@
#include "classic/sdp.h"
#include "debug.h"
#include "classic/hfp.h"
#include "classic/hfp_gsm_model.h"
#include "classic/hfp_ag.h"
static const char default_hfp_ag_service_name[] = "Voice gateway";
@ -262,7 +263,7 @@ static int string_len_for_uint32(uint32_t i){
if (i < 100) return 2;
if (i < 1000) return 3;
if (i < 10000) return 4;
if (i < 10000) return 5;
if (i < 100000) return 5;
if (i < 1000000) return 6;
if (i < 10000000) return 7;
if (i < 100000000) return 8;
@ -279,7 +280,7 @@ static int hfp_ag_indicators_string_size(hfp_connection_t * context, int i){
}
// store indicator
static void hfp_ag_indicators_string_store(hfp_connection * context, int i, uint8_t * buffer){
static void hfp_ag_indicators_string_store(hfp_connection_t * context, int i, uint8_t * buffer){
sprintf((char *) buffer, "(\"%s\",(%d,%d)),",
get_hfp_ag_indicators(context)[i].name,
get_hfp_ag_indicators(context)[i].min_range,
@ -312,8 +313,8 @@ static int hfp_ag_indicators_cmd_generator_get_segment_len(hfp_connection_t * co
static void hgp_ag_indicators_cmd_generator_store_segment(hfp_connection_t * context, int index, uint8_t * buffer){
if (index == 0){
*buffer++ = '\n';
*buffer++ = '\r';
*buffer++ = '\n';
int len = strlen(HFP_INDICATOR);
memcpy(buffer, HFP_INDICATOR, len);
buffer += len;
@ -1114,6 +1115,7 @@ static int call_setup_state_machine(hfp_connection_t * connection){
// connection is used to identify originating HF
static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connection){
int indicator_index;
switch (event){
case HFP_AG_INCOMING_CALL:
switch (hfp_ag_call_state){
@ -1377,16 +1379,21 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
break;
case HFP_AG_OUTGOING_CALL_INITIATED:
hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_INITIATED);
connection->call_state = HFP_CALL_OUTGOING_INITIATED;
hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, (const char *) &connection->line_buffer[3]);
break;
case HFP_AG_OUTGOING_REDIAL_INITIATED:
hfp_gsm_handle_event(HFP_AG_OUTGOING_REDIAL_INITIATED);
connection->call_state = HFP_CALL_OUTGOING_INITIATED;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_REDIAL_LAST_NUMBER, 0);
break;
case HFP_AG_OUTGOING_CALL_REJECTED:
hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_REJECTED);
connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_INITIATED);
if (!connection){
log_info("hfp_ag_call_sm: did not find outgoing connection in initiated state");
@ -1398,6 +1405,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
break;
case HFP_AG_OUTGOING_CALL_ACCEPTED:
// hfp_gsm_handle_event();
connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_INITIATED);
if (!connection){
log_info("hfp_ag_call_sm: did not find outgoing connection in initiated state");
@ -1425,6 +1433,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
break;
case HFP_AG_OUTGOING_CALL_RINGING:
// hfp_gsm_handle_event();
connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_DIALING);
if (!connection){
log_info("hfp_ag_call_sm: did not find outgoing connection in dialing state");
@ -1436,6 +1445,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
break;
case HFP_AG_OUTGOING_CALL_ESTABLISHED:
// hfp_gsm_handle_event();
// get outgoing call
connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_RINGING);
if (!connection){
@ -2169,6 +2179,7 @@ void hfp_ag_send_current_call_status(bd_addr_t bd_addr, int idx, hfp_enhanced_ca
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
char buffer[100];
// TODO: check length of a buffer, to fit the MTU
int offset = snprintf(buffer, sizeof(buffer), "\r\n%s: %d,%d,%d,%d,%d", HFP_LIST_CURRENT_CALLS, idx, dir, status, mode, mpty);
if (number){
offset += snprintf(buffer+offset, sizeof(buffer)-offset, ", \"%s\",%u", number, type);

View File

@ -48,6 +48,7 @@
#include "hci.h"
#include "classic/sdp_query_rfcomm.h"
#include "classic/hfp.h"
#include "classic/hfp_gsm_model.h"
#if defined __cplusplus
extern "C" {

172
src/classic/hfp_gsm_model.c Normal file
View File

@ -0,0 +1,172 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
// *****************************************************************************
//
// Minimal setup for HFP Audio Gateway (AG) unit (!! UNDER DEVELOPMENT !!)
//
// *****************************************************************************
#include "btstack-config.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "btstack_memory.h"
#include "classic/hfp.h"
#include "classic/hfp_gsm_model.h"
#include "classic/sdp.h"
#include "classic/sdp_query_rfcomm.h"
#include "debug.h"
#include "hci.h"
#include "hci_cmds.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "run_loop.h"
#define HFP_GSM_MAX_NR_CALLS 3
typedef enum{
CALL_NONE,
CALL_ACTIVE,
CALL_HELD
} hfp_gsm_call_status_t;
typedef struct {
hfp_gsm_call_status_t status;
} hfp_gsm_call_t;
//
static hfp_gsm_call_t gsm_calls[HFP_GSM_MAX_NR_CALLS];
//
static hfp_callsetup_status_t callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
static int get_number_calls_with_status(hfp_gsm_call_status_t status){
int i, count = 0;
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
if (gsm_calls[i].status == status) count++;
}
return count;
}
static int get_call_index_with_status(hfp_gsm_call_status_t status){
int i ;
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
if (gsm_calls[i].status == status) return i;
}
return -1;
}
static inline int get_none_call_index(){
return get_call_index_with_status(CALL_NONE);
}
static inline int get_active_call_index(){
return get_call_index_with_status(CALL_ACTIVE);
}
// static inline int get_number_none_calls(){
// return get_number_calls_with_status(CALL_NONE);
// }
static inline int get_number_active_calls(){
return get_number_calls_with_status(CALL_ACTIVE);
}
static inline int get_number_held_calls(){
return get_number_calls_with_status(CALL_HELD);
}
hfp_call_status_t hfp_gsm_call_status(){
if (get_number_active_calls() + get_number_held_calls()){
return HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT;
}
return HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS;
}
hfp_callheld_status_t hfp_gsm_callheld_status(){
// @note: order is important
if (get_number_held_calls() == 0){
return HFP_CALLHELD_STATUS_NO_CALLS_HELD;
}
if (get_number_active_calls() == 0) {
return HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS;
}
return HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED;
}
hfp_callsetup_status_t hfp_gsm_callsetup_status(){
return callsetup_status;
}
void hfp_gsm_handle_event(hfp_ag_call_event_t event){
int next_free_slot = get_none_call_index();
int current_call_index = get_active_call_index();
switch (event){
case HFP_AG_OUTGOING_CALL_INITIATED:
case HFP_AG_OUTGOING_REDIAL_INITIATED:
if (next_free_slot == -1){
log_error("max nr gsm call exceeded");
return;
}
if (current_call_index != -1){
gsm_calls[current_call_index].status = CALL_HELD;
}
gsm_calls[next_free_slot].status = CALL_ACTIVE;
callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE;
break;
case HFP_AG_OUTGOING_CALL_REJECTED:
break;
case HFP_AG_OUTGOING_CALL_ACCEPTED:
break;
case HFP_AG_OUTGOING_CALL_RINGING:
break;
case HFP_AG_OUTGOING_CALL_ESTABLISHED:
break;
default:
break;
}
}

229
src/classic/hfp_gsm_model.h Normal file
View File

@ -0,0 +1,229 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
// *****************************************************************************
//
// GSM model (!! UNDER DEVELOPMENT !!)
//
// *****************************************************************************
#ifndef BTSTACK_HFP_GSM_MODEL_H
#define BTSTACK_HFP_GSM_MODEL_H
#include "hci.h"
#include "sdp_query_rfcomm.h"
#include "hfp.h"
#if defined __cplusplus
extern "C" {
#endif
/* API_START */
/**
* @brief
*/
hfp_callheld_status_t hfp_gsm_callheld_status();
hfp_call_status_t hfp_gsm_call_status();
hfp_callsetup_status_t hfp_gsm_callsetup_status();
void hfp_gsm_handle_event(hfp_ag_call_event_t event);
// /**
// * @brief
// */
// void hfp_gsm_incoming_call(void);
// /
// /**
// * @brief Report the change in AG's call status.
// * Call status:
// * - 0 = No calls (held or active)
// * - 1 = Call is present (active or held)
// */
// void hfp_gsm_transfer_call_status(bd_addr_t bd_addr, hfp_call_status_t status);
// /**
// * @brief Report the change in AG's call setup status.
// * Call setup status:
// * - 0 = No call setup in progress
// * - 1 = Incoming call setup in progress
// * - 2 = Outgoing call setup in dialing state
// * - 3 = Outgoing call setup in alerting state
// */
// void hfp_gsm_transfer_callsetup_status(bd_addr_t bd_addr, hfp_callsetup_status_t status);
// /**
// * @brief Report the change in AG's held call status.
// * Held call status:
// * - 0 = No calls held
// * - 1 = Call is placed on hold or active/held calls are swapped
// * - 2 = Call on hold, no active calls
// */
// void hfp_gsm_transfer_callheld_status(bd_addr_t bd_addr, hfp_callheld_status_t status);
// /**
// * @brief Enable in-band ring tone
// */
// void hfp_gsm_set_use_in_band_ring_tone(int use_in_band_ring_tone);
// /**
// * @brief number is stored.
// */
// void hfp_gsm_set_clip(uint8_t type, const char * number);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_rejected(void);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_accepted(void);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_ringing(void);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_established(void);
// *
// * @brief
// void hfp_gsm_call_dropped(void);
// /**
// * @brief
// */
// void hfp_gsm_answer_incoming_call(void);
// /**
// * @brief
// */
// void hfp_gsm_join_held_call(void);
// /**
// * @brief
// */
// void hfp_gsm_terminate_call(void);
// /*
// * @brief
// */
// void hfp_gsm_set_registration_status(int status);
// /*
// * @brief
// */
// void hfp_gsm_set_signal_strength(int strength);
// /*
// * @brief
// */
// void hfp_gsm_set_roaming_status(int status);
// /*
// * @brief
// */
// void hfp_gsm_activate_voice_recognition(bd_addr_t bd_addr, int activate);
// /*
// * @brief
// */
// void hfp_gsm_send_phone_number_for_voice_tag(bd_addr_t bd_addr, const char * number);
// /*
// * @brief
// */
// void hfp_gsm_reject_phone_number_for_voice_tag(bd_addr_t bd_addr);
// /*
// * @brief
// */
// void hfp_gsm_send_dtmf_code_done(bd_addr_t bd_addr);
// /*
// * @brief
// */
// void hfp_gsm_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count);
// /*
// * @brief
// */
// void hfp_gsm_send_current_call_status(bd_addr_t bd_addr, int idx, hfp_enhanced_call_dir_t dir,
// hfp_enhanced_call_status_t status, hfp_enhanced_call_mode_t mode,
// hfp_enhanced_call_mpty_t mpty, uint8_t type, const char * number);
// /*
// * @brief
// */
// void hfp_gsm_send_current_call_status_done(bd_addr_t bd_addr);
// /*
// * @brief
// */
// void hfp_gsm_hold_incoming_call(void);
// /*
// * @brief
// */
// void hfp_gsm_accept_held_incoming_call(void);
// /*
// * @brief
// */
// void hfp_gsm_reject_held_incoming_call(void);
/* API_END */
#if defined __cplusplus
}
#endif
#endif

View File

@ -1063,6 +1063,10 @@ void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint16
}
}
void hfp_hf_set_supported_features(uint32_t supported_features){
hfp_supported_features = supported_features;
}
void hfp_hf_establish_service_level_connection(bd_addr_t bd_addr){
hfp_establish_service_level_connection(bd_addr, SDP_HandsfreeAudioGateway);
}

View File

@ -83,6 +83,7 @@ void hfp_hf_register_packet_handler(hfp_callback_t callback);
* - retrieve which HF indicators are enabled on the AG, if possible
*/
void hfp_hf_establish_service_level_connection(bd_addr_t bd_addr);
void hfp_hf_set_supported_features(uint32_t supported_features);
/**
* @brief Release the RFCOMM channel and the audio connection between the HF and the AG.

View File

@ -1093,6 +1093,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
log_info("Command complete for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode);
}
}
if (packet[0] == HCI_EVENT_COMMAND_STATUS){
uint8_t status = packet[2];
uint16_t opcode = READ_BT_16(packet,4);
@ -1107,12 +1108,44 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
log_info("Command status for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode);
}
}
// Vendor == CSR
if (hci_stack->substate == HCI_INIT_W4_CUSTOM_INIT && packet[0] == HCI_EVENT_VENDOR_SPECIFIC){
// TODO: track actual command
command_completed = 1;
}
// Vendor == Toshiba
if (hci_stack->substate == HCI_INIT_W4_SEND_BAUD_CHANGE && packet[0] == HCI_EVENT_VENDOR_SPECIFIC){
// TODO: track actual command
command_completed = 1;
}
// Late response (> 100 ms) for HCI Reset e.g. on Toshiba TC35661:
// Command complete for HCI Reset arrives after we've resent the HCI Reset command
//
// HCI Reset
// Timeout 100 ms
// HCI Reset
// Command Complete Reset
// HCI Read Local Version Information
// Command Complete Reset - but we expected Command Complete Read Local Version Information
// hang...
//
// Fix: Command Complete for HCI Reset in HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION trigger resend
if (!command_completed
&& packet[0] == HCI_EVENT_COMMAND_COMPLETE
&& hci_stack->substate == HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION){
uint16_t opcode = READ_BT_16(packet,3);
if (opcode == hci_reset.opcode){
hci_stack->substate = HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION;
return;
}
}
if (!command_completed) return;
int need_baud_change = hci_stack->config
@ -2392,14 +2425,23 @@ void hci_run(void){
if (connection->address_type == BD_ADDR_TYPE_CLASSIC){
hci_send_cmd(&hci_accept_connection_request, connection->address, 1);
} else {
// remote supported feature eSCO is set if link type is eSCO
uint16_t max_latency;
uint8_t retransmission_effort;
uint16_t packet_types;
// remote supported feature eSCO is set if link type is eSCO
if (connection->remote_supported_feature_eSCO){
// eSCO: S4 - max latency == transmission interval = 0x000c == 12 ms,
hci_send_cmd(&hci_accept_synchronous_connection, connection->address, 8000, 8000, 0x000c, hci_stack->sco_voice_setting, 0x02, 0x388);
max_latency = 0x000c;
retransmission_effort = 0x02;
packet_types = 0x388;
} else {
// SCO: max latency, retransmission interval: N/A. any packet type
hci_send_cmd(&hci_accept_synchronous_connection, connection->address, 8000, 8000, 0xffff, hci_stack->sco_voice_setting, 0xff, 0x003f);
max_latency = 0xffff;
retransmission_effort = 0xff;
packet_types = 0x003f;
}
hci_send_cmd(&hci_accept_synchronous_connection, connection->address, 8000, 8000, max_latency, hci_stack->sco_voice_setting, retransmission_effort, packet_types);
}
return;

View File

@ -65,7 +65,7 @@ all: ${BTSTACK_ROOT}/src/version.h ${EXAMPLES}
clean:
rm -rf *.o $(EXAMPLES) $(CLIENT_EXAMPLES) *.dSYM
hfp_ag_parser_test: ${COMMON_OBJ} hfp_ag.o hfp.o hfp_ag_parser_test.c
hfp_ag_parser_test: ${COMMON_OBJ} hfp_gsm_model.o hfp_ag.o hfp.o hfp_ag_parser_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
hfp_hf_parser_test: ${COMMON_OBJ} hfp_hf.o hfp.o hfp_hf_parser_test.c
@ -74,7 +74,7 @@ hfp_hf_parser_test: ${COMMON_OBJ} hfp_hf.o hfp.o hfp_hf_parser_test.c
hfp_hf_client_test: ${MOCK_OBJ} hfp_hf.o hfp.o hfp_hf_client_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
hfp_ag_client_test: ${MOCK_OBJ} hfp_ag.o hfp.o hfp_ag_client_test.c
hfp_ag_client_test: ${MOCK_OBJ} hfp_gsm_model.o hfp_ag.o hfp.o hfp_ag_client_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
test: all

View File

@ -66,6 +66,15 @@
#include "mock.h"
#include "test_sequences.h"
static bd_addr_t pts_addr = {0x00,0x15,0x83,0x5F,0x9D,0x46};
static int current_call_index = 0;
static hfp_enhanced_call_dir_t current_call_dir;
static int current_call_exists_a = 0;
static int current_call_exists_b = 0;
static hfp_enhanced_call_status_t current_call_status_a;
static hfp_enhanced_call_status_t current_call_status_b;
static hfp_enhanced_call_mpty_t current_call_mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
const uint8_t rfcomm_channel_nr = 1;
static bd_addr_t device_addr = {0xD8,0xBb,0x2C,0xDf,0xF1,0x08};
@ -129,6 +138,7 @@ char * get_next_hfp_ag_command(){
static void user_command(char cmd){
switch (cmd){
case 'a':
memcpy(device_addr, pts_addr, 6);
printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_service_level_connection(device_addr);
break;
@ -136,6 +146,10 @@ static void user_command(char cmd){
printf("Release HFP service level connection.\n");
hfp_ag_release_service_level_connection(device_addr);
break;
case 'Z':
printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr));
hfp_ag_release_service_level_connection(device_addr);
break;
case 'b':
printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_audio_connection(device_addr);
@ -146,17 +160,17 @@ static void user_command(char cmd){
break;
case 'c':
printf("Simulate incoming call from 1234567\n");
// current_call_exists_a = 1;
// current_call_status_a = HFP_ENHANCED_CALL_STATUS_INCOMING;
// current_call_dir = HFP_ENHANCED_CALL_DIR_INCOMING;
current_call_exists_a = 1;
current_call_status_a = HFP_ENHANCED_CALL_STATUS_INCOMING;
current_call_dir = HFP_ENHANCED_CALL_DIR_INCOMING;
hfp_ag_set_clip(129, "1234567");
hfp_ag_incoming_call();
break;
case 'm':
printf("Simulate incoming call from 7654321\n");
// current_call_exists_b = 1;
// current_call_status_b = HFP_ENHANCED_CALL_STATUS_INCOMING;
// current_call_dir = HFP_ENHANCED_CALL_DIR_INCOMING;
current_call_exists_b = 1;
current_call_status_b = HFP_ENHANCED_CALL_STATUS_INCOMING;
current_call_dir = HFP_ENHANCED_CALL_DIR_INCOMING;
hfp_ag_set_clip(129, "7654321");
hfp_ag_incoming_call();
break;
@ -170,12 +184,13 @@ static void user_command(char cmd){
break;
case 'e':
printf("Answer call on AG\n");
// if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){
// current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
// }
// if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){
// current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
// }
if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
}
if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
current_call_status_a = HFP_ENHANCED_CALL_STATUS_HELD;
}
hfp_ag_answer_incoming_call();
break;
case 'E':
@ -288,11 +303,12 @@ static void user_command(char cmd){
break;
case 'u':
printf("Join held call\n");
// current_call_mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
current_call_mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
hfp_ag_join_held_call();
break;
case 'v':
// start_scan();
printf("Starting inquiry scan..\n");
// hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, INQUIRY_INTERVAL, 0);
break;
case 'w':
printf("AG: Put incoming call on hold (Response and Hold)\n");
@ -307,7 +323,6 @@ static void user_command(char cmd){
hfp_ag_reject_held_incoming_call();
break;
default:
printf("AG: undefined user command\n");
break;
}
}
@ -318,10 +333,14 @@ static void simulate_test_sequence(hfp_test_item_t * test_item){
int i = 0;
static char * previous_cmd = NULL;
while (i < test_item->len){
int previous_step = -1;
while ( i < test_item->len){
previous_step++;
if (i < previous_step) exit(0);
char * expected_cmd = test_steps[i];
int expected_cmd_len = strlen(expected_cmd);
printf("\nStep %d, %s \n", i, expected_cmd);
if (strncmp(expected_cmd, "USER:", 5) == 0){
printf("\n---> USER: ");
@ -360,49 +379,57 @@ static void simulate_test_sequence(hfp_test_item_t * test_item){
}
void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE){
handle = READ_BT_16(event, 9);
printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE received for handle 0x%04x\n", handle);
return;
}
if (event[0] != HCI_EVENT_HFP_META) return;
if (event[3] && event[2] != HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR){
if (event[3]
&& event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
&& event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG
&& event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES
&& event[2] != HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL){
printf("ERROR, status: %u\n", event[3]);
return;
}
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
printf("\n** SLC established **\n\n");
service_level_connection_established = 1;
codecs_connection_established = 0;
audio_connection_established = 0;
break;
case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE:
printf("\n** CC established **\n\n");
codecs_connection_established = 1;
audio_connection_established = 0;
printf("Service level connection established.\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
printf("\n** SLC released **\n\n");
service_level_connection_established = 0;
printf("Service level connection released.\n");
break;
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
printf("\n** AC established **\n\n");
audio_connection_established = 1;
printf("\n** Audio connection established **\n");
break;
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
printf("\n** AC released **\n\n");
audio_connection_established = 0;
printf("\n** Audio connection released **\n");
break;
case HFP_SUBEVENT_START_RINGINIG:
printf("\n** Start ringing **\n\n");
start_ringing = 1;
break;
printf("\n** Start Ringing **\n");
break;
case HFP_SUBEVENT_STOP_RINGINIG:
printf("\n** Stop ringing **\n\n");
stop_ringing = 1;
start_ringing = 0;
printf("\n** Stop Ringing **\n");
break;
case HFP_SUBEVENT_CALL_TERMINATED:
call_termiated = 1;
break;
case HFP_CMD_CALL_ANSWERED:
//printf("HF answers call, accept call by GSM\n");
case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER:
printf("\n** Outgoing call '%s' **\n", &event[3]);
// validate number
if ( strcmp("1234567", (char*) &event[3]) == 0
|| strcmp("7654321", (char*) &event[3]) == 0
|| (memory_1_enabled && strcmp(">1", (char*) &event[3]) == 0)){
printf("Dialstring valid: accept call\n");
hfp_ag_outgoing_call_accepted();
// TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
// hfp_ag_outgoing_call_ringing();
} else {
printf("Dialstring invalid: reject call\n");
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_REDIAL_LAST_NUMBER:
printf("\n** Redial last number\n");
@ -416,11 +443,51 @@ void packet_handler(uint8_t * event, uint16_t event_size){
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
printf("\n** Attach number to voice tag. Sending '1234567\n");
hfp_ag_send_phone_number_for_voice_tag(device_addr, "1234567");
break;
case HFP_SUBEVENT_TRANSMIT_DTMF_CODES:
printf("\n** Send DTMF Codes: '%s'\n", &event[3]);
hfp_ag_send_dtmf_code_done(device_addr);
break;
case HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL:
if (current_call_index == 0 && current_call_exists_a){
printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 1\n");
hfp_ag_send_current_call_status(device_addr, 1, current_call_dir, current_call_status_a,
HFP_ENHANCED_CALL_MODE_VOICE, current_call_mpty, 129, "1234567");
current_call_index = 1;
break;
}
if (current_call_index == 1 && current_call_exists_b){
printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 2 \n");
hfp_ag_send_current_call_status(device_addr, 2, current_call_dir, current_call_status_b,
HFP_ENHANCED_CALL_MODE_VOICE, current_call_mpty, 129, "7654321");
current_call_index = 2;
break;
}
printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 3\n");
hfp_ag_send_current_call_status_done(device_addr);
break;
case HFP_CMD_CALL_ANSWERED:
printf("Call answered by HF\n");
if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
}
if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
}
break;
case HFP_SUBEVENT_CONFERENCE_CALL:
current_call_mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
break;
default:
printf("hfp_ag_client_test: event not handled %u\n", event[2]);
printf("Event not handled %u\n", event[2]);
break;
}
}
@ -444,32 +511,40 @@ TEST_GROUP(HFPClient){
hfp_ag_release_audio_connection(device_addr);
hfp_ag_release_service_level_connection(device_addr);
current_call_exists_a = 0;
current_call_exists_b = 0;
current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
current_call_mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
current_call_index = 0;
service_level_connection_established = 0;
codecs_connection_established = 0;
audio_connection_established = 0;
}
};
// TEST(HFPClient, PTSRHHTests){
// for (int i = 0; i < hfp_pts_ag_rhh_tests_size(); i++){
// simulate_test_sequence(&hfp_pts_ag_rhh_tests()[i]);
// teardown();
// }
// }
// TEST(HFPClient, PTSECCTests){
// for (int i = 0; i < hfp_pts_ag_ecc_tests_size(); i++){
// simulate_test_sequence(&hfp_pts_ag_ecc_tests()[i]);
// teardown();
// }
// }
TEST(HFPClient, PTSRHHTests){
for (int i = 0; i < hfp_pts_ag_rhh_tests_size(); i++){
simulate_test_sequence(&hfp_pts_ag_rhh_tests()[i]);
teardown();
}
}
// TEST(HFPClient, PTSECSTests){
// for (int i = 0; i < hfp_pts_ag_ecs_tests_size(); i++){
// simulate_test_sequence(&hfp_pts_ag_ecs_tests()[i]);
// teardown();
// }
// }
TEST(HFPClient, PTSECCTests){
for (int i = 0; i < hfp_pts_ag_ecc_tests_size(); i++){
simulate_test_sequence(&hfp_pts_ag_ecc_tests()[i]);
teardown();
}
}
TEST(HFPClient, PTSECSTests){
for (int i = 0; i < hfp_pts_ag_ecs_tests_size(); i++){
simulate_test_sequence(&hfp_pts_ag_ecs_tests()[i]);
teardown();
}
}
TEST(HFPClient, PTSTWCTests){
for (int i = 0; i < hfp_pts_ag_twc_tests_size(); i++){
@ -492,6 +567,7 @@ TEST(HFPClient, PTSSLCTests){
}
}
int main (int argc, const char * argv[]){
hfp_ag_register_packet_handler(packet_handler);

View File

@ -312,12 +312,16 @@ static void user_command(char cmd){
void simulate_test_sequence(hfp_test_item_t * test_item){
char ** test_steps = test_item->test;
printf("\nSimulate test sequence: \"%s\"\n", test_item->name);
printf("\nSimulate test sequence: \"%s\" [%d steps]\n", test_item->name, test_item->len);
int i = 0;
int previous_step = -1;
while ( i < test_item->len){
previous_step++;
if (i < previous_step) exit(0);
char * expected_cmd = test_steps[i];
int expected_cmd_len = strlen(expected_cmd);
printf("\nStep %d, %s \n", i, expected_cmd);
if (strncmp(expected_cmd, "USER:", 5) == 0){
user_command(expected_cmd[5]);
@ -343,6 +347,7 @@ void simulate_test_sequence(hfp_test_item_t * test_item){
int supported_features = 0;
sscanf(&expected_cmd[8],"%d", &supported_features);
printf("Call hfp_hf_init with SF %d\n", supported_features);
hfp_hf_release_service_level_connection(device_addr);
hfp_hf_init(rfcomm_channel_nr, supported_features, indicators, sizeof(indicators)/sizeof(uint16_t), 1);
user_command('a');
while (has_more_hfp_hf_commands()){
@ -361,7 +366,7 @@ void simulate_test_sequence(hfp_test_item_t * test_item){
printf("\n---> NEXT STEP expect from HF: %s\n", expected_cmd);
while (has_more_hfp_hf_commands()){
char * ag_cmd = get_next_hfp_hf_command();
//printf("HF response verify %s == %s[%d]\n", expected_cmd, ag_cmd, expected_cmd_len);
printf("HF response verify %s == %s[%d]\n", expected_cmd, ag_cmd, expected_cmd_len);
int equal_cmds = strncmp(ag_cmd, expected_cmd, expected_cmd_len) == 0;
if (!equal_cmds){
@ -487,6 +492,7 @@ TEST_GROUP(HFPClient){
}
};
TEST(HFPClient, PTSRHHTests){
for (int i = 0; i < hfp_pts_hf_rhh_tests_size(); i++){
simulate_test_sequence(&hfp_pts_hf_rhh_tests()[i]);

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ hsp_hs_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_hs.o hsp_hs_test.c
hfp_hf_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_hf.o hfp_hf_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
hfp_ag_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_ag.o hfp_ag_test.c
hfp_ag_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_ag_model.o hfp_ag.o hfp_ag_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
l2cap_test: ${CORE_OBJ} ${COMMON_OBJ} l2cap_test.c

View File

@ -420,6 +420,7 @@ static int stdin_process(struct data_source *ds){
}
if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
current_call_status_a = HFP_ENHANCED_CALL_STATUS_HELD;
}
hfp_ag_answer_incoming_call();
break;