⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcs.c

📁 linux系统下的关于蓝牙模块的源代码!十分的经典的程序!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * tcs.c -- Implementation of Bluetooth Telephony Control Protocol  *          Specification, TCS Binary * * Copyright (C) 2000, 2001  Axis Communications AB * * Author: Mattias Agren <mattias.agren@axis.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * Exceptionally, Axis Communications AB grants discretionary and * conditional permissions for additional use of the text contained * in the company's release of the AXIS OpenBT Stack under the * provisions set forth hereunder. * * Provided that, if you use the AXIS OpenBT Stack with other files, * that do not implement functionality as specified in the Bluetooth * System specification, to produce an executable, this does not by * itself cause the resulting executable to be covered by the GNU * General Public License. Your use of that executable is in no way * restricted on account of using the AXIS OpenBT Stack code with it. * * This exception does not however invalidate any other reasons why * the executable file might be covered by the provisions of the GNU * General Public License. * * $Id: tcs.c,v 1.15 2001/03/30 12:08:45 mattiasagren Exp $ * *//****************** INCLUDE FILES SECTION ***********************************/#define __NO_VERSION__ /* don't define kernel_version in module.h */#ifdef __KERNEL__#include <linux/malloc.h>#include <linux/bluetooth/btdebug.h>#include <linux/bluetooth/btcommon.h>#include <linux/bluetooth/btmem.h>#include <linux/bluetooth/tcs.h>#include <linux/bluetooth/l2cap.h>#include <linux/bluetooth/hci.h>#else /* user mode */#include <string.h>#include "include/btdebug.h"#include "include/btcommon.h"#include "include/btmem.h"#include "include/tcs.h"#include "include/l2cap.h"#include "include/hci.h"#endif/****************** DEBUG CONSTANT AND MACRO SECTION ************************/#define TCS_DBG_STR "           TCS "#if TCS_DEBUG_XMIT#define D_XMIT(fmt, args...) printk(TCS_DBG_STR fmt, ## args)#else#define D_XMIT(fmt, args...)#endif#if TCS_DEBUG_REC#define D_REC(fmt, args...) printk(TCS_DBG_STR fmt, ## args)#else#define D_REC(fmt, args...)#endif#if TCS_DEBUG_MISC#define D_MISC(fmt, args...) printk(TCS_DBG_STR fmt, ## args)#else#define D_MISC(fmt, args...)#endif#if TCS_PRINT_DATA#define PRINTPKT(str, data, len) print_data(str, data, len)#else#define PRINTPKT(str, data, len)#endif/****************** CONSTANT AND MACRO SECTION ******************************/#define TCS_NBR_OF_LINES 1/* Values used for the L2CAP configuration process */#define TCS_MTU 672/* Default, why should we be different */#define TCS_QOS 0x01 /* Best effort */#define TCS_FLUSH_TIMEOUT 0xffff /* Reliable channel, infinite amout of retransmissions *//* Call Control messages *//* Call Establishment */#define CALL_CONTROL 0x0#define ALERTING 0x0#define CALL_PROCEEDING 0x1#define CONNECT 0x2#define CONNECT_ACKNOWLEDGE 0x3#define PROGRESS 0x4#define SETUP 0x5#define SETUP_ACKNOWLEDGE 0x6/* Call clearing */#define DISCONNECT 0x7#define RELEASE 0x8#define RELEASE_COMPLETE 0x9/* Miscellaneous */#define INFORMATION 0xa#define START_DTMF 0x10#define START_DTMF_ACKNOWLEDGE 0x11#define START_DTMF_REJECT 0x12#define STOP_DTMF 0x13#define STOP_DTMF_ACKNOWLEDGE 0x14/* Group management messages */#define GROUP_MANAGEMENT 0x1#define INFO_SUGGEST 0x0#define INFO_ACCEPT 0x1#define LISTEN_REQUEST 0x2#define LISTEN_ACCEPT 0x3#define LISTEN_SUGGEST 0x4#define LISTEN_REJECT 0x5#define ACCESS_RIGHTS_REQUEST 0x6#define ACCESS_RIGHTS_ACCEPT 0x7#define ACCESS_RIGHTS_REJECT 0x8/* Connectionless messages */#define CONNECTIONLESS 0x2#define CL_INFO 0x0/* Single octet information elements */#define SENDING_COMPLETE 0xa1/* Double octet information elements */#define CALL_CLASS 0xc0#define CAUSE 0xc1#define PROGRESS_INDICATOR 0xc2 #define SIGNAL 0xc3#define KEYPAD_FACILITY 0xc4 #define SCO_HANDLE 0xc5/* Variable length information elements */#define CLOCK_OFFSET 0x0#define CONFIGURATION_DATA 0x1 #define BEARER_CAPABILITY 0x2#define DESTINATION_CID 0x3#define CALLING_PARTY_NUMBER 0x4 #define CALLED_PARTY_NUMBER 0x5#define AUDIO_CONTROL 0x6#define COMPANY_SPECIFIC 0x7/* Other information parameters *//* Bearer capability parameters */#define SCO_LINK 0x0#define ACL_LINK 0x1#define HV1_PACKET 0x5#define HV2_PACKET 0x6#define HV3_PACKET 0x7#define DV_PACKET 0x8#define CVSD 0x1#define PCM_A 0x2#define PCM_U 0x3/* Call class parameters */#define EXTERNAL_CALL 0x0#define INTERCOM_CALL 0x1#define SERVICE_CALL 0x2#define EMERGENCY_CALL 0x3/* Cause parameters */#define NORMAL_CALL_CLEARING 0x10/* Signal parameters */#define EXTERNAL_CALL_SIGNAL 0x40#define INTERNAL_CALL_SIGNAL 0x41#define CALL_BACK_SIGNAL 0x42/****************** TYPE DEFINITION SECTION *********************************/typedef struct tcs_message {	s32 type:5;	s32 prot_disc:3;	u8 info[0];} tcs_message;/****************** LOCAL FUNCTION DECLARATION SECTION **********************/static void process_cc_msg(l2cap_con *l2cap, u8* data, u32 len);static void process_gw_msg(l2cap_con *l2cap, u8* data, u32 len);static void process_cl_msg(l2cap_con *l2cap, u8* data, u32 len);static s32 send_single_octet_msg(l2cap_con *l2cap, u8 type, u8 prot_disc);static s32 send_tcs_msg(l2cap_con *l2cap, u8 type, u8 prot_disc, u8 *nfo, u32 nfo_len);/****************** GLOBAL VARIABLE DECLARATION SECTION *********************//****************** LOCAL VARIABLE DECLARATION SECTION **********************/tcs_con tcs[TCS_NBR_OF_LINES];/****************** FUNCTION DEFINITION SECTION *****************************/void tcs_init(void){	s32 i;	protocol_layer this_layer;	DSYS("Initialising TCS\n");	for (i = 0; i < TCS_NBR_OF_LINES; i++) {		tcs[i].tcs_cur_state = STATE_NULL;	}		/* Set the confirm and indication functions for the L2CAP-layer */	this_layer.con_ind = tcs_connect_ind;	this_layer.conf_ind = tcs_config_ind;	this_layer.disc_ind = tcs_disconnect_ind;	this_layer.con_cfm = tcs_connect_cfm;	this_layer.conf_cfm = tcs_config_cfm;	this_layer.disc_cfm = tcs_disconnect_cfm;	this_layer.receive_data = tcs_receive_data;	/* Register TCS in the L2CAP layer*/	l2cap_register_upper(TCS_LAYER, &this_layer);}void tcs_shutdown(void){	DSYS("Shutting down TCS\n");	tcs[0].tcs_cur_state = STATE_NULL;	}s32tcs_connect_req(u8 *bd){	if (l2ca_connect_req(bd, TCS_LAYER)) {		D_ERR(" tcs_connect_req: l2ca_connect_req failed\n");		return -1; 	}	return 0;}void tcs_connect_ind(l2cap_con *l2cap) {	D_MISC("tcs_connect_ind : remote cid : %d\n", l2cap->remote_cid);	tcs[0].l2cap = l2cap;		if(l2ca_connect_rsp(l2cap, RES_SUCCESS, STAT_NOINFO)){		D_ERR("tcs_connect_ind: l2ca_connect_rsp failed\n"); 	}}void tcs_connect_cfm(l2cap_con *l2cap, s32 status){	D_MISC("tcs_connect_cfm : remote cid : %d\n", l2cap->remote_cid);		if ( !l2ca_local_conf_done(l2cap) )	{		/* still haven't sent config request yet */		if(l2ca_config_req(l2cap, 0, NULL, 0, 0)){			D_ERR("tcs_connect_cfm : Conf req failed\n");		}		/* store connection */		tcs[0].l2cap = l2cap;	} else 	       		D_REC("tcs_config_cfm : already have sent config request\n");}void tcs_config_ind(l2cap_con* l2cap){	D_MISC("tcs_config_ind : remote cid : %d\n", l2cap->remote_cid);	/* check if we have sent a pos response yet */	if (!l2ca_remote_conf_done(l2cap)){		/* still haven't sent a pos configure response*/				if (l2ca_config_rsp(l2cap, l2cap->remote_mtu, 				    NULL, CONF_SUCCESS)){			D_ERR("tcs_config_ind : Conf rsp failed\n");		}    			} else 		printk("tcs_config_ind : already sent back a pos response\n");		/* check if we received a pos response on a previous config req */	if (!l2ca_local_conf_done(l2cap))	{		if (!l2cap->initiator) {			l2cap->local_mtu=l2cap->remote_mtu;			DSYS("tcs_config_ind : local l2cap mtu set to %d\n", 			     l2cap->local_mtu);						/* up3 -- fixme, use real options not static values */			if(l2ca_config_req(l2cap, 0, NULL, 0, 0)){				D_ERR("tcs_config_ind : Conf request failed\n");			}		}	} else 		DSYS("tcs_config_ind : already ready with config req\n");}void tcs_config_cfm(l2cap_con *l2cap, s32 status){	D_MISC("tcs_config_cfm :  remote cid : %d\n", l2cap->remote_cid);	DSYS("Now we have an open l2cap channel for TCS\n");	/* tcs negotiation */	if (!l2cap->initiator){		/* Server case */		tcs[0].acl_hdl = l2cap->hci_hdl;	} else {		tcs[0].acl_hdl = l2cap->hci_hdl;		/* Client case */	}}void tcs_disconnect_req(u32 tcs_hdl){	D_ERR("tcs_disconnect_req : NOT DONE\n");}  void tcs_disconnect_ind(l2cap_con *l2cap) {	D_MISC("tcs_disconnect_ind : remote cid : %d\n", l2cap->remote_cid);	l2ca_disconnect_rsp(l2cap);}void tcs_disconnect_cfm(l2cap_con *l2cap){	D_MISC("tcs_disconnect_cfm : remote cid : %d\n",l2cap->remote_cid);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -