/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define FASTTIMEOUTS 1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/poll.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#include <netinet/in.h>
#include "a2dpd_output_a2dp.h"
#include "a2dpd_tools.h"
#include "a2dpd_protocol.h"
#include "a2dpd_sdp.h"
#include "a2dpd_timer.h"
#include "a2dpd_ipc.h"
#include "sbc.h"
#include "../a2dp.h"
#define A2DPD_FLAGS_NONSPECAUDIO 1
#define NBSDPRETRIESMAX 0
#define BUFS 2048
#define MAXANSWERCOUNT 2000
//FIXME how should I choose the int_seid??
// The SEID used is the one that is advertised
#define A2DPD_SEID 1
enum { A2DPD_NOROLE, A2DPD_INITIATOR, A2DPD_ACCEPTOR };
typedef enum {
AVDTP_STATE_DISCONNECTED,
AVDTP_STATEX_DISCONNECTING,
AVDTP_STATEX_SDP_CONNECTING,
AVDTP_STATEX_SDP_CONNECTING_WAIT,
AVDTP_STATEX_CTL_CONNECTING,
AVDTP_STATEX_CTL_CONNECTING_WAIT,
AVDTP_STATEX_IDLE_CONNECTING,
AVDTP_STATE_IDLE,
AVDTP_STATEX_DISCOVERING,
AVDTP_STATEX_DISCOVERING_RESP,
AVDTP_STATEX_GETTING_CAPABILITIES,
AVDTP_STATEX_GETTING_CAPABILITIES_RESP,
AVDTP_STATEX_SETTING_CONFIGURATION,
AVDTP_STATEX_SETTING_CONFIGURATION_RESP,
AVDTP_STATEX_STREAM_OPENING,
AVDTP_STATEX_STREAM_OPENING_RESP,
AVDTP_STATE_CONFIGURED,
AVDTP_STATEX_STREAM_CONNECTING,
AVDTP_STATEX_STREAM_CONNECTING_WAIT,
AVDTP_STATE_OPEN_START_STREAMING,
AVDTP_STATE_OPEN,
AVDTP_STATEX_STREAM_STARTING,
AVDTP_STATEX_STREAM_STARTING_WAIT,
AVDTP_STATEX_STREAM_SUSPENDING,
AVDTP_STATEX_STREAM_SUSPENDING_WAIT,
AVDTP_STATEX_STREAM_CLOSING,
AVDTP_STATEX_STREAM_CLOSING_WAIT,
AVDTP_STATE_STREAMING,
AVDTP_STATE_CLOSING,
AVDTP_STATE_ABORTING,
} AVDTP_STATE;
typedef struct {
int nb_seid;
int curr_seid;
int curr_seid_acp_seid;
struct sepd_resp resp;
struct getcap_resp cap_resp;
} discover_state_info;
typedef struct {
int answer_count;
discover_state_info discover;
} STATE_INFO;
typedef struct snd_pcm_a2dp {
A2DPSETTINGS settings;
bdaddr_t src;
bdaddr_t dst;
char bdaddr[18];
sdp_session_t *sdp_session;
int role;
int sk_sdp;
int sk;
int control_sk;
sbc_t sbc;
int flags;
int user_flags;
unsigned char buf[1024]; // contain sbc encoded data, incrementally filled
unsigned int len; // number of valid bytes in buf
unsigned int frame_bytes; // fixed when initializing
AVDTP_STATE state; // State of a2dp
STATE_INFO state_info;
char bufe[BUFS]; // temporary encoding buffer
int lenbufe; //=0;
time_t timestamp; //=0;
uint16_t seq_num; //=1;
int frame_count; //=0; // Number of sbc frames in one AVDTP packet
int mtu; //=A2DPMAXIMUMTRANSFERUNITSIZE
uint8_t seid;
unsigned short psm_stream;
unsigned short psm_cmd;
// Bluetooth bandwith used
int bandwithcount;
struct timeval bandwithtimestamp;
// Used to control stream from headset
int pause_writing; // = 0;
} snd_pcm_a2dp_t;
// In fact sbc blocks are 76 bytes long, so a group of them is either 608 or 684 bytes
// So 650 or 678 makes no differences!
// However some devices may have longer transfer unit up to I saw omtu=733?
#define a2dp_set_state(new_state) do { DBG("State %s", #new_state); a2dp->state = new_state; } while (0)
#define a2dp_filter_state(new_state) do { DBG("State %s", #new_state); a2dp->state = new_state; } while (0)
#define FREQUENCY_16000 (1<<3)
#define FREQUENCY_32000 (1<<2)
#define FREQUENCY_44100 (1<<1)
#define FREQUENCY_48000 (1<<0)
unsigned int frequency_table [] = { 16000, 32000, 44100, 48000 };
#define BLOCK_LENGTH_4 (1<<3)
#define BLOCK_LENGTH_8 (1<<2)
#define BLOCK_LENGTH_12 (1<<1)
#define BLOCK_LENGTH_16 (1<<0)
unsigned int block_length_table [] = { 4, 8, 12, 16 };
#define CHANNEL_MODE_MONO (1<<3)
#define CHANNEL_MODE_DUAL (1<<2)
#define CHANNEL_MODE_STEREO (1<<1)
#define CHANNEL_MODE_JOINT (1<<0)
enum { MONO, DUAL_CHANNEL, STEREO, JOINT_STEREO };
unsigned int channel_mode_table [] = { MONO, DUAL_CHANNEL, STEREO, JOINT_STEREO };
#define ALLOCATION_SNR (1<<1)
#define ALLOCATION_LOUDNESS (1<<0)
enum { LOUDNESS, SNR };
unsigned int allocation_method_table [] = { LOUDNESS, SNR };
#define SUBBANDS_4 (1<<1)
#define SUBBANDS_8 (1<<0)
unsigned int subbands_table [] = { 4, 8 };
char* get_msgtype(int sigval)
{
char*sigtxt = "Unknown";
if(sigval==MESSAGE_TYPE_COMMAND)
sigtxt="MESSAGE_TYPE_COMMAND";
if(sigval==MESSAGE_TYPE_ACCEPT)
sigtxt="MESSAGE_TYPE_ACCEPT";
if(sigval==MESSAGE_TYPE_REJECT)
sigtxt="MESSAGE_TYPE_REJECT";
return sigtxt;
}
char* get_signal(int sigval)
{
char*sigtxt = "Unknown";
if(sigval==AVDTP_DISCOVER)
sigtxt="AVDTP_DISCOVER";
if(sigval==AVDTP_GET_CAPABILITIES)
sigtxt="AVDTP_GET_CAPABILITIES";
if(sigval==AVDTP_SET_CONFIGURATION)
sigtxt="AVDTP_SET_CONFIGURATION";
if(sigval==AVDTP_GET_CONFIGURATION)
sigtxt="AVDTP_GET_CONFIGURATION";
if(sigval==AVDTP_RECONFIGURE)
sigtxt="AVDTP_RECONFIGURE";
if(sigval==AVDTP_OPEN)
sigtxt="AVDTP_OPEN";
if(sigval==AVDTP_START)
sigtxt="AVDTP_START";
if(sigval==AVDTP_CLOSE)
sigtxt="AVDTP_CLOSE";
if(sigval==AVDTP_SUSPEND)
sigtxt="AVDTP_SUSPEND";
if(sigval==AVDTP_ABORT)
sigtxt="AVDTP_ABORT";
if(sigval==AVDTP_SECURITY_CONTROL)
sigtxt="AVDTP_SECURITY_CONTROL";
return sigtxt;
}
void memcpy_changeendian(void *dst, const void *src, int size)
{
int i;
const uint16_t *ptrsrc = src;
uint16_t *ptrdst = dst;
for (i = 0; i < size / 2; i++) {
*ptrdst++ = htons(*ptrsrc++);
}
}
// Prepare packet headers
void init_request(struct avdtp_header *header, int request_id)
{
static int transaction = 0;
header->packet_type = PACKET_TYPE_SINGLE;
header->message_type = MESSAGE_TYPE_COMMAND;
header->transaction_label = transaction;
header->signal_id = request_id;
// clear rfa bits
header->rfa0 = 0;
transaction = (transaction + 1) & 0xf;
}
uint16_t get_socket_omtu(int sockfd)
{
// Get mtu size
uint16_t mtu = A2DPMAXIMUMTRANSFERUNITSIZE;
struct l2cap_options opts;
unsigned int iOptSize = sizeof(opts);
if(getsockopt(sockfd, SOL_L2CAP, L2CAP_OPTIONS, &opts, &iOptSize) >= 0) {
if (opts.omtu)
mtu = opts.omtu;
if (!(mtu))
mtu = A2DPMAXIMUMTRANSFERUNITSIZE;
DBG("Socket %d imtu=%d, omtu=%d, flush_to=%d", sockfd, opts.imtu, opts.omtu, opts.flush_to);
}
return mtu;
}
/*
// Analyse the SEIDs the sink has sent to us
int process_seid(int s, struct acp_seid_info *get_seid_resp, unsigned short *psm, sbc_t * sbc)
{
int v, size;
int seid = get_seid_resp->acp_seid;
struct getcap_req put_req;
struct getcap_resp cap_resp;
struct set_config s_config;
struct set_config_resp s_resp;
struct stream_cmd open_stream;
struct open_stream_rsp open_resp;
memset(&put_req, 0, sizeof(put_req));
init_request(&put_req.header, AVDTP_GET_CAPABILITIES);
put_req.acp_seid = seid;
if (write(s, &put_req, sizeof(put_req)) != si
没有合适的资源?快使用搜索试试~ 我知道了~
linux下蓝牙耳塞源代码
共149个文件
c:25个
h:20个
entries:10个
需积分: 9 29 下载量 179 浏览量
2008-10-28
22:54:53
上传
评论
收藏 628KB RAR 举报
温馨提示
这是linux下蓝牙耳塞源代码,如果想开发蓝牙相关程序可以看看。
资源推荐
资源详情
资源评论
收起资源包目录
linux下蓝牙耳塞源代码 (149个子文件)
output.0 355KB
traces.0 313KB
output.1 354KB
traces.1 24KB
sample.a2dprc 2KB
Makefile.am 1KB
Makefile.am 864B
Makefile.am 287B
Makefile.am 280B
Makefile.am 199B
AUTHORS 0B
bootstrap 101B
btscorunner 212B
BUILD 947B
a2dpd_output_a2dp.c 63KB
a2dpd.c 51KB
states.c 26KB
pcm_a2dpd.c 17KB
pcm_sco.c 17KB
a2dpd_ipc.c 15KB
a2dpd_dbus.c 14KB
a2dpd_output_sco.c 12KB
daemon.c 11KB
ctl_a2dpd.c 11KB
skype_bt_hijacker.c 8KB
ctl_sco.c 8KB
a2dpd_tools.c 7KB
volctl.c 6KB
a2dpd_timer.c 5KB
a2dpd_output_alsa.c 5KB
a2dpd_sdp.c 5KB
a2dpd_ctl.c 4KB
avdtp.c 3KB
sdp.c 3KB
a2dpd_mixer.c 3KB
avtest.c 2KB
a2dpd_uinput.c 2KB
headsetd.c 2KB
dbus.c 1KB
ChangeLog 865B
ChangeLog 0B
compile 4KB
a2dpd.conf 597B
asound.conf 556B
linux.config 17KB
configure 354KB
COPYING 18KB
depcomp 16KB
sco-flowcontrol-v2.0.diff 38KB
sco-flowcontrol-v3.0.diff 22KB
pwlib.1.10.1.diff 1KB
Entries 1KB
Entries 614B
Entries 567B
Entries 519B
Entries 480B
Entries 469B
Entries 320B
Entries 207B
Entries 183B
Entries 24B
gumstix.gif 4KB
config.guess 42KB
a2dp.h 7KB
a2dpd_protocol.h 4KB
avrcp.h 3KB
a2dpd_output_a2dp.h 3KB
a2dpd_timer.h 2KB
states.h 2KB
a2dpd_ipc.h 2KB
volctl.h 2KB
a2dpd_output_sco.h 2KB
a2dpd_tools.h 2KB
a2dpd_output_alsa.h 1KB
avdtp.h 1KB
a2dpd_dbus.h 1KB
daemon.h 1KB
sockets.h 1KB
dbus.h 1KB
a2dpd_uinput.h 1KB
sdp.h 979B
a2dpd_sdp.h 949B
a2dpd_mixer.h 215B
build.html 10KB
future.html 7KB
embed.html 7KB
embedv1.html 5KB
history.html 4KB
contact.html 3KB
credits.html 2KB
index.html 2KB
Makefile.in 40KB
Makefile.in 20KB
Makefile.in 19KB
Makefile.in 14KB
Makefile.in 13KB
config.h.in 2KB
configure.in 2KB
com.access.a2dpd.service.in 58B
INSTALL 9KB
共 149 条
- 1
- 2
资源评论
fufufufufufufu
- 粉丝: 9
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功