?? bcsp_datagram.c
字號:
/* * bcsp_datagram.c -- Implementation of the Datagram layer in the BCSP * protocol stack * * Copyright (C) 2001 Axis Communications AB * * Author: Mats Friden <Mats.Friden@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: bcsp_datagram.c,v 1.10 2001/09/18 13:04:27 pkj Exp $ * *//****************** INCLUDE FILES SECTION ***********************************/#define __NO_VERSION__ /* don't define kernel_version in module.h */#ifdef __KERNEL__#include <linux/malloc.h>#include <asm/byteorder.h>#include <asm/unaligned.h>#include <linux/bluetooth/sysdep-2.1.h>#include <linux/bluetooth/btcommon.h>#include <linux/bluetooth/bcsp.h>#include <linux/bluetooth/bcsp_debug.h>#else#include <asm/unaligned.h>#include "include/btcommon.h"#include "include/bcsp.h"#include "include/bcsp_debug.h"#endif/****************** CONSTANT AND MACRO SECTION ******************************/#if DATAGRAM_DEBUG#define D(fmt...) printk("DATAGRAM: " fmt)#define PRINTPKT(data, len) print_data(NULL, data, len)#else#define D(fmt...)#define PRINTPKT(data, len)#endif/****************** TYPE DEFINITION SECTION *********************************//****************** LOCAL FUNCTION DECLARATION SECTION **********************/static s32 handle_sync_pkt(struct bcsp *bcsp);/****************** GLOBAL VARIABLE DECLARATION SECTION *********************//****************** LOCAL VARIABLE DECLARATION SECTION **********************/static s32 bcsp_datagram_initiated = 0;/****************** FUNCTION DEFINITION SECTION *****************************/void bcsp_datagram_init(void){ bcsp_datagram_initiated = 1;}void bcsp_datagram_shutdown(void){ bcsp_datagram_initiated = 0;}s32bcsp_datagram_receive(struct bcsp *bcsp){ if (!bcsp_datagram_initiated) return 0; /* FIXME: Should this be an error code? */ if (handle_sync_pkt(bcsp)) { return 0; } D(__FUNCTION__ ": Datagram packet received:\n"); PRINTPKT(bcsp->payload, bcsp->payload_length); return 0;}s32bcsp_datagram_send(u8 *data, u32 len, u8 chn){ struct bcsp bcsp; bcsp_init_packet(&bcsp); BCSP_SET_PROTOCOL_TYPE(&bcsp, BCSP_UNRELIABLE); bcsp.payload = data; bcsp.payload_length = len; return bcsp_mux_send(&bcsp);}s32handle_sync_pkt(struct bcsp *bcsp){ u32 sync_string; if (bcsp->payload_length < sizeof(u32)) { return FALSE; } sync_string = le32_to_cpu(get_unaligned((u32 *)bcsp->payload)); switch (sync_string) { case SYNC: D(__FUNCTION__ ": Found SYNC\n"); D(__FUNCTION__ ": Send SYNC_RSP\n"); bcsp_send_sync(SYNC_RSP); return TRUE; case SYNC_RSP: D(__FUNCTION__": Found SYNC_RSP\n"); bcsp_syncronized(); return TRUE; case CONF: /* this should always be done */ D(__FUNCTION__ ": Found CONF, silent discard\n"); return TRUE; case CONF_RSP: D(__FUNCTION__": Found CONF_RSP\n"); return TRUE; default: return FALSE; }}s32bcsp_send_sync(u32 type){ struct bcsp bcsp; u32 payload = cpu_to_le32(type); bcsp_init_packet(&bcsp); bcsp.identifier = 1; bcsp.payload = (u8 *)&payload; bcsp.payload_length = sizeof(u32); return bcsp_mux_send(&bcsp);}/****************** END OF FILE sequence.c **********************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -