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

📄 pdu.c

📁 蓝牙的各种编程接口和各种按理介绍,还有一些例子和说明
💻 C
字号:
/*   Service Discovery Protocol (SDP)   Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>      Based on original SDP implementation by Nokia Corporation.   Copyright (C) 2001,2002 Nokia Corporation.   Original author Guruprasad Krishnamurthy <guruprasad.krishnamurthy@nokia.com>      This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License version 2 as   published by the Free Software Foundation;      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.   IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,   OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER   RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE   USE OR PERFORMANCE OF THIS SOFTWARE.      ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,   TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.*//*   Methods for PDU form generation for a given service record.   All attributes(by default) are included or only a subset (if specified).   Fixes:	Guruprasad Krishnamurthy <guruprasad.krishnamurthy@nokia.com>*//* * $Id: pdu.c,v 1.11 2003/05/16 11:18:43 jscrane Exp $ */#include <malloc.h>#include "sdp.h"#include "sdp_lib.h"#include "sdp_internal.h"/* * This function appends data to the PDU buffer "dst" from source "src".  * The data length is also computed and set. * Should the PDU length exceed 2^8, then sequence type is * set accordingly and the data is memmove()'d. */void sdp_append_to_buf(sdp_buf_t *dst, char *data, int len){	char *p = dst->data;	uint8_t dtd = *(uint8_t *)p;	SDPDBG("Append src size: %d\n", len);	SDPDBG("Append dst size: %d\n", dst->data_size);	SDPDBG("Dst buffer size: %d\n", dst->buf_size);	if (dst->data_size + len > dst->buf_size) {		int need = SDP_PDU_CHUNK_SIZE * ((len / SDP_PDU_CHUNK_SIZE) + 1);		dst->data = (char *)realloc(dst->data, dst->buf_size + need);		SDPDBG("Realloc'ing : %d\n", need);		if (dst->data == NULL) {			SDPERR("Realloc fails \n");		}		dst->buf_size += need;	}	if (dst->data_size == 0 && dtd == 0) {		// create initial sequence		*(uint8_t *)p = SDP_SEQ8;		p += sizeof(uint8_t);		dst->data_size += sizeof(uint8_t);		// reserve space for sequence size		p += sizeof(uint8_t);		dst->data_size += sizeof(uint8_t);	}	memcpy(dst->data + dst->data_size, data, len);	dst->data_size += len;	dtd = *(uint8_t *)dst->data;	if (dst->data_size > UCHAR_MAX && dtd == SDP_SEQ8) {		short offset = sizeof(uint8_t) + sizeof(uint8_t);		memmove(dst->data + offset + 1, dst->data + offset, dst->data_size - offset);		p = dst->data;		*(uint8_t *)p = SDP_SEQ16;		p += sizeof(uint8_t);		dst->data_size += 1;	}	p = dst->data;	dtd = *(uint8_t *)p;	p += sizeof(uint8_t);	switch (dtd) {	case SDP_SEQ8:		*(uint8_t *)p = dst->data_size - sizeof(uint8_t) - sizeof(uint8_t);		break;	case SDP_SEQ16:		sdp_put_unaligned(htons(dst->data_size - sizeof(uint8_t) - sizeof(uint16_t)), (uint16_t *)p);		break;	case SDP_SEQ32:		sdp_put_unaligned(htonl(dst->data_size - sizeof(uint8_t) - sizeof(uint32_t)), (uint32_t *)p);		break;	}}void sdp_append_to_pdu(sdp_buf_t *pdu, sdp_data_t *d){	char buf[SDP_SEQ_PDUFORM_SIZE];	sdp_buf_t append;	append.data = buf;	append.buf_size = sizeof(buf);	append.data_size = 0;	sdp_set_attrid(&append, d->attrId);	sdp_gen_pdu(&append, d);	sdp_append_to_buf(pdu, append.data, append.data_size);}

⌨️ 快捷键说明

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