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

📄 sec_client.c

📁 bluetooth 驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * sec_client.c -- Implementation of interface to Bluetooth Security Manager * * Copyright (C) 2000, 2001  Axis Communications AB * * Author: Ulf Hansson <ulf.hansson@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: sec_client.c,v 1.18 2001/04/26 13:58:18 ulfh Exp $ * *//****************** INCLUDE FILES SECTION ***********************************/#define __NO_VERSION__ /* don't define kernel_version in module.h */#ifdef __KERNEL__#include <linux/malloc.h>#include <linux/bluetooth/sec_client.h>#include <linux/bluetooth/l2cap_sec.h>#include <linux/bluetooth/rfcomm_sec.h>#include <linux/bluetooth/btmem.h>#include <linux/proc_fs.h>#else /* user mode */#include <stdlib.h>#include <string.h>#include <sys/socket.h>#include <sys/un.h>#include <syslog.h>#include <signal.h>#include "include/l2cap_sec.h"#include "include/rfcomm_sec.h"#include "include/sec_client.h"#include "include/btmem.h"#include "include/btdebug.h"#endif/****************** DEBUG CONSTANT AND MACRO SECTION ************************/#if SEC_CLIENT_DEBUG_MISC/* Misc */#define D_MISC(fmt...) printk(SEC_DBG_STR fmt)#else#define D_MISC(fmt...)#endif#if SEC_CLIENT_DEBUG_PROC#define D_PROC(fmt...) printk(fmt)#else#define D_PROC(fmt...)#endif#if SEC_CLIENT_PRINT_DATA#define PRINTPKT(str, data, len) print_data(str, data, len)#else#define PRINTPKT(str, data, len)#endif/****************** CONSTANT AND MACRO SECTION ******************************/#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,14)#define USE_NEW_PROC#endif#ifndef __KERNEL__#define SEC_MAN_SRV_SOCK "/tmp/sec_sock"#endif#define HCI_VALUE_RETURN_LINK_KEYS 0x15#define BD_ADDRESS_SIZE 6#define LINK_KEY_SIZE 16#define BUFFER_SIZE 256#define MAX_EVENT_DATA_LENGTH 16#define MAX_LINKKEYLISTSIZE 255 /* for now *//****************** TYPE DEFINITION SECTION *********************************/typedef struct link_key_information_type {	unsigned char bd_addr[BD_ADDRESS_SIZE];	unsigned char link_key[LINK_KEY_SIZE];		struct link_key_information_type *prev;	struct link_key_information_type *next;} link_key_information_type;typedef struct link_key_list_type {	link_key_information_type *first;	link_key_information_type *last;	link_key_information_type *cur;	u32 count;} link_key_list_type;enum originator_types {	BT_SEC_MAN,	SEC_CLIENT,	KERNEL}; struct security_query {	u16 request_type;    /* out */	u32 request_value;   /* out */	u8  remote_bd[BD_ADDRESS_SIZE];                             /* out */        u8  event_param[MAX_EVENT_DATA_LENGTH];                             /* out */	u8  originator;      /* out/in BT_SEC_MAN, SEC_CLIENT or KERNEL*/        u32 originator_data; /* out/in con or rfcomm struct pointer */	u16 request_result;  /* in */	} security_query;/****************** LOCAL FUNCTION DECLARATION SECTION **********************/#ifdef __KERNEL__#ifdef USE_NEW_PROCstatic ssize_t sec_man_read(struct file * file, char * buf,			    size_t count, loff_t *offset);static ssize_t sec_man_write(struct file * file, const char * buf,			     size_t count, loff_t *offset);#elsestatic s32 sec_man_read(struct inode *inode, struct file * file,			char * buf, s32 count);static s32 sec_man_write(struct inode *inode, struct file * file,			 const char * buf, s32 count);#endifstatic s32 sec_man_proc_dir_entry_read(char *buf, char **start, off_t offset,				       s32 len, s32 unused);#elsestatic s32 open_socket(char *name);static s32 sec_man_doquery(s32 fd, u8 *request);#endifvoid init_link_key_list(void);void free_link_key_list(void);link_key_information_type* create_link_key(unsigned char *bd_addr,					   unsigned char *link_key_str);link_key_information_type* get_first_link_key(void);link_key_information_type* get_next_link_key(link_key_information_type* link_key);void insert_link_key(link_key_information_type *new_link_key);s32 delete_link_key(link_key_information_type *link_key);/****************** GLOBAL VARIABLE DECLARATION SECTION *********************//****************** LOCAL VARIABLE DECLARATION SECTION **********************/static link_key_list_type link_key_list;#ifdef __KERNEL__#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)static struct wait_queue *sec_man_wq = NULL;#elsestatic wait_queue_head_t sec_man_wq;#endif#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)static struct file_operations sec_man_procfile_operation = {	NULL,                   /* lseek - default */	sec_man_read,           /* read - bad */	sec_man_write,          /* write - bad */	NULL,                   /* readdir */	NULL,                   /* select - default */	NULL,                   /* ioctl - default */	NULL,                   /* mmap */	NULL,                   /* no special open code */	NULL,                   /* no special release code */	NULL                    /* can't fsync */};#else static struct file_operations sec_man_procfile_operation = {	NULL,                   /* module owner */	NULL,                   /* lseek - default */	sec_man_read,           /* read - bad */	sec_man_write,          /* write - bad */	NULL,                   /* readdir */	NULL,                   /* select - default */	NULL,                   /* ioctl - default */	NULL,                   /* mmap */	NULL,                   /* no special open code */	NULL,                   /* no special release code */	NULL                    /* can't fsync */};#endif /* LINUX_VERSION_CODE */ /*  * proc directories can do almost nothing..  */#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)static struct inode_operations sec_man_proc_inode_operations = {	&sec_man_procfile_operation,   /* default net file-ops */	NULL,                   /* create */	NULL,                   /* lookup */	NULL,                   /* link */	NULL,                   /* unlink */	NULL,                   /* symlink */	NULL,                   /* mkdir */	NULL,                   /* rmdir */	NULL,                   /* mknod */	NULL,                   /* rename */	NULL,                   /* readlink */	NULL,                   /* follow_link */	NULL,                   /* readpage */	NULL,                   /* writepage */	NULL,                   /* bmap */	NULL,                   /* truncate */	NULL                    /* permission */};#elsestatic struct inode_operations sec_man_proc_inode_operations = {	NULL,                   /* create */	NULL,                   /* lookup */	NULL,                   /* link */	NULL,                   /* unlink */	NULL,                   /* symlink */	NULL,                   /* mkdir */	NULL,                   /* rmdir */	NULL,                   /* mknod */	NULL,                   /* rename */	NULL,                   /* readlink */	NULL,                   /* follow_link */	NULL,                   /* readpage */	NULL,                   /* writepage */	NULL,                   /* bmap */	NULL,                   /* truncate */	NULL                    /* permission */};#endif#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)static struct proc_dir_entry sec_man_proc_entry = {	0,	7, "sec_srv",	S_IFREG | S_IRUGO | S_IWUSR,	1, 0, 0,	0,	&sec_man_proc_inode_operations,	sec_man_proc_dir_entry_read,};#elsestatic struct proc_dir_entry sec_man_proc_entry = {	0,	7, "sec_srv",	S_IFREG | S_IRUGO | S_IWUSR,	1, 0, 0,	0,	&sec_man_proc_inode_operations,	&sec_man_procfile_operation,};#endif /* LINUX_VERSION_CODE */#endif /* __KERNEL__ */#ifndef __KERNEL__static s32 sec_man_sock;#endif/****************** FUNCTION DEFINITION SECTION *****************************/void sec_client_shutdown(){  security_query.originator = KERNEL;  #ifdef __KERNEL__  D_PROC("wake_up process %i (%s) awakening\n", current->pid, current->comm);  wake_up_interruptible(&sec_man_wq);  D_PROC("wake_up process %i (%s) woke up\n", current->pid, current->comm);#endif}void sec_man_init(enum security_requests user){#ifndef __KERNEL__	sec_man_sock = open_socket(SEC_MAN_SRV_SOCK);#endif	init_link_key_list();	/* To indicate that nothing is ready */	security_query.originator = SEC_CLIENT; }voidinit_link_key_list(void){        /* Init list */	link_key_list.first = NULL;	link_key_list.last = NULL;	link_key_list.cur = NULL;	link_key_list.count = 0;	}void free_link_key_list(void){	while (link_key_list.count)		delete_link_key(link_key_list.first);} link_key_information_type* create_link_key(unsigned char *bd_addr, unsigned char *link_key_str){ 	link_key_information_type *link_key;	if (link_key_list.count == MAX_LINKKEYLISTSIZE) {		D_ERR("Connection list full!\n");		return NULL;	}	/* Add check if already in list ?? or rely on that otherwhere ?*/  	/* Allocate new element */	if ((link_key = kmalloc(sizeof *link_key, GFP_ATOMIC)) < 0) {		D_ERR(__FUNCTION__ ": could not allocate new link key element\n");		return NULL;	}		memcpy(link_key->bd_addr, bd_addr, BD_ADDRESS_SIZE);	memcpy(link_key->link_key, link_key_str, LINK_KEY_SIZE);	link_key->next = link_key;	link_key->prev = link_key;	return link_key;}link_key_information_type* get_first_link_key(void){	return link_key_list.first;}link_key_information_type* get_next_link_key(link_key_information_type* link_key){	if (link_key->next == link_key_list.first)		return NULL;	else		return link_key->next;}void insert_link_key(link_key_information_type *new_link_key){	link_key_information_type *old_link_key;	if (!link_key_list.count) {		/* Empty list */		D_PROC("Inserting into empty list\n");		link_key_list.first = new_link_key; 		link_key_list.cur = new_link_key;		link_key_list.last = new_link_key;		link_key_list.count++;		new_link_key->next = link_key_list.first; /* Pos32 at itself */		new_link_key->prev = link_key_list.first;		return;	}  	/* Not empty */	D_PROC("Inserting into list\n");		old_link_key = link_key_list.first; /* mark oldlink_key first */	new_link_key->next = old_link_key;	link_key_list.last->next = new_link_key;	old_link_key->prev = new_link_key;	new_link_key->prev = link_key_list.last;

⌨️ 快捷键说明

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