Merge branch 'develop' of https://github.com/bluekitchen/btstack into develop

This commit is contained in:
Milanka Ringwald 2016-04-01 15:24:29 +02:00
commit d644943f45
14 changed files with 113 additions and 124 deletions

View File

@ -48,8 +48,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
static struct timeval init_tv;
static CFAbsoluteTime init_cf;
static const btstack_run_loop_t btstack_run_loop_corefoundation;
typedef struct {
@ -167,9 +170,7 @@ static int btstack_run_loop_corefoundation_remove_data_source(btstack_data_sour
static void btstack_run_loop_corefoundation_add_timer(btstack_timer_source_t * ts)
{
// note: ts uses unix time: seconds since Jan 1st 1970, CF uses Jan 1st 2001 as reference date
// printf("kCFAbsoluteTimeIntervalSince1970 = %f\n", kCFAbsoluteTimeIntervalSince1970);
CFAbsoluteTime fireDate = ((double)ts->timeout.tv_sec) + (((double)ts->timeout.tv_usec)/1000000.0) - kCFAbsoluteTimeIntervalSince1970; // unix time - since Jan 1st 1970
CFAbsoluteTime fireDate = init_cf + ts->timeout;
CFRunLoopTimerContext timerContext = {0, ts, NULL, NULL, NULL};
CFRunLoopTimerRef timerRef = CFRunLoopTimerCreate (kCFAllocatorDefault,fireDate,0,0,0,theCFRunLoopTimerCallBack,&timerContext);
CFRetain(timerRef);
@ -189,29 +190,30 @@ static int btstack_run_loop_corefoundation_remove_timer(btstack_timer_source_t *
return 0;
}
// set timer
static void btstack_run_loop_corefoundation_set_timer(btstack_timer_source_t *a, uint32_t timeout_in_ms){
gettimeofday(&a->timeout, NULL);
a->timeout.tv_sec += timeout_in_ms / 1000;
a->timeout.tv_usec += (timeout_in_ms % 1000) * 1000;
if (a->timeout.tv_usec > 1000000) {
a->timeout.tv_usec -= 1000000;
a->timeout.tv_sec++;
}
}
/**
* @brief Queries the current time in ms since start
*/
static uint32_t btstack_run_loop_corefoundation_get_time_ms(void){
struct timeval current_tv;
gettimeofday(&current_tv, NULL);
return (current_tv.tv_sec - init_tv.tv_sec) * 1000
+ (current_tv.tv_usec - init_tv.tv_usec) / 1000;
struct timeval tv;
gettimeofday(&tv, NULL);
uint32_t time_ms = ((tv.tv_sec - init_tv.tv_sec) * 1000) + (tv.tv_usec / 1000);
log_debug("btstack_run_loop_corefoundation_get_time_ms: %u <- %u / %u", time_ms, (int) tv.tv_sec, (int) tv.tv_usec);
return time_ms;
}
// set timer
static void btstack_run_loop_corefoundation_set_timer(btstack_timer_source_t *a, uint32_t timeout_in_ms){
uint32_t time_ms = btstack_run_loop_corefoundation_get_time_ms();
a->timeout = time_ms + timeout_in_ms;
log_debug("btstack_run_loop_corefoundation_set_timer to %u ms (now %u, timeout %u)", a->timeout, time_ms, timeout_in_ms);
}
static void btstack_run_loop_corefoundation_init(void){
gettimeofday(&init_tv, NULL);
// calc CFAbsoluteTime for init_tv
// note: timeval uses unix time: seconds since Jan 1st 1970, CF uses Jan 1st 2001 as reference date
init_cf = ((double)init_tv.tv_sec) + (((double)init_tv.tv_usec)/1000000.0) - kCFAbsoluteTimeIntervalSince1970; // unix time - since Jan 1st 1970
}
static void btstack_run_loop_corefoundation_execute(void)

View File

@ -120,7 +120,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet);
rfcomm_channel_id = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
rfcomm_accept_connection(rfcomm_channel_id);
bt_send_cmd(&rfcomm_accept_connection_cmd, rfcomm_channel_id);
break;
case RFCOMM_EVENT_CHANNEL_OPENED:

View File

@ -141,7 +141,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet);
rfcomm_channel_id = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
rfcomm_accept_connection(rfcomm_channel_id);
bt_send_cmd(&rfcomm_accept_connection_cmd, rfcomm_channel_id);
break;
case RFCOMM_EVENT_CHANNEL_OPENED:

View File

@ -39,6 +39,7 @@
#include <stdint.h>
#include "ble/att_db.h"
#include "btstack_defines.h"
#if defined __cplusplus
extern "C" {

View File

@ -49,21 +49,20 @@
#include "btstack_config.h"
#include "btstack_run_loop.h"
#include "btstack_debug.h"
#include "btstack_memory.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "ble/sm.h"
#include "ble/ad_parser.h"
#include "ble/att_db.h"
#include "ble/att_server.h"
#include "gap.h"
#include "ble/le_device_db.h"
#include "ble/sm.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "gap.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "stdin_support.h"
#include "ble/ad_parser.h"
// test profile
#include "ble_central_test.h"
@ -1598,29 +1597,33 @@ static void ui_process_command(char buffer){
}
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
if (ui_digits_for_passkey){
return ui_process_digits_for_passkey(buffer);
ui_process_digits_for_passkey(buffer);
return;
}
if (ui_uint16_request){
return ui_process_uint16_request(buffer);
ui_process_uint16_request(buffer);
return;
}
if (ui_uuid128_request){
return ui_process_uuid128_request(buffer);
ui_process_uuid128_request(buffer);
return;
}
if (ui_value_request){
return ui_process_data_request(buffer);
ui_process_data_request(buffer);
return;
}
ui_process_command(buffer);
return 0;
return;
}
static int get_oob_data_callback(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data){

View File

@ -49,19 +49,18 @@
#include "btstack_config.h"
#include "btstack_run_loop.h"
#include "btstack_debug.h"
#include "btstack_memory.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "ble/sm.h"
#include "ble/att_db.h"
#include "ble/att_server.h"
#include "gap.h"
#include "ble/le_device_db.h"
#include "ble/sm.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "gap.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "stdin_support.h"
#define HEARTBEAT_PERIOD_MS 1000
@ -573,7 +572,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
if (!advertisements_enabled == 0 && gap_discoverable){
if (advertisements_enabled && gap_discoverable){
todos = ENABLE_ADVERTISEMENTS;
}
att_attributes_init();
@ -711,13 +710,13 @@ static void update_auth_req(void){
sm_set_authentication_requirements(auth_req);
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
// passkey input
if (ui_digits_for_passkey){
if (buffer < '0' || buffer > '9') return 0;
if (buffer < '0' || buffer > '9') return;
printf("%c", buffer);
fflush(stdout);
ui_passkey = ui_passkey * 10 + buffer - '0';
@ -726,7 +725,7 @@ static int stdin_process(btstack_data_source_t *ds){
printf("\nSending Passkey '%06x'\n", ui_passkey);
sm_passkey_input(handle, ui_passkey);
}
return 0;
return;
}
switch (buffer){
@ -930,7 +929,7 @@ static int stdin_process(btstack_data_source_t *ds){
break;
}
return 0;
return;
}
static int get_oob_data_callback(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data){

View File

@ -55,15 +55,15 @@
#include <unistd.h>
#include <errno.h>
#include "hci_cmd.h"
#include "btstack_run_loop.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "classic/sdp_server.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "classic/sdp_server.h"
#include "pan.h"
#include "stdin_support.h"
@ -92,6 +92,7 @@
// prototypes
static void show_usage(void);
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
// Configuration for PTS
static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
@ -595,14 +596,14 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
switch (buffer){
case 'p':
printf("Connecting to PTS at %s...\n", bd_addr_to_str(pts_addr));
bnep_connect(pts_addr, bnep_l2cap_psm, bnep_src_uuid, bnep_dest_uuid);
bnep_connect(&packet_handler, pts_addr, bnep_l2cap_psm, bnep_src_uuid, bnep_dest_uuid);
break;
case 'e':
printf("Sending general ethernet packet\n");
@ -657,7 +658,6 @@ static int stdin_process(btstack_data_source_t *ds){
break;
}
return 0;
}
/*************** PANU client routines *********************/
@ -707,12 +707,12 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
printf("BNEP channel open failed, status %02x\n", bnep_event_channel_opened_get_status(packet));
} else {
// data: event(8), len(8), status (8), bnep source uuid (16), bnep destination uuid (16), remote_address (48)
bnep_cid = bnep_event_channel_opened_get_cid(packet);
uuid_source = bnep_event_channel_opened_get_source_uuid(packet);
uuid_dest = bnep_event_channel_opened_get_destination_uuid(packet);
mtu = bnep_event_channel_opened_get_mtu(packet);
bnep_cid = channel;
//bt_flip_addr(event_addr, &packet[9]);
memcpy(&event_addr, &packet[9], sizeof(bd_addr_t));
memcpy(&event_addr, &packet[11], sizeof(bd_addr_t));
printf("BNEP connection open succeeded to %s source UUID 0x%04x dest UUID: 0x%04x, max frame size %u\n", bd_addr_to_str(event_addr), uuid_source, uuid_dest, mtu);
}
break;
@ -823,8 +823,7 @@ int btstack_main(int argc, const char * argv[]){
/* Initialise BNEP */
bnep_init();
bnep_register_packet_handler(packet_handler);
bnep_register_service(bnep_local_service_uuid, 1691); /* Minimum L2CAP MTU for bnep is 1691 bytes */
bnep_register_service(&packet_handler, bnep_local_service_uuid, 1691); /* Minimum L2CAP MTU for bnep is 1691 bytes */
/* Initialize SDP and add PANU record */
sdp_init();

View File

@ -473,13 +473,12 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
// passkey input
if (ui_digits_for_passkey){
if (buffer < '0' || buffer > '9') return 0;
printf("%c", buffer);
fflush(stdout);
ui_passkey = ui_passkey * 10 + buffer - '0';
@ -488,7 +487,6 @@ static int stdin_process(btstack_data_source_t *ds){
printf("\nSending Passkey '%06u'\n", ui_passkey);
hci_send_cmd(&hci_user_passkey_request_reply, remote, ui_passkey);
}
return 0;
}
if (ui_chars_for_pin){
printf("%c", buffer);
@ -499,7 +497,6 @@ static int stdin_process(btstack_data_source_t *ds){
} else {
ui_pin[ui_pin_offset++] = buffer;
}
return 0;
}
switch (buffer){
@ -689,7 +686,6 @@ static int stdin_process(btstack_data_source_t *ds){
break;
}
return 0;
}
static void sdp_create_dummy_service(uint8_t *service, const char *name){

View File

@ -54,16 +54,16 @@
#include <unistd.h>
#include <errno.h>
#include "hci_cmd.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_run_loop.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "l2cap.h"
#include "classic/hfp_ag.h"
#include "classic/rfcomm.h"
#include "classic/sdp_server.h"
#include "btstack_debug.h"
#include "classic/hfp_ag.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "hci_cmd.h"
#include "l2cap.h"
#include "stdin_support.h"
@ -339,7 +339,7 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
read(ds->fd, &cmd, 1);
switch (cmd){
case 'a':
@ -563,8 +563,6 @@ static int stdin_process(btstack_data_source_t *ds){
show_usage();
break;
}
return 0;
}

View File

@ -173,13 +173,13 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
read(ds->fd, &cmd, 1);
if (cmd >= '0' && cmd <= '9'){
printf("DTMF Code: %c\n", cmd);
hfp_hf_send_dtmf_code(device_addr, cmd);
return 0;
return;
}
switch (cmd){
@ -455,8 +455,6 @@ static int stdin_process(btstack_data_source_t *ds){
show_usage();
break;
}
return 0;
}

View File

@ -41,28 +41,28 @@
//
// *****************************************************************************
#include <errno.h>
#include <fcntl.h>
#include <net/if_arp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "hci_cmd.h"
#include "btstack_run_loop.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "l2cap.h"
#include "classic/sdp_server.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_run_loop.h"
#include "classic/sdp_server.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hsp_ag.h"
#include "l2cap.h"
#include "stdin_support.h"
static uint32_t hsp_service_buffer[150/4]; // implicit alignment to 4-byte memory address
@ -94,7 +94,7 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
@ -144,7 +144,6 @@ static int stdin_process(btstack_data_source_t *ds){
break;
}
return 0;
}
// Audio Gateway routines

View File

@ -43,34 +43,32 @@
#include "btstack_config.h"
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <net/if_arp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "hci_cmd.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_run_loop.h"
#include "classic/sdp_server.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hsp_hs.h"
#include "l2cap.h"
#include "rfcomm.h"
#include "sdp.h"
#include "debug.h"
#include "hsp_hs.h"
#include "stdin_support.h"
const uint32_t hsp_service_buffer[150/4]; // implicit alignment to 4-byte memory address
const uint8_t rfcomm_channel_nr = 1;
const char hsp_hs_service_name[] = "Headset Test";
@ -108,7 +106,7 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
@ -159,8 +157,6 @@ static int stdin_process(btstack_data_source_t *ds){
show_usage();
break;
}
return 0;
}
static void packet_handler(uint8_t * event, uint16_t event_size){

View File

@ -65,7 +65,7 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
switch (buffer){
@ -74,7 +74,6 @@ static int stdin_process(btstack_data_source_t *ds){
break;
}
return 0;
}
static uint8_t pan_service_buffer[200];
@ -120,6 +119,6 @@ int btstack_main(int argc, const char * argv[]){
// turn on!
hci_power_control(HCI_POWER_ON);
btstack_stdin_setup(stdin_process);
btstack_stdin_setup(&stdin_process);
return 0;
}

View File

@ -49,12 +49,12 @@
#include <string.h>
#include <unistd.h>
#include "hci_cmd.h"
#include "btstack_run_loop.h"
#include "hci.h"
#include "gap.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "gap.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "stdin_support.h"
@ -120,7 +120,7 @@ static void show_usage(void){
printf("---\n");
}
static int stdin_process(btstack_data_source_t *ds){
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
switch (buffer){
@ -131,7 +131,7 @@ static int stdin_process(btstack_data_source_t *ds){
case 's':
printf("Send L2CAP Data\n");
l2cap_send(local_cid, (uint8_t *) "0123456789", 10);
break;
break;
case 'e':
printf("Send L2CAP ECHO Request\n");
l2cap_send_echo_request(handle, (uint8_t *) "Hello World!", 13);
@ -148,7 +148,6 @@ static int stdin_process(btstack_data_source_t *ds){
break;
}
return 0;
}