diff options
author | Mattias Agren <magren@broadcom.com> | 2012-03-26 08:25:00 -0700 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:13 -0700 |
commit | 254588bfe6c3e70625b0f725b908598f30f476c8 (patch) | |
tree | 259c87422e70b74abeab96b3e3155c88791e5b6d | |
parent | 3e6f399bdbaca7f8ab0a8b1c6eab7cc1088ab74a (diff) | |
download | external_bluetooth_bluedroid-254588bfe6c3e70625b0f725b908598f30f476c8.zip external_bluetooth_bluedroid-254588bfe6c3e70625b0f725b908598f30f476c8.tar.gz external_bluetooth_bluedroid-254588bfe6c3e70625b0f725b908598f30f476c8.tar.bz2 |
Added new control and data path interface between audioflinger a2dp HAL
and stack. Added support for suspend and a dedicated HAL callback
notifying framework on audiopath events. Cleanup.
Change-Id: I3b738611bc8e1d84794f7207413fd9e7dd1fc668
39 files changed, 3636 insertions, 1643 deletions
diff --git a/a2dp_audio_hw/Android.mk b/audio_a2dp_hw/Android.mk index 4487306..b451970 100644..100755 --- a/a2dp_audio_hw/Android.mk +++ b/audio_a2dp_hw/Android.mk @@ -3,8 +3,10 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - audio_a2dp_hw.c \ + audio_a2dp_hw.c +LOCAL_C_INCLUDES+= . + LOCAL_SHARED_LIBRARIES := \ libcutils diff --git a/a2dp_audio_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c index a6d4cd1..c7c5810 100644 --- a/a2dp_audio_hw/audio_a2dp_hw.c +++ b/audio_a2dp_hw/audio_a2dp_hw.c @@ -45,45 +45,62 @@ * *****************************************************************************/ -#define LOG_TAG "audio_a2dp_hw" -#define LOG_NDEBUG 0 +/***************************************************************************** + * + * Filename: audio_a2dp_hw.c + * + * Description: Implements hal for bluedroid a2dp audio device + * + *****************************************************************************/ #include <errno.h> #include <pthread.h> #include <stdint.h> #include <sys/time.h> - #include <sys/socket.h> #include <sys/un.h> #include <sys/poll.h> #include <sys/errno.h> - #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> - #include <cutils/str_parms.h> -#include <cutils/log.h> #include <cutils/sockets.h> - -#include <hardware/hardware.h> #include <system/audio.h> #include <hardware/audio.h> -#define A2DP_AUDIO_HARDWARE_INTERFACE "audio.a2dp" +#include <hardware/hardware.h> +#include "audio_a2dp_hw.h" + +#define LOG_TAG "audio_a2dp_hw" +#define LOG_NDEBUG 0 +#include <cutils/log.h> -#define A2DP_SOCK_PATH "/data/misc/bluedroid/.a2dp_sock" +/***************************************************************************** +** Constants & Macros +******************************************************************************/ -#define AUDIO_CHANNEL_DEFAULT_RATE 44100 -#define AUDIO_CHANNEL_DEFAULT_FORMAT AUDIO_FORMAT_PCM_16_BIT; -#define AUDIO_CHANNEL_OUTPUT_BUFFER_SZ (20*512) /* fixme -- tune this */ +#define CTRL_CHAN_RETRY_COUNT 3 +#define USEC_PER_SEC 1000000L -#define SKT_DISCONNECTED (-1) +#define CASE_RETURN_STR(const) case const: return #const; -#define ADEV_TRACE() LOGV("%s", __FUNCTION__); -#define ADEV_LOG(fmt, ...) LOGD ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define FNLOG() LOGV("%s", __FUNCTION__); +#define DEBUG(fmt, ...) LOGD ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +/***************************************************************************** +** Local type definitions +******************************************************************************/ + +typedef enum { + AUDIO_A2DP_STATE_STARTING, + AUDIO_A2DP_STATE_STARTED, + AUDIO_A2DP_STATE_STOPPING, + AUDIO_A2DP_STATE_STOPPED, + AUDIO_A2DP_STATE_SUSPENDED, /* need explicit set param call to resume (suspend=false) */ + AUDIO_A2DP_STATE_STANDBY /* allows write to autoresume */ +} a2dp_state; struct a2dp_stream_out; @@ -92,78 +109,126 @@ struct a2dp_audio_device { struct a2dp_stream_out *output; }; +struct a2dp_config { + uint32_t rate; + uint32_t channels; + int format; +}; + +/* move ctrl_fd outside output stream and keep open until HAL unloaded ? */ + struct a2dp_stream_out { struct audio_stream_out stream; - int sock_fd; + pthread_mutex_t lock; + int ctrl_fd; + int audio_fd; + a2dp_state state; + struct a2dp_config cfg; + size_t buffer_sz; }; struct a2dp_stream_in { struct audio_stream_in stream; }; +/***************************************************************************** +** Static variables +******************************************************************************/ + +/***************************************************************************** +** Static functions +******************************************************************************/ + static size_t out_get_buffer_size(const struct audio_stream *stream); /***************************************************************************** -** -** BT stack adaptation -** -*****************************************************************************/ +** Externs +******************************************************************************/ + +/***************************************************************************** +** Functions +******************************************************************************/ -void set_blocking(int s) +/***************************************************************************** +** Miscellaneous helper functions +******************************************************************************/ + +static const char* dump_a2dp_ctrl_event(char event) { - int opts; - opts = fcntl(s, F_GETFL); - if (opts < 0) - ADEV_LOG("set blocking (%s)", strerror(errno)); - opts &= ~O_NONBLOCK; - fcntl(s, F_SETFL, opts); + switch(event) + { + CASE_RETURN_STR(A2DP_CTRL_CMD_NONE) + CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY) + CASE_RETURN_STR(A2DP_CTRL_CMD_START) + CASE_RETURN_STR(A2DP_CTRL_CMD_STOP) + CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND) + default: + return "UNKNOWN MSG ID"; + } } -static inline int connect_server_socket(const char* name) +/* logs timestamp with microsec precision + pprev is optional in case a dedicated diff is required */ +static void ts_log(char *tag, int val, struct timespec *pprev_opt) { - int s = socket(AF_LOCAL, SOCK_STREAM, 0); + struct timespec now; + static struct timespec prev = {0,0}; + unsigned long long now_us; + unsigned long long diff_us; - set_blocking(s); + clock_gettime(CLOCK_MONOTONIC, &now); - if(socket_local_client_connect(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) >= 0) + now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000; + + if (pprev_opt) { - ADEV_LOG("connect to %s (fd:%d)", name, s); - return s; + diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000; + *pprev_opt = now; + DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val); } else { - ADEV_LOG("connect to %s (fd:%d) failed, errno:%s", name, s, strerror(errno)); + diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000; + prev = now; + DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val); } - - close(s); - - return -1; } -static int skt_connect(char *path) +/***************************************************************************** +** +** bluedroid stack adaptation +** +*****************************************************************************/ + +static int skt_connect(struct a2dp_stream_out *out, char *path) { int ret; - int fd; + int skt_fd; struct sockaddr_un remote; int len; - ADEV_LOG("connect to %s", path); + DEBUG("connect to %s (sz %d)", path, out->buffer_sz); - if ((fd = connect_server_socket(path)) == -1) + skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0); + + if(socket_local_client_connect(skt_fd, path, + ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0) { - ADEV_LOG("failed to connect (%s)", strerror(errno)); - close(fd); + DEBUG("failed to connect (%s)", strerror(errno)); + close(skt_fd); return -1; } - len = AUDIO_CHANNEL_OUTPUT_BUFFER_SZ; - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len)); + len = out->buffer_sz; + ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len)); - /* add checks for return status */ + /* only issue warning if failed */ + if (ret < 0) + DEBUG("setsockopt failed (%s)", strerror(errno)); - LOGD("sonnected to stack fd = %d", fd); + DEBUG("connected to stack fd = %d", skt_fd); - return fd; + return skt_fd; } static int skt_write(int fd, const void *p, size_t len) @@ -171,7 +236,7 @@ static int skt_write(int fd, const void *p, size_t len) int sent; struct pollfd pfd; - ADEV_TRACE(); + FNLOG(); pfd.fd = fd; pfd.events = POLLOUT; @@ -182,8 +247,11 @@ static int skt_write(int fd, const void *p, size_t len) if (poll(&pfd, 1, 500) == 0) return 0; - if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1) { - LOGE("stream_write failed with errno=%d", errno); + ts_log("skt_write", len, NULL); + + if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1) + { + DEBUG("write failed with errno=%d\n", errno); return -1; } @@ -192,31 +260,249 @@ static int skt_write(int fd, const void *p, size_t len) static int skt_disconnect(int fd) { - ADEV_LOG("fd %d", fd); + DEBUG("fd %d", fd); - if (fd != SKT_DISCONNECTED) + if (fd != AUDIO_SKT_DISCONNECTED) { + shutdown(fd, SHUT_RDWR); close(fd); } return 0; } + + +/***************************************************************************** +** +** AUDIO CONTROL PATH +** +*****************************************************************************/ + +static int a2dp_command(struct a2dp_stream_out *out, char cmd) +{ + char ack; + + DEBUG("A2DP COMMAND %s", dump_a2dp_ctrl_event(cmd)); + + /* send command */ + if (send(out->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1) + { + DEBUG("cmd failed (%s)", strerror(errno)); + skt_disconnect(out->ctrl_fd); + out->ctrl_fd = AUDIO_SKT_DISCONNECTED; + return -1; + } + + /* wait for ack byte */ + if (recv(out->ctrl_fd, &ack, 1, MSG_NOSIGNAL) < 0) + { + DEBUG("ack failed (%s)", strerror(errno)); + skt_disconnect(out->ctrl_fd); + out->ctrl_fd = AUDIO_SKT_DISCONNECTED; + return -1; + } + + DEBUG("A2DP COMMAND %s DONE STATUS %d", dump_a2dp_ctrl_event(cmd), ack); + + if (ack != A2DP_CTRL_ACK_SUCCESS) + return -1; + + return 0; +} + +/***************************************************************************** +** +** AUDIO DATA PATH +** +*****************************************************************************/ + +static void a2dp_stream_out_init(struct a2dp_stream_out *out) +{ + pthread_mutexattr_t lock_attr; + + FNLOG(); + + pthread_mutexattr_init(&lock_attr); + pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&out->lock, &lock_attr); + + out->ctrl_fd = AUDIO_SKT_DISCONNECTED; + out->audio_fd = AUDIO_SKT_DISCONNECTED; + out->state = AUDIO_A2DP_STATE_STOPPED; + + out->cfg.channels = AUDIO_CHANNEL_OUT_STEREO; + out->cfg.format = AUDIO_CHANNEL_DEFAULT_FORMAT; + out->cfg.rate = AUDIO_CHANNEL_DEFAULT_RATE; + + /* manages max capacity of socket pipe */ + out->buffer_sz = AUDIO_CHANNEL_OUTPUT_BUFFER_SZ; +} + +static int start_audio_datapath(struct a2dp_stream_out *out) +{ + int oldstate = out->state; + + DEBUG("state %d", out->state); + + if (out->ctrl_fd == AUDIO_SKT_DISCONNECTED) + return -1; + + out->state = AUDIO_A2DP_STATE_STARTING; + + if (a2dp_command(out, A2DP_CTRL_CMD_START) < 0) + { + DEBUG("audiopath start failed"); + + out->state = oldstate; + return -1; + } + + /* connect socket if not yet connected */ + if (out->audio_fd == AUDIO_SKT_DISCONNECTED) + { + out->audio_fd = skt_connect(out, A2DP_DATA_PATH); + + if (out->audio_fd < 0) + { + out->state = oldstate; + return -1; + } + + out->state = AUDIO_A2DP_STATE_STARTED; + } + + return 0; +} + + +static int stop_audio_datapath(struct a2dp_stream_out *out) +{ + int oldstate = out->state; + + DEBUG("state %d", out->state); + + if (out->ctrl_fd == AUDIO_SKT_DISCONNECTED) + return -1; + + /* prevent any stray output writes from autostarting the stream + while stopping audiopath */ + out->state = AUDIO_A2DP_STATE_STOPPING; + + if (a2dp_command(out, A2DP_CTRL_CMD_STOP) < 0) + { + DEBUG("audiopath stop failed"); + out->state = oldstate; + return -1; + } + + out->state = AUDIO_A2DP_STATE_STOPPED; + + /* disconnect audio path */ + skt_disconnect(out->audio_fd); + out->audio_fd = AUDIO_SKT_DISCONNECTED; + + return 0; +} + +static int suspend_audio_datapath(struct a2dp_stream_out *out, bool standby) +{ + DEBUG("state %d", out->state); + + if (out->ctrl_fd == AUDIO_SKT_DISCONNECTED) + return -1; + + if (out->state == AUDIO_A2DP_STATE_STOPPING) + return -1; + + if (a2dp_command(out, A2DP_CTRL_CMD_SUSPEND) < 0) + return -1; + + if (standby) + out->state = AUDIO_A2DP_STATE_STANDBY; + else + out->state = AUDIO_A2DP_STATE_SUSPENDED; + + /* disconnect audio path */ + skt_disconnect(out->audio_fd); + out->audio_fd = AUDIO_SKT_DISCONNECTED; + + return 0; +} + +static int check_a2dp_ready(struct a2dp_stream_out *out) +{ + DEBUG("state %d", out->state); + + if (a2dp_command(out, A2DP_CTRL_CMD_CHECK_READY) < 0) + { + DEBUG("check a2dp ready failed"); + return -1; + } + return 0; +} + + /***************************************************************************** ** ** audio output callbacks ** *****************************************************************************/ +static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, + size_t bytes) +{ + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + int sent; + + DEBUG("write %d bytes (fd %d)", bytes, out->audio_fd); + + if (out->state == AUDIO_A2DP_STATE_SUSPENDED) + { + DEBUG("stream suspended"); + return -1; + } + + /* only allow autostarting if we are in stopped or standby */ + if ((out->state == AUDIO_A2DP_STATE_STOPPED) || + (out->state == AUDIO_A2DP_STATE_STANDBY)) + { + if (start_audio_datapath(out) < 0) + return -1; + } + else if (out->state != AUDIO_A2DP_STATE_STARTED) + { + DEBUG("stream not in stopped or standby"); + return -1; + } + + sent = skt_write(out->audio_fd, buffer, bytes); + + if (sent == -1) + { + skt_disconnect(out->audio_fd); + out->audio_fd = AUDIO_SKT_DISCONNECTED; + out->state = AUDIO_A2DP_STATE_STOPPED; + } + + DEBUG("wrote %d bytes out of %d bytes", sent, bytes); + return sent; +} + static uint32_t out_get_sample_rate(const struct audio_stream *stream) { - ADEV_TRACE(); - return AUDIO_CHANNEL_DEFAULT_RATE; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + DEBUG("rate %d", out->cfg.rate); + + return out->cfg.rate; } static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) { - ADEV_LOG("out_set_sample_rate : %d", rate); + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + DEBUG("out_set_sample_rate : %d", rate); if (rate != AUDIO_CHANNEL_DEFAULT_RATE) { @@ -224,116 +510,167 @@ static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) return -1; } + out->cfg.rate = rate; + return 0; } static size_t out_get_buffer_size(const struct audio_stream *stream) { - ADEV_TRACE(); - return AUDIO_CHANNEL_OUTPUT_BUFFER_SZ; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + DEBUG("buffer_size : %d", out->buffer_sz); + + return out->buffer_sz; } static uint32_t out_get_channels(const struct audio_stream *stream) { - ADEV_TRACE(); - return AUDIO_CHANNEL_OUT_STEREO; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + DEBUG("channels %d", out->cfg.channels); + + return out->cfg.channels; } static int out_get_format(const struct audio_stream *stream) { - ADEV_TRACE(); - return AUDIO_CHANNEL_DEFAULT_FORMAT; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + DEBUG("format %x", out->cfg.format); + return out->cfg.format; } static int out_set_format(struct audio_stream *stream, int format) { - ADEV_LOG("out_set_format %x", format); - return 0; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + DEBUG("setting format not yet supported (%x)", format); + return -ENOSYS; } static int out_standby(struct audio_stream *stream) { - ADEV_TRACE(); - return 0; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + FNLOG(); + + if (out->state == AUDIO_A2DP_STATE_STARTED) + return suspend_audio_datapath(out, true); + else + return 0; } static int out_dump(const struct audio_stream *stream, int fd) { - ADEV_TRACE(); + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + FNLOG(); return 0; } static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) { - int ret; + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; struct str_parms *parms; + char keyval[16]; + int retval = 0; - ADEV_TRACE(); + DEBUG("state %d", out->state); + + pthread_mutex_lock(&out->lock); parms = str_parms_create_str(kvpairs); - /* fixme -- translate parameter settings to bluedroid */ + /* dump params */ + str_parms_dump(parms); + + retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval)); - return 0; + if (retval >= 0) + { + if (strcmp(keyval, "true") == 0) + { + DEBUG("stream closing, disallow any writes"); + out->state = AUDIO_A2DP_STATE_STOPPING; + } + } + + retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval)); + + if (retval >= 0) + { + if (strcmp(keyval, "true") == 0) + { + if (out->state == AUDIO_A2DP_STATE_STARTED) + retval = suspend_audio_datapath(out, false); + } + else + { + /* only start stream if we were previously suspended */ + if (out->state == AUDIO_A2DP_STATE_SUSPENDED) + retval = start_audio_datapath(out); + } + } + + pthread_mutex_unlock(&out->lock); + str_parms_destroy(parms); + + return retval; } static char * out_get_parameters(const struct audio_stream *stream, const char *keys) { - ADEV_TRACE(); + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + FNLOG(); + + /* add populating param here */ + return strdup(""); } static uint32_t out_get_latency(const struct audio_stream_out *stream) { - ADEV_TRACE(); - return 0; + int latency_us; + + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + FNLOG(); + + latency_us = ((out->buffer_sz * 1000 ) / + audio_stream_frame_size(&out->stream.common) / + out->cfg.rate) * 1000; + + + return (latency_us / 1000) + 200; } static int out_set_volume(struct audio_stream_out *stream, float left, float right) { - ADEV_TRACE(); - return 0; -} + FNLOG(); -static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, - size_t bytes) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; - int sent; + /* volume controlled in audioflinger mixer (digital) */ - ADEV_LOG("write %d bytes", bytes); - - /* connect socket if not available */ - if (out->sock_fd == SKT_DISCONNECTED) - { - out->sock_fd = skt_connect(A2DP_SOCK_PATH); - if (out->sock_fd < 0) - return -1; - } + return -ENOSYS; +} - sent = skt_write(out->sock_fd, buffer, bytes); - ADEV_LOG("wrote %d bytes out of %d bytes", sent, bytes); - return sent; -} static int out_get_render_position(const struct audio_stream_out *stream, uint32_t *dsp_frames) { - ADEV_TRACE(); + FNLOG(); return -EINVAL; } static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) { - ADEV_TRACE(); + FNLOG(); return 0; } static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) { - ADEV_TRACE(); + FNLOG(); return 0; } @@ -343,111 +680,111 @@ static int out_remove_audio_effect(const struct audio_stream *stream, effect_han static uint32_t in_get_sample_rate(const struct audio_stream *stream) { - ADEV_TRACE(); + FNLOG(); return 8000; } static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) { - ADEV_TRACE(); + FNLOG(); return 0; } static size_t in_get_buffer_size(const struct audio_stream *stream) { - ADEV_TRACE(); + FNLOG(); return 320; } static uint32_t in_get_channels(const struct audio_stream *stream) { - ADEV_TRACE(); + FNLOG(); return AUDIO_CHANNEL_IN_MONO; } static int in_get_format(const struct audio_stream *stream) { - ADEV_TRACE(); + FNLOG(); return AUDIO_FORMAT_PCM_16_BIT; } static int in_set_format(struct audio_stream *stream, int format) { - ADEV_TRACE(); + FNLOG(); return 0; } static int in_standby(struct audio_stream *stream) { - ADEV_TRACE(); + FNLOG(); return 0; } static int in_dump(const struct audio_stream *stream, int fd) { - ADEV_TRACE(); + FNLOG(); return 0; } static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) { - ADEV_TRACE(); + FNLOG(); return 0; } static char * in_get_parameters(const struct audio_stream *stream, const char *keys) { - ADEV_TRACE(); + FNLOG(); return strdup(""); } static int in_set_gain(struct audio_stream_in *stream, float gain) { - ADEV_TRACE(); + FNLOG(); return 0; } static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t bytes) { - ADEV_TRACE(); + FNLOG(); return bytes; } static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) { - ADEV_TRACE(); + FNLOG(); return 0; } static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) { - ADEV_TRACE(); + FNLOG(); return 0; } static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) { - ADEV_TRACE(); + FNLOG(); return 0; } - static int adev_open_output_stream(struct audio_hw_device *dev, uint32_t devices, int *format, uint32_t *channels, uint32_t *sample_rate, struct audio_stream_out **stream_out) { struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - struct a2dp_stream_out *out; - int ret; + int ret = 0; + int i; - ADEV_TRACE(); + DEBUG("opening output"); out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out)); + if (!out) return -ENOMEM; @@ -469,8 +806,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->stream.get_render_position = out_get_render_position; /* initialize a2dp specifics */ - a2dp_dev->output = (struct a2dp_stream_out *)&out->stream; - a2dp_dev->output->sock_fd = SKT_DISCONNECTED; + a2dp_stream_out_init(out); /* set output variables */ if (format) @@ -481,12 +817,41 @@ static int adev_open_output_stream(struct audio_hw_device *dev, *sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream); *stream_out = &out->stream; + a2dp_dev->output = out; + /* retry logic to catch any timing variations on control channel */ + for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++) + { + /* connect control channel if not already connected */ + if ((out->ctrl_fd = skt_connect(out, A2DP_CTRL_PATH)) > 0) + { + /* success, now check if stack is ready */ + if (check_a2dp_ready(out) == 0) + break; + + DEBUG("error : a2dp not ready, wait 250 ms and retry"); + usleep(250000); + skt_disconnect(out->ctrl_fd); + } + + /* ctrl channel not ready, wait a bit */ + usleep(250000); + } + + if (out->ctrl_fd == AUDIO_SKT_DISCONNECTED) + { + DEBUG("ctrl socket failed to connect (%s)", strerror(errno)); + ret = -1; + goto err_open; + } + + DEBUG("success"); return 0; err_open: free(out); *stream_out = NULL; + DEBUG("failed"); return ret; } @@ -494,24 +859,36 @@ static void adev_close_output_stream(struct audio_hw_device *dev, struct audio_stream_out *stream) { struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - ADEV_TRACE(); - skt_disconnect(a2dp_dev->output->sock_fd); + struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + + DEBUG("closing output (state %d)", out->state); + + if ((out->state == AUDIO_A2DP_STATE_STARTED) || (out->state == AUDIO_A2DP_STATE_STOPPING)) + stop_audio_datapath(out); + + skt_disconnect(out->ctrl_fd); free(stream); + a2dp_dev->output = NULL; + + DEBUG("done"); } static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) { - struct str_parms *parms; + struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; + struct a2dp_stream_out *out = a2dp_dev->output; + int retval = 0; - ADEV_TRACE(); + if (out == NULL) + return retval; - parms = str_parms_create_str(kvpairs); + DEBUG("state %d", out->state); - str_parms_dump(parms); + pthread_mutex_lock(&out->lock); + retval = out->stream.common.set_parameters((struct audio_stream *)out, kvpairs); + pthread_mutex_unlock(&out->lock); - ADEV_LOG("### not handled ###"); - - return 0; + return retval; } static char * adev_get_parameters(const struct audio_hw_device *dev, @@ -519,7 +896,7 @@ static char * adev_get_parameters(const struct audio_hw_device *dev, { struct str_parms *parms; - ADEV_TRACE(); + FNLOG(); parms = str_parms_create_str(keys); @@ -532,44 +909,42 @@ static int adev_init_check(const struct audio_hw_device *dev) { struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device*)dev; - ADEV_TRACE(); - - /* fixme -- setup control path for a2dp datapath */ + FNLOG(); return 0; } static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) { - ADEV_TRACE(); + FNLOG(); return -ENOSYS; } static int adev_set_master_volume(struct audio_hw_device *dev, float volume) { - ADEV_TRACE(); + FNLOG(); return -ENOSYS; } static int adev_set_mode(struct audio_hw_device *dev, int mode) { - ADEV_TRACE(); + FNLOG(); return 0; } static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) { - ADEV_TRACE(); + FNLOG(); return -ENOSYS; } static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) { - ADEV_TRACE(); + FNLOG(); return -ENOSYS; } @@ -578,7 +953,7 @@ static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, uint32_t sample_rate, int format, int channel_count) { - ADEV_TRACE(); + FNLOG(); return 320; } @@ -593,7 +968,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, uint32_t devices, struct a2dp_stream_in *in; int ret; - ADEV_TRACE(); + FNLOG(); in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in)); @@ -628,21 +1003,21 @@ err_open: static void adev_close_input_stream(struct audio_hw_device *dev, struct audio_stream_in *in) { - ADEV_TRACE(); + FNLOG(); return; } static int adev_dump(const audio_hw_device_t *device, int fd) { - ADEV_TRACE(); + FNLOG(); return 0; } static int adev_close(hw_device_t *device) { - ADEV_TRACE(); + FNLOG(); free(device); return 0; @@ -650,7 +1025,7 @@ static int adev_close(hw_device_t *device) static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev) { - ADEV_TRACE(); + FNLOG(); return (AUDIO_DEVICE_OUT_ALL_A2DP); } @@ -661,15 +1036,16 @@ static int adev_open(const hw_module_t* module, const char* name, struct a2dp_audio_device *adev; int ret; - ADEV_TRACE(); + FNLOG(); if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) { - ADEV_LOG("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE); + DEBUG("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE); return -EINVAL; } adev = calloc(1, sizeof(struct a2dp_audio_device)); + if (!adev) return -ENOMEM; @@ -694,6 +1070,8 @@ static int adev_open(const hw_module_t* module, const char* name, adev->device.close_input_stream = adev_close_input_stream; adev->device.dump = adev_dump; + adev->output = NULL; + *device = &adev->device.common; return 0; diff --git a/audio_a2dp_hw/audio_a2dp_hw.h b/audio_a2dp_hw/audio_a2dp_hw.h new file mode 100644 index 0000000..77e113a --- /dev/null +++ b/audio_a2dp_hw/audio_a2dp_hw.h @@ -0,0 +1,114 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * This program is the proprietary software of Broadcom Corporation and/or its + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. + * + * Except as expressly set forth in the Authorized License, + * + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of + * Broadcom integrated circuit products. + * + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING + * OUT OF USE OR PERFORMANCE OF THE SOFTWARE. + * + * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM + * OR ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. + * + *****************************************************************************/ + +/***************************************************************************** + * + * Filename: audio_a2dp_hw.h + * + * Description: + * + *****************************************************************************/ + +#ifndef AUDIO_A2DP_HW_H +#define AUDIO_A2DP_HW_H + +/***************************************************************************** +** Constants & Macros +******************************************************************************/ + +#define A2DP_AUDIO_HARDWARE_INTERFACE "audio.a2dp" +#define A2DP_CTRL_PATH "/data/misc/bluedroid/.a2dp_ctrl" +#define A2DP_DATA_PATH "/data/misc/bluedroid/.a2dp_data" + +#define AUDIO_CHANNEL_DEFAULT_RATE 44100 +#define AUDIO_CHANNEL_DEFAULT_FORMAT AUDIO_FORMAT_PCM_16_BIT +#define AUDIO_CHANNEL_OUTPUT_BUFFER_SZ (20*512) +#define AUDIO_SKT_DISCONNECTED (-1) + +typedef enum { + A2DP_CTRL_CMD_NONE, + A2DP_CTRL_CMD_CHECK_READY, + A2DP_CTRL_CMD_START, + A2DP_CTRL_CMD_STOP, + A2DP_CTRL_CMD_SUSPEND +} tA2DP_CTRL_CMD; + +typedef enum { + A2DP_CTRL_ACK_SUCCESS, + A2DP_CTRL_ACK_FAILURE +} tA2DP_CTRL_ACK; + + +/***************************************************************************** +** Type definitions for callback functions +******************************************************************************/ + +/***************************************************************************** +** Type definitions and return values +******************************************************************************/ + +/***************************************************************************** +** Extern variables and functions +******************************************************************************/ + +/***************************************************************************** +** Functions +******************************************************************************/ + + +/***************************************************************************** +** +** Function +** +** Description +** +** Returns +** +******************************************************************************/ + +#endif /* A2DP_AUDIO_HW_H */ + diff --git a/bta/av/bta_av_aact.c b/bta/av/bta_av_aact.c index 423c322..2bcbf01 100644 --- a/bta/av/bta_av_aact.c +++ b/bta/av/bta_av_aact.c @@ -1701,7 +1701,7 @@ void bta_av_do_start (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) { bta_av_start_ok(p_scb, NULL); } - APPL_TRACE_DEBUG1("role:x%x", p_scb->role); + APPL_TRACE_DEBUG2("started %d role:x%x", p_scb->started, p_scb->role); } /******************************************************************************* @@ -1721,7 +1721,9 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) BT_HDR *p_buf; UINT8 policy = HCI_ENABLE_SNIFF_MODE; - APPL_TRACE_ERROR1("bta_av_str_stopped:audio_open_cnt=%d", bta_av_cb.audio_open_cnt); + APPL_TRACE_ERROR2("bta_av_str_stopped:audio_open_cnt=%d, p_data %x", + bta_av_cb.audio_open_cnt, p_data); + bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr); if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 || bta_av_cb.audio_open_cnt == 1) policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; @@ -1749,6 +1751,7 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) suspend_rsp.chnl = p_scb->chnl; suspend_rsp.hndl = p_scb->hndl; + if (p_data && p_data->api_stop.suspend) { APPL_TRACE_DEBUG2("suspending: %d, sup:%d", start, p_scb->suspend_sup); @@ -1768,6 +1771,10 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) } else { + suspend_rsp.status = BTA_AV_SUCCESS; + suspend_rsp.initiator = TRUE; + APPL_TRACE_EVENT1("bta_av_str_stopped status %d", suspend_rsp.status); + (*bta_av_cb.p_cback)(BTA_AV_STOP_EVT, (tBTA_AV *) &suspend_rsp); } } @@ -2075,7 +2082,9 @@ void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) p_scb->p_cos->start(p_scb->hndl, p_scb->codec_type); p_scb->co_started = TRUE; - APPL_TRACE_ERROR2("bta_av_start_ok suspending: %d, role:x%x", suspend, p_scb->role); + APPL_TRACE_DEBUG3("bta_av_start_ok suspending: %d, role:x%x, init %d", + suspend, p_scb->role, initiator); + start.suspending = suspend; start.initiator = initiator; start.chnl = p_scb->chnl; diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c index 3c93f23..3c93f23 100755..100644 --- a/bta/dm/bta_dm_act.c +++ b/bta/dm/bta_dm_act.c diff --git a/bta/dm/bta_dm_api.c b/bta/dm/bta_dm_api.c index 4c77f37..4c77f37 100755..100644 --- a/bta/dm/bta_dm_api.c +++ b/bta/dm/bta_dm_api.c diff --git a/bta/dm/bta_dm_int.h b/bta/dm/bta_dm_int.h index 6d220e7..6d220e7 100755..100644 --- a/bta/dm/bta_dm_int.h +++ b/bta/dm/bta_dm_int.h diff --git a/bta/dm/bta_dm_main.c b/bta/dm/bta_dm_main.c index 38bf0af..38bf0af 100755..100644 --- a/bta/dm/bta_dm_main.c +++ b/bta/dm/bta_dm_main.c diff --git a/bta/include/bta_api.h b/bta/include/bta_api.h index 57baa4d..57baa4d 100755..100644 --- a/bta/include/bta_api.h +++ b/bta/include/bta_api.h diff --git a/btif/co/bta_ag_co.c b/btif/co/bta_ag_co.c index ec1d5bb..92c96c3 100644 --- a/btif/co/bta_ag_co.c +++ b/btif/co/bta_ag_co.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2011 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -72,8 +72,8 @@ ** Description This callout function is executed by AG when it is ** started by calling BTA_AgEnable(). This function can be ** used by the phone to initialize audio paths or for other -** initialization purposes. -** +** initialization purposes. +** ** ** Returns Void. ** @@ -90,7 +90,7 @@ void bta_ag_co_init(void) ** ** Description This function is called by the AG before the audio connection ** is brought up, after it comes up, and after it goes down. -** +** ** Parameters handle - handle of the AG instance ** state - Audio state ** BTA_AG_CO_AUD_STATE_OFF - Audio has been turned off @@ -115,7 +115,7 @@ void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state) ** is opened. The phone can use this function to set ** up data paths or perform any required initialization or ** set up particular to the connected service. -** +** ** ** Returns void ** @@ -131,7 +131,7 @@ void bta_ag_co_data_open(UINT16 handle, tBTA_SERVICE_ID service) ** ** Description This function is called by AG when a service level ** connection is closed -** +** ** ** Returns void ** diff --git a/btif/co/bta_av_co.c b/btif/co/bta_av_co.c index 1dbd940..bddde54 100644 --- a/btif/co/bta_av_co.c +++ b/btif/co/bta_av_co.c @@ -21,7 +21,7 @@ #include "btif_media.h" #include "sbc_encoder.h" -#include "btif_av.h" +#include "btif_av_co.h" /***************************************************************************** @@ -216,7 +216,7 @@ static tBTA_AV_CO_PEER *bta_av_co_get_peer(tBTA_AV_HNDL hndl) FUNC_TRACE(); index = BTA_AV_CO_AUDIO_HNDL_TO_INDX(hndl); - APPL_TRACE_ERROR2("%s index:%d", __FUNCTION__, index); + /* Sanity check */ if (index >= BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers)) { @@ -504,7 +504,7 @@ BTA_API void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_ty APPL_TRACE_DEBUG6("bta_av_co_audio_setconfig p_codec_info[%x:%x:%x:%x:%x:%x]", p_codec_info[1], p_codec_info[2], p_codec_info[3], p_codec_info[4], p_codec_info[5], p_codec_info[6]); - APPL_TRACE_DEBUG4("num_protect:0x%02x protect_info:0x%02x%02x%02x", + APPL_TRACE_DEBUG4("num_protect:0x%02x protect_info:0x%02x%02x%02x", num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]); /* Retrieve the peer info */ @@ -813,11 +813,15 @@ static BOOLEAN bta_av_co_audio_codec_build_config(const UINT8 *p_codec_caps, UIN { FUNC_TRACE(); - /* By default, just copy the current codec configuration */ - memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg.info, AVDT_CODEC_SIZE); + memset(p_codec_cfg, 0, AVDT_CODEC_SIZE); + switch (bta_av_co_cb.codec_cfg.id) { case BTIF_AV_CODEC_SBC: + /* only copy the relevant portions for this codec to avoid issues when + comparing codec configs covering larger codec sets than SBC (7 bytes) */ + memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg.info, BTA_AV_CO_SBC_MAX_BITPOOL_OFF+1); + /* Update the bit pool boundaries with the codec capabilities */ p_codec_cfg[BTA_AV_CO_SBC_MIN_BITPOOL_OFF] = p_codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF]; p_codec_cfg[BTA_AV_CO_SBC_MAX_BITPOOL_OFF] = p_codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF]; @@ -850,10 +854,10 @@ static BOOLEAN bta_av_co_audio_codec_cfg_matches_caps(UINT8 codec_id, const UINT if (!((p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF] & p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF]) && (p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF] & p_codec_cfg[BTA_AV_CO_SBC_BLOCK_BAND_OFF]))) { - APPL_TRACE_EVENT4("FALSE %x %x %x %x", - p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF], - p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF], - p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF], + APPL_TRACE_EVENT4("FALSE %x %x %x %x", + p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF], + p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF], + p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF], p_codec_cfg[BTA_AV_CO_SBC_BLOCK_BAND_OFF]); return FALSE; } @@ -927,7 +931,7 @@ static BOOLEAN bta_av_co_cp_is_scmst(const UINT8 *p_protectinfo) return TRUE; } } - + return FALSE; } @@ -1008,6 +1012,7 @@ static BOOLEAN bta_av_co_audio_peer_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT /* Configure the codec type to look for */ codec_type = bta_av_co_cb.codec_cfg.id; + for (index = 0; index < p_peer->num_sup_snks; index++) { if (p_peer->snks[index].codec_type == codec_type) @@ -1173,6 +1178,7 @@ void bta_av_co_audio_codec_reset(void) /* Reset the current configuration to SBC */ bta_av_co_cb.codec_cfg.id = BTIF_AV_CODEC_SBC; + if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_SBC_CIE *)&btif_av_sbc_default_config, bta_av_co_cb.codec_cfg.info) != A2D_SUCCESS) { APPL_TRACE_ERROR0("bta_av_co_audio_codec_reset A2D_BldSbcInfo failed"); @@ -1311,10 +1317,10 @@ BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_min { /* Update the bitpool boundaries of the current config */ p_sbc_config->min_bitpool = - BTA_AV_CO_MAX(p_sink->codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF], + BTA_AV_CO_MAX(p_sink->codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF], p_sbc_config->min_bitpool); p_sbc_config->max_bitpool = - BTA_AV_CO_MIN(p_sink->codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF], + BTA_AV_CO_MIN(p_sink->codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF], p_sbc_config->max_bitpool); break; } diff --git a/btif/co/bta_dm_co.c b/btif/co/bta_dm_co.c index b4c893c..da9a5ce 100644 --- a/btif/co/bta_dm_co.c +++ b/btif/co/bta_dm_co.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2011 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -81,7 +81,7 @@ BOOLEAN bta_dm_co_get_compress_memory(tBTA_SYS_ID id, UINT8 **memory_p, UINT32 * ** Parameters bd_addr - The peer device ** *p_io_cap - The local Input/Output capabilities ** *p_oob_data - TRUE, if OOB data is available for the peer device. -** *p_auth_req - TRUE, if MITM protection is required. +** *p_auth_req - TRUE, if MITM protection is required. ** ** Returns void. ** @@ -101,7 +101,7 @@ void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_o ** Parameters bd_addr - The peer device ** io_cap - The remote Input/Output capabilities ** oob_data - TRUE, if OOB data is available for the peer device. -** auth_req - TRUE, if MITM protection is required. +** auth_req - TRUE, if MITM protection is required. ** ** Returns void. ** @@ -119,7 +119,7 @@ void bta_dm_co_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, ** platform wants allow link key upgrade ** ** Parameters bd_addr - The peer device -** *p_upgrade - TRUE, if link key upgrade is desired. +** *p_upgrade - TRUE, if link key upgrade is desired. ** ** Returns void. ** @@ -175,8 +175,8 @@ void bta_dm_co_rmt_oob(BD_ADDR bd_addr) ** ** Function btui_sco_codec_callback ** -** Description Callback for btui codec. -** +** Description Callback for btui codec. +** ** ** Returns void ** @@ -189,15 +189,15 @@ static void btui_sco_codec_callback(UINT16 event, UINT16 sco_handle) ** ** Function bta_dm_sco_co_init ** -** Description This function can be used by the phone to initialize audio +** Description This function can be used by the phone to initialize audio ** codec or for other initialization purposes before SCO connection -** is opened. -** +** is opened. +** ** ** Returns tBTA_DM_SCO_ROUTE_TYPE: SCO routing configuration type. ** *******************************************************************************/ -tBTA_DM_SCO_ROUTE_TYPE bta_dm_sco_co_init(UINT32 rx_bw, UINT32 tx_bw, +tBTA_DM_SCO_ROUTE_TYPE bta_dm_sco_co_init(UINT32 rx_bw, UINT32 tx_bw, tBTA_CODEC_INFO * p_codec_type, UINT8 app_id) { tBTM_SCO_ROUTE_TYPE route = BTA_DM_SCO_ROUTE_PCM; @@ -236,7 +236,7 @@ tBTA_DM_SCO_ROUTE_TYPE bta_dm_sco_co_init(UINT32 rx_bw, UINT32 tx_bw, ** Function bta_dm_sco_co_open ** ** Description This function is executed when a SCO connection is open. -** +** ** ** Returns void ** @@ -264,7 +264,7 @@ void bta_dm_sco_co_open(UINT16 handle, UINT8 pkt_size, UINT16 event) ** Function bta_dm_sco_co_close ** ** Description This function is called when a SCO connection is closed -** +** ** ** Returns void ** @@ -285,7 +285,7 @@ void bta_dm_sco_co_close(void) ** ** Function bta_dm_sco_co_in_data ** -** Description This function is called to send incoming SCO data to application. +** Description This function is called to send incoming SCO data to application. ** ** Returns void ** @@ -302,13 +302,13 @@ void bta_dm_sco_co_in_data(BT_HDR *p_buf) ** ** Function bta_dm_sco_co_out_data ** -** Description This function is called to send SCO data over HCI. +** Description This function is called to send SCO data over HCI. ** ** Returns void ** *******************************************************************************/ void bta_dm_sco_co_out_data(BT_HDR **p_buf) -{ +{ btui_sco_codec_readbuf(p_buf); } @@ -326,20 +326,20 @@ void bta_dm_sco_co_out_data(BT_HDR **p_buf) ** Parameters bd_addr - The peer device ** *p_max_key_size - max key size local device supported. ** *p_init_key - initiator keys. -** *p_resp_key - responder keys. +** *p_resp_key - responder keys. ** ** Returns void. ** *******************************************************************************/ -void bta_dm_co_le_io_key_req(BD_ADDR bd_addr, UINT8 *p_max_key_size, - tBTA_LE_KEY_TYPE *p_init_key, +void bta_dm_co_le_io_key_req(BD_ADDR bd_addr, UINT8 *p_max_key_size, + tBTA_LE_KEY_TYPE *p_init_key, tBTA_LE_KEY_TYPE *p_resp_key ) { BTIF_TRACE_ERROR0("##################################"); BTIF_TRACE_ERROR0("bta_dm_co_le_io_key_req: only setting max size to 16"); BTIF_TRACE_ERROR0("##################################"); *p_max_key_size = 16; - *p_init_key = *p_resp_key = + *p_init_key = *p_resp_key = (BTA_LE_KEY_PENC|BTA_LE_KEY_PID|BTA_LE_KEY_PCSRK|BTA_LE_KEY_LENC|BTA_LE_KEY_LID|BTA_LE_KEY_LCSRK); } @@ -351,7 +351,7 @@ void bta_dm_co_le_io_key_req(BD_ADDR bd_addr, UINT8 *p_max_key_size, ** Description This callout function is to load the local BLE keys if available ** on the device. ** -** Parameters none +** Parameters none ** ** Returns void. ** @@ -374,22 +374,22 @@ void bta_dm_co_ble_load_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OC ** Parameters bd_addr - The peer device ** *p_io_cap - The local Input/Output capabilities ** *p_oob_data - TRUE, if OOB data is available for the peer device. -** *p_auth_req - Auth request setting (Bonding and MITM required or not) +** *p_auth_req - Auth request setting (Bonding and MITM required or not) ** *p_max_key_size - max key size local device supported. ** *p_init_key - initiator keys. -** *p_resp_key - responder keys. +** *p_resp_key - responder keys. ** ** Returns void. ** *******************************************************************************/ -void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, +void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data, tBTA_LE_AUTH_REQ *p_auth_req, - UINT8 *p_max_key_size, - tBTA_LE_KEY_TYPE *p_init_key, + UINT8 *p_max_key_size, + tBTA_LE_KEY_TYPE *p_init_key, tBTA_LE_KEY_TYPE *p_resp_key ) { - /* if OOB is not supported, this call-out function does not need to do anything + /* if OOB is not supported, this call-out function does not need to do anything * otherwise, look for the OOB data associated with the address and set *p_oob_data accordingly * If the answer can not be obtained right away, * set *p_oob_data to BTA_OOB_UNKNOWN and call bta_dm_ci_io_req() when the answer is available */ diff --git a/btif/co/bta_fs_co.c b/btif/co/bta_fs_co.c index 9b0ab0a..0ba35bd 100644 --- a/btif/co/bta_fs_co.c +++ b/btif/co/bta_fs_co.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2011 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -86,7 +86,7 @@ extern const tBTA_PBS_CFG bta_pbs_cfg; -static int del_path (const char *path) +static int del_path (const char *path) { DIR *dir; struct dirent *de; @@ -107,7 +107,7 @@ static int del_path (const char *path) strcat(nameBuffer, "/"); int nameLen = strlen(nameBuffer); filenameOffset = nameBuffer + nameLen; - + for (;;) { de = readdir(dir); @@ -117,15 +117,15 @@ static int del_path (const char *path) break; } - if (0 == strcmp(de->d_name, ".") || 0 == strcmp(de->d_name, "..")) + if (0 == strcmp(de->d_name, ".") || 0 == strcmp(de->d_name, "..")) continue; - + if((int)strlen(de->d_name) > PATH_MAX - nameLen) { BTIF_TRACE_DEBUG1("d_name len:%d is too big", strlen(de->d_name)); ret = -1; break; } - + strcpy(filenameOffset, de->d_name); ret = lstat (nameBuffer, &statBuffer); @@ -154,18 +154,18 @@ static int del_path (const char *path) ret = rmdir(path); BTIF_TRACE_DEBUG2("rmdir return:%d for path:%s", ret, path); } - + return ret; } -inline int getAccess(int accType, struct stat *buffer, char *p_path) +inline int getAccess(int accType, struct stat *buffer, char *p_path) { struct statfs fsbuffer; int idType; - if(! buffer) + if(! buffer) return BTA_FS_CO_FAIL; //idType= (buffer->st_uid== BT_UID) ? 1 : (buffer->st_uid== BT_GID) ? 2 : 3; @@ -178,7 +178,7 @@ inline int getAccess(int accType, struct stat *buffer, char *p_path) idType = 2; else idType = 3; - if(statfs(p_path, &fsbuffer)==0) + if(statfs(p_path, &fsbuffer)==0) { if(fsbuffer.f_type == FAT_FS) return BTA_FS_CO_OK; @@ -186,43 +186,43 @@ inline int getAccess(int accType, struct stat *buffer, char *p_path) else { return BTA_FS_CO_FAIL; } - + switch(accType) { case 4: if(idType== 1) { //Id is User Id - if(buffer-> st_mode & S_IRUSR) + if(buffer-> st_mode & S_IRUSR) return BTA_FS_CO_OK; } else if(idType==2) { //Id is Group Id - if(buffer-> st_mode & S_IRGRP) + if(buffer-> st_mode & S_IRGRP) return BTA_FS_CO_OK; } else { //Id is Others - if(buffer-> st_mode & S_IROTH) + if(buffer-> st_mode & S_IROTH) return BTA_FS_CO_OK; } break; case 6: if(idType== 1) { //Id is User Id - if((buffer-> st_mode & S_IRUSR) && (buffer-> st_mode & S_IWUSR)) + if((buffer-> st_mode & S_IRUSR) && (buffer-> st_mode & S_IWUSR)) return BTA_FS_CO_OK; } else if(idType==2) { //Id is Group Id - if((buffer-> st_mode & S_IRGRP) && (buffer-> st_mode & S_IWGRP)) + if((buffer-> st_mode & S_IRGRP) && (buffer-> st_mode & S_IWGRP)) return BTA_FS_CO_OK; } else { //Id is Others - if((buffer-> st_mode & S_IROTH) && (buffer-> st_mode & S_IWOTH)) + if((buffer-> st_mode & S_IROTH) && (buffer-> st_mode & S_IWOTH)) return BTA_FS_CO_OK; } break; - + default: return BTA_FS_CO_OK; - } + } BTIF_TRACE_DEBUG0("*************FTP- Access Failed **********"); - return BTA_FS_CO_EACCES; + return BTA_FS_CO_EACCES; } @@ -347,7 +347,7 @@ static int btapp_fs_check_space( const char *p_path, const UINT32 size, const UI ** of the call-out function. ** ** Returns void -** +** ** Note: Upon completion of the request, a file descriptor (int), ** if successful, and an error code (tBTA_FS_CO_STATUS) ** are returned in the call-in function, bta_fs_ci_open(). @@ -366,7 +366,7 @@ void bta_fs_co_open(const char *p_path, int oflags, UINT32 size, UINT16 evt, /* Convert BTA oflags into os specific flags */ oflags = bta_fs_convert_bta_oflags(oflags); - + /* check available space in case of write access. oflags are in OS format! */ if (oflags & (O_RDWR|O_WRONLY)) { @@ -472,7 +472,7 @@ tBTA_FS_CO_STATUS bta_fs_co_close(int fd, UINT8 app_id) ** of the call-out function. ** ** Returns void -** +** ** Note: Upon completion of the request, bta_fs_ci_read() is ** called with the buffer of data, along with the number ** of bytes read into the buffer, and a status. The @@ -518,7 +518,7 @@ void bta_fs_co_read(int fd, UINT8 *p_buf, UINT16 nbytes, UINT16 evt, UINT8 ssn, ** of the call-out function. ** ** Returns void -** +** ** Note: Upon completion of the request, bta_fs_ci_write() is ** called with the file descriptor and the status. The ** call-in function should only be called when ALL requested @@ -547,7 +547,7 @@ void bta_fs_co_write(int fd, const UINT8 *p_buf, UINT16 nbytes, UINT16 evt, ** Function bta_fs_co_seek ** ** Description This function is called by io to move the file pointer -** of a previously opened file to the specified location for +** of a previously opened file to the specified location for ** the next read or write operation. ** ** Parameters fd - file descriptor of file. @@ -555,7 +555,7 @@ void bta_fs_co_write(int fd, const UINT8 *p_buf, UINT16 nbytes, UINT16 evt, ** origin - Initial position. ** ** Returns void -** +** *******************************************************************************/ void bta_fs_co_seek (int fd, INT32 offset, INT16 origin, UINT8 app_id) { @@ -592,28 +592,28 @@ tBTA_FS_CO_STATUS bta_fs_co_access(const char *p_path, int mode, BOOLEAN *p_is_d struct stat buffer; #if (TRUE==BTA_FS_DEBUG) - LOGI("***********CHECKING ACCESS TO = %s", p_path); + LOGI("***********CHECKING ACCESS TO = %s", p_path); #endif - #if (defined BTA_PBS_INCLUDED) && (BTA_PBS_INCLUDED == TRUE) + #if (defined BTA_PBS_INCLUDED) && (BTA_PBS_INCLUDED == TRUE) if (app_id == UI_PBS_ID) { - + *p_is_dir = TRUE; #if (TRUE==BTA_FS_DEBUG) - LOGI("***********SUPPORTED REPO = %d", bta_pbs_cfg.supported_repositories); + LOGI("***********SUPPORTED REPO = %d", bta_pbs_cfg.supported_repositories); #endif - //Check if SIM contact requested, and if so if it's supported. + //Check if SIM contact requested, and if so if it's supported. //If not, return error! if (strstr(p_path,"SIM1") && !(bta_pbs_cfg.supported_repositories & 0x2)) { - LOGI("***********RETURNING FAIL!"); + LOGI("***********RETURNING FAIL!"); return BTA_FS_CO_FAIL; } #if (TRUE==BTA_FS_DEBUG) - LOGI("***********RETURNING success!"); + LOGI("***********RETURNING success!"); #endif return (status); } @@ -621,24 +621,24 @@ tBTA_FS_CO_STATUS bta_fs_co_access(const char *p_path, int mode, BOOLEAN *p_is_d *p_is_dir = FALSE; - + if (mode == BTA_FS_ACC_RDWR) os_mode = 6; else if (mode == BTA_FS_ACC_READ) os_mode = 4; - - if (stat(p_path, &buffer) == 0) + + if (stat(p_path, &buffer) == 0) { /* Determine if the object is a file or directory */ if (S_ISDIR(buffer.st_mode)) *p_is_dir = TRUE; } - else + else { BTIF_TRACE_DEBUG0("stat() failed! "); return BTA_FS_CO_FAIL; } - + status=getAccess (os_mode, &buffer, (char*)p_path); return (status); } @@ -701,14 +701,14 @@ tBTA_FS_CO_STATUS bta_fs_co_rmdir(const char *p_path, UINT8 app_id) tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; struct stat buffer; char *dirName, *tmp = NULL; - + path_len = strlen( p_path )+1; BTIF_TRACE_DEBUG2( "bta_fs_co_rmdir( app_id: %d ): path_len: %d", app_id, path_len ); #if (TRUE==BTA_FS_DEBUG) BTIF_TRACE_DEBUG1( "bta_fs_co_rmdir():path_len: %d, p_path", app_id ); BTIF_TRACE_DEBUG0( p_path ); #endif - + /* allocate a temp buffer for path with 0 char. make sure not to crash if path is too big! */ dirName = (char*) calloc(1, path_len+1); if ( NULL != dirName ) @@ -721,7 +721,7 @@ tBTA_FS_CO_STATUS bta_fs_co_rmdir(const char *p_path, UINT8 app_id) app_id, path_len ); return BTA_FS_CO_FAIL; } - + if (NULL!= (tmp = strrchr(dirName, '/'))) { *tmp = '\0'; @@ -738,7 +738,7 @@ tBTA_FS_CO_STATUS bta_fs_co_rmdir(const char *p_path, UINT8 app_id) #endif return BTA_FS_CO_FAIL; } - + free(dirName); if (status != BTA_FS_CO_OK) { @@ -747,7 +747,7 @@ tBTA_FS_CO_STATUS bta_fs_co_rmdir(const char *p_path, UINT8 app_id) #endif return status; } - + if (stat(p_path, &buffer) == 0) { status = getAccess(6, &buffer, (char*)p_path); @@ -759,7 +759,7 @@ tBTA_FS_CO_STATUS bta_fs_co_rmdir(const char *p_path, UINT8 app_id) #endif return BTA_FS_CO_FAIL; } - + if (status != BTA_FS_CO_OK) { #if (TRUE==BTA_FS_DEBUG) @@ -807,37 +807,37 @@ tBTA_FS_CO_STATUS bta_fs_co_unlink(const char *p_path, UINT8 app_id) tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; char *dirName, *tmp=NULL; struct stat buffer; - + if(! p_path) return BTA_FS_CO_FAIL; /* buffer needs to be NULL terminated - so add one more byte to be zero'd out */ -#if 0 +#if 0 dirName= (char*) calloc(1, strlen(p_path)); /* <--- this can cause problems */ -#else +#else dirName= (char*) calloc(1, strlen(p_path) + 1); -#endif - +#endif + strncpy(dirName, p_path, strlen(p_path)); - if((tmp=strrchr(dirName, '/'))) + if((tmp=strrchr(dirName, '/'))) { *tmp='\0'; - } - if (stat(dirName, &buffer) == 0) + } + if (stat(dirName, &buffer) == 0) { status=getAccess (6, &buffer, dirName); free(dirName); } - else + else { BTIF_TRACE_DEBUG0("stat() failed! "); free(dirName); return BTA_FS_CO_FAIL; } - + if(status!= BTA_FS_CO_OK) return status; - + if ((unlink (p_path)) != 0) { err = errno; @@ -869,7 +869,7 @@ tBTA_FS_CO_STATUS bta_fs_co_unlink(const char *p_path, UINT8 app_id) ** of the call-out function. ** ** Returns void -** +** ** Note: Upon completion of the request, the status is passed ** in the bta_fs_ci_direntry() call-in function. ** BTA_FS_CO_OK is returned when p_entry is valid, @@ -996,7 +996,7 @@ void bta_fs_co_getdirentry(const char *p_path, BOOLEAN first_item, ** ** Function bta_fs_co_setdir ** -** Description This function is executed by BTA when the server changes the +** Description This function is executed by BTA when the server changes the ** local path ** ** Parameters p_path - the new path. @@ -1005,7 +1005,7 @@ void bta_fs_co_getdirentry(const char *p_path, BOOLEAN first_item, ** of the call-out function. ** ** Returns void -** +** *******************************************************************************/ void bta_fs_co_setdir(const char *p_path, UINT8 app_id) { @@ -1013,7 +1013,7 @@ void bta_fs_co_setdir(const char *p_path, UINT8 app_id) } /******************************************************************************* -** OBEX14 Reliable Session not supported. Stub associated callouts. +** OBEX14 Reliable Session not supported. Stub associated callouts. ******************************************************************************/ /******************************************************************************* @@ -1029,7 +1029,7 @@ void bta_fs_co_setdir(const char *p_path, UINT8 app_id) ** of the call-out function. ** ** Returns void -** +** ** Note: Upon completion of the request, the related session information, ** if successful, and an error code (tBTA_FS_CO_STATUS) ** are returned in the call-in function, bta_fs_ci_resume(). @@ -1055,7 +1055,7 @@ void bta_fs_co_resume(UINT16 evt, UINT8 app_id) ** ** Returns (tBTA_FS_CO_STATUS) status of the call. ** [BTA_FS_CO_OK if successful] -** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); +** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); ** or p_src_path is a directory and p_dest_path specifies a different path. ] ** [BTA_FS_CO_FAIL otherwise] ** @@ -1081,7 +1081,7 @@ void bta_fs_co_set_perms(const char *p_src_path, UINT8 *p_perms, UINT16 evt, UI ** ** Returns (tBTA_FS_CO_STATUS) status of the call. ** [BTA_FS_CO_OK if successful] -** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); +** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); ** or p_src_path is a directory and p_dest_path specifies a different path. ] ** [BTA_FS_CO_FAIL otherwise] ** @@ -1109,7 +1109,7 @@ void bta_fs_co_rename(const char *p_src_path, const char *p_dest_path, UINT8 *p_ ** Returns (tBTA_FS_CO_STATUS) status of the call. ** [BTA_FS_CO_OK if successful] ** [BTA_FS_CO_EIS_DIR if p_src_path is a folder] -** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); +** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); ** or p_src_path is a directory and p_dest_path specifies a different path. ] ** [BTA_FS_CO_FAIL otherwise] ** @@ -1133,7 +1133,7 @@ void bta_fs_co_copy(const char *p_src_path, const char *p_dest_path, UINT8 *p_pe ** of the call-out function. ** ** Returns void -** +** *******************************************************************************/ void bta_fs_co_resume_op(UINT32 offset, UINT16 evt, UINT8 app_id) { @@ -1155,7 +1155,7 @@ void bta_fs_co_resume_op(UINT32 offset, UINT16 evt, UINT8 app_id) ** of the call-out function. ** ** Returns void -** +** *******************************************************************************/ void bta_fs_co_session_info(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn, tBTA_FS_CO_SESS_ST new_st, char *p_path, UINT8 *p_info, UINT8 app_id) @@ -1180,7 +1180,7 @@ void bta_fs_co_session_info(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn, ** of the call-out function. ** ** Returns void -** +** *******************************************************************************/ void bta_fs_co_suspend(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn, UINT32 *p_timeout, UINT32 *p_offset, UINT8 info, UINT8 app_id) @@ -1203,7 +1203,7 @@ void bta_fs_co_suspend(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn, ** of the call-out function. ** ** Returns void -** +** *******************************************************************************/ void bta_fs_co_sess_ssn(int fd, UINT8 ssn, UINT8 app_id) { diff --git a/btif/co/bta_sys_co.c b/btif/co/bta_sys_co.c index 66643bf..a2d0d44 100644 --- a/btif/co/bta_sys_co.c +++ b/btif/co/bta_sys_co.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2011 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -51,7 +51,7 @@ ** ** Function bta_sys_hw_co_enable ** -** Description This function is called by the stack to power up the HW +** Description This function is called by the stack to power up the HW ** ** Returns void ** @@ -59,7 +59,7 @@ void bta_sys_hw_co_enable( tBTA_SYS_HW_MODULE module ) { /* platform specific implementation to power-up the HW */ - + /* if no client/server asynchronous system like linux-based OS, directly call the ci here */ bta_sys_hw_ci_enabled( module ); @@ -70,7 +70,7 @@ void bta_sys_hw_co_enable( tBTA_SYS_HW_MODULE module ) ** ** Function bta_sys_hw_co_disable ** -** Description This function is called by the stack to power down the HW +** Description This function is called by the stack to power down the HW ** ** Returns void ** @@ -78,9 +78,9 @@ void bta_sys_hw_co_enable( tBTA_SYS_HW_MODULE module ) void bta_sys_hw_co_disable( tBTA_SYS_HW_MODULE module ) { /* platform specific implementation to power-down the HW */ - + /* if no client/server asynchronous system like linux-based OS, directly call the ci here */ bta_sys_hw_ci_disabled( module ); - + } diff --git a/btif/include/btif_api.h b/btif/include/btif_api.h index b5157de..087add5 100644 --- a/btif/include/btif_api.h +++ b/btif/include/btif_api.h @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING * OUT OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM - * OR ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * OR ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * *****************************************************************************/ @@ -50,10 +50,10 @@ * Filename: btif_api.h * * Description: Main API header file for all BTIF functions accessed - * from main bluetooth HAL. All HAL extensions will not + * from main bluetooth HAL. All HAL extensions will not * require headerfiles as they would be accessed through * callout/callins. - * + * *****************************************************************************/ #ifndef BTIF_API_H @@ -81,7 +81,7 @@ /***************************************************************************** ** Functions ******************************************************************************/ - + /***************************************************************************** ** BTIF CORE API @@ -93,8 +93,8 @@ ** Function btif_init_bluetooth ** ** Description Creates BTIF task and prepares BT scheduler for startup -** -** Returns bt_status_t +** +** Returns bt_status_t ** *******************************************************************************/ @@ -105,8 +105,8 @@ bt_status_t btif_init_bluetooth(void); ** Function btif_enable_bluetooth ** ** Description Performs chip power on and kickstarts OS scheduler -** -** Returns bt_status_t +** +** Returns bt_status_t ** *******************************************************************************/ @@ -119,8 +119,8 @@ bt_status_t btif_enable_bluetooth(void); ** Description Inititates shutdown of Bluetooth system. ** Any active links will be dropped and device entering ** non connectable/discoverable mode -** -** Returns void +** +** Returns void ** *******************************************************************************/ @@ -132,9 +132,9 @@ bt_status_t btif_disable_bluetooth(void); ** ** Description Finalizes BT scheduler shutdown and terminates BTIF ** task. -** -** -** Returns void +** +** +** Returns void ** *******************************************************************************/ @@ -146,8 +146,8 @@ bt_status_t btif_shutdown_bluetooth(void); ** Function btif_get_adapter_properties ** ** Description Fetches all local adapter properties -** -** Returns bt_status_t +** +** Returns bt_status_t ** *******************************************************************************/ @@ -159,7 +159,7 @@ bt_status_t btif_get_adapter_properties(void); ** ** Description Fetches property value from local cache ** -** Returns bt_status_t +** Returns bt_status_t ** *******************************************************************************/ @@ -169,10 +169,10 @@ bt_status_t btif_get_adapter_property( bt_property_type_t type); ** ** Function btif_set_adapter_property ** -** Description Updates core stack with property value and stores it in +** Description Updates core stack with property value and stores it in ** local cache ** -** Returns bt_status_t +** Returns bt_status_t ** *******************************************************************************/ @@ -187,8 +187,8 @@ bt_status_t btif_set_adapter_property( const bt_property_t *property); ** Returns bt_status_t ** *******************************************************************************/ - -bt_status_t btif_get_remote_device_property( bt_bdaddr_t *remote_addr, + +bt_status_t btif_get_remote_device_property( bt_bdaddr_t *remote_addr, bt_property_type_t type); @@ -215,11 +215,11 @@ bt_status_t btif_get_remote_device_properties( bt_bdaddr_t *remote_addr); ** ** Returns bt_status_t ** -*******************************************************************************/ +*******************************************************************************/ -bt_status_t btif_set_remote_device_property( bt_bdaddr_t *remote_addr, +bt_status_t btif_set_remote_device_property( bt_bdaddr_t *remote_addr, const bt_property_t *property); - + /******************************************************************************* ** @@ -230,9 +230,9 @@ bt_status_t btif_set_remote_device_property( bt_bdaddr_t *remote_addr, ** ** Returns bt_status_t ** -*******************************************************************************/ +*******************************************************************************/ -bt_status_t btif_get_remote_service_record( bt_bdaddr_t *remote_addr, +bt_status_t btif_get_remote_service_record( bt_bdaddr_t *remote_addr, bt_uuid_t *uuid); /***************************************************************************** @@ -247,9 +247,9 @@ bt_status_t btif_get_remote_service_record( bt_bdaddr_t *remote_addr, ** ** ** Returns bt_status_t -** +** *******************************************************************************/ - + bt_status_t btif_dm_start_discovery(void); /******************************************************************************* @@ -322,8 +322,8 @@ bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept, ** Returns bt_status_t ** *******************************************************************************/ - -bt_status_t btif_dm_passkey_reply( const bt_bdaddr_t *bd_addr, + +bt_status_t btif_dm_passkey_reply( const bt_bdaddr_t *bd_addr, uint8_t accept, uint32_t passkey); /******************************************************************************* @@ -336,7 +336,7 @@ bt_status_t btif_dm_passkey_reply( const bt_bdaddr_t *bd_addr, ** *******************************************************************************/ -bt_status_t btif_dm_ssp_reply( const bt_bdaddr_t *bd_addr, +bt_status_t btif_dm_ssp_reply( const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant, uint8_t accept, uint32_t passkey); @@ -350,7 +350,7 @@ bt_status_t btif_dm_ssp_reply( const bt_bdaddr_t *bd_addr, ** *******************************************************************************/ -bt_status_t btif_dm_get_adapter_property(bt_property_t *prop); +bt_status_t btif_dm_get_adapter_property(bt_property_t *prop); /******************************************************************************* ** @@ -362,7 +362,7 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t *prop); ** *******************************************************************************/ -bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr, +bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid); #endif /* BTIF_API_H */ diff --git a/btif/include/btif_av.h b/btif/include/btif_av.h index 720fa87..8d67f66 100644 --- a/btif/include/btif_av.h +++ b/btif/include/btif_av.h @@ -46,145 +46,111 @@ *****************************************************************************/ /***************************************************************************** -** -** Name: btif_av.h -** -** Description: -** -******************************************************************************/ - + * + * Filename: btif_av.h + * + * Description: Main API header file for all BTIF AV functions accessed + * from internal stack. + * + *****************************************************************************/ #ifndef BTIF_AV_H #define BTIF_AV_H -#include "btif_media.h" +#include "btif_common.h" +#include "btif_sm.h" +#include "bta_av_api.h" -enum -{ - BTIF_SV_AV_AA_SBC_INDEX = 0, - BTIF_SV_AV_AA_SEP_INDEX /* Last index */ -}; +/***************************************************************************** +** Constants & Macros +******************************************************************************/ -/******************************************************************************* - ** - ** Function bta_av_co_cp_is_active - ** - ** Description Get the current configuration of content protection - ** - ** Returns TRUE if the current streaming has CP, FALSE otherwise - ** - *******************************************************************************/ -BOOLEAN bta_av_co_cp_is_active(void); +/***************************************************************************** +** Type definitions for callback functions +******************************************************************************/ -/******************************************************************************* - ** - ** Function bta_av_co_cp_get_flag - ** - ** Description Get content protection flag - ** BTA_AV_CP_SCMS_COPY_NEVER - ** BTA_AV_CP_SCMS_COPY_ONCE - ** BTA_AV_CP_SCMS_COPY_FREE - ** - ** Returns The current flag value - ** - *******************************************************************************/ -UINT8 bta_av_co_cp_get_flag(void); -/******************************************************************************* - ** - ** Function bta_av_co_cp_set_flag - ** - ** Description Set content protection flag - ** BTA_AV_CP_SCMS_COPY_NEVER - ** BTA_AV_CP_SCMS_COPY_ONCE - ** BTA_AV_CP_SCMS_COPY_FREE - ** - ** Returns TRUE if setting the SCMS flag is supported else FALSE - ** - *******************************************************************************/ -BOOLEAN bta_av_co_cp_set_flag(UINT8 cp_flag); +typedef enum { + /* Reuse BTA_AV_XXX_EVT - No need to redefine them here */ + BTIF_AV_CONNECT_REQ_EVT = BTA_AV_MAX_EVT, + BTIF_AV_DISCONNECT_REQ_EVT, + BTIF_AV_START_STREAM_REQ_EVT, + BTIF_AV_STOP_STREAM_REQ_EVT, + BTIF_AV_SUSPEND_STREAM_REQ_EVT, + BTIF_AV_RECONFIGURE_REQ_EVT, +} btif_av_sm_event_t; -/******************************************************************************* - ** - ** Function bta_av_co_audio_codec_reset - ** - ** Description Reset the current codec configuration - ** - ** Returns void - ** - *******************************************************************************/ -void bta_av_co_audio_codec_reset(void); +/***************************************************************************** +** Type definitions and return values +******************************************************************************/ -/******************************************************************************* - ** - ** Function bta_av_co_audio_codec_supported - ** - ** Description Check if all opened connections are compatible with a codec - ** configuration - ** - ** Returns TRUE if all opened devices support this codec, FALSE otherwise - ** - *******************************************************************************/ -BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status); +/***************************************************************************** +** Extern variables and functions +******************************************************************************/ -/******************************************************************************* - ** - ** Function bta_av_co_audio_set_codec - ** - ** Description Set the current codec configuration from the feeding type. - ** This function is starting to modify the configuration, it - ** should be protected. - ** - ** Returns TRUE if successful, FALSE otherwise - ** - *******************************************************************************/ -BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTIF_STATUS *p_status); +/***************************************************************************** +** Functions +******************************************************************************/ + + +/***************************************************************************** +** BTIF CORE API +******************************************************************************/ + +/***************************************************************************** +** BTIF AV API +******************************************************************************/ /******************************************************************************* - ** - ** Function bta_av_co_audio_get_sbc_config - ** - ** Description Retrieves the SBC codec configuration. If the codec in use - ** is not SBC, return the default SBC codec configuration. - ** - ** Returns TRUE if codec is SBC, FALSE otherwise - ** - *******************************************************************************/ -BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_minmtu); +** +** Function btif_av_get_sm_handle +** +** Description Fetches current av SM handle +** +** Returns None +** +*******************************************************************************/ + +btif_sm_handle_t btif_av_get_sm_handle(void); /******************************************************************************* - ** - ** Function bta_av_co_audio_discard_config - ** - ** Description Discard the codec configuration of a connection - ** - ** Returns Nothing - ** - *******************************************************************************/ -void bta_av_co_audio_discard_config(tBTA_AV_HNDL hndl); +** +** Function btif_av_stream_ready +** +** Description Checks whether AV is ready for starting a stream +** +** Returns None +** +*******************************************************************************/ + +BOOLEAN btif_av_stream_ready(void); /******************************************************************************* - ** - ** Function bta_av_co_init - ** - ** Description Initialization - ** - ** Returns Nothing - ** - *******************************************************************************/ -void bta_av_co_init(void); +** +** Function btif_av_stream_started +** +** Description Checks whether AV is already started (remotely) +** +** Returns None +** +*******************************************************************************/ +BOOLEAN btif_av_stream_started(void); /******************************************************************************* - ** - ** Function bta_av_co_peer_cp_supported - ** - ** Description Checks if the peer supports CP - ** - ** Returns TRUE if the peer supports CP - ** - *******************************************************************************/ -BOOLEAN bta_av_co_peer_cp_supported(tBTA_AV_HNDL hndl); - -#endif +** +** Function btif_dispatch_sm_event +** +** Description Send event to AV statemachine +** +** Returns None +** +*******************************************************************************/ + +/* used to pass events to AV statemachine from other tasks */ +void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len); + + +#endif /* BTIF_AV_H */ + diff --git a/btif/include/btif_av_co.h b/btif/include/btif_av_co.h new file mode 100644 index 0000000..fd108d1 --- /dev/null +++ b/btif/include/btif_av_co.h @@ -0,0 +1,189 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * This program is the proprietary software of Broadcom Corporation and/or its + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. + * + * Except as expressly set forth in the Authorized License, + * + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of + * Broadcom integrated circuit products. + * + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING + * OUT OF USE OR PERFORMANCE OF THE SOFTWARE. + * + * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM + * OR ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. + * + *****************************************************************************/ + +/***************************************************************************** + * + * Filename: btif_av_co.h + * + * Description: + * + *****************************************************************************/ + +#ifndef BTIF_AV_CO_H +#define BTIF_AV_CO_H + +#include "btif_media.h" + +enum +{ + BTIF_SV_AV_AA_SBC_INDEX = 0, + BTIF_SV_AV_AA_SEP_INDEX /* Last index */ +}; + + +/******************************************************************************* + ** + ** Function bta_av_co_cp_is_active + ** + ** Description Get the current configuration of content protection + ** + ** Returns TRUE if the current streaming has CP, FALSE otherwise + ** + *******************************************************************************/ +BOOLEAN bta_av_co_cp_is_active(void); + +/******************************************************************************* + ** + ** Function bta_av_co_cp_get_flag + ** + ** Description Get content protection flag + ** BTA_AV_CP_SCMS_COPY_NEVER + ** BTA_AV_CP_SCMS_COPY_ONCE + ** BTA_AV_CP_SCMS_COPY_FREE + ** + ** Returns The current flag value + ** + *******************************************************************************/ +UINT8 bta_av_co_cp_get_flag(void); + +/******************************************************************************* + ** + ** Function bta_av_co_cp_set_flag + ** + ** Description Set content protection flag + ** BTA_AV_CP_SCMS_COPY_NEVER + ** BTA_AV_CP_SCMS_COPY_ONCE + ** BTA_AV_CP_SCMS_COPY_FREE + ** + ** Returns TRUE if setting the SCMS flag is supported else FALSE + ** + *******************************************************************************/ +BOOLEAN bta_av_co_cp_set_flag(UINT8 cp_flag); + +/******************************************************************************* + ** + ** Function bta_av_co_audio_codec_reset + ** + ** Description Reset the current codec configuration + ** + ** Returns void + ** + *******************************************************************************/ +void bta_av_co_audio_codec_reset(void); + +/******************************************************************************* + ** + ** Function bta_av_co_audio_codec_supported + ** + ** Description Check if all opened connections are compatible with a codec + ** configuration + ** + ** Returns TRUE if all opened devices support this codec, FALSE otherwise + ** + *******************************************************************************/ +BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status); + +/******************************************************************************* + ** + ** Function bta_av_co_audio_set_codec + ** + ** Description Set the current codec configuration from the feeding type. + ** This function is starting to modify the configuration, it + ** should be protected. + ** + ** Returns TRUE if successful, FALSE otherwise + ** + *******************************************************************************/ +BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTIF_STATUS *p_status); + +/******************************************************************************* + ** + ** Function bta_av_co_audio_get_sbc_config + ** + ** Description Retrieves the SBC codec configuration. If the codec in use + ** is not SBC, return the default SBC codec configuration. + ** + ** Returns TRUE if codec is SBC, FALSE otherwise + ** + *******************************************************************************/ +BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_minmtu); + +/******************************************************************************* + ** + ** Function bta_av_co_audio_discard_config + ** + ** Description Discard the codec configuration of a connection + ** + ** Returns Nothing + ** + *******************************************************************************/ +void bta_av_co_audio_discard_config(tBTA_AV_HNDL hndl); + +/******************************************************************************* + ** + ** Function bta_av_co_init + ** + ** Description Initialization + ** + ** Returns Nothing + ** + *******************************************************************************/ +void bta_av_co_init(void); + + +/******************************************************************************* + ** + ** Function bta_av_co_peer_cp_supported + ** + ** Description Checks if the peer supports CP + ** + ** Returns TRUE if the peer supports CP + ** + *******************************************************************************/ +BOOLEAN bta_av_co_peer_cp_supported(tBTA_AV_HNDL hndl); + +#endif diff --git a/btif/include/btif_common.h b/btif/include/btif_common.h index a440802..48ed00f 100755..100644 --- a/btif/include/btif_common.h +++ b/btif/include/btif_common.h @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -49,8 +49,8 @@ * * Filename: btif_common.h * - * Description: - * + * Description: + * ***********************************************************************************/ #ifndef BTIF_COMMON_H @@ -87,15 +87,16 @@ extern bt_callbacks_t *bt_hal_cbacks; -#define CHECK_CALL_CBACK(P_CB, P_CBACK, ...)\ +#define HAL_CBACK(P_CB, P_CBACK, ...)\ if (P_CB && P_CB->P_CBACK) { \ + LOGD("HAL %s->%s", #P_CB, #P_CBACK); \ P_CB->P_CBACK(__VA_ARGS__); \ } \ else { \ ASSERTC(0, "Callback is NULL", 0); \ } -/* btif events for requests that require context switch to btif task +/* btif events for requests that require context switch to btif task on downstreams path */ enum { @@ -107,7 +108,7 @@ enum BTIF_CORE_STORAGE_REMOTE_WRITE, BTIF_CORE_STORAGE_REMOTE_READ, BTIF_CORE_STORAGE_REMOTE_READ_ALL, - BTIF_CORE_STORAGE_READ_ALL, + BTIF_CORE_STORAGE_READ_ALL, BTIF_CORE_STORAGE_NOTIFY_STATUS, /* add here */ @@ -121,7 +122,7 @@ enum BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV), /* add here */ - + }; /* btif events for callbacks that require context switch to btif task @@ -168,8 +169,8 @@ tBTA_SERVICE_MASK btif_get_enabled_services_mask(void); bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id); bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id); -/* - * BTIF_Events +/* + * BTIF_Events */ void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd); diff --git a/btif/include/btif_dm.h b/btif/include/btif_dm.h index 766f4ee..45e3e98 100644 --- a/btif/include/btif_dm.h +++ b/btif/include/btif_dm.h @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -49,8 +49,8 @@ * * Filename: btif_dm.h * - * Description: - * + * Description: + * ***********************************************************************************/ #ifndef BTIF_DM_H diff --git a/btif/include/btif_media.h b/btif/include/btif_media.h index 0280d5c..5985580 100644 --- a/btif/include/btif_media.h +++ b/btif/include/btif_media.h @@ -43,16 +43,16 @@ * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * - *****************************************************************************/ + ************************************************************************************/ + +/************************************************************************************ + * + * Filename: btif_media.h + * + * Description: This is the audio module for the BTIF system. + * + ***********************************************************************************/ -/**************************************************************************** - ** - ** Name: btif_media.h - ** - ** Description: This is the audio module for the BTIF system. It contains - ** task implementations of A2DP - ** - ******************************************************************************/ #ifndef BTIF_MEDIA_H #define BTIF_MEDIA_H @@ -61,6 +61,11 @@ #include "bd.h" #include "gki.h" #include "btif_av_api.h" +#include "audio_a2dp_hw.h" + +/***************************************************************************** + ** Constants + *****************************************************************************/ /* Generic part */ #define BTIF_SUCCESS 0 @@ -75,11 +80,6 @@ #define BTIF_ERROR_SRV_AV_NOT_STARTED 704 /* AV is not started */ #define BTIF_ERROR_SRV_AV_CP_NOT_SUPPORTED 705 /* Content protection is not supported by all headsets */ -/***************************************************************************** - ** Constants - *****************************************************************************/ - - /* transcoding definition for TxTranscoding and RxTranscoding */ #define BTIF_MEDIA_TRSCD_OFF 0 #define BTIF_MEDIA_TRSCD_PCM_2_SBC 1 /* Tx */ @@ -261,5 +261,23 @@ extern BOOLEAN btif_media_task_audio_feeding_init_req(tBTIF_MEDIA_INIT_AUDIO_FEE *******************************************************************************/ extern void dump_codec_info(unsigned char *p_codec); +/* + * local adaptation helper functions between btif and media task + */ + +int btif_a2dp_start_media_task(void); +void btif_a2dp_stop_media_task(void); + +void btif_a2dp_on_init(void); +void btif_a2dp_on_idle(void); +void btif_a2dp_on_open(void); +void btif_a2dp_on_start_req(void); +void btif_a2dp_on_started(tBTA_AV_START *p_av); +void btif_a2dp_on_stop_req(void); +void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av); +void btif_a2dp_on_suspend(void); +void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av); +void btif_a2dp_set_tx_flush(BOOLEAN enable); + #endif diff --git a/btif/include/btif_sm.h b/btif/include/btif_sm.h index f4d5ede..fb8ddc7 100644 --- a/btif/include/btif_sm.h +++ b/btif/include/btif_sm.h @@ -50,7 +50,7 @@ * Filename: btif_sm.h * * Description: Generic BTIF state machine API - * + * *****************************************************************************/ #ifndef BTIF_SM_H diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h index c1b5bcf..c57f7df 100644 --- a/btif/include/btif_storage.h +++ b/btif/include/btif_storage.h @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -49,8 +49,8 @@ * * Filename: btif_storage.h * - * Description: - * + * Description: + * ***********************************************************************************/ #ifndef BTIF_STORAGE_H diff --git a/btif/include/btif_util.h b/btif/include/btif_util.h index d455e9e..2688b09 100644 --- a/btif/include/btif_util.h +++ b/btif/include/btif_util.h @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -49,8 +49,8 @@ * * Filename: btif_util.h * - * Description: - * + * Description: + * ***********************************************************************************/ #ifndef BTIF_UTIL_H @@ -95,6 +95,7 @@ const char* dump_adapter_scan_mode(bt_scan_mode_t mode); const char* dump_thread_evt(bt_cb_thread_evt evt); const char* dump_av_conn_state(UINT16 event); +const char* dump_av_audio_state(UINT16 event); int str2bd(char *str, bt_bdaddr_t *addr); char *bd2str(bt_bdaddr_t *addr, bdstr_t *bdstr); diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 0b839ac..2480e28 100644 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -50,7 +50,7 @@ * Filename: bluetooth.c * * Description: Bluetooth HAL implementation - * + * ***********************************************************************************/ #include <stdio.h> @@ -63,8 +63,8 @@ #define LOG_NDDEBUG 0 #define LOG_TAG "bluedroid" - -#include "btif_api.h" + +#include "btif_api.h" /************************************************************************************ ** Constants & Macros @@ -121,6 +121,10 @@ static int init(bt_callbacks_t* callbacks ) { LOGI("init"); + /* sanity check */ + if (interface_ready() == TRUE) + return BT_STATUS_DONE; + /* store reference to user callbacks */ bt_hal_cbacks = callbacks; @@ -307,7 +311,7 @@ static const void* get_profile_interface (const char *profile_id) if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID)) return btif_av_get_interface(); - + return NULL; } @@ -330,15 +334,15 @@ static const bt_interface_t bluetoothInterface = { remove_bond, cancel_bond, pin_reply, - ssp_reply, + ssp_reply, get_profile_interface }; const bt_interface_t* bluetooth__get_bluetooth_interface () { /* fixme -- add property to disable bt interface ? */ - - return &bluetoothInterface; + + return &bluetoothInterface; } static int close_bluetooth_stack(struct hw_device_t* device) @@ -358,7 +362,7 @@ struct hw_device_t** abstraction) stack->common.close = close_bluetooth_stack; stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface; *abstraction = (struct hw_device_t*)stack; - return 0; + return 0; } diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c index a822c7f..87ee8fb 100644 --- a/btif/src/btif_av.c +++ b/btif/src/btif_av.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING * OUT OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM - * OR ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * OR ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * *****************************************************************************/ @@ -51,15 +51,18 @@ * Filename: btif_av.c * * Description: Bluedroid AV implementation - * + * *****************************************************************************/ + #include <hardware/bluetooth.h> #include "hardware/bt_av.h" #define LOG_TAG "BTIF_AV" -#include "btif_common.h" -#include "btif_sm.h" + +#include "btif_av.h" +#include "btif_util.h" #include "bta_api.h" +#include "btif_media.h" #include "bta_av_api.h" #include "gki.h" #include "bd.h" @@ -70,24 +73,16 @@ ******************************************************************************/ #define BTIF_AV_SERVICE_NAME "Advanced Audio" -#define BTIF_TIMEOUT_AV_OPEN_ON_RC 2 /* 2 seconds */ +#define BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS 2 typedef enum { BTIF_AV_STATE_IDLE = 0x0, BTIF_AV_STATE_OPENING, BTIF_AV_STATE_OPENED, - BTIF_AV_STATE_STARTED + BTIF_AV_STATE_STARTED, + BTIF_AV_STATE_CLOSING } btif_av_state_t; -typedef enum { - /* Reuse BTA_AV_XXX_EVT - No need to redefine them here */ - BTIF_AV_CONNECT_REQ_EVT = BTA_AV_MAX_EVT, - BTIF_AV_DISCONNECT_REQ_EVT, - BTIF_AV_START_STREAM_REQ_EVT, - BTIF_AV_STOP_STREAM_REQ_EVT, - BTIF_AV_SUSPEND_STREAM_REQ_EVT, - BTIF_AV_RECONFIGURE_REQ_EVT, -} btif_av_sm_event_t; /***************************************************************************** ** Local type definitions ******************************************************************************/ @@ -131,16 +126,17 @@ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *data); static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *data); static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *data); static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *data); +static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *data); static const btif_sm_handler_t btif_av_state_handlers[] = { btif_av_state_idle_handler, btif_av_state_opening_handler, btif_av_state_opened_handler, - btif_av_state_started_handler + btif_av_state_started_handler, + btif_av_state_closing_handler }; - /************************************************************************* ** Extern functions *************************************************************************/ @@ -151,54 +147,57 @@ extern BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr); /***************************************************************************** ** Local helper functions ******************************************************************************/ + const char *dump_av_sm_state_name(btif_av_state_t state) { - switch (state) { - case BTIF_AV_STATE_IDLE: return "BTIF_AV_STATE_IDLE"; - case BTIF_AV_STATE_OPENING: return "BTIF_AV_STATE_OPENING"; - case BTIF_AV_STATE_OPENED: return "BTIF_AV_STATE_OPENED"; - case BTIF_AV_STATE_STARTED: return "BTIF_AV_STATE_STARTED"; - default: return "UNKNOWN_STATE"; - } + switch (state) + { + CASE_RETURN_STR(BTIF_AV_STATE_IDLE) + CASE_RETURN_STR(BTIF_AV_STATE_OPENING) + CASE_RETURN_STR(BTIF_AV_STATE_OPENED) + CASE_RETURN_STR(BTIF_AV_STATE_STARTED) + CASE_RETURN_STR(BTIF_AV_STATE_CLOSING) + default: return "UNKNOWN_STATE"; + } } const char *dump_av_sm_event_name(btif_av_sm_event_t event) { - switch(event) { - case BTA_AV_ENABLE_EVT: return "BTA_AV_ENABLE_EVT"; - case BTA_AV_REGISTER_EVT: return "BTA_AV_REGISTER_EVT"; - case BTA_AV_OPEN_EVT: return "BTA_AV_OPEN_EVT"; - case BTA_AV_CLOSE_EVT: return "BTA_AV_CLOSE_EVT"; - case BTA_AV_START_EVT: return "BTA_AV_START_EVT"; - case BTA_AV_STOP_EVT: return "BTA_AV_STOP_EVT"; - case BTA_AV_PROTECT_REQ_EVT: return "BTA_AV_PROTECT_REQ_EVT"; - case BTA_AV_PROTECT_RSP_EVT: return "BTA_AV_PROTECT_RSP_EVT"; - case BTA_AV_RC_OPEN_EVT: return "BTA_AV_RC_OPEN_EVT"; - case BTA_AV_RC_CLOSE_EVT: return "BTA_AV_RC_CLOSE_EVT"; - case BTA_AV_REMOTE_CMD_EVT: return "BTA_AV_REMOTE_CMD_EVT"; - case BTA_AV_REMOTE_RSP_EVT: return "BTA_AV_REMOTE_RSP_EVT"; - case BTA_AV_VENDOR_CMD_EVT: return "BTA_AV_VENDOR_CMD_EVT"; - case BTA_AV_VENDOR_RSP_EVT: return "BTA_AV_VENDOR_RSP_EVT"; - case BTA_AV_RECONFIG_EVT: return "BTA_AV_RECONFIG_EVT"; - case BTA_AV_SUSPEND_EVT: return "BTA_AV_SUSPEND_EVT"; - case BTA_AV_PENDING_EVT: return "BTA_AV_PENDING_EVT"; - case BTA_AV_META_MSG_EVT: return "BTA_AV_META_MSG_EVT"; - case BTA_AV_REJECT_EVT: return "BTA_AV_REJECT_EVT"; - case BTA_AV_RC_FEAT_EVT: return "BTA_AV_RC_FEAT_EVT"; - - case BTIF_SM_ENTER_EVT: return "BTIF_SM_ENTER_EVT"; - case BTIF_SM_EXIT_EVT: return "BTIF_SM_EXIT_EVT"; - case BTIF_AV_CONNECT_REQ_EVT: return "BTIF_AV_CONNECT_REQ_EVT"; - case BTIF_AV_DISCONNECT_REQ_EVT: return "BTIF_AV_DISCONNECT_REQ_EVT"; - case BTIF_AV_START_STREAM_REQ_EVT: return "BTIF_AV_START_STREAM_REQ_EVT"; - case BTIF_AV_STOP_STREAM_REQ_EVT: return "BTIF_AV_STOP_STREAM_REQ_EVT"; - case BTIF_AV_SUSPEND_STREAM_REQ_EVT: return "BTIF_AV_SUSPEND_STREAM_REQ_EVT"; - case BTIF_AV_RECONFIGURE_REQ_EVT: return "BTIF_AV_RECONFIGURE_REQ_EVT"; + switch(event) + { + CASE_RETURN_STR(BTA_AV_ENABLE_EVT) + CASE_RETURN_STR(BTA_AV_REGISTER_EVT) + CASE_RETURN_STR(BTA_AV_OPEN_EVT) + CASE_RETURN_STR(BTA_AV_CLOSE_EVT) + CASE_RETURN_STR(BTA_AV_START_EVT) + CASE_RETURN_STR(BTA_AV_STOP_EVT) + CASE_RETURN_STR(BTA_AV_PROTECT_REQ_EVT) + CASE_RETURN_STR(BTA_AV_PROTECT_RSP_EVT) + CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT) + CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT) + CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT) + CASE_RETURN_STR(BTA_AV_REMOTE_RSP_EVT) + CASE_RETURN_STR(BTA_AV_VENDOR_CMD_EVT) + CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT) + CASE_RETURN_STR(BTA_AV_RECONFIG_EVT) + CASE_RETURN_STR(BTA_AV_SUSPEND_EVT) + CASE_RETURN_STR(BTA_AV_PENDING_EVT) + CASE_RETURN_STR(BTA_AV_META_MSG_EVT) + CASE_RETURN_STR(BTA_AV_REJECT_EVT) + CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT) + CASE_RETURN_STR(BTIF_SM_ENTER_EVT) + CASE_RETURN_STR(BTIF_SM_EXIT_EVT) + CASE_RETURN_STR(BTIF_AV_CONNECT_REQ_EVT) + CASE_RETURN_STR(BTIF_AV_DISCONNECT_REQ_EVT) + CASE_RETURN_STR(BTIF_AV_START_STREAM_REQ_EVT) + CASE_RETURN_STR(BTIF_AV_STOP_STREAM_REQ_EVT) + CASE_RETURN_STR(BTIF_AV_SUSPEND_STREAM_REQ_EVT) + CASE_RETURN_STR(BTIF_AV_RECONFIGURE_REQ_EVT) + default: return "UNKNOWN_EVENT"; } } - /**************************************************************************** ** Local helper functions *****************************************************************************/ @@ -232,13 +231,15 @@ static void btif_initiate_av_open_tmr_hdlr(TIMER_LIST_ENT *tle) ** Static functions ******************************************************************************/ -void btif_a2dp_set_busy_level(UINT8 level); -void btif_a2dp_upon_init(void); -void btif_a2dp_upon_idle(void); -void btif_a2dp_upon_start_req(void); -void btif_a2dp_upon_started(void); -int btif_a2dp_start_media_task(void); -void btif_a2dp_stop_media_task(void); +/***************************************************************************** +** +** Function btif_av_state_idle_handler +** +** Description State managing disconnected AV link +** +** Returns TRUE if event was processed, FALSE otherwise +** +*******************************************************************************/ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data) { @@ -247,41 +248,38 @@ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data) switch (event) { case BTIF_SM_ENTER_EVT: - { /* clear the peer_bda */ memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t)); - btif_a2dp_upon_idle(); - } break; - + btif_a2dp_on_idle(); + break; + case BTIF_SM_EXIT_EVT: break; case BTA_AV_ENABLE_EVT: - { - BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0); - } break; + break; case BTA_AV_REGISTER_EVT: - { btif_av_cb.bta_handle = ((tBTA_AV*)p_data)->registr.hndl; - } break; + break; + case BTA_AV_PENDING_EVT: case BTIF_AV_CONNECT_REQ_EVT: { if (event == BTIF_AV_CONNECT_REQ_EVT) { - memcpy(&btif_av_cb.peer_bda, (bt_bdaddr_t*)p_data, sizeof(bt_bdaddr_t)); - BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle, - TRUE, BTA_SEC_NONE); + memcpy(&btif_av_cb.peer_bda, (bt_bdaddr_t*)p_data, sizeof(bt_bdaddr_t)); } else if (event == BTA_AV_PENDING_EVT) { bdcpy(btif_av_cb.peer_bda.address, ((tBTA_AV*)p_data)->pend.bd_addr); } + BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle, + TRUE, BTA_SEC_NONE); btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENING); } break; + case BTA_AV_RC_OPEN_EVT: - { /* IOP_FIX: Jabra 620 only does RC open without AV open whenever it connects. So * as per the AV WP, an AVRC connection cannot exist without an AV connection. Therefore, * we initiate an AV connection if an RC_OPEN_EVT is received when we are in AV_CLOSED state. @@ -291,35 +289,48 @@ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data) * * TODO: We may need to do this only on an AVRCP Play. FixMe */ + BTIF_TRACE_DEBUG0("BTA_AV_RC_OPEN_EVT received w/o AV"); memset(&tle_av_open_on_rc, 0, sizeof(tle_av_open_on_rc)); tle_av_open_on_rc.param = (UINT32)btif_initiate_av_open_tmr_hdlr; btu_start_timer(&tle_av_open_on_rc, BTU_TTYPE_USER_FUNC, - BTIF_TIMEOUT_AV_OPEN_ON_RC); + BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS); btif_rc_handler(event, p_data); - }break; + break; + case BTA_AV_REMOTE_CMD_EVT: case BTA_AV_VENDOR_CMD_EVT: case BTA_AV_META_MSG_EVT: case BTA_AV_RC_FEAT_EVT: - { btif_rc_handler(event, (tBTA_AV*)p_data); - }break; + break; + case BTA_AV_RC_CLOSE_EVT: - { if (tle_av_open_on_rc.in_use) { BTIF_TRACE_DEBUG0("BTA_AV_RC_CLOSE_EVT: Stopping AV timer."); btu_stop_timer(&tle_av_open_on_rc); } btif_rc_handler(event, p_data); - }break; + break; default: - BTIF_TRACE_WARNING2("%s Unhandled event:%s", __FUNCTION__, + BTIF_TRACE_WARNING2("%s : unhandled event:%s", __FUNCTION__, dump_av_sm_event_name(event)); + return FALSE; + } return TRUE; } +/***************************************************************************** +** +** Function btif_av_state_opening_handler +** +** Description Intermediate state managing events during establishment +** of avdtp channel +** +** Returns TRUE if event was processed, FALSE otherwise +** +*******************************************************************************/ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data) { @@ -328,11 +339,10 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data switch (event) { case BTIF_SM_ENTER_EVT: - { - /* inform the application that we are entering connecting state */ - CHECK_CALL_CBACK(bt_av_callbacks, connection_state_cb, + /* inform the application that we are entering connecting state */ + HAL_CBACK(bt_av_callbacks, connection_state_cb, BTAV_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda)); - } break; + break; case BTIF_SM_EXIT_EVT: break; @@ -343,6 +353,7 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data btav_connection_state_t state; btif_sm_state_t av_state; BTIF_TRACE_DEBUG1("status:%d", p_bta_data->open.status); + if (p_bta_data->open.status == BTA_AV_SUCCESS) { state = BTAV_CONNECTION_STATE_CONNECTED; @@ -355,9 +366,11 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data state = BTAV_CONNECTION_STATE_DISCONNECTED; av_state = BTIF_AV_STATE_IDLE; } + /* inform the application of the event */ - CHECK_CALL_CBACK(bt_av_callbacks, connection_state_cb, + HAL_CBACK(bt_av_callbacks, connection_state_cb, state, &(btif_av_cb.peer_bda)); + /* change state to open/idle based on the status */ btif_sm_change_state(btif_av_cb.sm_handle, av_state); } break; @@ -365,14 +378,27 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data CHECK_RC_EVENT(event, p_data); default: - BTIF_TRACE_WARNING2("%s Unhandled event:%s", __FUNCTION__, + BTIF_TRACE_WARNING2("%s : unhandled event:%s", __FUNCTION__, dump_av_sm_event_name(event)); + return FALSE; + } return TRUE; } -static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data) +/***************************************************************************** +** +** Function btif_av_state_closing_handler +** +** Description Intermediate state managing events during closing +** of avdtp channel +** +** Returns TRUE if event was processed, FALSE otherwise +** +*******************************************************************************/ + +static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data) { BTIF_TRACE_DEBUG2("%s event:%s", __FUNCTION__, dump_av_sm_event_name(event)); @@ -380,105 +406,251 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data) { case BTIF_SM_ENTER_EVT: - BTIF_TRACE_DEBUG0("starting av...sleeping before that"); + /* immediately stop transmission of frames */ + btif_a2dp_set_tx_flush(TRUE); - /* Auto-starting on Open could introduce race conditions. So delaying - * the start. - * - * This is anyway temporary and will be removed once the START/STOP stream - * requests are processed. - */ - GKI_delay(3000); + /* wait for audioflinger to stop a2dp */ + break; - btif_a2dp_upon_start_req(); + case BTIF_AV_STOP_STREAM_REQ_EVT: + /* immediately flush any pending tx frames while suspend is pending */ + btif_a2dp_set_tx_flush(TRUE); - /* autostart for now to test media task */ - BTA_AvStart(); + btif_a2dp_on_stopped(NULL); + + break; + + case BTIF_SM_EXIT_EVT: + break; + + case BTA_AV_CLOSE_EVT: + + /* inform the application that we are disconnecting */ + HAL_CBACK(bt_av_callbacks, connection_state_cb, + BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda)); + + btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE); + break; + + default: + BTIF_TRACE_WARNING2("%s : unhandled event:%s", __FUNCTION__, + dump_av_sm_event_name(event)); + return FALSE; + } + return TRUE; +} + + +/***************************************************************************** +** +** Function btif_av_state_opened_handler +** +** Description Handles AV events while AVDTP is in OPEN state +** +** Returns TRUE if event was processed, FALSE otherwise +** +*******************************************************************************/ + +static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data) +{ + tBTA_AV *p_av = (tBTA_AV*)p_data; + + BTIF_TRACE_DEBUG2("%s event:%s", __FUNCTION__, dump_av_sm_event_name(event)); + switch (event) + { + case BTIF_SM_ENTER_EVT: break; case BTIF_SM_EXIT_EVT: break; case BTIF_AV_START_STREAM_REQ_EVT: - /* fixme */ + /* prepare media task */ + btif_a2dp_on_start_req(); + BTA_AvStart(); break; case BTA_AV_START_EVT: { - tBTA_AV *p_bta_data = (tBTA_AV*)p_data; + BTIF_TRACE_EVENT3("BTA_AV_START_EVT status %d, suspending %d, init %d", + p_av->start.status, p_av->start.suspending, p_av->start.initiator); + + if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE)) + return TRUE; + + btif_a2dp_on_started(&p_av->start); + + /* remain in open state if status failed */ + if (p_av->start.status != BTA_AV_SUCCESS) + return FALSE; + + /* change state to started */ + btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED); - if (p_bta_data->start.status == BTA_AV_SUCCESS) - { - /* change state to started */ - btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED); - } - else - { - /* fixme */ - } } break; case BTIF_AV_DISCONNECT_REQ_EVT: - { - BTA_AvClose(btif_av_cb.bta_handle); - /* inform the application that we are disconnecting */ - CHECK_CALL_CBACK(bt_av_callbacks, connection_state_cb, + BTA_AvClose(btif_av_cb.bta_handle); + + /* inform the application that we are disconnecting */ + HAL_CBACK(bt_av_callbacks, connection_state_cb, BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda)); - } break; + break; case BTA_AV_CLOSE_EVT: - { - /* inform the application that we are disconnecting */ - CHECK_CALL_CBACK(bt_av_callbacks, connection_state_cb, + + /* inform the application that we are disconnected */ + HAL_CBACK(bt_av_callbacks, connection_state_cb, BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda)); + btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE); - } break; + break; CHECK_RC_EVENT(event, p_data); default: - BTIF_TRACE_WARNING2("%s Unhandled event:%s", __FUNCTION__, + BTIF_TRACE_WARNING2("%s : unhandled event:%s", __FUNCTION__, dump_av_sm_event_name(event)); + return FALSE; + } return TRUE; } +/***************************************************************************** +** +** Function btif_av_state_started_handler +** +** Description Handles AV events while A2DP stream is started +** +** Returns TRUE if event was processed, FALSE otherwise +** +*******************************************************************************/ + static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data) { + tBTA_AV *p_av = (tBTA_AV*)p_data; + BTIF_TRACE_DEBUG2("%s event:%s", __FUNCTION__, dump_av_sm_event_name(event)); switch (event) { - case BTIF_SM_ENTER_EVT: - btif_a2dp_upon_started(); + case BTIF_SM_ENTER_EVT: +#ifdef ENABLE_AUDIO_STATE_CB + HAL_CBACK(bt_av_callbacks, audio_state_cb, + BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda)); +#endif break; - + case BTIF_SM_EXIT_EVT: break; + + case BTIF_AV_STOP_STREAM_REQ_EVT: + /* immediately flush any pending tx frames while suspend is pending */ + btif_a2dp_set_tx_flush(TRUE); + + BTA_AvStop(TRUE); + break; + + case BTIF_AV_SUSPEND_STREAM_REQ_EVT: + + /* immediately stop transmission of frames whiel suspend is pending */ + btif_a2dp_set_tx_flush(TRUE); + + BTA_AvStop(TRUE); + break; + case BTIF_AV_DISCONNECT_REQ_EVT: - { - BTA_AvClose(btif_av_cb.bta_handle); - /* inform the application that we are disconnecting */ - CHECK_CALL_CBACK(bt_av_callbacks, connection_state_cb, - BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda)); - } break; - case BTA_AV_STOP_EVT: - { + /* request avdtp to close */ + BTA_AvClose(btif_av_cb.bta_handle); + /* inform the application that we are disconnecting */ + HAL_CBACK(bt_av_callbacks, connection_state_cb, + BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda)); + + /* wait in closing state until fully closed */ + btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_CLOSING); + break; + + case BTA_AV_SUSPEND_EVT: + + BTIF_TRACE_EVENT2("BTA_AV_SUSPEND_EVT status %d, init %d", + p_av->suspend.status, p_av->suspend.initiator); + + /* a2dp suspended, stop media task until resumed */ + btif_a2dp_on_suspended(&p_av->suspend); + + /* if not successful, remain in current state */ + if (p_av->suspend.status != BTA_AV_SUCCESS) + { + /* suspend failed, reset back tx flush state */ + btif_a2dp_set_tx_flush(FALSE); + return FALSE; + } + +#ifdef ENABLE_AUDIO_STATE_CB + if (p_av->suspend.initiator != TRUE) + { + /* remote suspend, notify HAL and await audioflinger to + suspend/stop stream */ + + HAL_CBACK(bt_av_callbacks, audio_state_cb, + BTAV_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda)); + } + else + { + HAL_CBACK(bt_av_callbacks, audio_state_cb, + BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda)); + } +#endif btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED); - } break; + break; + + case BTA_AV_STOP_EVT: + + btif_a2dp_on_stopped(&p_av->suspend); + +#ifdef ENABLE_AUDIO_STATE_CB + HAL_CBACK(bt_av_callbacks, audio_state_cb, + BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda)); +#endif + + /* if stop was successful, change state to open */ + if (p_av->suspend.status == BTA_AV_SUCCESS) + btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED); + + break; + + case BTA_AV_CLOSE_EVT: + + /* avdtp link is closed */ + + btif_a2dp_on_stopped(NULL); + + /* inform the application that we are disconnected */ + HAL_CBACK(bt_av_callbacks, connection_state_cb, + BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda)); + + btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE); + break; CHECK_RC_EVENT(event, p_data); default: - BTIF_TRACE_WARNING2("%s Unhandled event:%s", __FUNCTION__, + BTIF_TRACE_WARNING2("%s : unhandled event:%s", __FUNCTION__, dump_av_sm_event_name(event)); + return FALSE; + } return TRUE; } +/***************************************************************************** +** Local event handlers +******************************************************************************/ + static void btif_av_handle_event(UINT16 event, char* p_param) { btif_sm_dispatch(btif_av_cb.sm_handle, event, (void*)p_param); @@ -490,13 +662,6 @@ static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data) btif_transfer_context(btif_av_handle_event, event, (char*)p_data, sizeof(tBTA_AV), NULL); } -/***************************************************************************** -** Externs -******************************************************************************/ - -/***************************************************************************** -** Functions -******************************************************************************/ /******************************************************************************* ** @@ -522,12 +687,14 @@ static bt_status_t init(btav_callbacks_t* callbacks ) bt_av_callbacks = callbacks; btif_enable_service(BTA_A2DP_SERVICE_ID); + /* Initialize the AVRC CB */ btif_rc_init(); + /* Also initialize the AV state machine */ btif_av_cb.sm_handle = btif_sm_init((const btif_sm_handler_t*)btif_av_state_handlers, BTIF_AV_STATE_IDLE); - btif_a2dp_upon_init(); + btif_a2dp_on_init(); return BT_STATUS_SUCCESS; } @@ -610,6 +777,75 @@ static const btav_interface_t bt_av_interface = { /******************************************************************************* ** +** Function btif_av_get_sm_handle +** +** Description Fetches current av SM handle +** +** Returns None +** +*******************************************************************************/ + +btif_sm_handle_t btif_av_get_sm_handle(void) +{ + return btif_av_cb.sm_handle; +} + +/******************************************************************************* +** +** Function btif_av_stream_ready +** +** Description Checks whether AV is ready for starting a stream +** +** Returns None +** +*******************************************************************************/ + +BOOLEAN btif_av_stream_ready(void) +{ + btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle); + BTIF_TRACE_EVENT2("btif_av_stream_ready : sm hdl %d, state %d", + btif_av_cb.sm_handle, state); + return (state == BTIF_AV_STATE_OPENED); +} + +/******************************************************************************* +** +** Function btif_av_stream_started +** +** Description Checks whether AV is already started (remotely) +** +** Returns None +** +*******************************************************************************/ + +BOOLEAN btif_av_stream_started(void) +{ + btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle); + BTIF_TRACE_EVENT2("btif_av_stream_started : sm hdl %d, state %d", + btif_av_cb.sm_handle, state); + return (state == BTIF_AV_STATE_STARTED); +} + +/******************************************************************************* +** +** Function btif_dispatch_sm_event +** +** Description Send event to AV statemachine +** +** Returns None +** +*******************************************************************************/ + +/* used to pass events to AV statemachine from other tasks */ +void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len) +{ + /* Switch to BTIF context */ + btif_transfer_context(btif_av_handle_event, event, + (char*)p_data, len, NULL); +} + +/******************************************************************************* +** ** Function btif_av_execute_service ** ** Description Initializes/Shuts down the service @@ -650,7 +886,7 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable) ** Returns btav_interface_t ** *******************************************************************************/ -const btav_interface_t *btif_av_get_interface() +const btav_interface_t *btif_av_get_interface(void) { BTIF_TRACE_EVENT1("%s", __FUNCTION__); return &bt_av_interface; diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c index 50ee650..2226a0f 100644 --- a/btif/src/btif_core.c +++ b/btif/src/btif_core.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -51,7 +51,7 @@ * * Description: Contains core functionality related to interfacing between * Bluetooth HAL and BTE core stack. - * + * ***********************************************************************************/ #include <hardware/bluetooth.h> @@ -177,9 +177,9 @@ static void btif_context_switched(void *p_msg) ** event : event id of message ** p_params : parameter area passed to callback (copied) ** param_len : length of parameter area -** p_copy_cback : If set this function will be invoked for deep copy +** p_copy_cback : If set this function will be invoked for deep copy ** -** Returns void +** Returns void ** *******************************************************************************/ @@ -191,7 +191,7 @@ bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_p /* allocate and send message that will be executed in btif context */ if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) - { + { p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */ p_msg->p_cb = p_cback; @@ -242,12 +242,12 @@ static void btif_task(UINT32 params) /* wait for specified events */ event = GKI_wait(0xFFFF, 0); - /* + /* * Wait for the trigger to init chip and stack. This trigger will - * be received by btu_task once the UART is opened and ready + * be received by btu_task once the UART is opened and ready */ - if (event == BT_EVT_TRIGGER_STACK_INIT) + if (event == BT_EVT_TRIGGER_STACK_INIT) { BTIF_TRACE_DEBUG0("btif_task: received trigger stack init event"); BTA_EnableBluetooth(bte_dm_evt); @@ -280,11 +280,11 @@ static void btif_task(UINT32 params) btif_disassociate_evt(); GKI_task_self_cleanup(BTIF_TASK); - + if (btif_shutdown_pending) { btif_shutdown_pending = 0; - + bte_main_shutdown(); /* shutdown complete, all events notified and we reset HAL callbacks */ @@ -301,7 +301,7 @@ static void btif_task(UINT32 params) ** ** Description Sends msg to BTIF task ** -** Returns void +** Returns void ** *******************************************************************************/ @@ -321,14 +321,13 @@ void btif_sendmsg(void *p_msg) ** Function btif_init_bluetooth ** ** Description Creates BTIF task and prepares BT scheduler for startup -** -** Returns bt_status_t +** +** Returns bt_status_t ** *******************************************************************************/ bt_status_t btif_init_bluetooth(void) { - bte_main_boot_entry(); return BT_STATUS_SUCCESS; @@ -348,7 +347,7 @@ bt_status_t btif_init_bluetooth(void) static bt_status_t btif_associate_evt(void) { BTIF_TRACE_DEBUG1("%s: notify ASSOCIATE_JVM", __FUNCTION__); - CHECK_CALL_CBACK(bt_hal_cbacks, thread_evt_cb, ASSOCIATE_JVM); + HAL_CBACK(bt_hal_cbacks, thread_evt_cb, ASSOCIATE_JVM); return BT_STATUS_SUCCESS; } @@ -359,8 +358,8 @@ static bt_status_t btif_associate_evt(void) ** Function btif_enable_bluetooth ** ** Description Performs chip power on and kickstarts OS scheduler -** -** Returns bt_status_t +** +** Returns bt_status_t ** *******************************************************************************/ @@ -399,8 +398,8 @@ bt_status_t btif_enable_bluetooth(void) ** ** Description Event indicating bluetooth enable is completed ** Notifies HAL user with updated adapter state -** -** Returns void +** +** Returns void ** *******************************************************************************/ @@ -424,12 +423,12 @@ void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd) { /* store state */ btif_enabled = 1; - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_ON); + HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_ON); } else { btif_enabled = 0; - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF); + HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF); } } @@ -440,8 +439,8 @@ void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd) ** Description Inititates shutdown of Bluetooth system. ** Any active links will be dropped and device entering ** non connectable/discoverable mode -** -** Returns void +** +** Returns void ** *******************************************************************************/ @@ -464,7 +463,7 @@ bt_status_t btif_disable_bluetooth(void) BTIF_TRACE_ERROR1("disable bt failed (%d)", status); return BT_STATUS_FAIL; } - return BT_STATUS_SUCCESS; + return BT_STATUS_SUCCESS; } /******************************************************************************* @@ -472,10 +471,10 @@ bt_status_t btif_disable_bluetooth(void) ** Function btif_disable_bluetooth_evt ** ** Description Event notifying BT disable is now complete. -** Terminates main stack tasks and notifies HAL -** user with updated BT state. -** -** Returns void +** Terminates main stack tasks and notifies HAL +** user with updated BT state. +** +** Returns void ** *******************************************************************************/ @@ -486,7 +485,7 @@ void btif_disable_bluetooth_evt(void) bte_main_disable(); /* callback to HAL */ - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF); + HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF); /* update local state */ btif_enabled = 0; @@ -501,8 +500,8 @@ void btif_disable_bluetooth_evt(void) ** ** Description Finalizes BT scheduler shutdown and terminates BTIF ** task. -** -** Returns void +** +** Returns void ** *******************************************************************************/ @@ -543,7 +542,8 @@ bt_status_t btif_shutdown_bluetooth(void) static bt_status_t btif_disassociate_evt(void) { BTIF_TRACE_DEBUG1("%s: notify DISASSOCIATE_JVM", __FUNCTION__); - CHECK_CALL_CBACK(bt_hal_cbacks, thread_evt_cb, DISASSOCIATE_JVM); + + HAL_CBACK(bt_hal_cbacks, thread_evt_cb, DISASSOCIATE_JVM); return BT_STATUS_SUCCESS; } @@ -605,7 +605,7 @@ static bt_status_t btif_in_get_adapter_properties(void) btif_storage_get_adapter_property(&properties[num_props]); num_props++; - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_properties_cb, + HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, num_props, properties); return BT_STATUS_SUCCESS; @@ -651,7 +651,7 @@ static bt_status_t btif_in_get_remote_device_properties(bt_bdaddr_t *bd_addr) &remote_properties[num_props]); num_props++; - CHECK_CALL_CBACK(bt_hal_cbacks, remote_device_properties_cb, + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, BT_STATUS_SUCCESS, bd_addr, num_props, remote_properties); return BT_STATUS_SUCCESS; @@ -664,16 +664,16 @@ static bt_status_t btif_in_get_remote_device_properties(bt_bdaddr_t *bd_addr) ** ** Description Executes adapter storage request in BTIF context ** -** Returns bt_status_t +** Returns bt_status_t ** *******************************************************************************/ static void execute_storage_request(UINT16 event, char *p_param) { uint8_t is_local; - int num_entries = 0; + int num_entries = 0; bt_status_t status = BT_STATUS_SUCCESS; - + BTIF_TRACE_EVENT1("execute storage request event : %d", event); switch(event) @@ -686,7 +686,7 @@ static void execute_storage_request(UINT16 event, char *p_param) p_prop->len, p_prop->val); status = btif_storage_set_adapter_property(p_prop); - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 1, p_prop); + HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 1, p_prop); } break; case BTIF_CORE_STORAGE_ADAPTER_READ: @@ -699,9 +699,9 @@ static void execute_storage_request(UINT16 event, char *p_param) prop.len = sizeof(buf); status = btif_storage_get_adapter_property(&prop); - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 1, &prop); + HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 1, &prop); } break; - + case BTIF_CORE_STORAGE_ADAPTER_READ_ALL: { status = btif_in_get_adapter_properties(); @@ -709,7 +709,7 @@ static void execute_storage_request(UINT16 event, char *p_param) case BTIF_CORE_STORAGE_NOTIFY_STATUS: { - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 0, NULL); + HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 0, NULL); } break; default: @@ -737,7 +737,7 @@ static void execute_storage_remote_request(UINT16 event, char *p_param) status = btif_storage_get_remote_device_property(&(p_req->read_req.bd_addr), &prop); - CHECK_CALL_CBACK(bt_hal_cbacks, remote_device_properties_cb, + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, status, &(p_req->read_req.bd_addr), 1, &prop); }break; case BTIF_CORE_STORAGE_REMOTE_WRITE: @@ -757,14 +757,14 @@ static void execute_storage_remote_request(UINT16 event, char *p_param) void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props) { - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_properties_cb, + HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, num_props, p_props); } void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr, uint32_t num_props, bt_property_t *p_props) { - CHECK_CALL_CBACK(bt_hal_cbacks, remote_device_properties_cb, + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, status, remote_addr, num_props, p_props); } @@ -808,7 +808,7 @@ static void btif_in_storage_request_copy_cb(UINT16 event, ** ** Description Fetch all available properties (local & remote) ** -** Returns bt_status_t +** Returns bt_status_t ** *******************************************************************************/ @@ -830,7 +830,7 @@ bt_status_t btif_get_adapter_properties(void) ** ** Description Fetches property value from local cache ** -** Returns bt_status_t +** Returns bt_status_t ** *******************************************************************************/ @@ -855,10 +855,10 @@ bt_status_t btif_get_adapter_property(bt_property_type_t type) ** ** Function btif_set_adapter_property ** -** Description Updates core stack with property value and stores it in +** Description Updates core stack with property value and stores it in ** local cache ** -** Returns bt_status_t +** Returns bt_status_t ** *******************************************************************************/ @@ -881,11 +881,11 @@ bt_status_t btif_set_adapter_property(const bt_property_t *property) BTIF_TRACE_EVENT1("set property name : %s", (char *)property->val); BTA_DmSetDeviceName((char *)property->val); - + storage_req_id = BTIF_CORE_STORAGE_ADAPTER_WRITE; } break; - + case BT_PROPERTY_ADAPTER_SCAN_MODE: { bt_scan_mode_t mode = *(bt_scan_mode_t*)property->val; @@ -898,12 +898,12 @@ bt_status_t btif_set_adapter_property(const bt_property_t *property) disc_mode = BTA_DM_NON_DISC; conn_mode = BTA_DM_NON_CONN; break; - + case BT_SCAN_MODE_CONNECTABLE: disc_mode = BTA_DM_NON_DISC; conn_mode = BTA_DM_CONN; break; - + case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE: disc_mode = BTA_DM_GENERAL_DISC; conn_mode = BTA_DM_CONN; @@ -913,9 +913,9 @@ bt_status_t btif_set_adapter_property(const bt_property_t *property) BTIF_TRACE_ERROR1("invalid scan mode (0x%x)", mode); return BT_STATUS_PARM_INVALID; } - + BTIF_TRACE_EVENT1("set property scan mode : %x", mode); - + BTA_DmSetVisibility(disc_mode, conn_mode, BTA_DM_IGNORE, BTA_DM_IGNORE); storage_req_id = BTIF_CORE_STORAGE_ADAPTER_WRITE; @@ -930,9 +930,9 @@ bt_status_t btif_set_adapter_property(const bt_property_t *property) status = BT_STATUS_FAIL; break; default: - BTIF_TRACE_ERROR1("btif_get_adapter_property : invalid type %d", + BTIF_TRACE_ERROR1("btif_get_adapter_property : invalid type %d", property->type); - status = BT_STATUS_FAIL; + status = BT_STATUS_FAIL; break; } @@ -992,7 +992,7 @@ bt_status_t btif_get_remote_device_property(bt_bdaddr_t *remote_addr, bt_status_t btif_get_remote_device_properties(bt_bdaddr_t *remote_addr) { btif_storage_req_t req; - + if (btif_enabled == 0) return BT_STATUS_FAIL; @@ -1043,7 +1043,7 @@ bt_status_t btif_set_remote_device_property(bt_bdaddr_t *remote_addr, ** Returns bt_status_t ** *******************************************************************************/ -bt_status_t btif_get_remote_service_record(bt_bdaddr_t *remote_addr, +bt_status_t btif_get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid) { if (btif_enabled == 0) diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c index b5e7079..75a844f 100755..100644 --- a/btif/src/btif_dm.c +++ b/btif/src/btif_dm.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -49,14 +49,14 @@ * * Filename: btif_dm.c * - * Description: Contains Device Management (DM) related functionality + * Description: Contains Device Management (DM) related functionality + * * - * ***********************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> - + #include <hardware/bluetooth.h> #include <utils/Log.h> @@ -64,7 +64,7 @@ #include "gki.h" #include "btu.h" #include "bd.h" -#include "bta_api.h" +#include "bta_api.h" #include "btif_api.h" #include "btif_util.h" #include "btif_storage.h" @@ -151,7 +151,7 @@ static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data, p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir, BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len); } - + if (p_eir_remote_name) { if (remote_name_len > BD_NAME_LEN) @@ -215,7 +215,7 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond BTIF_TRACE_DEBUG3("%s: state=%d prev_state=%d", __FUNCTION__, state, pairing_cb.state); - CHECK_CALL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); + HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); if (state == BT_BOND_STATE_BONDING) { @@ -297,13 +297,13 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req) bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); cod = devclass2uint(p_pin_req->dev_class); - - if ( cod == 0) { + + if ( cod == 0) { LOGD("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } - CHECK_CALL_CBACK(bt_hal_cbacks, pin_request_cb, + HAL_CBACK(bt_hal_cbacks, pin_request_cb, &bd_addr, &bd_name, cod); } @@ -345,14 +345,14 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req) } cod = devclass2uint(p_ssp_cfm_req->dev_class); - + if ( cod == 0) { LOGD("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } /* TODO: pairing variant passkey_entry? */ - CHECK_CALL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, + HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod, BT_SSP_VARIANT_PASSKEY_CONFIRMATION, p_ssp_cfm_req->num_val); } @@ -376,7 +376,7 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif) cod = COD_UNCLASSIFIED; } - CHECK_CALL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, + HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION, p_ssp_key_notif->passkey); } @@ -462,7 +462,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]); ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status); - CHECK_CALL_CBACK(bt_hal_cbacks, remote_device_properties_cb, + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, status, &bdaddr, 1, properties); } /* TODO: Services? */ @@ -494,7 +494,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) cod = devclass2uint (p_search_data->inq_res.dev_class); - if ( cod == 0) { + if ( cod == 0) { LOGD("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } @@ -530,7 +530,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) strlen((char *)bdname.name)+1, &bdname); num_properties++; } - + /* DEV_CLASS */ BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod); @@ -543,7 +543,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) dev_type = BT_DEVICE_TYPE_BREDR; #endif BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], - BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type); + BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type); num_properties++; /* RSSI */ BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], @@ -555,7 +555,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status); /* Callback to notify upper layer of device */ - CHECK_CALL_CBACK(bt_hal_cbacks, device_found_cb, + HAL_CBACK(bt_hal_cbacks, device_found_cb, num_properties, properties); } } @@ -569,7 +569,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) case BTA_DM_DISC_CMPL_EVT: case BTA_DM_SEARCH_CANCEL_CMPL_EVT: { - CHECK_CALL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED); + HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED); } break; } @@ -612,7 +612,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) &(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) { memset(&uuid_arr[j], 0, sizeof(bt_uuid_t)); - uuid16_to_uuid128(bta_service_id_to_uuid_lkup_tbl[i], &uuid_arr[j]); + uuid16_to_uuid128(bta_service_id_to_uuid_lkup_tbl[i], &uuid_arr[j]); prop.len += sizeof(bt_uuid_t); j++; } @@ -622,7 +622,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret); /* Send the event to the BTIF */ - CHECK_CALL_CBACK(bt_hal_cbacks, remote_device_properties_cb, + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, BT_STATUS_SUCCESS, &bd_addr, 1, &prop); } break; @@ -678,7 +678,7 @@ static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param) /* TODO: Need to get the service name using p_raw_data */ rec.name[0] = 0; - CHECK_CALL_CBACK(bt_hal_cbacks, remote_device_properties_cb, + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, BT_STATUS_SUCCESS, &bd_addr, 1, &prop); } break; @@ -795,12 +795,12 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param) case BTA_DM_AUTHORIZE_EVT: case BTA_DM_LINK_DOWN_EVT: - case BTA_DM_SIG_STRENGTH_EVT: + case BTA_DM_SIG_STRENGTH_EVT: case BTA_DM_BUSY_LEVEL_EVT: case BTA_DM_BOND_CANCEL_CMPL_EVT: case BTA_DM_SP_RMT_OOB_EVT: case BTA_DM_SP_KEYPRESS_EVT: - case BTA_DM_ROLE_CHG_EVT: + case BTA_DM_ROLE_CHG_EVT: case BTA_DM_BLE_KEY_EVT: case BTA_DM_BLE_SEC_REQ_EVT: case BTA_DM_BLE_PASSKEY_NOTIF_EVT: @@ -832,7 +832,7 @@ static void btif_dm_generic_evt(UINT16 event, char* p_param) { case BTIF_DM_CB_DISCOVERY_STARTED: { - CHECK_CALL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED); + HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED); } break; @@ -863,7 +863,7 @@ static void btif_dm_generic_evt(UINT16 event, char* p_param) void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data) { bt_status_t status; - + /* switch context to btif task context (copy full union size for convenience) */ status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event, (void*)p_data, sizeof(tBTA_DM_SEC), NULL); @@ -1019,7 +1019,7 @@ bt_status_t btif_dm_cancel_discovery(void) bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr) { bdstr_t bdstr; - + BTIF_TRACE_EVENT2("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *) bd_addr, &bdstr)); if (pairing_cb.state != BT_BOND_STATE_NONE) @@ -1083,7 +1083,7 @@ bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr) /* TODO: special handling for HID devices */ if (BTA_DmRemoveDevice((UINT8 *)bd_addr->address) == BTA_SUCCESS) { - BTIF_TRACE_DEBUG1("Successfully removed bonding with device: %s", + BTIF_TRACE_DEBUG1("Successfully removed bonding with device: %s", bd2str((bt_bdaddr_t *)bd_addr, &bdstr)); } @@ -1224,7 +1224,7 @@ bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr) ** ** Returns bt_status_t *******************************************************************************/ -bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr, +bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid) { tSDP_UUID sdp_uuid; @@ -1258,7 +1258,7 @@ void btif_dm_execute_service_request(UINT16 event, char *p_param) BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS, sizeof(local_uuids), local_uuids); btif_storage_get_adapter_property(&property); - CHECK_CALL_CBACK(bt_hal_cbacks, adapter_properties_cb, + HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &property); } return; diff --git a/btif/src/btif_hf.c b/btif/src/btif_hf.c index ddc4a14..18939cb 100644 --- a/btif/src/btif_hf.c +++ b/btif/src/btif_hf.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -50,8 +50,8 @@ * Filename: btif_hf.c * * Description: Handsfree Profile Bluetooth Interface - * - * + * + * ***********************************************************************************/ #include <hardware/bluetooth.h> @@ -252,13 +252,13 @@ void clear_phone_state() ** ** Description Executes HF UPSTREAMS events in btif context ** -** Returns void +** Returns void ** *******************************************************************************/ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) { tBTA_AG *p_data = (tBTA_AG *)p_param; - bdstr_t bdstr; + bdstr_t bdstr; BTIF_TRACE_DEBUG2("%s: event=%s", __FUNCTION__, dump_hf_event(event)); @@ -291,7 +291,7 @@ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) break; } - CHECK_CALL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); + HAL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); if (btif_hf_cb.state == BTHF_CONNECTION_STATE_DISCONNECTED) bdsetany(btif_hf_cb.connected_bda.address); @@ -299,8 +299,7 @@ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) case BTA_AG_CLOSE_EVT: btif_hf_cb.state = BTHF_CONNECTION_STATE_DISCONNECTED; - CHECK_CALL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); - + HAL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); bdsetany(btif_hf_cb.connected_bda.address); btif_hf_cb.peer_feat = 0; clear_phone_state(); @@ -311,56 +310,56 @@ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) btif_hf_cb.peer_feat = p_data->conn.peer_feat; btif_hf_cb.state = BTHF_CONNECTION_STATE_SLC_CONNECTED; - CHECK_CALL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, + HAL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); break; case BTA_AG_AUDIO_OPEN_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_CONNECTED, &btif_hf_cb.connected_bda); + HAL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_CONNECTED, &btif_hf_cb.connected_bda); break; case BTA_AG_AUDIO_CLOSE_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_DISCONNECTED, &btif_hf_cb.connected_bda); + HAL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_DISCONNECTED, &btif_hf_cb.connected_bda); break; /* BTA auto-responds, silently discard */ case BTA_AG_SPK_EVT: case BTA_AG_MIC_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, volume_cmd_cb, + HAL_CBACK(bt_hf_callbacks, volume_cmd_cb, (event == BTA_AG_SPK_EVT) ? BTHF_VOLUME_TYPE_SPK : BTHF_VOLUME_TYPE_MIC, p_data->val.num); break; case BTA_AG_AT_A_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, answer_call_cmd_cb); + HAL_CBACK(bt_hf_callbacks, answer_call_cmd_cb); break; /* Java needs to send OK/ERROR for these commands */ case BTA_AG_AT_BLDN_EVT: case BTA_AG_AT_D_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, dial_call_cmd_cb, + HAL_CBACK(bt_hf_callbacks, dial_call_cmd_cb, (event == BTA_AG_AT_D_EVT) ? p_data->val.str : NULL); break; case BTA_AG_AT_CHUP_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, hangup_call_cmd_cb); + HAL_CBACK(bt_hf_callbacks, hangup_call_cmd_cb); break; case BTA_AG_AT_CIND_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, cind_cmd_cb); + HAL_CBACK(bt_hf_callbacks, cind_cmd_cb); break; case BTA_AG_AT_VTS_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, dtmf_cmd_cb, p_data->val.str[0]); + HAL_CBACK(bt_hf_callbacks, dtmf_cmd_cb, p_data->val.str[0]); break; case BTA_AG_AT_BVRA_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, vr_cmd_cb, + HAL_CBACK(bt_hf_callbacks, vr_cmd_cb, (p_data->val.num == 1) ? BTHF_VR_STATE_STARTED : BTHF_VR_STATE_STOPPED); break; case BTA_AG_AT_NREC_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, nrec_cmd_cb, + HAL_CBACK(bt_hf_callbacks, nrec_cmd_cb, (p_data->val.num == 1) ? BTHF_NREC_START : BTHF_NREC_STOP); break; @@ -369,29 +368,29 @@ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) break; case BTA_AG_AT_CKPD_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, key_pressed_cmd_cb); + HAL_CBACK(bt_hf_callbacks, key_pressed_cmd_cb); break; /* Java needs to send OK/ERROR for these commands */ case BTA_AG_AT_CHLD_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, chld_cmd_cb, atoi(p_data->val.str)); + HAL_CBACK(bt_hf_callbacks, chld_cmd_cb, atoi(p_data->val.str)); break; case BTA_AG_AT_CLCC_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, clcc_cmd_cb, p_data->val.num); + HAL_CBACK(bt_hf_callbacks, clcc_cmd_cb, p_data->val.num); break; case BTA_AG_AT_COPS_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, cops_cmd_cb); + HAL_CBACK(bt_hf_callbacks, cops_cmd_cb); break; case BTA_AG_AT_UNAT_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, unknown_at_cmd_cb, + HAL_CBACK(bt_hf_callbacks, unknown_at_cmd_cb, p_data->val.str); break; case BTA_AG_AT_CNUM_EVT: - CHECK_CALL_CBACK(bt_hf_callbacks, cnum_cmd_cb); + HAL_CBACK(bt_hf_callbacks, cnum_cmd_cb); break; /* TODO: Some of these commands may need to be sent to app. For now respond with error */ @@ -413,7 +412,7 @@ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) ** ** Description Switches context from BTE to BTIF for all HF events ** -** Returns void +** Returns void ** *******************************************************************************/ @@ -433,7 +432,7 @@ static void bte_hf_evt(tBTA_AG_EVT event, tBTA_AG *p_data) param_len = sizeof(tBTA_AG_HDR); else if (p_data) param_len = sizeof(tBTA_AG_VAL); - + /* switch context to btif task context (copy full union size for convenience) */ status = btif_transfer_context(btif_hf_upstreams_evt, (uint16_t)event, (void*)p_data, param_len, NULL); @@ -482,7 +481,7 @@ static bt_status_t connect( bt_bdaddr_t *bd_addr ) btif_hf_cb.state = BTHF_CONNECTION_STATE_CONNECTING; bdcpy(btif_hf_cb.connected_bda.address, bd_addr->address); - BTA_AgOpen(btif_hf_cb.handle, btif_hf_cb.connected_bda.address, + BTA_AgOpen(btif_hf_cb.handle, btif_hf_cb.connected_bda.address, BTIF_HF_SECURITY, BTA_HSP_SERVICE_MASK | BTA_HFP_SERVICE_MASK); return BT_STATUS_SUCCESS; @@ -725,7 +724,7 @@ static bt_status_t cind_response(int svc, int num_active, int num_held, if (is_connected(NULL)) { tBTA_AG_RES_DATA ag_res; - + memset (&ag_res, 0, sizeof (ag_res)); sprintf (ag_res.str, "%d,%d,%d,%d,%d,%d,%d", (num_active ? 1 : 0), /* Call state */ @@ -735,7 +734,7 @@ static bt_status_t cind_response(int svc, int num_active, int num_held, roam, /* Roaming indicator */ batt_chg, /* Battery level */ (num_held ? 1 : 0)); /* Call held */ - + BTA_AgResult (btif_hf_cb.handle, BTA_AG_CIND_RES, &ag_res); return BT_STATUS_SUCCESS; @@ -978,7 +977,7 @@ static bt_status_t phone_state_change(int num_active, int num_held, bthf_call_st case BTHF_CALL_STATE_ALERTING: /* if we went from idle->alert, force SCO setup here. dialing usually triggers it */ if (btif_hf_cb.call_setup_state == BTHF_CALL_STATE_IDLE) - ag_res.audio_handle = btif_hf_cb.handle; + ag_res.audio_handle = btif_hf_cb.handle; res = BTA_AG_OUT_CALL_ALERT_RES; break; default: diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index e11d307..22893c9 100644 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -81,7 +81,7 @@ #include "l2c_api.h" -#include "btif_av.h" +#include "btif_av_co.h" #include "btif_media.h" @@ -89,7 +89,13 @@ #include "sbc_encoder.h" #endif +#define LOG_TAG "BTIF-MEDIA" +#include <hardware/bluetooth.h> +#include "audio_a2dp_hw.h" +#include "btif_av.h" +#include "btif_sm.h" +#include "btif_util.h" /***************************************************************************** ** Constants @@ -166,6 +172,35 @@ enum #define DEFAULT_SBC_BITRATE 220 +#ifndef A2DP_MEDIA_TASK_STACK_SIZE +#define A2DP_MEDIA_TASK_STACK_SIZE 0x2000 /* In bytes */ +#endif + +#define A2DP_MEDIA_TASK_TASK_STR ((INT8 *) "A2DP-MEDIA") +static UINT32 a2dp_media_task_stack[(A2DP_MEDIA_TASK_STACK_SIZE + 3) / 4]; + +#define BT_MEDIA_TASK A2DP_MEDIA_TASK + +#define USEC_PER_SEC 1000000L +#define TPUT_STATS_INTERVAL_US (1000*1000) + +/* + * CONGESTION COMPENSATION CTRL :: + * + * Thus setting controls how many buffers we will hold in media task + * during temp link congestion. Together with the stack buffer queues + * it controls much temporary a2dp link congestion we can + * compensate for. It however also depends on the default run level of sinks + * jitterbuffers. Depending on type of sink this would vary. + * Ideally the (SRC) max tx buffer capacity should equal the sinks + * jitterbuffer runlevel including any intermediate buffers on the way + * towards the sinks codec. + */ + +/* fixme -- define this in pcm time instead of buffer count */ +/* fixme -- tune optimal value. For now set a large buffer capacity */ +#define MAX_OUTPUT_BUFFER_QUEUE_SZ 12 + /***************************************************************************** ** Data types *****************************************************************************/ @@ -196,6 +231,10 @@ typedef struct tBTIF_AV_MEDIA_FEEDINGS_STATE media_feeding_state; SBC_ENC_PARAMS encoder; UINT8 busy_level; + void* av_sm_hdl; + UINT8 a2dp_cmd_pending; /* we can have max one command pending */ + BOOLEAN tx_flush; /* discards any outgoing data when true */ + #if ((defined(BTIF_MEDIA_OVERFEED_INCLUDED) && (BTIF_MEDIA_OVERFEED_INCLUDED == TRUE)) || \ (defined(BTIF_MEDIA_UNDERFEED_INCLUDED) && (BTIF_MEDIA_UNDERFEED_INCLUDED == TRUE))) UINT8 tx_counter; @@ -204,16 +243,34 @@ typedef struct } tBTIF_MEDIA_CB; +typedef struct { + int rx; + int rx_tot; + int tx; + int tx_tot; + int ts_prev_us; +} t_stat; + /***************************************************************************** ** Local data *****************************************************************************/ static tBTIF_MEDIA_CB btif_media_cb; +static int media_task_running = 0; + /***************************************************************************** ** Local functions *****************************************************************************/ +static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event); +static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event); +static void btif_a2dp_encoder_update(void); + +/***************************************************************************** + ** Externs + *****************************************************************************/ + static void btif_media_task_handle_cmd(BT_HDR *p_msg); static void btif_media_task_handle_media(BT_HDR *p_msg); @@ -231,41 +288,9 @@ static void btif_media_aa_prep_2_send(UINT8 nb_frame); /***************************************************************************** - ** + ** Misc helper functions *****************************************************************************/ -#define UIPC_CH_ID_AV_AUDIO 0 - -/* Events generated */ -#define UIPC_OPEN_EVT 0x01 -#define UIPC_CLOSE_EVT 0x02 -#define UIPC_RX_DATA_EVT 0x03 -#define UIPC_RX_DATA_READY_EVT 0x04 -#define UIPC_TX_DATA_READY_EVT 0x05 - -#ifndef A2DP_MEDIA_TASK_STACK_SIZE -#define A2DP_MEDIA_TASK_STACK_SIZE 0x2000 /* In bytes */ -#endif - -#define A2DP_MEDIA_TASK_TASK_STR ((INT8 *) "A2DP-MEDIA") -static UINT32 a2dp_media_task_stack[(A2DP_MEDIA_TASK_STACK_SIZE + 3) / 4]; - -#define BT_MEDIA_TASK A2DP_MEDIA_TASK - -#define CASE_RETURN_STR(const) case const: return #const; - - -#define USEC_PER_SEC 1000000L -#define TPUT_STATS_INTERVAL_US (1000*1000) - -typedef struct { - int rx; - int rx_tot; - int tx; - int tx_tot; - int ts_prev_us; -} t_stat; - static void tput_mon(int is_rx, int len, int reset) { /* only monitor one connection at a time for now */ @@ -279,7 +304,7 @@ static void tput_mon(int is_rx, int len, int reset) memset(&cur_stat, 0, sizeof(t_stat)); return; } - + if (is_rx) { cur_stat.rx+=len; @@ -288,13 +313,13 @@ static void tput_mon(int is_rx, int len, int reset) else { cur_stat.tx+=len; - cur_stat.tx_tot+=len; + cur_stat.tx_tot+=len; } clock_gettime(CLOCK_MONOTONIC, &now); - + now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000; - //APPL_TRACE_EVENT1("%d us", now_us - cur_stat.ts_prev_us); + //APPL_TRACE_DEBUG1("%d us", now_us - cur_stat.ts_prev_us); if ((now_us - cur_stat.ts_prev_us) < TPUT_STATS_INTERVAL_US) return; @@ -311,7 +336,7 @@ static void tput_mon(int is_rx, int len, int reset) } -void log_tstamps_us(char *comment) +static void log_tstamps_us(char *comment) { #define USEC_PER_SEC 1000000L static struct timespec prev = {0, 0}; @@ -322,10 +347,11 @@ void log_tstamps_us(char *comment) clock_gettime(CLOCK_MONOTONIC, &now); now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000; diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000; - - APPL_TRACE_EVENT3("[%s] ts %08d, diff : %08d", comment, now_us, diff_us); - prev = now; + APPL_TRACE_DEBUG4("[%s] ts %08d, diff : %08d, queue sz %d", comment, now_us, diff_us, + btif_media_cb.TxAaQ.count); + + prev = now; } const char* dump_media_event(UINT16 event) @@ -350,7 +376,211 @@ const char* dump_media_event(UINT16 event) } } -void btif_av_encoder_init(void) + +/***************************************************************************** + ** A2DP CTRL PATH + *****************************************************************************/ + +static const char* dump_a2dp_ctrl_event(UINT8 event) +{ + switch(event) + { + CASE_RETURN_STR(A2DP_CTRL_CMD_NONE) + CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY) + CASE_RETURN_STR(A2DP_CTRL_CMD_START) + CASE_RETURN_STR(A2DP_CTRL_CMD_STOP) + CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND) + default: + return "UNKNOWN MSG ID"; + } +} + +static void btif_audiopath_detached(void) +{ + APPL_TRACE_EVENT0("## AUDIO PATH DETACHED ##"); + + /* send stop request only if we are actively streaming and haven't received + a stop request. Potentially audioflinger detached abnormally */ + if (btif_media_cb.is_tx_timer) + { + /* post stop event and wait for audio path to stop */ + btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0); + } +} + +static void a2dp_cmd_acknowledge(int status) +{ + UINT8 ack = status; + + APPL_TRACE_EVENT2("## a2dp ack : %s, status %d ##", dump_a2dp_ctrl_event(btif_media_cb.a2dp_cmd_pending), status); + + /* sanity check */ + if (btif_media_cb.a2dp_cmd_pending == A2DP_CTRL_CMD_NONE) + { + APPL_TRACE_ERROR0("warning : no command pending, ignore ack"); + return; + } + + /* clear pending */ + btif_media_cb.a2dp_cmd_pending = A2DP_CTRL_CMD_NONE; + + /* acknowledge start request */ + UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &ack, 1); +} + + +static void btif_recv_ctrl_data(void) +{ + UINT8 cmd = 0; + int n; + + n = UIPC_Read(UIPC_CH_ID_AV_CTRL, NULL, &cmd, 1); + + /* detach on ctrl channel means audioflinger process was terminated */ + if (n == 0) + { + APPL_TRACE_EVENT0("CTRL CH DETACHED"); + UIPC_Close(UIPC_CH_ID_AV_CTRL); + /* we can operate only on datachannel, if af client wants to + do send additional commands the ctrl channel would be reestablished */ + //btif_audiopath_detached(); + return; + } + + APPL_TRACE_EVENT1("a2dp-ctrl-cmd : %s", dump_a2dp_ctrl_event(cmd)); + + btif_media_cb.a2dp_cmd_pending = cmd; + + switch(cmd) + { + case A2DP_CTRL_CMD_CHECK_READY: + + /* check whether avdtp is ready to start */ + if (btif_av_stream_ready() == TRUE) + { + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); + } + else + { + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); + } + break; + + case A2DP_CTRL_CMD_START: + + if (btif_av_stream_ready() == TRUE) + { + /* setup audio data channel listener */ + UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb); + + /* post start event and wait for audio path to open */ + btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0); + + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); + } + else if (btif_av_stream_started()) + { + /* setup audio data channel listener */ + UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb); + + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); + } + else + { + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); + break; + } + break; + + case A2DP_CTRL_CMD_STOP: + + if (btif_media_cb.is_tx_timer == FALSE) + { + /* we are already stopped, just ack back */ + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); + break; + } + + btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0); + break; + + case A2DP_CTRL_CMD_SUSPEND: + /* local suspend */ + btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0); + break; + + default: + APPL_TRACE_ERROR1("UNSUPPORTED CMD (%d)", cmd); + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); + break; + } + APPL_TRACE_EVENT1("a2dp-ctrl-cmd : %s DONE", dump_a2dp_ctrl_event(cmd)); +} + +static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event) +{ + APPL_TRACE_DEBUG1("A2DP-CTRL-CHANNEL EVENT %s", dump_uipc_event(event)); + + switch(event) + { + case UIPC_OPEN_EVT: + /* fetch av statemachine handle */ + btif_media_cb.av_sm_hdl = btif_av_get_sm_handle(); + break; + + case UIPC_CLOSE_EVT: + /* restart ctrl server */ + UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb); + break; + + case UIPC_RX_DATA_READY_EVT: + btif_recv_ctrl_data(); + break; + + default : + APPL_TRACE_ERROR1("### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event); + break; + } +} + +static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event) +{ + APPL_TRACE_DEBUG1("BTIF MEDIA (A2DP-DATA) EVENT %s", dump_uipc_event(event)); + + switch(event) + { + case UIPC_OPEN_EVT: + + /* read directly from media task from here on (keep callback for + connection events */ + UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_REMOVE_ACTIVE_READSET, NULL); + + /* make sure we update any changed sbc encoder params */ + btif_a2dp_encoder_update(); + + /* Start the media task to encode SBC */ + btif_media_task_start_aa_req(); + + /* ack back when media task is fully started */ + break; + + case UIPC_CLOSE_EVT: + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); + btif_audiopath_detached(); + break; + + default : + APPL_TRACE_ERROR1("### A2DP-DATA EVENT %d NOT HANDLED ###", event); + break; + } +} + + +/***************************************************************************** + ** BTIF ADAPTATION + *****************************************************************************/ + +static void btif_a2dp_encoder_init(void) { UINT16 minmtu; tBTIF_MEDIA_INIT_AUDIO msg; @@ -365,7 +595,7 @@ void btif_av_encoder_init(void) /* lookup table to convert freq */ UINT16 freq_block_tbl[5] = { SBC_sf48000, SBC_sf44100, SBC_sf32000, 0, SBC_sf16000 }; - APPL_TRACE_DEBUG0("btif_av_encoder_init"); + APPL_TRACE_DEBUG0("btif_a2dp_encoder_init"); /* Retrieve the current SBC configuration (default if currently not used) */ bta_av_co_audio_get_sbc_config(&sbc_config, &minmtu); @@ -380,24 +610,24 @@ void btif_av_encoder_init(void) btif_media_task_enc_init_req(&msg); } -static void btif_av_encoder_update(void) +static void btif_a2dp_encoder_update(void) { UINT16 minmtu; tA2D_SBC_CIE sbc_config; tBTIF_MEDIA_UPDATE_AUDIO msg; - APPL_TRACE_DEBUG0("btif_av_encoder_update"); + APPL_TRACE_DEBUG0("btif_a2dp_encoder_update"); /* Retrieve the current SBC configuration (default if currently not used) */ bta_av_co_audio_get_sbc_config(&sbc_config, &minmtu); - APPL_TRACE_DEBUG4("btif_av_encoder_update: Common min_bitpool:%d(0x%x) max_bitpool:%d(0x%x)", + APPL_TRACE_DEBUG4("btif_a2dp_encoder_update: Common min_bitpool:%d(0x%x) max_bitpool:%d(0x%x)", sbc_config.min_bitpool, sbc_config.min_bitpool, sbc_config.max_bitpool, sbc_config.max_bitpool); if (sbc_config.min_bitpool > sbc_config.max_bitpool) { - APPL_TRACE_ERROR0("btif_av_encoder_update: ERROR btif_av_encoder_update min_bitpool > max_bitpool"); + APPL_TRACE_ERROR0("btif_a2dp_encoder_update: ERROR btif_a2dp_encoder_update min_bitpool > max_bitpool"); } msg.MinBitPool = sbc_config.min_bitpool; @@ -408,42 +638,79 @@ static void btif_av_encoder_update(void) } -static int media_task_running = 0; +/***************************************************************************** +** +** Function btif_a2dp_start_media_task +** +** Description +** +** Returns +** +*******************************************************************************/ int btif_a2dp_start_media_task(void) { if (media_task_running) { - APPL_TRACE_EVENT0("warning : media task already running"); + APPL_TRACE_ERROR0("warning : media task already running"); return GKI_FAILURE; } + APPL_TRACE_EVENT0("## A2DP START MEDIA TASK ##"); + media_task_running = 1; /* start a2dp media task */ - return GKI_create_task((TASKPTR)btif_media_task, A2DP_MEDIA_TASK, + return GKI_create_task((TASKPTR)btif_media_task, A2DP_MEDIA_TASK, A2DP_MEDIA_TASK_TASK_STR, (UINT16 *) ((UINT8 *)a2dp_media_task_stack + A2DP_MEDIA_TASK_STACK_SIZE), - sizeof(a2dp_media_task_stack)); + sizeof(a2dp_media_task_stack)); } +/***************************************************************************** +** +** Function btif_a2dp_stop_media_task +** +** Description +** +** Returns +** +*******************************************************************************/ + void btif_a2dp_stop_media_task(void) { - APPL_TRACE_EVENT1("%s", __FUNCTION__); + APPL_TRACE_EVENT0("## A2DP STOP MEDIA TASK ##"); GKI_send_msg(BT_MEDIA_TASK, BTIF_MEDIA_TASK_KILL, NULL); } -void btif_a2dp_upon_init(void) +/***************************************************************************** +** +** Function btif_a2dp_on_init +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_init(void) { - void btif_media_task_init(void); - btif_media_task_init(); - //tput_mon(1, 0, 1); } -void btif_a2dp_upon_idle(void) +/***************************************************************************** +** +** Function btif_a2dp_on_idle +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_idle(void) { - APPL_TRACE_EVENT1("%s", __FUNCTION__); + APPL_TRACE_EVENT0("## ON A2DP IDLE ##"); /* Make sure media task is stopped */ btif_media_task_stop_aa_req(); @@ -451,27 +718,55 @@ void btif_a2dp_upon_idle(void) bta_av_co_init(); } -void btif_a2dp_upon_start_req(void) +/***************************************************************************** +** +** Function btif_a2dp_on_open +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_open(void) +{ + APPL_TRACE_EVENT0("## ON A2DP OPEN ##"); + + /* always use callback to notify socket events */ + UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb); +} + +/***************************************************************************** +** +** Function btif_a2dp_on_start_req +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_start_req(void) { tBTIF_AV_MEDIA_FEEDINGS media_feeding; tBTIF_STATUS status; - APPL_TRACE_EVENT1("%s", __FUNCTION__); + APPL_TRACE_EVENT0("## ON A2DP START ##"); GKI_disable(); - + /* for now hardcode 44.1 khz 16 bit stereo */ media_feeding.cfg.pcm.sampling_freq = 44100; media_feeding.cfg.pcm.bit_per_sample = 16; media_feeding.cfg.pcm.num_channel = 2; media_feeding.format = BTIF_AV_CODEC_PCM; - if (bta_av_co_audio_set_codec(&media_feeding, &status)) - { + if (bta_av_co_audio_set_codec(&media_feeding, &status)) + { tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed; /* Init the encoding task */ - btif_av_encoder_init(); + btif_a2dp_encoder_init(); /* Build the media task configuration */ mfeed.feeding = media_feeding; @@ -483,13 +778,117 @@ void btif_a2dp_upon_start_req(void) GKI_enable(); } -void btif_a2dp_upon_started(void) + +/***************************************************************************** +** +** Function btif_a2dp_on_started +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_started(tBTA_AV_START *p_av) +{ + APPL_TRACE_EVENT0("## ON A2DP STARTED ##"); + + if (p_av->status == BTA_AV_SUCCESS) + { + if (p_av->suspending == FALSE) + { + if (p_av->initiator) + { + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); + } + else + { + /* we were remotely started */ + } + + /* media task is autostarted upon a2dp audiopath connection */ + } + } + else + { + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); + } +} + + +/***************************************************************************** +** +** Function btif_a2dp_on_stopped +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av) { - APPL_TRACE_EVENT1("%s", __FUNCTION__); - btif_av_encoder_update(); + APPL_TRACE_EVENT0("## ON A2DP STOPPED ##"); + + /* allow using this api for other than suspend */ + if (p_av != NULL) + { + if (p_av->status != BTA_AV_SUCCESS) + { + APPL_TRACE_EVENT1("AV STOP FAILED (%d)", p_av->status); + + if (p_av->initiator) + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); + return; + } + } + + /* ensure tx frames are immediately suspended */ + btif_media_cb.tx_flush = 1; - /* Start the media task to encode SBC */ - btif_media_task_start_aa_req(); + /* request to stop media task */ + btif_media_task_aa_tx_flush_req(); + btif_media_task_stop_aa_req(); + + /* once stream is fully stopped we will ack back */ +} + + +/***************************************************************************** +** +** Function btif_a2dp_on_suspended +** +** Description +** +** Returns +** +*******************************************************************************/ + +void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av) +{ + APPL_TRACE_EVENT0("## ON A2DP SUSPENDED ##"); + + /* check for status failures */ + if (p_av->status != BTA_AV_SUCCESS) + { + if (p_av->initiator == TRUE) + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); + } + + /* once stream is fully stopped we will ack back */ + + /* ensure tx frames are immediately flushed */ + btif_media_cb.tx_flush = 1; + + /* stop timer tick */ + btif_media_task_stop_aa_req(); +} + +/* when true media task discards any tx frames */ +void btif_a2dp_set_tx_flush(BOOLEAN enable) +{ + APPL_TRACE_EVENT1("## DROP TX %d ##", enable); + btif_media_cb.tx_flush = enable; } /******************************************************************************* @@ -502,7 +901,6 @@ void btif_a2dp_upon_started(void) ** *******************************************************************************/ - static void btif_media_task_aa_handle_timer(void) { #if (defined(DEBUG_MEDIA_AV_FLOW) && (DEBUG_MEDIA_AV_FLOW == TRUE)) @@ -510,7 +908,7 @@ static void btif_media_task_aa_handle_timer(void) APPL_TRACE_DEBUG1("btif_media_task_aa_handle_timer: %d", Debug++); #endif - //log_tstamps_us("timer"); + log_tstamps_us("media task tx timer"); #if (BTA_AV_INCLUDED == TRUE) btif_media_send_aa_frame(); @@ -552,14 +950,16 @@ static void btif_media_task_aa_handle_uipc_rx_rdy(void) ** Returns void ** *******************************************************************************/ + void btif_media_task_init(void) { memset(&(btif_media_cb), 0, sizeof(btif_media_cb)); + UIPC_Init(NULL); + #if (BTA_AV_INCLUDED == TRUE) - UIPC_Open(UIPC_CH_ID_AV_AUDIO , NULL); + UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb); #endif - } /******************************************************************************* ** @@ -580,7 +980,7 @@ int btif_media_task(void *p) UINT16 event; BT_HDR *p_msg; - APPL_TRACE_EVENT0("MEDIA TASK STARTING"); + APPL_TRACE_DEBUG0("================ MEDIA TASK STARTING ================"); btif_media_task_init(); @@ -588,6 +988,8 @@ int btif_media_task(void *p) { event = GKI_wait(0xffff, 0); + APPL_TRACE_DEBUG1("================= MEDIA TASK EVENT %d ===============", event); + if (event & BTIF_MEDIA_TASK_CMD) { /* Process all messages in the queue */ @@ -613,13 +1015,17 @@ int btif_media_task(void *p) } + APPL_TRACE_DEBUG1("=============== MEDIA TASK EVENT %d DONE ============", event); + /* When we get this event we exit the task - should only happen on GKI_shutdown */ if (event & BTIF_MEDIA_TASK_KILL) + { + UIPC_Close(UIPC_CH_ID_ALL); break; - + } } - APPL_TRACE_EVENT0("MEDIA TASK EXITING"); + APPL_TRACE_DEBUG0("MEDIA TASK EXITING"); return 0; } @@ -677,7 +1083,7 @@ static void btif_media_flush_q(BUFFER_Q *p_q) *******************************************************************************/ static void btif_media_task_handle_cmd(BT_HDR *p_msg) { - //APPL_TRACE_EVENT2("EVENT (%d) %s", p_msg->event, dump_media_event(p_msg->event)); + APPL_TRACE_DEBUG2("btif_media_task_handle_cmd : %d %s", p_msg->event, dump_media_event(p_msg->event)); switch (p_msg->event) { @@ -708,7 +1114,7 @@ static void btif_media_task_handle_cmd(BT_HDR *p_msg) APPL_TRACE_ERROR1("ERROR in btif_media_task_handle_cmd unknown event %d", p_msg->event); } GKI_freebuf(p_msg); - //APPL_TRACE_EVENT1("MEDIA TASK RX EVENT PROCESSED %s", dump_media_event(p_msg->event)); + APPL_TRACE_EVENT1("btif_media_task_handle_cmd : %s DONE", dump_media_event(p_msg->event)); } /******************************************************************************* @@ -722,7 +1128,7 @@ static void btif_media_task_handle_cmd(BT_HDR *p_msg) *******************************************************************************/ static void btif_media_task_handle_media(BT_HDR *p_msg) { - APPL_TRACE_ERROR0("ERROR btif_media_task_handle_media: TODO"); + APPL_TRACE_ERROR0("ERROR btif_media_task_handle_media: not in use"); GKI_freebuf(p_msg); } @@ -1166,7 +1572,7 @@ static void btif_media_task_audio_feeding_init(BT_HDR *p_msg) btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_SBC; btif_media_task_pcm2sbc_init(p_feeding); break; - + default : APPL_TRACE_ERROR1("unknown feeding format %d", p_feeding->feeding.format); break; @@ -1233,7 +1639,7 @@ static void btif_media_task_aa_start_tx(void) /* Use a timer to poll the UIPC, get rid of the UIPC call back */ - UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_CBACK, NULL); + // UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_CBACK, NULL); btif_media_cb.is_tx_timer = TRUE; @@ -1261,12 +1667,16 @@ static void btif_media_task_aa_start_tx(void) static void btif_media_task_aa_stop_tx(void) { APPL_TRACE_DEBUG1("btif_media_task_aa_stop_tx is timer: %d", btif_media_cb.is_tx_timer); + /* Stop the timer first */ GKI_stop_timer(BTIF_MEDIA_AA_TASK_TIMER_ID); btif_media_cb.is_tx_timer = FALSE; UIPC_Close(UIPC_CH_ID_AV_AUDIO); + /* audio engine stopped, reset tx suspended flag */ + btif_media_cb.tx_flush = 0; + /* Reset the media feeding state */ btif_media_task_feeding_state_reset(); } @@ -1449,24 +1859,14 @@ BOOLEAN btif_media_aa_read_feeding(tUIPC_CH_ID channel_id) //tput_mon(TRUE, nb_byte_read, FALSE); - if (nb_byte_read == 0) - { - APPL_TRACE_EVENT0("REMOTE SOURCE DETACHED"); - - /* temp workaround before full socket interface implented - stop and restart media task as remote source disconnected - read socket will again wait for an incoming a2dp source connection */ - - btif_media_task_stop_aa_req(); - btif_a2dp_upon_started(); - return FALSE; - } - if (nb_byte_read < read_size) { - APPL_TRACE_WARNING2("btif_media_aa_read_feeding UIPC empty UIPC_Read returns:%d asked:%d", + APPL_TRACE_WARNING2("### UNDERRUN :: ONLY READ %d BYTES OUT OF %d ###", nb_byte_read, read_size); + if (nb_byte_read == 0) + return FALSE; + if(btif_media_cb.feeding_mode == BTIF_AV_FEEDING_ASYNCHRONOUS) { /* Fill the unfilled part of the read buffer with silence (0) */ @@ -1487,6 +1887,7 @@ BOOLEAN btif_media_aa_read_feeding(tUIPC_CH_ID channel_id) nb_byte_read, sizeof(up_sampled_buffer) - btif_media_cb.media_feeding_state.pcm.aa_feed_residue, &src_size_used); + #if (defined(DEBUG_MEDIA_AV_FLOW) && (DEBUG_MEDIA_AV_FLOW == TRUE)) APPL_TRACE_DEBUG3("btif_media_aa_read_feeding read_size:%d src_size_used:%d dst_size_used:%d", read_size, src_size_used, dst_size_used); @@ -1560,6 +1961,7 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame) /* coverity[SIGN_EXTENSION] False-positive: Parameter are always in range avoiding sign extension*/ memset(btif_media_cb.encoder.as16PcmBuffer, 0, blocm_x_subband * btif_media_cb.encoder.s16NumOfChannels); + /* Read PCM data and upsample them if needed */ if (btif_media_aa_read_feeding(UIPC_CH_ID_AV_AUDIO)) { @@ -1576,6 +1978,10 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame) { /* no more pcm to read */ nb_frame = 0; + + /* break read loop if timer was stopped (media task stopped) */ + if ( btif_media_cb.is_tx_timer == FALSE ) + return; } } while (((p_buf->len + btif_media_cb.encoder.u16PacketLength) < btif_media_cb.TxAaMtuSize) @@ -1587,6 +1993,19 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame) /* store the time stamp in the buffer to send */ *((UINT32 *) (p_buf + 1)) = btif_media_cb.timestamp; + APPL_TRACE_EVENT1("TX QUEUE NOW %d", btif_media_cb.TxAaQ.count); + + if (btif_media_cb.tx_flush) + { + APPL_TRACE_DEBUG0("### tx suspended, discarded frame ###"); + + if (btif_media_cb.TxAaQ.count > 0) + btif_media_flush_q(&(btif_media_cb.TxAaQ)); + + GKI_freebuf(p_buf); + return; + } + /* Enqueue the encoded SBC frame in AA Tx Queue */ GKI_enqueue(&(btif_media_cb.TxAaQ), p_buf); } @@ -1602,10 +2021,13 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame) ** Returns void ** *******************************************************************************/ + static void btif_media_aa_prep_2_send(UINT8 nb_frame) { + APPL_TRACE_DEBUG1("btif_media_aa_prep_2_send : %d frames in queue", btif_media_cb.TxAaQ.count); + /* Remove all the buffers not sent until there are only 4 in the queue */ - while (btif_media_cb.TxAaQ.count > 4) + while (btif_media_cb.TxAaQ.count >= MAX_OUTPUT_BUFFER_QUEUE_SZ) { APPL_TRACE_WARNING1("btif_media_aa_prep_2_send congestion buf count %d",btif_media_cb.TxAaQ.count); GKI_freebuf(GKI_dequeue(&(btif_media_cb.TxAaQ))); diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c index 04d5681..7aab520 100644 --- a/btif/src/btif_rc.c +++ b/btif/src/btif_rc.c @@ -51,7 +51,7 @@ * Filename: btif_rc.c * * Description: Bluetooth AVRC implementation - * + * *****************************************************************************/ #include <hardware/bluetooth.h> #include <fcntl.h> @@ -265,12 +265,12 @@ const char *dump_rc_event_name(tBTA_AV_EVT event) } /*************************************************************************** - * Function handle_rc_connect - * - * - Argument: tBTA_AV_RC_OPEN RC open data structure - * - * - Description: RC connection event handler - * + * Function handle_rc_connect + * + * - Argument: tBTA_AV_RC_OPEN RC open data structure + * + * - Description: RC connection event handler + * ***************************************************************************/ void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open) { @@ -286,12 +286,12 @@ void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open) } /*************************************************************************** - * Function handle_rc_disconnect - * - * - Argument: tBTA_AV_RC_CLOSE RC close data structure - * + * Function handle_rc_disconnect + * + * - Argument: tBTA_AV_RC_CLOSE RC close data structure + * * - Description: RC disconnection event handler - * + * ***************************************************************************/ void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close) { @@ -306,13 +306,13 @@ void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close) } /*************************************************************************** - * Function handle_rc_passthrough_cmd - * - * - Argument: tBTA_AV_RC rc_id remote control command ID - * tBTA_AV_STATE key_state status of key press - * - * - Description: Remote control command handler - * + * Function handle_rc_passthrough_cmd + * + * - Argument: tBTA_AV_RC rc_id remote control command ID + * tBTA_AV_STATE key_state status of key press + * + * - Description: Remote control command handler + * ***************************************************************************/ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd) { @@ -346,7 +346,7 @@ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd) } #ifdef BTIF_RC_USE_UINPUT send_key(uinput_fd, key_map[i].mapped_id, pressed); -#endif +#endif if ((key_map[i].release_quirk == 1) && (pressed == 1)) { GKI_delay(30); // 30ms @@ -354,7 +354,7 @@ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd) __FUNCTION__, key_map[i].name); #ifdef BTIF_RC_USE_UINPUT send_key(uinput_fd, key_map[i].mapped_id, 0); -#endif +#endif } break; } diff --git a/btif/src/btif_sm.c b/btif/src/btif_sm.c index 77d12d9..c260119 100644 --- a/btif/src/btif_sm.c +++ b/btif/src/btif_sm.c @@ -51,7 +51,7 @@ * Filename: btif_sm.c * * Description: Generic BTIF state machine API - * + * *****************************************************************************/ #include <hardware/bluetooth.h> @@ -69,8 +69,8 @@ ** Local type definitions ******************************************************************************/ typedef struct { - btif_sm_state_t state; - btif_sm_handler_t *p_handlers; + btif_sm_state_t state; + btif_sm_handler_t *p_handlers; } btif_sm_cb_t; /***************************************************************************** @@ -101,6 +101,7 @@ typedef struct { ** Returns Returns a pointer to the initialized state machine handle. ** ******************************************************************************/ + btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state_t initial_state) { btif_sm_cb_t *p_cb; @@ -117,7 +118,7 @@ btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state /* Send BTIF_SM_ENTER_EVT to the initial state */ p_cb->p_handlers[initial_state](BTIF_SM_ENTER_EVT, NULL); - + return (btif_sm_handle_t)p_cb; } @@ -170,12 +171,16 @@ btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle) ** ** Description Dispatches the 'event' along with 'data' to the current state handler ** -** Returns Returns BT_STATUS_OK on success, BT_STATUS_FAIL otherwise +** Returns BT_STATUS_SUCCESS on success +** BT_STATUS_UNHANDLED if event was not processed +** BT_STATUS_FAIL otherwise ** ******************************************************************************/ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event, void *data) { + bt_status_t status = BT_STATUS_SUCCESS; + btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle; if (p_cb == NULL) @@ -184,9 +189,10 @@ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event, return BT_STATUS_FAIL; } - p_cb->p_handlers[p_cb->state](event, data); + if (p_cb->p_handlers[p_cb->state](event, data) == FALSE) + return BT_STATUS_UNHANDLED; - return BT_STATUS_SUCCESS; + return status; } /***************************************************************************** @@ -197,11 +203,14 @@ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event, ** shall be invoked before exiting the current state. The ** 'BTIF_SM_ENTER_EVT' shall be invoked before entering the new state ** -** Returns Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise +** Returns BT_STATUS_SUCCESS on success +** BT_STATUS_UNHANDLED if event was not processed +** BT_STATUS_FAIL otherwise ** ******************************************************************************/ bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state) { + bt_status_t status = BT_STATUS_SUCCESS; btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle; if (p_cb == NULL) @@ -211,13 +220,15 @@ bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state) } /* Send exit event to the current state */ - p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL); + if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE) + status = BT_STATUS_UNHANDLED; /* Change to the new state */ p_cb->state = state; /* Send enter event to the new state */ - p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL); + if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE) + status = BT_STATUS_UNHANDLED; - return BT_STATUS_SUCCESS; + return status; } diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c index e3ca7ef..9ed6e9e 100644 --- a/btif/src/btif_storage.c +++ b/btif/src/btif_storage.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -49,11 +49,11 @@ * * Filename: btif_storage.c * - * Description: Stores the local BT adapter and remote device properties in - * NVRAM storage, typically as text files in the + * Description: Stores the local BT adapter and remote device properties in + * NVRAM storage, typically as text files in the * mobile's filesystem - * - * + * + * * Data storage directory structure * * data @@ -67,7 +67,7 @@ * |-- remote_names - Remote devices' names * |-- remote_aliases - Remote devices' Friendly names * `-- remote_services - Remote devices' services - * + * * * adapter_info - Key/Value * name <space> <Name of Local Bluetooth device> @@ -94,7 +94,7 @@ * * remote_services - Key/Value * <remote_device bd_addr> <space> <List of UUIDs separated by semicolons> - * + * ***********************************************************************************/ #include <stdlib.h> #include <time.h> @@ -103,7 +103,7 @@ #define LOG_TAG "BTIF_STORAGE" -#include "btif_api.h" +#include "btif_api.h" #include "btif_util.h" #include "unv.h" @@ -199,15 +199,15 @@ static char* btif_in_make_filename(bt_bdaddr_t *bd_addr, char *fname) if (fname == NULL)return NULL; if (bd_addr) { - sprintf(path, "%s/%s/%s", BTIF_STORAGE_PATH_BLUEDROID, + sprintf(path, "%s/%s/%s", BTIF_STORAGE_PATH_BLUEDROID, bd2str(bd_addr, &bdstr), fname); } else { /* local adapter */ - sprintf(path, "%s/LOCAL/%s", BTIF_STORAGE_PATH_BLUEDROID, fname); + sprintf(path, "%s/LOCAL/%s", BTIF_STORAGE_PATH_BLUEDROID, fname); } - + return (char*)path; } @@ -227,9 +227,9 @@ static const char *btif_in_get_adapter_key_from_type(bt_property_type_t type) { case BT_PROPERTY_BDNAME: return BTIF_STORAGE_KEY_ADAPTER_NAME; - case BT_PROPERTY_ADAPTER_SCAN_MODE: + case BT_PROPERTY_ADAPTER_SCAN_MODE: return BTIF_STORAGE_KEY_ADAPTER_SCANMODE; - case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: + case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: return BTIF_STORAGE_KEY_ADAPTER_DISC_TIMEOUT; default: /* return valid string to avoid passing NULL to NV RAM driver */ @@ -275,7 +275,7 @@ static void btif_in_split_uuids_string_to_list(char *str, bt_uuid_t *p_uuid, ** NVRAM into a property->val. Also sets the property->len. ** Assumption is that property->val has enough memory to ** store the string fetched from NVRAM -** +** ** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise ** *******************************************************************************/ @@ -284,7 +284,7 @@ static bt_status_t btif_in_str_to_property(char *value, bt_property_t *property) bt_status_t status = BT_STATUS_SUCCESS; property->len = 0; - /* if Value is NULL, then just set the property->len to 0 and return. + /* if Value is NULL, then just set the property->len to 0 and return. This is possible if the entry does not exist */ if (value == NULL) { status = BT_STATUS_FAIL; @@ -301,7 +301,7 @@ static bt_status_t btif_in_str_to_property(char *value, bt_property_t *property) strcpy((char*)property->val, value); } } break; - case BT_PROPERTY_ADAPTER_SCAN_MODE: + case BT_PROPERTY_ADAPTER_SCAN_MODE: case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: { *((uint32_t *)property->val) = 0; @@ -416,13 +416,13 @@ static char* btif_in_get_remote_device_path_from_property(bt_property_type_t typ case BT_PROPERTY_BDADDR: case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: return BTIF_STORAGE_PATH_REMOTE_DEVICES; - case BT_PROPERTY_BDNAME: + case BT_PROPERTY_BDNAME: return BTIF_STORAGE_PATH_REMOTE_NAMES; case BT_PROPERTY_CLASS_OF_DEVICE: return BTIF_STORAGE_PATH_REMOTE_DEVCLASSES; case BT_PROPERTY_TYPE_OF_DEVICE: return BTIF_STORAGE_PATH_REMOTE_DEVTYPES; - case BT_PROPERTY_REMOTE_FRIENDLY_NAME: + case BT_PROPERTY_REMOTE_FRIENDLY_NAME: return BTIF_STORAGE_PATH_REMOTE_ALIASES; case BT_PROPERTY_UUIDS: return BTIF_STORAGE_PATH_REMOTE_SERVICES; @@ -455,17 +455,17 @@ int btif_in_load_device_iter_cb(char *key, char *value, void *userdata) uint32_t i; memset(temp, 0, sizeof(temp)); - + BTIF_TRACE_DEBUG3("%s %s %s", __FUNCTION__, key, value); - + /* convert 32 char linkkey (fixed size) */ - for (i = 0; i < LINK_KEY_LEN; i++) + for (i = 0; i < LINK_KEY_LEN; i++) { memcpy(temp, value + (i * 2), 2); link_key[i] = (uint8_t) strtol((const char *)temp, NULL, 16); offset+=2; } - + /* skip space */ offset++; @@ -476,7 +476,7 @@ int btif_in_load_device_iter_cb(char *key, char *value, void *userdata) /* value + space */ offset+=2; - + /* convert decimal pinlen (max 2 ascii chars) */ memset(temp, 0, sizeof(temp)); memcpy(temp, value + offset, 2); @@ -484,10 +484,10 @@ int btif_in_load_device_iter_cb(char *key, char *value, void *userdata) /* convert bd address (keystring) */ str2bd(key, &bd_addr); - + /* add extracted information to BTA security manager */ BTA_DmAddDevice(bd_addr.address, dev_class, link_key, 0, 0, key_type, 0); - + /* Fill in the bonded devices */ memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t)); @@ -512,13 +512,13 @@ static bt_status_t btif_in_fetch_bonded_devices(btif_bonded_devices_t *p_bonded_ memset(p_bonded_devices, 0, sizeof(btif_bonded_devices_t)); fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_REMOTE_LINKKEYS); - - if (fname == NULL) + + if (fname == NULL) return BT_STATUS_FAIL; ret = unv_read_key_iter(fname, btif_in_load_device_iter_cb, p_bonded_devices); - if (ret < 0) + if (ret < 0) return BT_STATUS_FAIL; return BT_STATUS_SUCCESS; @@ -580,7 +580,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property) BTIF_TRACE_DEBUG2("%s: Number of bonded devices: %d", __FUNCTION__, bonded_devices.num_devices); - if (bonded_devices.num_devices > 0) + if (bonded_devices.num_devices > 0) { property->len = bonded_devices.num_devices * sizeof(bt_bdaddr_t); memcpy(property->val, bonded_devices.devices, property->len); @@ -628,7 +628,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property) } /* fall through for other properties */ - + /* create filepath */ fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_ADAPTER_INFO); @@ -644,8 +644,8 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property) return BT_STATUS_FAIL; } - value = unv_read_key( fname, - btif_in_get_adapter_key_from_type(property->type), + value = unv_read_key( fname, + btif_in_get_adapter_key_from_type(property->type), linebuf, UNV_MAXLINE_LENGTH); if (value == NULL) @@ -678,7 +678,7 @@ bt_status_t btif_storage_set_adapter_property(bt_property_t *property) char *fname; char value[1200]; int ret; - + fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_ADAPTER_INFO); if (fname == NULL) { @@ -695,11 +695,11 @@ bt_status_t btif_storage_set_adapter_property(bt_property_t *property) return BT_STATUS_FAIL; } ret = unv_write_key(fname, btif_in_get_adapter_key_from_type(property->type), value); - if (ret < 0) + if (ret < 0) { return BT_STATUS_FAIL; } - + return BT_STATUS_SUCCESS; } @@ -716,7 +716,7 @@ bt_status_t btif_storage_set_adapter_property(bt_property_t *property) ** BT_STATUS_FAIL otherwise ** *******************************************************************************/ -bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, +bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, bt_property_t *property) { char linebuf[BTIF_STORAGE_MAX_LINE_SZ]; @@ -737,7 +737,7 @@ bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, { return BT_STATUS_FAIL; } - + value = unv_read_key(fname, bd2str(remote_bd_addr, &bdstr), linebuf, BTIF_STORAGE_MAX_LINE_SZ); return btif_in_str_to_property(value, property); @@ -754,7 +754,7 @@ bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, ** BT_STATUS_FAIL otherwise ** *******************************************************************************/ -bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, +bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, bt_property_t *property) { char value[1200]; @@ -779,13 +779,13 @@ bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, { return BT_STATUS_FAIL; } - + ret = unv_write_key(fname, bd2str(remote_bd_addr, &bdstr), value); - if (ret < 0) + if (ret < 0) { return BT_STATUS_FAIL; } - + return BT_STATUS_SUCCESS; } @@ -811,19 +811,19 @@ bt_status_t btif_storage_add_remote_device(bt_bdaddr_t *remote_bdaddr, for (i=0; i < num_properties; i++) { /* Ignore the RSSI as this is not stored in DB */ - if (properties[i].type == BT_PROPERTY_REMOTE_RSSI) + if (properties[i].type == BT_PROPERTY_REMOTE_RSSI) continue; /* BD_ADDR for remote device needs special handling as we also store timestamp */ - if (properties[i].type == BT_PROPERTY_BDADDR) + if (properties[i].type == BT_PROPERTY_BDADDR) { bt_property_t addr_prop; - memcpy(&addr_prop, &properties[i], sizeof(bt_property_t)); + memcpy(&addr_prop, &properties[i], sizeof(bt_property_t)); addr_prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP; btif_storage_set_remote_device_property(remote_bdaddr, &addr_prop); - } - else + } + else { btif_storage_set_remote_device_property(remote_bdaddr, &properties[i]); @@ -877,7 +877,7 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, return BT_STATUS_FAIL; memset(value, 0, sizeof(value)); - + for (i = 0; i < LINK_KEY_LEN; i++) sprintf(value + (i * 2), "%2.2X", link_key[i]); @@ -891,7 +891,7 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, } return BT_STATUS_SUCCESS; -} +} /******************************************************************************* ** @@ -908,7 +908,7 @@ bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr) char *fname; int ret; bdstr_t bdstr; - + fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_REMOTE_LINKKEYS); if (fname == NULL) diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c index 453d470..a1a5d97 100644 --- a/btif/src/btif_util.c +++ b/btif/src/btif_util.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -50,12 +50,13 @@ * Filename: btif_util.c * * Description: Miscellaneous helper functions - * - * + * + * ***********************************************************************************/ #include <hardware/bluetooth.h> #include <hardware/bt_hf.h> +#include <hardware/bt_av.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> @@ -200,7 +201,7 @@ const char* dump_dm_search_event(UINT16 event) CASE_RETURN_STR(BTA_DM_DISC_CMPL_EVT) CASE_RETURN_STR(BTA_DM_DI_DISC_CMPL_EVT) CASE_RETURN_STR(BTA_DM_SEARCH_CANCEL_CMPL_EVT) - + default: return "UNKNOWN MSG ID"; } @@ -221,11 +222,11 @@ const char* dump_property_type(bt_property_type_t type) CASE_RETURN_STR(BT_PROPERTY_ADAPTER_BONDED_DEVICES) CASE_RETURN_STR(BT_PROPERTY_ADAPTER_SCAN_MODE) CASE_RETURN_STR(BT_PROPERTY_REMOTE_FRIENDLY_NAME) - + default: return "UNKNOWN PROPERTY ID"; - } -} + } +} const char* dump_hf_event(UINT16 event) @@ -279,7 +280,7 @@ const char* dump_hf_conn_state(UINT16 event) CASE_RETURN_STR(BTHF_CONNECTION_STATE_SLC_CONNECTED) CASE_RETURN_STR(BTHF_CONNECTION_STATE_DISCONNECTING) default: - return "UNKNOWN MSG ID"; + return "UNKNOWN MSG ID"; } } @@ -305,11 +306,11 @@ const char* dump_thread_evt(bt_cb_thread_evt evt) { CASE_RETURN_STR(ASSOCIATE_JVM) CASE_RETURN_STR(DISASSOCIATE_JVM) - + default: return "unknown thread evt"; - } -} + } +} const char* dump_hf_audio_state(UINT16 event) @@ -326,6 +327,30 @@ const char* dump_hf_audio_state(UINT16 event) } } +const char* dump_av_conn_state(UINT16 event) +{ + switch(event) + { + CASE_RETURN_STR(BTAV_CONNECTION_STATE_DISCONNECTED) + CASE_RETURN_STR(BTAV_CONNECTION_STATE_CONNECTING) + CASE_RETURN_STR(BTAV_CONNECTION_STATE_CONNECTED) + CASE_RETURN_STR(BTAV_CONNECTION_STATE_DISCONNECTING) + default: + return "UNKNOWN MSG ID"; + } +} + +const char* dump_av_audio_state(UINT16 event) +{ + switch(event) + { + CASE_RETURN_STR(BTAV_AUDIO_STATE_REMOTE_SUSPEND) + CASE_RETURN_STR(BTAV_AUDIO_STATE_STOPPED) + CASE_RETURN_STR(BTAV_AUDIO_STATE_STARTED) + default: + return "UNKNOWN MSG ID"; + } +} const char* dump_adapter_scan_mode(bt_scan_mode_t mode) { diff --git a/main/Android.mk b/main/Android.mk index e1c17bc..45859e4 100644..100755 --- a/main/Android.mk +++ b/main/Android.mk @@ -26,7 +26,8 @@ LOCAL_SRC_FILES += \ ../btif/src/btif_sm.c \ ../btif/src/btif_hf.c \ ../btif/src/btif_av.c \ - ../btif/src/btif_rc.c + ../btif/src/btif_rc.c \ + ../btif/src/btif_media_task.c # callouts LOCAL_SRC_FILES+= \ @@ -46,7 +47,7 @@ LOCAL_SRC_FILES+= \ ../embdrv/sbc/encoder/srce/sbc_enc_coeffs.c \ ../embdrv/sbc/encoder/srce/sbc_encoder.c \ ../embdrv/sbc/encoder/srce/sbc_packing.c \ - ../btif/src/btif_media_task.c + # candidates for vendor lib (keep here for now) LOCAL_SRC_FILES+= \ @@ -74,7 +75,8 @@ LOCAL_C_INCLUDES+= . \ $(LOCAL_PATH)/../btif/co \ $(LOCAL_PATH)/../vendor/libvendor/include\ $(LOCAL_PATH)/../brcm/include \ - $(LOCAL_PATH)/../embdrv/sbc/encoder/include + $(LOCAL_PATH)/../embdrv/sbc/encoder/include \ + $(LOCAL_PATH)/../audio_a2dp_hw LOCAL_CFLAGS += -DBUILDCFG -Werror diff --git a/stack/smp/smp_utils.c b/stack/smp/smp_utils.c index 89c9f5e..91e7057 100644 --- a/stack/smp/smp_utils.c +++ b/stack/smp/smp_utils.c @@ -12,25 +12,25 @@ #if SMP_INCLUDED == TRUE - #include "bt_types.h" - #include <string.h> - #include <ctype.h> - #include "hcidefs.h" - #include "btm_ble_api.h" - #include "l2c_api.h" - #include "l2c_int.h" - #include "smp_int.h" - - - #define SMP_PAIRING_REQ_SIZE 7 - #define SMP_CONFIRM_CMD_SIZE (BT_OCTET16_LEN + 1) - #define SMP_INIT_CMD_SIZE (BT_OCTET16_LEN + 1) - #define SMP_ENC_INFO_SIZE (BT_OCTET16_LEN + 1) - #define SMP_MASTER_ID_SIZE (BT_OCTET8_LEN + 2 + 1) - #define SMP_ID_INFO_SIZE (BT_OCTET16_LEN + 1) - #define SMP_ID_ADDR_SIZE (BD_ADDR_LEN + 1 + 1) - #define SMP_SIGN_INFO_SIZE (BT_OCTET16_LEN + 1) - #define SMP_PAIR_FAIL_SIZE 2 +#include "bt_types.h" +#include <string.h> +#include <ctype.h> +#include "hcidefs.h" +#include "btm_ble_api.h" +#include "l2c_api.h" +#include "l2c_int.h" +#include "smp_int.h" + + +#define SMP_PAIRING_REQ_SIZE 7 +#define SMP_CONFIRM_CMD_SIZE (BT_OCTET16_LEN + 1) +#define SMP_INIT_CMD_SIZE (BT_OCTET16_LEN + 1) +#define SMP_ENC_INFO_SIZE (BT_OCTET16_LEN + 1) +#define SMP_MASTER_ID_SIZE (BT_OCTET8_LEN + 2 + 1) +#define SMP_ID_INFO_SIZE (BT_OCTET16_LEN + 1) +#define SMP_ID_ADDR_SIZE (BD_ADDR_LEN + 1 + 1) +#define SMP_SIGN_INFO_SIZE (BT_OCTET16_LEN + 1) +#define SMP_PAIR_FAIL_SIZE 2 /* type for action functions */ diff --git a/udrv/include/uipc.h b/udrv/include/uipc.h index 9fa6fbd..f5847c9 100644 --- a/udrv/include/uipc.h +++ b/udrv/include/uipc.h @@ -16,65 +16,44 @@ #define UDRV_API #endif +#define UIPC_CH_ID_AV_CTRL 0 +#define UIPC_CH_ID_AV_AUDIO 1 +#define UIPC_CH_NUM 2 -#define UIPC_CH_ID_ALL 0 /* used to address all the ch id at once */ -#define UIPC_CH_ID_0 1 /* shared mem interface */ -#define UIPC_CH_ID_1 2 /* TCP socket (GPS) */ -#define UIPC_CH_ID_2 3 /* BTIF control socket */ -#define UIPC_CH_ID_3 4 /* BTIF HH */ -#define UIPC_CH_ID_4 5 /* Future usage */ -#define UIPC_CH_ID_5 6 /* Future usage */ -#define UIPC_CH_ID_6 7 /* Future usage */ -#define UIPC_CH_ID_7 8 /* Future usage */ -#define UIPC_CH_ID_8 9 /* Future usage */ -#define UIPC_CH_ID_9 10 /* Future usage */ -#define UIPC_CH_ID_10 11 /* Future usage */ -#define UIPC_CH_ID_11 12 /* Future usage */ -#define UIPC_CH_ID_12 13 /* Future usage */ -#define UIPC_CH_ID_13 14 /* Future usage */ -#define UIPC_CH_ID_14 15 /* Future usage */ -#define UIPC_CH_ID_15 16 /* Future usage */ -#define UIPC_CH_ID_16 17 /* Future usage */ -#define UIPC_CH_ID_17 18 /* Future usage */ -#define UIPC_CH_ID_18 19 /* Future usage */ -#define UIPC_CH_ID_19 20 /* Future usage */ -#define UIPC_CH_ID_20 21 /* Future usage */ -#define UIPC_CH_ID_21 22 /* Future usage */ -#define UIPC_CH_ID_22 23 /* Future usage */ -#define UIPC_CH_ID_23 24 /* Future usage */ -#define UIPC_CH_ID_24 25 /* Future usage */ - - - -#define UIPC_CH_NUM 25 +#define UIPC_CH_ID_ALL 3 /* used to address all the ch id at once */ + +#define DEFAULT_READ_POLL_TMO_MS 100 typedef UINT8 tUIPC_CH_ID; +/* Events generated */ +typedef enum { + UIPC_OPEN_EVT = 0x0001, + UIPC_CLOSE_EVT = 0x0002, + UIPC_RX_DATA_EVT = 0x0004, + UIPC_RX_DATA_READY_EVT = 0x0008, + UIPC_TX_DATA_READY_EVT = 0x0010 +} tUIPC_EVENT; + /* * UIPC IOCTL Requests */ -enum -{ - UIPC_REQ_TX_FLUSH = 1, /* Request to flush the TX FIFO */ - UIPC_REQ_RX_FLUSH, /* Request to flush the RX FIFO */ - - UIPC_WRITE_BLOCK, /* Make write blocking */ - UIPC_WRITE_NONBLOCK, /* Make write non blocking */ - UIPC_REG_CBACK, /* Set a new call back */ - UIPC_SET_RX_WM, /* Set Rx water mark */ +#define UIPC_REQ_RX_FLUSH 1 +#define UIPC_REG_CBACK 2 +#define UIPC_REG_REMOVE_ACTIVE_READSET 3 +#define UIPC_SET_READ_POLL_TMO 4 - UIPC_REQ_TX_READY, /* Request an indication when Tx ready */ - UIPC_REQ_RX_READY /* Request an indication when Rx data ready */ -}; - -typedef void (tUIPC_RCV_CBACK)(BT_HDR *p_msg); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */ +typedef void (tUIPC_RCV_CBACK)(tUIPC_CH_ID ch_id, tUIPC_EVENT event); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */ #ifdef __cplusplus extern "C" { #endif +const char* dump_uipc_event(tUIPC_EVENT event); + + /******************************************************************************* ** ** Function UIPC_Init @@ -153,6 +132,7 @@ UDRV_API extern UINT32 UIPC_Read(tUIPC_CH_ID ch_id, UINT16 *p_msg_evt, UINT8 *p_ *******************************************************************************/ UDRV_API extern BOOLEAN UIPC_Ioctl(tUIPC_CH_ID ch_id, UINT32 request, void *param); + #ifdef __cplusplus } #endif diff --git a/udrv/include/unv.h b/udrv/include/unv.h index 9e85bc8..87983da 100644 --- a/udrv/include/unv.h +++ b/udrv/include/unv.h @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -50,7 +50,7 @@ * Filename: unv.h * * Description: Universal NV Ram API - * + * ***********************************************************************************/ #ifndef UNV_H @@ -84,7 +84,7 @@ typedef int (*unv_iter_cb)(char *key, char *val, void *userdata); ** ** Function unv_create_directory ** -** Description Creates directory, if full path is not available it +** Description Creates directory, if full path is not available it ** will construct it. Must be called from BTIF task context. ** ** Parameters @@ -107,7 +107,7 @@ int unv_create_directory(const char *path); ** Parameters ** filename : file path to be created ** -** Returns 0 if successful, -1 if failure +** Returns 0 if successful, -1 if failure ** *******************************************************************************/ @@ -131,7 +131,7 @@ int unv_create_file(const char *filename); ** *******************************************************************************/ -char* unv_read_key( const char *path, +char* unv_read_key( const char *path, const char *key, char *p_out, int out_len); @@ -154,8 +154,8 @@ char* unv_read_key( const char *path, ** *******************************************************************************/ -int unv_read_key_iter( const char *path, - unv_iter_cb cb, +int unv_read_key_iter( const char *path, + unv_iter_cb cb, void *userdata ); @@ -163,7 +163,7 @@ int unv_read_key_iter( const char *path, ** ** Function unv_write_key ** -** Description Writes key to file. If key value exists it will be updated +** Description Writes key to file. If key value exists it will be updated ** Path must be an existing absolute path ** Must be called from BTIF task context ** @@ -172,12 +172,12 @@ int unv_read_key_iter( const char *path, ** key : key string to write ** value : value string to set for this key ** -** Returns 0 if successful, -1 if failure +** Returns 0 if successful, -1 if failure ** *******************************************************************************/ -int unv_write_key( const char *path, - const char *key, +int unv_write_key( const char *path, + const char *key, const char *value ); @@ -197,7 +197,7 @@ int unv_write_key( const char *path, ** *******************************************************************************/ -int unv_remove_key( const char *path, +int unv_remove_key( const char *path, const char *key ); #endif /* UNV_H */ diff --git a/udrv/ulinux/uipc.c b/udrv/ulinux/uipc.c index a06a057..8af45f1 100644 --- a/udrv/ulinux/uipc.c +++ b/udrv/ulinux/uipc.c @@ -1,12 +1,56 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * This program is the proprietary software of Broadcom Corporation and/or its + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. + * + * Except as expressly set forth in the Authorized License, + * + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of + * Broadcom integrated circuit products. + * + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING + * OUT OF USE OR PERFORMANCE OF THE SOFTWARE. + * + * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM + * OR ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. + * + *****************************************************************************/ + /***************************************************************************** - ** - ** Name: uipc.c - ** - ** Description: UIPC wrapper interface definition - ** - ** Copyright (c) 2009-2011, Broadcom Corp., All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ** + * + * Filename: uipc.c + * + * Description: UIPC implementation for bluedroid + * *****************************************************************************/ #include <stdio.h> @@ -17,98 +61,541 @@ #include <unistd.h> #include <fcntl.h> -#include <cutils/sockets.h> - #include <sys/socket.h> #include <sys/un.h> #include <signal.h> #include <errno.h> +#include <pthread.h> +#include <sys/select.h> +#include <sys/poll.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/prctl.h> + #include "gki.h" #include "data_types.h" #include "uipc.h" +#include <cutils/sockets.h> +#include "audio_a2dp_hw.h" + +/***************************************************************************** +** Constants & Macros +******************************************************************************/ + #define PCM_FILENAME "/data/test.pcm" -#define SOCKPATH "/data/misc/bluedroid/.a2dp_sock" -/* TEST CODE TO VERIFY DATAPATH */ +#define MAX(a,b) ((a)>(b)?(a):(b)) + +#define CASE_RETURN_STR(const) case const: return #const; + +#define UIPC_DISCONNECTED (-1) + +#define UIPC_LOCK() /*BTIF_TRACE_EVENT1(" %s lock", __FUNCTION__);*/ pthread_mutex_lock(&uipc_main.mutex); +#define UIPC_UNLOCK() /*BTIF_TRACE_EVENT1("%s unlock", __FUNCTION__);*/ pthread_mutex_unlock(&uipc_main.mutex); + +/***************************************************************************** +** Local type definitions +******************************************************************************/ + +typedef enum { + UIPC_TASK_FLAG_DISCONNECT_CHAN = 0x1, +} tUIPC_TASK_FLAGS; + +typedef struct { + int srvfd; + int fd; + int read_poll_tmo_ms; + int task_evt_flags; /* event flags pending to be processed in read task */ + tUIPC_EVENT cond_flags; + pthread_mutex_t cond_mutex; + pthread_cond_t cond; + tUIPC_RCV_CBACK *cback; +} tUIPC_CHAN; + +typedef struct { + pthread_t tid; /* main thread id */ + int running; + pthread_mutex_t mutex; + + fd_set active_set; + fd_set read_set; + int max_fd; + int signal_fds[2]; + + tUIPC_CHAN ch[UIPC_CH_NUM]; +} tUIPC_MAIN; + + +/***************************************************************************** +** Static variables +******************************************************************************/ + +static tUIPC_MAIN uipc_main; + + +/***************************************************************************** +** Static functions +******************************************************************************/ + +static int uipc_close_ch_locked(tUIPC_CH_ID ch_id); + +/***************************************************************************** +** Externs +******************************************************************************/ + + +/***************************************************************************** +** Helper functions +******************************************************************************/ + + +const char* dump_uipc_event(tUIPC_EVENT event) +{ + switch(event) + { + CASE_RETURN_STR(UIPC_OPEN_EVT) + CASE_RETURN_STR(UIPC_CLOSE_EVT) + CASE_RETURN_STR(UIPC_RX_DATA_EVT) + CASE_RETURN_STR(UIPC_RX_DATA_READY_EVT) + CASE_RETURN_STR(UIPC_TX_DATA_READY_EVT) + default: + return "UNKNOWN MSG ID"; + } +} + +/***************************************************************************** +** +** Function +** +** Description +** +** Returns +** +*******************************************************************************/ + +static void uipc_wait(tUIPC_CH_ID ch_id, tUIPC_EVENT wait_event_flags) +{ + int ret; + tUIPC_CHAN *p = &uipc_main.ch[ch_id]; + + //BTIF_TRACE_EVENT2("WAIT UIPC CH %d EVT %x BEGIN", ch_id, wait_event_flags); + pthread_mutex_lock(&p->cond_mutex); + p->cond_flags |= wait_event_flags; + ret = pthread_cond_wait(&p->cond, &p->cond_mutex); + pthread_mutex_unlock(&p->cond_mutex); + //BTIF_TRACE_EVENT2("WAIT UIPC CH %d EVT %x DONE", ch_id, wait_event_flags); +} -#define SOURCE_MODE_PCMFILE 1 -#define SOURCE_MODE_A2DP_SOCKET 2 -#define SOURCE_MODE SOURCE_MODE_A2DP_SOCKET +static void uipc_signal(tUIPC_CH_ID ch_id, tUIPC_EVENT event) +{ + int ret; + tUIPC_CHAN *p = &uipc_main.ch[ch_id]; -static int listen_fd = -1; -static int sock_fd = -1; -static int source_fd = -1; + //BTIF_TRACE_EVENT2("SIGNAL UIPC CH %d EVT %x BEGIN", ch_id, dump_uipc_event(event)); + pthread_mutex_lock(&p->cond_mutex); + + if (event & p->cond_flags) + { + //BTIF_TRACE_EVENT0("UNBLOCK"); + ret = pthread_cond_signal(&p->cond); + p->cond_flags = 0; + } + + pthread_mutex_unlock(&p->cond_mutex); +} + + + +/***************************************************************************** +** socket helper functions +*****************************************************************************/ static inline int create_server_socket(const char* name) { int s = socket(AF_LOCAL, SOCK_STREAM, 0); - - if(socket_local_server_bind(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT) >= 0) + + BTIF_TRACE_EVENT1("create_server_socket %s", name); + + if(socket_local_server_bind(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT) < 0) { - if(listen(s, 5) == 0) - { - APPL_TRACE_EVENT2("listen to local socket:%s, fd:%d", name, s); - return s; - } - else - APPL_TRACE_EVENT3("listen to local socket:%s, fd:%d failed, errno:%d", name, s, errno); + BTIF_TRACE_EVENT1("socket failed to create (%s)", strerror(errno)); + return -1; } - else - APPL_TRACE_EVENT3("create local socket:%s fd:%d, failed, errno:%d", name, s, errno); - close(s); - return -1; + + if(listen(s, 5) < 0) + { + BTIF_TRACE_EVENT1("listen failed", strerror(errno)); + close(s); + return -1; + } + + BTIF_TRACE_EVENT1("created socket fd %d", s); + return s; } -int wait_socket(void) +static int accept_server_socket(int sfd) { struct sockaddr_un remote; + int fd; int t; - APPL_TRACE_DEBUG0("wait socket"); + //BTIF_TRACE_EVENT1("accept fd %d", sfd); + + if ((fd = accept(sfd, (struct sockaddr *)&remote, &t)) == -1) { + BTIF_TRACE_ERROR1("sock accept failed (%s)", strerror(errno)); + return -1; + } + + //BTIF_TRACE_EVENT1("new fd %d", fd); + + return fd; +} + +/***************************************************************************** +** +** uipc helper functions +** +*****************************************************************************/ + +static int uipc_main_init(void) +{ + int i; + const pthread_mutexattr_t attr = PTHREAD_MUTEX_RECURSIVE; + pthread_mutex_init(&uipc_main.mutex, &attr); + + BTIF_TRACE_EVENT0("### uipc_main_init ###"); + + /* setup interrupt socket pair */ + if (socketpair(AF_UNIX, SOCK_STREAM, 0, uipc_main.signal_fds) < 0) + { + return -1; + } + + FD_SET(uipc_main.signal_fds[0], &uipc_main.active_set); + uipc_main.max_fd = MAX(uipc_main.max_fd, uipc_main.signal_fds[0]); + + for (i=0; i< UIPC_CH_NUM; i++) + { + tUIPC_CHAN *p = &uipc_main.ch[i]; + p->srvfd = UIPC_DISCONNECTED; + p->fd = UIPC_DISCONNECTED; + p->task_evt_flags = 0; + pthread_cond_init(&p->cond, NULL); + pthread_mutex_init(&p->cond_mutex, NULL); + p->cback = NULL; + } + + return 0; +} + +void uipc_main_cleanup(void) +{ + int i; + + close(uipc_main.signal_fds[0]); + close(uipc_main.signal_fds[1]); + + /* close any open channels */ + for (i=0; i<UIPC_CH_NUM; i++) + UIPC_Close(i); +} + + + +/* check pending events in read task */ +static void uipc_check_task_flags_locked(void) +{ + int i; + + for (i=0; i<UIPC_CH_NUM; i++) + { + //BTIF_TRACE_EVENT2("CHECK TASK FLAGS %x %x", uipc_main.ch[i].task_evt_flags, UIPC_TASK_FLAG_DISCONNECT_CHAN); + if (uipc_main.ch[i].task_evt_flags & UIPC_TASK_FLAG_DISCONNECT_CHAN) + { + uipc_main.ch[i].task_evt_flags &= ~UIPC_TASK_FLAG_DISCONNECT_CHAN; + uipc_close_ch_locked(i); + } + + /* add here */ + + } +} + + +static int uipc_check_fd_locked(tUIPC_CH_ID ch_id) +{ + if (ch_id >= UIPC_CH_NUM) + return -1; + + //BTIF_TRACE_EVENT2("CHECK SRVFD %d (ch %d)", uipc_main.ch[ch_id].srvfd, ch_id); + + if (FD_ISSET(uipc_main.ch[ch_id].srvfd, &uipc_main.read_set)) + { + BTIF_TRACE_EVENT1("INCOMING CONNECTION ON CH %d", ch_id); + + uipc_main.ch[ch_id].fd = accept_server_socket(uipc_main.ch[ch_id].srvfd); + + //BTIF_TRACE_EVENT1("NEW FD %d", uipc_main.ch[ch_id].fd); + + if (uipc_main.ch[ch_id].cback) + { + /* if we have a callback we should add this fd to the active set + and notify user with callback event */ + BTIF_TRACE_EVENT1("ADD FD %d TO ACTIVE SET", uipc_main.ch[ch_id].fd); + FD_SET(uipc_main.ch[ch_id].fd, &uipc_main.active_set); + uipc_main.max_fd = MAX(uipc_main.max_fd, uipc_main.ch[ch_id].fd); + } + + if (uipc_main.ch[ch_id].fd < 0) + { + BTIF_TRACE_ERROR2("FAILED TO ACCEPT CH %d (%s)", ch_id, strerror(errno)); + return -1; + } + + if (uipc_main.ch[ch_id].cback) + uipc_main.ch[ch_id].cback(ch_id, UIPC_OPEN_EVT); + } + + //BTIF_TRACE_EVENT2("CHECK FD %d (ch %d)", uipc_main.ch[ch_id].fd, ch_id); + + if (FD_ISSET(uipc_main.ch[ch_id].fd, &uipc_main.read_set)) + { + //BTIF_TRACE_EVENT1("INCOMING DATA ON CH %d", ch_id); + + if (uipc_main.ch[ch_id].cback) + uipc_main.ch[ch_id].cback(ch_id, UIPC_RX_DATA_READY_EVT); + } + return 0; +} + +static void uipc_check_interrupt_locked(void) +{ + if (FD_ISSET(uipc_main.signal_fds[0], &uipc_main.read_set)) + { + char sig_recv = 0; + //BTIF_TRACE_EVENT0("UIPC INTERRUPT"); + recv(uipc_main.signal_fds[0], &sig_recv, sizeof(sig_recv), MSG_WAITALL); + } +} + +static inline void uipc_wakeup_locked(void) +{ + char sig_on = 1; + BTIF_TRACE_EVENT0("UIPC SEND WAKE UP"); + send(uipc_main.signal_fds[1], &sig_on, sizeof(sig_on), 0); +} + +static int uipc_setup_server_locked(tUIPC_CH_ID ch_id, char *name, tUIPC_RCV_CBACK *cback) +{ + int fd; + + BTIF_TRACE_EVENT1("SETUP CHANNEL SERVER %d", ch_id); - listen_fd = create_server_socket(SOCKPATH); + if (ch_id >= UIPC_CH_NUM) + return -1; - if ((sock_fd = accept(listen_fd, (struct sockaddr *)&remote, &t)) == -1) { - APPL_TRACE_ERROR1("a2dp sock accept failed (%d)", errno); + UIPC_LOCK(); + + fd = create_server_socket(name); + + if (fd < 0) + { + BTIF_TRACE_ERROR2("failed to setup %s", name, strerror(errno)); + UIPC_UNLOCK(); return -1; } - return sock_fd; + BTIF_TRACE_EVENT1("ADD SERVER FD TO ACTIVE SET %d", fd); + FD_SET(fd, &uipc_main.active_set); + uipc_main.max_fd = MAX(uipc_main.max_fd, fd); + + uipc_main.ch[ch_id].srvfd = fd; + uipc_main.ch[ch_id].cback = cback; + uipc_main.ch[ch_id].read_poll_tmo_ms = DEFAULT_READ_POLL_TMO_MS; + + /* trigger main thread to update read set */ + uipc_wakeup_locked(); + + UIPC_UNLOCK(); + + return 0; } -int open_source(void) +static void uipc_flush_ch_locked(tUIPC_CH_ID ch_id) { - int s; -#if (SOURCE_MODE == SOURCE_MODE_PCMFILE) - s = open((char*)PCM_FILENAME , O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + char buf; + struct pollfd pfd; + int ret; + + pfd.events = POLLIN|POLLHUP; + pfd.fd = uipc_main.ch[ch_id].fd; + + if (uipc_main.ch[ch_id].fd == UIPC_DISCONNECTED) + return; - if (s == -1) + while (1) { - APPL_TRACE_ERROR0("unable to open pcm file\n"); - s = -1; + ret = poll(&pfd, 1, 1); + BTIF_TRACE_EVENT3("uipc_flush_ch_locked polling : fd %d, rxev %x, ret %d", pfd.fd, pfd.revents, ret); + + if (pfd.revents | (POLLERR|POLLHUP)) + return; + + if (ret <= 0) + { + BTIF_TRACE_EVENT1("uipc_flush_ch_locked : error (%d)", ret); + return; + } + read(pfd.fd, &buf, 1); + } +} + + +static void uipc_flush_locked(tUIPC_CH_ID ch_id) +{ + if (ch_id >= UIPC_CH_NUM) + return; + + switch(ch_id) + { + case UIPC_CH_ID_AV_CTRL: + uipc_flush_ch_locked(UIPC_CH_ID_AV_CTRL); + break; + + case UIPC_CH_ID_AV_AUDIO: + uipc_flush_ch_locked(UIPC_CH_ID_AV_AUDIO); + break; + } +} + + +static int uipc_close_ch_locked(tUIPC_CH_ID ch_id) +{ + int wakeup = 0; + + BTIF_TRACE_EVENT1("CLOSE CHANNEL %d", ch_id); + + if (ch_id >= UIPC_CH_NUM) + return -1; + + if (ch_id == UIPC_CH_ID_ALL) + { + /* shutdown read thread */ + uipc_main.running = 0; + uipc_wakeup_locked(); return 0; } -#endif -#if (SOURCE_MODE == SOURCE_MODE_A2DP_SOCKET) - s = wait_socket(); -#endif - return s; + if (uipc_main.ch[ch_id].srvfd != UIPC_DISCONNECTED) + { + BTIF_TRACE_EVENT1("CLOSE SERVER (FD %d)", uipc_main.ch[ch_id].srvfd); + close(uipc_main.ch[ch_id].srvfd); + FD_CLR(uipc_main.ch[ch_id].srvfd, &uipc_main.active_set); + uipc_main.ch[ch_id].srvfd = UIPC_DISCONNECTED; + wakeup = 1; + } + + if (uipc_main.ch[ch_id].fd != UIPC_DISCONNECTED) + { + BTIF_TRACE_EVENT1("CLOSE CONNECTION (FD %d)", uipc_main.ch[ch_id].fd); + close(uipc_main.ch[ch_id].fd); + FD_CLR(uipc_main.ch[ch_id].fd, &uipc_main.active_set); + uipc_main.ch[ch_id].fd = UIPC_DISCONNECTED; + wakeup = 1; + } + + /* notify this connection is closed */ + if (uipc_main.ch[ch_id].cback) + uipc_main.ch[ch_id].cback(ch_id, UIPC_CLOSE_EVT); + + /* trigger main thread update if something was updated */ + if (wakeup) + uipc_wakeup_locked(); + + return 0; } -void close_source(int fd) + +void uipc_close_locked(tUIPC_CH_ID ch_id) { - close(fd); + if (uipc_main.ch[ch_id].srvfd == UIPC_DISCONNECTED) + { + BTIF_TRACE_EVENT1("CHANNEL %d ALREADY CLOSED", ch_id); + return; + } + + /* schedule close on this channel */ + uipc_main.ch[ch_id].task_evt_flags |= UIPC_TASK_FLAG_DISCONNECT_CHAN; + uipc_wakeup_locked(); +} + + +static void uipc_read_task(void *arg) +{ + int ch_id; + int result; + + prctl(PR_SET_NAME, (unsigned long)"uipc-main", 0, 0, 0); + + while (uipc_main.running) + { + uipc_main.read_set = uipc_main.active_set; + + result = select(uipc_main.max_fd+1, &uipc_main.read_set, NULL, NULL, NULL); + + if (result == 0) + { + BTIF_TRACE_EVENT0("select timeout"); + continue; + } + else if (result < 0) + { + BTIF_TRACE_EVENT1("select failed %s", strerror(errno)); + continue; + } + + UIPC_LOCK(); -#if (SOURCE_MODE == SOURCE_MODE_A2DP_SOCKET) - close(listen_fd); - listen_fd = -1; -#endif + /* clear any wakeup interrupt */ + uipc_check_interrupt_locked(); + + /* check pending task events */ + uipc_check_task_flags_locked(); + + /* make sure we service audio channel first */ + uipc_check_fd_locked(UIPC_CH_ID_AV_AUDIO); + + /* check for other connections */ + for (ch_id = 0; ch_id < UIPC_CH_NUM; ch_id++) + { + if (ch_id != UIPC_CH_ID_AV_AUDIO) + uipc_check_fd_locked(ch_id); + } + + UIPC_UNLOCK(); + } + + BTIF_TRACE_EVENT0("UIPC READ THEAD EXITING"); + + uipc_main_cleanup(); } +int uipc_start_main_server_thread(void) +{ + uipc_main.running = 1; + + if (pthread_create(&uipc_main.tid, (const pthread_attr_t *) NULL, (void*)uipc_read_task, NULL) < 0) + { + BTIF_TRACE_ERROR1("uipc_thread_create pthread_create failed:%d", errno); + return -1; + } + + return 0; +} + /******************************************************************************* ** ** Function UIPC_Init @@ -121,7 +608,13 @@ void close_source(int fd) UDRV_API void UIPC_Init(void *p_data) { - APPL_TRACE_DEBUG0("UIPC_Init"); + BTIF_TRACE_DEBUG0("UIPC_Init"); + + memset(&uipc_main, 0, sizeof(tUIPC_MAIN)); + + uipc_main_init(); + + uipc_start_main_server_thread(); } /******************************************************************************* @@ -135,9 +628,37 @@ UDRV_API void UIPC_Init(void *p_data) *******************************************************************************/ UDRV_API BOOLEAN UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback) { - APPL_TRACE_DEBUG2("UIPC_Open : ch_id %d, p_cback %x", ch_id, p_cback); + BTIF_TRACE_DEBUG2("UIPC_Open : ch_id %d, p_cback %x", ch_id, p_cback); - return FALSE; + UIPC_LOCK(); + + if (ch_id >= UIPC_CH_NUM) + { + UIPC_UNLOCK(); + return FALSE; + } + + if (uipc_main.ch[ch_id].srvfd != UIPC_DISCONNECTED) + { + BTIF_TRACE_EVENT1("CHANNEL %d ALREADY OPEN", ch_id); + UIPC_UNLOCK(); + return 0; + } + + switch(ch_id) + { + case UIPC_CH_ID_AV_CTRL: + uipc_setup_server_locked(ch_id, A2DP_CTRL_PATH, p_cback); + break; + + case UIPC_CH_ID_AV_AUDIO: + uipc_setup_server_locked(ch_id, A2DP_DATA_PATH, p_cback); + break; + } + + UIPC_UNLOCK(); + + return TRUE; } /******************************************************************************* @@ -149,11 +670,14 @@ UDRV_API BOOLEAN UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback) ** Returns void ** *******************************************************************************/ + UDRV_API void UIPC_Close(tUIPC_CH_ID ch_id) { - APPL_TRACE_DEBUG1("UIPC_Close : ch_id %d", ch_id); - close_source(source_fd); - source_fd = -1; + BTIF_TRACE_DEBUG1("UIPC_Close : ch_id %d", ch_id); + + UIPC_LOCK(); + uipc_close_locked(ch_id); + UIPC_UNLOCK(); } /******************************************************************************* @@ -168,7 +692,14 @@ UDRV_API void UIPC_Close(tUIPC_CH_ID ch_id) *******************************************************************************/ UDRV_API BOOLEAN UIPC_SendBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg) { - APPL_TRACE_DEBUG1("UIPC_SendBuf : ch_id %d", ch_id); + BTIF_TRACE_DEBUG1("UIPC_SendBuf : ch_id %d NOT IMPLEMENTED", ch_id); + + UIPC_LOCK(); + + /* currently not used */ + + UIPC_UNLOCK(); + return FALSE; } @@ -184,7 +715,19 @@ UDRV_API BOOLEAN UIPC_SendBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg) UDRV_API BOOLEAN UIPC_Send(tUIPC_CH_ID ch_id, UINT16 msg_evt, UINT8 *p_buf, UINT16 msglen) { - APPL_TRACE_DEBUG1("UIPC_Send : ch_id:%d", ch_id); + int n; + + BTIF_TRACE_DEBUG2("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen); + + UIPC_LOCK(); + + if (write(uipc_main.ch[ch_id].fd, p_buf, msglen) < 0) + { + BTIF_TRACE_ERROR1("failed to write (%s)", strerror(errno)); + } + + UIPC_UNLOCK(); + return FALSE; } @@ -199,7 +742,10 @@ UDRV_API BOOLEAN UIPC_Send(tUIPC_CH_ID ch_id, UINT16 msg_evt, UINT8 *p_buf, *******************************************************************************/ UDRV_API void UIPC_ReadBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg) { - APPL_TRACE_DEBUG1("UIPC_ReadBuf : ch_id:%d", ch_id); + BTIF_TRACE_DEBUG1("UIPC_ReadBuf : ch_id:%d NOT IMPLEMENTED", ch_id); + + UIPC_LOCK(); + UIPC_UNLOCK(); } /******************************************************************************* @@ -211,31 +757,75 @@ UDRV_API void UIPC_ReadBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg) ** Returns return the number of bytes read. ** *******************************************************************************/ -UDRV_API UINT32 UIPC_Read(tUIPC_CH_ID ch_id, UINT16 *p_msg_evt, UINT8 *p_buf, - UINT32 len) + +UDRV_API UINT32 UIPC_Read(tUIPC_CH_ID ch_id, UINT16 *p_msg_evt, UINT8 *p_buf, UINT32 len) { int n; int n_read = 0; + int fd = uipc_main.ch[ch_id].fd; + struct pollfd pfd; - //APPL_TRACE_DEBUG1("UIPC_Read : ch_id %d", ch_id); + if (ch_id >= UIPC_CH_NUM) + { + BTIF_TRACE_ERROR1("UIPC_Read : invalid ch id %d", ch_id); + return 0; + } - if (source_fd == -1) + if (fd == UIPC_DISCONNECTED) { - source_fd = open_source(); - } + BTIF_TRACE_ERROR1("UIPC_Read : channel %d closed", ch_id); + return 0; + } + + BTIF_TRACE_DEBUG4("UIPC_Read : ch_id %d, len %d, fd %d, polltmo %d", ch_id, len, + fd, uipc_main.ch[ch_id].read_poll_tmo_ms); while (n_read < (int)len) { - n = read(source_fd, p_buf, len); - + pfd.fd = fd; + pfd.events = POLLIN|POLLHUP; + + /* make sure there is data prior to attempting read */ + if (poll(&pfd, 1, uipc_main.ch[ch_id].read_poll_tmo_ms) == 0) + { + BTIF_TRACE_EVENT1("poll timeout (%d ms)", uipc_main.ch[ch_id].read_poll_tmo_ms); + return 0; + } + + BTIF_TRACE_EVENT1("poll revents %x", pfd.revents); + + if (pfd.revents & (POLLHUP|POLLNVAL) ) + { + BTIF_TRACE_EVENT0("poll : channel detached remotely"); + UIPC_LOCK(); + uipc_close_locked(ch_id); + UIPC_UNLOCK(); + return 0; + } + + UIPC_UNLOCK(); + + n = recv(fd, p_buf, len, 0); + + //BTIF_TRACE_EVENT1("read %d bytes", n); + if (n == 0) { - APPL_TRACE_EVENT0("remote source detached"); - source_fd = -1; + BTIF_TRACE_EVENT0("UIPC_Read : channel detached remotely"); + UIPC_LOCK(); + uipc_close_locked(ch_id); + UIPC_UNLOCK(); return 0; } + + if (n < 0) + { + BTIF_TRACE_EVENT1("UIPC_Read : read failed (%s)", strerror(errno)); + return 0; + } + n_read+=n; - //APPL_TRACE_EVENT1("read %d bytes", n_read); + } return n_read; @@ -250,9 +840,49 @@ UDRV_API UINT32 UIPC_Read(tUIPC_CH_ID ch_id, UINT16 *p_msg_evt, UINT8 *p_buf, ** Returns void ** *******************************************************************************/ + UDRV_API extern BOOLEAN UIPC_Ioctl(tUIPC_CH_ID ch_id, UINT32 request, void *param) { - APPL_TRACE_DEBUG2("#### UIPC_Ioctl : ch_ud %d, request %d ####", ch_id, request); + BTIF_TRACE_DEBUG2("#### UIPC_Ioctl : ch_id %d, request %d ####", ch_id, request); + + UIPC_LOCK(); + + switch(request) + { + case UIPC_REQ_RX_FLUSH: + uipc_flush_locked(ch_id); + break; + + case UIPC_REG_CBACK: + //BTIF_TRACE_EVENT3("register callback ch %d srvfd %d, fd %d", ch_id, uipc_main.ch[ch_id].srvfd, uipc_main.ch[ch_id].fd); + uipc_main.ch[ch_id].cback = (tUIPC_RCV_CBACK*)param; + break; + + case UIPC_REG_REMOVE_ACTIVE_READSET: + + /* user will read data directly and not use select loop */ + if (uipc_main.ch[ch_id].fd != UIPC_DISCONNECTED) + { + /* remove this channel from active set */ + FD_CLR(uipc_main.ch[ch_id].fd, &uipc_main.active_set); + + /* refresh active set */ + uipc_wakeup_locked(); + } + break; + + case UIPC_SET_READ_POLL_TMO: + uipc_main.ch[ch_id].read_poll_tmo_ms = (int)param; + BTIF_TRACE_EVENT2("UIPC_SET_READ_POLL_TMO : CH %d, TMO %d ms", ch_id, uipc_main.ch[ch_id].read_poll_tmo_ms ); + break; + + default: + BTIF_TRACE_EVENT1("UIPC_Ioctl : request not handled (%d)", request); + break; + } + + UIPC_UNLOCK(); + return FALSE; } diff --git a/udrv/ulinux/unv_linux.c b/udrv/ulinux/unv_linux.c index 6737ca0..dc79fa4 100644 --- a/udrv/ulinux/unv_linux.c +++ b/udrv/ulinux/unv_linux.c @@ -3,44 +3,44 @@ * Copyright (C) 2009-2012 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its - * licensors, and may only be used, duplicated, modified or distributed - * pursuant to the terms and conditions of a separate, written license - * agreement executed between you and Broadcom (an "Authorized License"). - * Except as set forth in an Authorized License, Broadcom grants no license - * (express or implied), right to use, or waiver of any kind with respect to - * the Software, and Broadcom expressly reserves all rights in and to the - * Software and all intellectual property rights therein. - * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS - * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE - * ALL USE OF THE SOFTWARE. + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * - * 1. This program, including its structure, sequence and organization, - * constitutes the valuable trade secrets of Broadcom, and you shall - * use all reasonable efforts to protect the confidentiality thereof, - * and to use this information only in connection with your use of + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of * Broadcom integrated circuit products. * - * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED - * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, - * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, - * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY - * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, - * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, - * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT * OF USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR - * ITS LICENSORS BE LIABLE FOR - * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY - * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO - * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM - * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR - * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE - * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE - * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. * ************************************************************************************/ @@ -50,11 +50,11 @@ * Filename: unv_linux.c * * Description: Universal NV Ram API. - * Manages all non volatile (file) database entries used by + * Manages all non volatile (file) database entries used by * bluetooth upper layer stack. - * + * ***********************************************************************************/ - + #include "unv.h" #include <stdio.h> @@ -68,7 +68,7 @@ #include <sys/mman.h> #include <stdlib.h> #include <sys/prctl.h> -#include <pthread.h> +#include <pthread.h> #define LOG_TAG "UNV_LINUX" #include <utils/Log.h> @@ -118,7 +118,7 @@ /******************************************************************************* ** -** Function check_caller_context +** Function check_caller_context ** ** Description Checks pthread name of caller. Currently only BTIF thread ** is allowed to call in here to avoid multithreading issues @@ -132,7 +132,7 @@ static int check_caller_context(void) char name[16]; prctl(PR_GET_NAME, name, 0, 0, 0); - + if (strncmp(name, BTIF_TASK_STR, strlen(BTIF_TASK_STR)) != 0) { error("only btif context allowed (%s)", name); @@ -143,7 +143,7 @@ static int check_caller_context(void) /******************************************************************************* ** -** Function mk_dir +** Function mk_dir ** ** Description Create directory ** @@ -154,7 +154,7 @@ static int check_caller_context(void) static int mk_dir(const char *path) { struct stat st; - + if (stat(path, &st) == 0) { if (!S_ISDIR(st.st_mode)) @@ -163,11 +163,11 @@ static int mk_dir(const char *path) error("directory path %s is not a directory (%s)", path, strerror(errno)); return -1; } - + /* already exist */ - return 0; - } - + return 0; + } + /* no existing dir path, try creating it */ if (mkdir(path, DIR_MODE) != 0) { @@ -197,7 +197,7 @@ static int rm_dir(const char *path) error("rmdir %s failed (%s)", path, strerror(errno)); return -1; } - return 0; + return 0; } /******************************************************************************* @@ -210,8 +210,8 @@ static int rm_dir(const char *path) ** *******************************************************************************/ -static int write_keyval( int fd, - const char *key, +static int write_keyval( int fd, + const char *key, const char *val ) { int len = 0; @@ -230,16 +230,16 @@ static int write_keyval( int fd, error("alloc failed (%s)", strerror(errno)); return -1; } - + len = sprintf(line, "%s %s%s", key, val, UNV_DELIM); - //info("write_keyval %s %s (%d bytes)", key, val, len); + //info("write_keyval %s %s (%d bytes)", key, val, len); /* update line */ written = write(fd, line, len); free(line); - + return written; } @@ -258,10 +258,10 @@ static int write_keyval( int fd, ** *******************************************************************************/ -static int update_key( int fd, - const char *key, - const char *value, - int pos_start, +static int update_key( int fd, + const char *key, + const char *value, + int pos_start, int pos_stop ) { char *line; @@ -278,7 +278,7 @@ static int update_key( int fd, { verbose("remove key [%s]", key); } - + /* update file with new value for this key */ if (fstat(fd, &st) != 0) @@ -286,7 +286,7 @@ static int update_key( int fd, error("stat failed (%s)", strerror(errno)); return -1; } - + tail_sz = st.st_size-pos_stop; if (tail_sz > 0) @@ -312,7 +312,7 @@ static int update_key( int fd, } /* rewind and update new line */ - lseek(fd, pos_start, SEEK_SET); + lseek(fd, pos_start, SEEK_SET); len = pos_start; /* a null key means remove entry */ @@ -320,14 +320,14 @@ static int update_key( int fd, { len += write_keyval(fd, key, value); } - + /* write tail content */ if (p_tail) { len += write(fd, p_tail, tail_sz); free(p_tail); } - + /* finally truncate file to new length */ ftruncate(fd, len); @@ -345,18 +345,18 @@ static int update_key( int fd, ** key : string to search for in keyfile ** p_out : output buffer supplied by caller ** out_len : max length of output line buffer -** pos_begin : returns keyvalue start offset in file +** pos_begin : returns keyvalue start offset in file ** pos_end : returns keyvalue end offset in file -** +** ** Returns String of key value, NULL if not found ** ******************************************************************************/ static char *get_keyval( int fd, - const char *key, + const char *key, char *p_out, int out_len, - int *pos_begin, + int *pos_begin, int *pos_end) { char *p_value = NULL; @@ -373,7 +373,7 @@ static char *get_keyval( int fd, p_buf = malloc(st.st_size + 1); - if (!p_buf) + if (!p_buf) return NULL; p = p_buf; @@ -387,9 +387,9 @@ static char *get_keyval( int fd, /* tokenize first line */ line = strtok(p, UNV_DELIM); - + while (line && (p_value == NULL)) - { + { /* check for match */ if (strncmp(line, key, strlen(key)) == 0) { @@ -409,25 +409,25 @@ static char *get_keyval( int fd, p_value = p_out; /* should be ok to just strcpy from 'line' as - * strrok shall null-terminate the token + * strrok shall null-terminate the token * in the above call */ strcpy(p_value, line); verbose("found [%s=%s]", key, p_value); - + if (pos_end) *pos_end = (line-p_buf) + strlen(line) + strlen(UNV_DELIM); } /* check next line */ - line = strtok(NULL, UNV_DELIM); + line = strtok(NULL, UNV_DELIM); } - + free(p_buf); /* rewind */ lseek(fd, 0, SEEK_SET); - + return p_value; } @@ -446,7 +446,7 @@ static char *get_keyval( int fd, ** ** Function unv_create_directory ** -** Description Creates directory, if full path is not available it +** Description Creates directory, if full path is not available it ** will construct it. Must be called from BTIF task context. ** ** Parameters @@ -467,14 +467,14 @@ int unv_create_directory(const char *path) if (check_caller_context() == 0) return -1; - + /* assumes absolute paths */ if (strncmp(path, "./", 2) == 0) { error("%s not an absolute path", path); return -1; } - + /* try creating dir directly */ if (mk_dir(path) == 0) return 0; @@ -493,11 +493,11 @@ int unv_create_directory(const char *path) p = strchr(p_copy+1, '/'); /* skip root */ while ((status == 0) && p) - { - /* - * temporarily null terminate to allow creating + { + /* + * temporarily null terminate to allow creating * directories up to this point - */ + */ *p= '\0'; status = mk_dir(p_copy); *p= '/'; @@ -519,7 +519,7 @@ int unv_create_directory(const char *path) ** Parameters ** filename : file path to be created ** -** Returns 0 if successful, -1 if failure +** Returns 0 if successful, -1 if failure ** *******************************************************************************/ @@ -534,7 +534,7 @@ int unv_create_file(const char *filename) /* separate path from filename */ p = strrchr(path, '/'); - + if (p) { *p = '\0'; @@ -544,21 +544,21 @@ int unv_create_file(const char *filename) return -1; } } - + free(path); - + verbose("CREATE FILE %s", filename); - + fd = open(filename, O_RDWR|O_CREAT, FILE_MODE); - if (fd < 0) + if (fd < 0) { error("file failed to create %s errno: (%s)", filename, strerror(errno)); return -1; } close(fd); - + return 0; } @@ -581,14 +581,14 @@ int unv_create_file(const char *filename) ** ******************************************************************************/ -char* unv_read_key( const char *path, +char* unv_read_key( const char *path, const char *key, char *p_out, int out_len) { int fd; char *p_search; - + verbose("READ KEY [%s]", key); /* sanity check */ @@ -597,7 +597,7 @@ char* unv_read_key( const char *path, if (check_caller_context() == 0) return NULL; - + fd = open(path, O_RDONLY, FILE_MODE); if (fd < 0) { @@ -608,7 +608,7 @@ char* unv_read_key( const char *path, p_search = get_keyval(fd, key, p_out, out_len, NULL, NULL); close(fd); - + return p_search; } @@ -629,8 +629,8 @@ char* unv_read_key( const char *path, ** *******************************************************************************/ -int unv_read_key_iter( const char *path, - unv_iter_cb cb, +int unv_read_key_iter( const char *path, + unv_iter_cb cb, void *userdata ) { int fd; @@ -703,7 +703,7 @@ int unv_read_key_iter( const char *path, ** ** Function unv_write_key ** -** Description Writes key to file. If key value exists it will be updated +** Description Writes key to file. If key value exists it will be updated ** Path must be an existing absolute path ** Must be called from BTIF task context ** @@ -712,12 +712,12 @@ int unv_read_key_iter( const char *path, ** key : key string to write ** value : value string to set for this key ** -** Returns 0 if successful, -1 if failure +** Returns 0 if successful, -1 if failure ** *******************************************************************************/ -int unv_write_key( const char *path, - const char *key, +int unv_write_key( const char *path, + const char *key, const char *value ) { int fd; @@ -737,7 +737,7 @@ int unv_write_key( const char *path, fd = open(path, O_RDWR, FILE_MODE); - if (fd < 0) + if (fd < 0) { error("file failed to create %s (%s)", path, strerror(errno)); return -1; @@ -748,18 +748,18 @@ int unv_write_key( const char *path, if (keyval) { - update_key(fd, key, value, pos_start, pos_stop); + update_key(fd, key, value, pos_start, pos_stop); } else { /* append at end of file */ lseek(fd, 0, SEEK_END); write_keyval(fd, key, value); - } + } free(p_line); close(fd); - + return 0; } @@ -779,7 +779,7 @@ int unv_write_key( const char *path, ** *******************************************************************************/ -int unv_remove_key( const char *path, +int unv_remove_key( const char *path, const char *key ) { int fd; @@ -787,7 +787,7 @@ int unv_remove_key( const char *path, int pos_begin = 0; int pos_stop = 0; char *p_line = malloc(UNV_MAXLINE_LENGTH); - + verbose("READ KEY [%s]", key); /* sanity check */ @@ -796,7 +796,7 @@ int unv_remove_key( const char *path, if (check_caller_context() == 0) return -1; - + fd = open(path, O_RDWR, FILE_MODE); if (fd < 0) { @@ -804,14 +804,14 @@ int unv_remove_key( const char *path, return -1; } - p_search = get_keyval(fd, key, p_line, UNV_MAXLINE_LENGTH, &pos_begin, &pos_stop); + p_search = get_keyval(fd, key, p_line, UNV_MAXLINE_LENGTH, &pos_begin, &pos_stop); if (p_search) { /* NULL value entry means remove key/val line in file */ - update_key(fd, key, NULL, pos_begin, pos_stop); + update_key(fd, key, NULL, pos_begin, pos_stop); } - + return (p_search ? 0 : -1); } |