|
From: Peter K. <pk...@us...> - 2001-03-04 15:44:45
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_parser.c 1.9 1.10=20=20=20=20=20=20=20=20=20=20=20=20
sdp_parser.h 1.2 1.3=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Made the SDP server wait until the stack is initiated before it
tries to read from the /proc/sdp_srv file. This was necessitated
by the change of how the wait queue is initialised in the stack.
* Unified the main() function for both kernel and user mode.
* Some minor code clean-ups.
The diff of the modified file(s):
--- sdp_parser.c 2001/02/27 15:32:14 1.9
+++ sdp_parser.c 2001/03/04 15:46:08 1.10
@@ -51,6 +51,7 @@
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <sys/ioctl.h>
=20
#include "sdp_server.h"
#include "sdp_parser.h"
@@ -65,7 +66,6 @@
#define SDP_PRINT_DATA 0
=20
#ifdef BTD_USERSTACK
-
#define syslog(x, fmt...) printf(fmt)
#endif
=20
@@ -121,6 +121,9 @@
#define UUID32_HDR 0x1a
#define UUID128_HDR 0x1c
=20
+#define BT_IOC_MAGIC 'B'
+#define BTISINITIATED _IOR(BT_IOC_MAGIC, 0x09, unsigned int)
+
/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
/****************** LOCAL FUNCTION DECLARATION SECTION *******************=
***/
@@ -185,7 +188,8 @@
switch (id)
{
case SDP_ERROR_RSP:
- switch (CHAR2INT16(db_hdl->data[5], db_hdl->data[6])) {
+ switch (CHAR2INT16(db_hdl->data[5], db_hdl->data[6]))
+ {
case 0x0001: D_ERR(FNC"Got Invalid/unsupported SDP version\n");
break;
case 0x0002: D_ERR(FNC"Got Invalid Service Record Handle\n");
@@ -275,7 +279,8 @@
cur_pos +=3D *new_pos;
D_MISC(FNC"des_len: %d, new_pos:%d\n",des_len, *new_pos);
=20=09
- if (des_len > (len - DES_HDR_LEN)) {
+ if (des_len > (len - DES_HDR_LEN))
+ {
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
send_error_rsp(sdp_con_id, trans_id, 3);
@@ -286,7 +291,8 @@
i =3D 0;
while (tmp_pos < des_len)
{
- if (i >=3D 12) {
+ if (i >=3D 12)
+ {
D_REC(FNC"More than 12 UUID in one request\n");
/* Send an error msg with error code Invalid request
syntax */
@@ -556,7 +562,8 @@
cur_pos +=3D *new_pos;
D_MISC(FNC"des_len: %d, new_pos:%d\n",des_len, *new_pos);
=20=09
- if (des_len > (len - DES_HDR_LEN)) {
+ if (des_len > (len - DES_HDR_LEN))
+ {
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
send_error_rsp(sdp_con_id, trans_id, 3);
@@ -565,7 +572,8 @@
=20=20=20
tmp_pos =3D 0;
i =3D 0;
- while (tmp_pos < des_len) {
+ while (tmp_pos < des_len)
+ {
if (i >=3D 12)
{
D_REC(FNC"More than 12 UUID in one request\n");
@@ -822,52 +830,54 @@
}
=20
#ifndef BTD_USERSTACK
-int
-main(int argc, char **argv)
+static void
+wait_till_stack_is_initiated()
{
- char *xml_file, *proc_file;
- int len, i;
- int xml_fd;
- char buf[256];
- char *arg[2];
-
- arg[0] =3D "/etc/sdp.xml";
- arg[1] =3D "/proc/sdp_srv";
+ int bt_cfd;
+ int stack_initiated =3D 0;
=20
- if (argc > 3) {
- fprintf(stderr, "Syntax: sdp_server <xml_file> <proc_file>\n");
+ if ((bt_cfd =3D open("/dev/ttyBTC", O_RDWR, 0)) < 0)
+ {
+ perror("Can't open TTY");
exit(1);
}
=20=20=20
- for (i =3D 1; i < argc; i ++)
+ while (!stack_initiated)
{
- arg[i - 1] =3D argv[i];
+ if (ioctl(bt_cfd, BTISINITIATED, &stack_initiated) < 0)
+ {
+ perror("Checking BT stack initiated");
+ exit(1);
}
-=20=20
- xml_file =3D arg[0];
- proc_file =3D arg[1];
+ if (!stack_initiated)
+ {
+ sleep(1);
+ }
+ }
=20=20=20
- xml_fd =3D open(xml_file, O_RDONLY);
- if(xml_fd < 0) {
- perror(xml_file);
- exit(1);
+ close(bt_cfd);
}
=20
- init_sdp_server(xml_fd);
+void
+start_srvsock(char *name)
+{
+ wait_till_stack_is_initiated();
=20=20=20
- stack_if_fd =3D open(proc_file, O_RDWR);
- if(stack_if_fd < 0) {
- perror(proc_file);
+ stack_if_fd =3D open(name, O_RDWR);
+ if (stack_if_fd < 0)
+ {
+ perror("Could not open proc file");
exit(1);
}
=20
while (1)
{
- len =3D read(stack_if_fd, buf, 256);
+ char buf[256];
+ int len =3D read(stack_if_fd, buf, 256);
=20=20=20=20=20
if (len < 0)
{
- fprintf(stderr, "Error, len:%d\n",len);
+ perror("Read error");
}
else if (len =3D=3D 0)
{
@@ -878,8 +888,6 @@
sdp_parse_data(buf, len);
}
}
-
- return 0;
}
=20
#else
@@ -901,7 +909,7 @@
=20=20=20=20=20
if (FD_ISSET(clnt_fd, &rfd))
{
- int len =3D read(clnt_fd, &databuf, 256);
+ int len =3D read(clnt_fd, databuf, 256);
=20=20=20=20=20=20=20
if (len > 0)
{
@@ -927,7 +935,6 @@
int sdp_srv_sock;
int sdp_clnt_sock;
=20
-
syslog(LOG_INFO, "Opening server socket %s\n", name);
=20
/* remove any old socket */
@@ -950,8 +957,9 @@
syslog(LOG_INFO, "SDP Server listens...\n");
listen(sdp_srv_sock, 5);
=20=20=20=20=20
- sdp_clnt_sock =3D accept(sdp_srv_sock,=20
- (struct sockaddr*) &(client_address), &client_len=
);
+ client_len =3D sizeof(client_address);
+ sdp_clnt_sock =3D
+ accept(sdp_srv_sock, (struct sockaddr*)&client_address, &client_len);
=20
stack_if_fd =3D sdp_clnt_sock;
=20=20=20=20=20
@@ -959,36 +967,36 @@
close(sdp_clnt_sock);
}
}
+#endif /* BTD_USERSTACK */
=20
int
main(int argc, char **argv)
{
char *xml_file;
+ char *proc_file;
int xml_fd;
=20=20=20
- if (argc !=3D 2)
+ if (argc > 3)
{
- fprintf(stderr, "Syntax: sdp_server <xml_file>\n");
+ fprintf(stderr, "Syntax: sdp_server [<xml file> [<proc file>]]\n");
exit(1);
}
- else
- {
- xml_file =3D argv[1];
- }
=20=20=20=20=20
+ xml_file =3D (argc >=3D 2 ? argv[1] : SDP_XML_FILE);
+ proc_file =3D (argc >=3D 3 ? argv[2] : SDP_PROC_FILE);
+=20=20
xml_fd =3D open(xml_file, O_RDONLY);
- if(xml_fd < 0) {
- perror(xml_file);
+ if (xml_fd < 0)
+ {
+ perror("Could not open xml file");
exit(1);
}
=20
init_sdp_server(xml_fd);
=20
- start_srvsock(SDP_SRV_SOCK);
+ start_srvsock(proc_file);
=20
- return 0;
+ exit(0);
}
-
-#endif /* BTD_USERSTACK */
=20
/****************** END OF FILE sdp_parser.c *****************************=
***/
--- sdp_parser.h 2001/02/15 16:31:02 1.2
+++ sdp_parser.h 2001/03/04 15:46:08 1.3
@@ -46,7 +46,12 @@
=20
/****************** CONSTANT AND MACRO SECTION ***************************=
***/
=20
-#define SDP_SRV_SOCK "/tmp/sdp_sock"
+#define SDP_XML_FILE "/etc/sdp.xml"
+#ifndef BTD_USERSTACK
+#define SDP_PROC_FILE "/proc/sdp_srv"
+#else
+#define SDP_PROC_FILE "/tmp/sdp_sock"
+#endif
=20
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
@@ -64,6 +69,7 @@
((unsigned int)((c2) & 0xff) << 16) + \
((unsigned int)((c1) & 0xff) << 8) + \
(unsigned int)((c0) &0xff))
+
/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
typedef struct data_struct {
|
|
From: Peter K. <pk...@us...> - 2001-03-23 16:06:20
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_parser.c 1.12 1.13=20=20=20=20=20=20=20=20=20=20=20=20
sdp_parser.h 1.3 1.4=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Added definitions for the various SDP errors.
The diff of the modified file(s):
--- sdp_parser.c 2001/03/21 17:17:38 1.12
+++ sdp_parser.c 2001/03/23 16:06:18 1.13
@@ -176,7 +176,7 @@
if (par_len > (len - SDP_HDR_SIZE - sizeof(data_struct)))
{
D_XMIT(FNC"Packetlength don't match recievd data length par_len%d, pkt=
_len %d\n", par_len, len);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20
@@ -187,17 +187,23 @@
case SDP_ERROR_RSP:
switch (CHAR2INT16(db_hdl->data[5], db_hdl->data[6]))
{
- case 0x0001: D_ERR(FNC"Got Invalid/unsupported SDP version\n");
+ case SDP_INVALID_SDP_VERSION:
+ D_ERR(FNC"Got Invalid/unsupported SDP version\n");
break;
- case 0x0002: D_ERR(FNC"Got Invalid Service Record Handle\n");
+ case SDP_INVALID_SERVICE_RECORD_HANDLE:
+ D_ERR(FNC"Got Invalid Service Record Handle\n");
break;
- case 0x0003: D_ERR(FNC"Got Invalid request syntax\n");
+ case SDP_INVALID_REQUEST_SYNTAX:
+ D_ERR(FNC"Got Invalid Request Syntax\n");
break;
- case 0x0004: D_ERR(FNC"Got Invalid PDU Size\n");
+ case SDP_INVALID_PDU_SIZE:
+ D_ERR(FNC"Got Invalid PDU Size\n");
break;
- case 0x0005: D_ERR(FNC"Got Invalid Continuation State\n");
+ case SDP_INVALID_CONTINUATION_STATE:
+ D_ERR(FNC"Got Invalid Continuation State\n");
break;
- case 0x0006: D_ERR(FNC"Got Insufficient Resources to satisfy Request\n=
");
+ case SDP_INSUFFICIENT_RESOURCES:
+ D_ERR(FNC"Got Insufficient Resources to satisfy Request\n");
break;
default:
D_ERR(FNC" Error code 0x%04x is not specified\n",
@@ -241,9 +247,8 @@
=20=20=20=20=20
default:
D_REC(FNC"ERROR Invalid pdu type\n");
- /* Send an error response with error code Invalid request
- syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ /* Send an error response with error code Invalid request syntax */
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
break;
}
#undef FNC
@@ -268,7 +273,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -280,7 +285,7 @@
{
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20=09
@@ -293,7 +298,7 @@
D_REC(FNC"More than 12 UUID in one request\n");
/* Send an error msg with error code Invalid request
syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
break;
}
=20=09=09
@@ -333,7 +338,7 @@
D_REC(FNC"Unknown UUID size 0x%02x\n",data[cur_pos]);
/* Send an error msg with error code Invalid request
syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
}
@@ -350,13 +355,13 @@
if (len < cur_pos)
{
D_ERR(__FUNCTION__", packet len shorter than actual packet lengthlen:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
else if (len > cur_pos)
{
D_ERR(__FUNCTION__", packet len longer than actual packet length len:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20=20=20
@@ -429,7 +434,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -441,7 +446,7 @@
{
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -485,13 +490,13 @@
if (len < cur_pos)
{
D_ERR(__FUNCTION__", packet len shorter than actual packet lengthlen:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
else if (len > cur_pos)
{
D_ERR(__FUNCTION__", packet len longer than actual packet length len:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20=20=20
@@ -551,7 +556,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -563,7 +568,7 @@
{
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20=20=20
@@ -609,7 +614,7 @@
else
{
D_REC(FNC"Unknown UUID size 0x%02x\n",data[cur_pos]);
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
}
@@ -623,7 +628,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -674,13 +679,13 @@
if (len < cur_pos)
{
D_ERR(__FUNCTION__", packet len shorter than actual packet lengthlen:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
else if (len > cur_pos)
{
D_ERR(__FUNCTION__", packet len longer than actual packet length len:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20=20=20
--- sdp_parser.h 2001/03/04 15:46:08 1.3
+++ sdp_parser.h 2001/03/23 16:06:18 1.4
@@ -70,6 +70,13 @@
((unsigned int)((c1) & 0xff) << 8) + \
(unsigned int)((c0) &0xff))
=20
+#define SDP_INVALID_SDP_VERSION 0x0001
+#define SDP_INVALID_SERVICE_RECORD_HANDLE 0x0002
+#define SDP_INVALID_REQUEST_SYNTAX 0x0003
+#define SDP_INVALID_PDU_SIZE 0x0004
+#define SDP_INVALID_CONTINUATION_STATE 0x0005
+#define SDP_INSUFFICIENT_RESOURCES 0x0006
+
/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
typedef struct data_struct {
|
|
From: Peter K. <pk...@us...> - 2001-03-23 16:19:38
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_parser.c 1.13 1.14=20=20=20=20=20=20=20=20=20=20=20=20
sdp_parser.h 1.4 1.5=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Removed two unnecessary malloc()'s.
* Fail with an error if one of the remaining malloc()'s fails.
* Use writev() in send2stack() to avoid malloc().
* Use sizeof instead of constants where appropriate.
The diff of the modified file(s):
--- sdp_parser.c 2001/03/23 16:06:18 1.13
+++ sdp_parser.c 2001/03/23 16:19:36 1.14
@@ -52,6 +52,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
+#include <sys/uio.h>
=20
#include "sdp_server.h"
#include "sdp_parser.h"
@@ -163,19 +164,22 @@
int sdp_con_id;
data_struct *db_hdl;
=20
+ PRINTPKT(FNC, data, len);=20=20
+
db_hdl =3D (data_struct*) data;
+ data +=3D sizeof *db_hdl;
+ len -=3D sizeof *db_hdl;
=20
- PRINTPKT(FNC, data, len);=20=20
sdp_con_id =3D db_hdl->sdp_con_id;
pkt_len =3D db_hdl->len;
=20
- id =3D db_hdl->data[0];
- trans_id =3D CHAR2INT16(db_hdl->data[1], db_hdl->data[2]);
- par_len =3D CHAR2INT16(db_hdl->data[3], db_hdl->data[4]);
+ id =3D data[0];
+ trans_id =3D CHAR2INT16(data[1], data[2]);
+ par_len =3D CHAR2INT16(data[3], data[4]);
=20
- if (par_len > (len - SDP_HDR_SIZE - sizeof(data_struct)))
+ if (par_len > (len - SDP_HDR_SIZE))
{
- D_XMIT(FNC"Packetlength don't match recievd data length par_len%d, pkt=
_len %d\n", par_len, len);
+ D_XMIT(FNC"Packet length does not match received data length par_len %=
d, pkt_len %d\n", par_len, len);
send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
@@ -185,7 +189,7 @@
switch (id)
{
case SDP_ERROR_RSP:
- switch (CHAR2INT16(db_hdl->data[5], db_hdl->data[6]))
+ switch (CHAR2INT16(data[5], data[6]))
{
case SDP_INVALID_SDP_VERSION:
D_ERR(FNC"Got Invalid/unsupported SDP version\n");
@@ -207,42 +211,39 @@
break;
default:
D_ERR(FNC"Error code 0x%04x is not specified\n",
- CHAR2INT16(db_hdl->data[5], db_hdl->data[6]));
+ CHAR2INT16(data[5], data[6]));
break;
}
break;
=20=09=09
case SDP_SERVICESEARCH_REQ:
D_REC(FNC"SDP_SERVICESEARCH_REQ %d bytes\n", par_len);
- process_service_search_req(sdp_con_id, db_hdl->data + 5, par_len,
- trans_id);
+ process_service_search_req(sdp_con_id, data + 5, par_len, trans_id);
break;
=20=20=20=20=20
case SDP_SERVICESEARCH_RSP:
D_REC(FNC"SDP_SERVICESEARCH_RSP\n");
- process_service_search_rsp(sdp_con_id, db_hdl->data + 5);
+ process_service_search_rsp(sdp_con_id, data + 5);
break;
=20=20=20=20=20
case SDP_SERVICEATTR_REQ:
D_REC(FNC"SDP_SERVICEATTR_REQ\n");
- process_service_attr_req(sdp_con_id, db_hdl->data + 5, par_len,
- trans_id);
+ process_service_attr_req(sdp_con_id, data + 5, par_len, trans_id);
break;
=20=20=20=20=20
case SDP_SERVICEATTR_RSP:
D_REC(FNC"SDP_SERVICEATTR_RSP\n");
- process_service_attr_rsp(sdp_con_id, db_hdl->data + 5);
+ process_service_attr_rsp(sdp_con_id, data + 5);
break;
=20=20=20=20=20
case SDP_SERVICESEARCHATTR_REQ:
D_REC(FNC"SDP_SERVICESEARCHATTR_REQ\n");
- process_service_search_attr_req(sdp_con_id, db_hdl->data + 5, par_len,
- trans_id);
+ process_service_search_attr_req(sdp_con_id, data + 5, par_len, trans_i=
d);
break;
=20=20=20=20=20
case SDP_SERVICESEARCHATTR_RSP:
D_REC(FNC"SDP_SERVICESEARCHATTR_RSP\n");
- process_service_search_attr_rsp(sdp_con_id, db_hdl->data + 5);
+ process_service_search_attr_rsp(sdp_con_id, data + 5);
break;
=20=20=20=20=20
default:
@@ -258,8 +259,6 @@
process_service_search_req(int sdp_con_id, unsigned char *data, unsigned s=
hort len, unsigned int trans_id)
{
#define FNC "process_service_search_req: "
- service_search_struct *db_hdl;
-=09
unsigned int service_search_uuid[12];
int service_search_uuid_cnt;
unsigned char des_len;
@@ -375,28 +374,20 @@
}
else
{
- len =3D sizeof(service_search_struct);
-=20=20=20=20
- db_hdl =3D (service_search_struct*) malloc(len);
- D_MEM("---> malloc%d %d bytes at 0x%08x\n", malloc_dbg++,len, (int)db_=
hdl);
+ service_search_struct db_hdl;
=20=20=20=20=20
- db_hdl->db.sdp_con_id =3D sdp_con_id;
- db_hdl->db.trans_id =3D trans_id;
- db_hdl->db.pkt_type =3D SDP_SERVICESEARCH_REQ;
+ db_hdl.db.sdp_con_id =3D sdp_con_id;
+ db_hdl.db.trans_id =3D trans_id;
+ db_hdl.db.pkt_type =3D SDP_SERVICESEARCH_REQ;
=20=20=20=20=20
- db_hdl->max_rec_cnt =3D max_rec_cnt;
- db_hdl->service_class_cnt =3D service_search_uuid_cnt;
- memcpy(db_hdl->service_class_list, service_search_uuid,
- service_search_uuid_cnt * 4);
+ db_hdl.max_rec_cnt =3D max_rec_cnt;
+ db_hdl.service_class_cnt =3D service_search_uuid_cnt;
+ memcpy(db_hdl.service_class_list, service_search_uuid,
+ service_search_uuid_cnt * sizeof *service_search_uuid);
=20=20=20=20=20
/* Here we ask the database for the requested attributes */
-=20=20=20=20
- handle_query((database_query_struct*) db_hdl);
-=20=20=20=20
- D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
- free(db_hdl);
+ handle_query(&db_hdl.db);
}
-=20=20=20=20
#undef FNC
}
=20
@@ -508,9 +499,14 @@
}
else
{
- len =3D sizeof(service_attr_struct) + attr_list_pos * 4;
+ len =3D sizeof(service_attr_struct) + attr_list_pos * sizeof *attr_lis=
t;
=20=09
- db_hdl =3D (service_attr_struct*) malloc(len);
+ if (!(db_hdl =3D malloc(len))) {
+ D_ERR(__FUNCTION__ ": malloc failed to allocate %d bytes!\n", =
len);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INSUFFICIENT_RESOURCE=
S);
+ return;
+ }
+
D_MEM("---> malloc%d %d bytes at 0x%08x\n",malloc_dbg++, len, (int)db_=
hdl);
=20=20=20=20=20
db_hdl->db.sdp_con_id =3D sdp_con_id;
@@ -520,11 +516,11 @@
db_hdl->max_attr_byte_cnt =3D max_attr_cnt;
db_hdl->rec_hdl =3D rec_hdl;
db_hdl->attr_cnt =3D attr_list_pos;
- memcpy(db_hdl->attr_list, attr_list, attr_list_pos * 4);
+ memcpy(db_hdl->attr_list, attr_list, attr_list_pos * sizeof *attr_list=
);
=20=20=20=20=20
/* Here we ask the database for the requested attributes */
=20=20=20=20=20
- handle_query((database_query_struct*) db_hdl);
+ handle_query(&db_hdl->db);
=20=20=20=20=20
D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
free(db_hdl);
@@ -697,9 +693,14 @@
}
else
{
- tmp_len =3D sizeof(service_search_attr_struct) + attr_list_pos * 4;
+ tmp_len =3D sizeof(service_search_attr_struct) + attr_list_pos * sizeo=
f *attr_list;
=20=09
- db_hdl =3D (service_search_attr_struct*) malloc(tmp_len);
+ if (!(db_hdl =3D malloc(tmp_len))) {
+ D_ERR(__FUNCTION__ ": malloc failed to allocate %d bytes!\n", =
tmp_len);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INSUFFICIENT_RESOURCE=
S);
+ return;
+ }
+
D_MEM("---> malloc%d %d bytes at 0x%08x\n",malloc_dbg++, tmp_len, (int=
) db_hdl);
=20=20=20=20=20
db_hdl->db.sdp_con_id =3D sdp_con_id;
@@ -708,12 +709,12 @@
=20=20=20=20=20
db_hdl->max_attr_byte_cnt =3D max_attr_cnt;
db_hdl->service_class_cnt =3D service_search_uuid_cnt;
- memcpy(db_hdl->service_class_list, service_search_uuid, service_search=
_uuid_cnt * 4);
+ memcpy(db_hdl->service_class_list, service_search_uuid, service_search=
_uuid_cnt * sizeof *service_search_uuid);
db_hdl->attr_cnt =3D attr_list_pos;
- memcpy(db_hdl->attr_list, attr_list, attr_list_pos * 4);
+ memcpy(db_hdl->attr_list, attr_list, attr_list_pos * sizeof *attr_list=
);
=20=20=20=20=20
/* Here we ask the database for the requested attributes */
- handle_query((database_query_struct*) db_hdl);
+ handle_query(&db_hdl->db);
=20
D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
free(db_hdl);
@@ -753,8 +754,8 @@
unsigned char sdp_data[7];
unsigned short pdu_len;
=20
- /* Since we not send any error information the pdu length is just the si=
ze
- of the error code length, whoch is two bytes */
+ /* Since we do not send any error information, the pdu length is just the
+ size of the error code length, which is two bytes */
=20
pdu_len =3D 2;
=20=20=20
@@ -799,7 +800,7 @@
return 16;
case 5:
*new_pos =3D 2;
- return *(data + 1);
+ return data[1];
case 6:
*new_pos =3D 3;
return CHAR2INT16(data[1], data[2]);
@@ -813,22 +814,20 @@
void
write2stack(int sdp_con_id, char *data, int len)
{
- data_struct *db_hdl;
- int send_len;
+ data_struct db_hdl;
+ struct iovec vec[2];
=20
D_XMIT("write2stack: writing %d bytes to sdp_con_id %d\n", len,sdp_con_i=
d);
=20=20=20
- send_len =3D sizeof(data_struct) + len;
- db_hdl =3D (data_struct*) malloc(send_len);
- D_MEM("---> malloc%d %d bytes at 0x%08x\n",malloc_dbg++, send_len, (int)=
db_hdl);
+ db_hdl.sdp_con_id =3D sdp_con_id;
+ db_hdl.len =3D len;
=20=20=20
- db_hdl->sdp_con_id =3D sdp_con_id;
- db_hdl->len =3D len;
- memcpy(db_hdl->data, data, len);
+ vec[0].iov_base =3D &db_hdl;
+ vec[0].iov_len =3D sizeof db_hdl;
+ vec[1].iov_base =3D data;
+ vec[1].iov_len =3D len;
=20=20=20
- write(stack_if_fd, (char*) db_hdl, send_len);
- D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
- free(db_hdl);
+ writev(stack_if_fd, vec, 2);
}
=20
#ifndef BTD_USERSTACK
--- sdp_parser.h 2001/03/23 16:06:18 1.4
+++ sdp_parser.h 2001/03/23 16:19:36 1.5
@@ -82,7 +82,6 @@
typedef struct data_struct {
unsigned int sdp_con_id;
int len;
- unsigned char data[0];
} data_struct;
=20
/****************** EXPORTED FUNCTION DECLARATION SECTION ****************=
***/
|
|
From: Gordon M. <gm...@us...> - 2001-03-24 21:12:09
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_parser.c 1.11 1.11.2.1=20=20=20=20=20=20=20=20
sdp_parser.h 1.3 1.3.2.1=20=20=20=20=20=20=20=20=20
The accompanying log:
Merged from trunk
The diff of the modified file(s):
--- sdp_parser.c 2001/03/06 11:07:37 1.11
+++ sdp_parser.c 2001/03/24 21:11:38 1.11.2.1
@@ -52,6 +52,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
+#include <sys/uio.h>
=20
#include "sdp_server.h"
#include "sdp_parser.h"
@@ -163,20 +164,23 @@
int sdp_con_id;
data_struct *db_hdl;
=20
+ PRINTPKT(FNC, data, len);=20=20
+
db_hdl =3D (data_struct*) data;
+ data +=3D sizeof *db_hdl;
+ len -=3D sizeof *db_hdl;
=20
- PRINTPKT(FNC, data, len);=20=20
sdp_con_id =3D db_hdl->sdp_con_id;
pkt_len =3D db_hdl->len;
=20
- id =3D db_hdl->data[0];
- trans_id =3D CHAR2INT16(db_hdl->data[1], db_hdl->data[2]);
- par_len =3D CHAR2INT16(db_hdl->data[3], db_hdl->data[4]);
+ id =3D data[0];
+ trans_id =3D CHAR2INT16(data[1], data[2]);
+ par_len =3D CHAR2INT16(data[3], data[4]);
=20
- if (par_len > (len - SDP_HDR_SIZE - sizeof(data_struct)))
+ if (par_len > (len - SDP_HDR_SIZE))
{
- D_XMIT(FNC"Packetlength don't match recievd data length par_len%d, pkt=
_len %d\n", par_len, len);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ D_XMIT(FNC"Packet length does not match received data length par_len %=
d, pkt_len %d\n", par_len, len);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20
@@ -185,65 +189,67 @@
switch (id)
{
case SDP_ERROR_RSP:
- switch (CHAR2INT16(db_hdl->data[5], db_hdl->data[6]))
+ switch (CHAR2INT16(data[5], data[6]))
{
- case 0x0001: D_ERR(FNC"Got Invalid/unsupported SDP version\n");
+ case SDP_INVALID_SDP_VERSION:
+ D_ERR(FNC"Got Invalid/unsupported SDP version\n");
break;
- case 0x0002: D_ERR(FNC"Got Invalid Service Record Handle\n");
+ case SDP_INVALID_SERVICE_RECORD_HANDLE:
+ D_ERR(FNC"Got Invalid Service Record Handle\n");
break;
- case 0x0003: D_ERR(FNC"Got Invalid request syntax\n");
+ case SDP_INVALID_REQUEST_SYNTAX:
+ D_ERR(FNC"Got Invalid Request Syntax\n");
break;
- case 0x0004: D_ERR(FNC"Got Invalid PDU Size\n");
+ case SDP_INVALID_PDU_SIZE:
+ D_ERR(FNC"Got Invalid PDU Size\n");
break;
- case 0x0005: D_ERR(FNC"Got Invalid Continuation State\n");
+ case SDP_INVALID_CONTINUATION_STATE:
+ D_ERR(FNC"Got Invalid Continuation State\n");
break;
- case 0x0006: D_ERR(FNC"Got Insufficient Resources to satisfy Request\n=
");
+ case SDP_INSUFFICIENT_RESOURCES:
+ D_ERR(FNC"Got Insufficient Resources to satisfy Request\n");
break;
default:
D_ERR(FNC" Error code 0x%04x is not specified\n",
- CHAR2INT16(db_hdl->data[5], db_hdl->data[6]));
+ CHAR2INT16(data[5], data[6]));
break;
}
break;
=20=09=09
case SDP_SERVICESEARCH_REQ:
D_REC(FNC"SDP_SERVICESEARCH_REQ %d bytes\n", par_len);
- process_service_search_req(sdp_con_id, db_hdl->data + 5, par_len,
- trans_id);
+ process_service_search_req(sdp_con_id, data + 5, par_len, trans_id);
break;
=20=20=20=20=20
case SDP_SERVICESEARCH_RSP:
D_REC(FNC"SDP_SERVICESEARCH_RSP\n");
- process_service_search_rsp(sdp_con_id, db_hdl->data + 5);
+ process_service_search_rsp(sdp_con_id, data + 5);
break;
=20=20=20=20=20
case SDP_SERVICEATTR_REQ:
D_REC(FNC"SDP_SERVICEATTR_REQ\n");
- process_service_attr_req(sdp_con_id, db_hdl->data + 5, par_len,
- trans_id);
+ process_service_attr_req(sdp_con_id, data + 5, par_len, trans_id);
break;
=20=20=20=20=20
case SDP_SERVICEATTR_RSP:
D_REC(FNC"SDP_SERVICEATTR_RSP\n");
- process_service_attr_rsp(sdp_con_id, db_hdl->data + 5);
+ process_service_attr_rsp(sdp_con_id, data + 5);
break;
=20=20=20=20=20
case SDP_SERVICESEARCHATTR_REQ:
D_REC(FNC"SDP_SERVICESEARCHATTR_REQ\n");
- process_service_search_attr_req(sdp_con_id, db_hdl->data + 5, par_len,
- trans_id);
+ process_service_search_attr_req(sdp_con_id, data + 5, par_len, trans_i=
d);
break;
=20=20=20=20=20
case SDP_SERVICESEARCHATTR_RSP:
D_REC(FNC"SDP_SERVICESEARCHATTR_RSP\n");
- process_service_search_attr_rsp(sdp_con_id, db_hdl->data + 5);
+ process_service_search_attr_rsp(sdp_con_id, data + 5);
break;
=20=20=20=20=20
default:
D_REC(FNC"ERROR Invalid pdu type\n");
- /* Send an error response with error code Invalid request
- syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ /* Send an error response with error code Invalid request syntax */
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
break;
}
#undef FNC
@@ -253,8 +259,6 @@
process_service_search_req(int sdp_con_id, unsigned char *data, unsigned s=
hort len, unsigned int trans_id)
{
#define FNC "process_service_search_req: "
- service_search_struct *db_hdl;
-=09
unsigned int service_search_uuid[12];
int service_search_uuid_cnt;
unsigned char des_len;
@@ -268,7 +272,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -280,7 +284,7 @@
{
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20=09
@@ -293,7 +297,7 @@
D_REC(FNC"More than 12 UUID in one request\n");
/* Send an error msg with error code Invalid request
syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
break;
}
=20=09=09
@@ -333,7 +337,7 @@
D_REC(FNC"Unknown UUID size 0x%02x\n",data[cur_pos]);
/* Send an error msg with error code Invalid request
syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
}
@@ -350,13 +354,13 @@
if (len < cur_pos)
{
D_ERR(__FUNCTION__", packet len shorter than actual packet lengthlen:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
else if (len > cur_pos)
{
D_ERR(__FUNCTION__", packet len longer than actual packet length len:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20=20=20
@@ -370,28 +374,20 @@
}
else
{
- len =3D sizeof(service_search_struct);
-=20=20=20=20
- db_hdl =3D (service_search_struct*) malloc(len);
- D_MEM("---> malloc%d %d bytes at 0x%08x\n", malloc_dbg++,len, (int)db_=
hdl);
+ service_search_struct db_hdl;
=20=20=20=20=20
- db_hdl->db.sdp_con_id =3D sdp_con_id;
- db_hdl->db.trans_id =3D trans_id;
- db_hdl->db.pkt_type =3D SDP_SERVICESEARCH_REQ;
+ db_hdl.db.sdp_con_id =3D sdp_con_id;
+ db_hdl.db.trans_id =3D trans_id;
+ db_hdl.db.pkt_type =3D SDP_SERVICESEARCH_REQ;
=20=20=20=20=20
- db_hdl->max_rec_cnt =3D max_rec_cnt;
- db_hdl->service_class_cnt =3D service_search_uuid_cnt;
- memcpy(db_hdl->service_class_list, service_search_uuid,
- service_search_uuid_cnt * 4);
+ db_hdl.max_rec_cnt =3D max_rec_cnt;
+ db_hdl.service_class_cnt =3D service_search_uuid_cnt;
+ memcpy(db_hdl.service_class_list, service_search_uuid,
+ service_search_uuid_cnt * sizeof *service_search_uuid);
=20=20=20=20=20
/* Here we ask the database for the requested attributes */
-=20=20=20=20
- handle_query((database_query_struct*) db_hdl);
-=20=20=20=20
- D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
- free(db_hdl);
+ handle_query(&db_hdl.db);
}
-=20=20=20=20
#undef FNC
}
=20
@@ -429,7 +425,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -441,7 +437,7 @@
{
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -485,13 +481,13 @@
if (len < cur_pos)
{
D_ERR(__FUNCTION__", packet len shorter than actual packet lengthlen:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
else if (len > cur_pos)
{
D_ERR(__FUNCTION__", packet len longer than actual packet length len:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20=20=20
@@ -503,9 +499,14 @@
}
else
{
- len =3D sizeof(service_attr_struct) + attr_list_pos * 4;
+ len =3D sizeof(service_attr_struct) + attr_list_pos * sizeof *attr_lis=
t;
=20=09
- db_hdl =3D (service_attr_struct*) malloc(len);
+ if (!(db_hdl =3D malloc(len))) {
+ D_ERR(__FUNCTION__ ": malloc failed to allocate %d bytes!\n", =
len);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INSUFFICIENT_RESOURCE=
S);
+ return;
+ }
+
D_MEM("---> malloc%d %d bytes at 0x%08x\n",malloc_dbg++, len, (int)db_=
hdl);
=20=20=20=20=20
db_hdl->db.sdp_con_id =3D sdp_con_id;
@@ -515,11 +516,11 @@
db_hdl->max_attr_byte_cnt =3D max_attr_cnt;
db_hdl->rec_hdl =3D rec_hdl;
db_hdl->attr_cnt =3D attr_list_pos;
- memcpy(db_hdl->attr_list, attr_list, attr_list_pos * 4);
+ memcpy(db_hdl->attr_list, attr_list, attr_list_pos * sizeof *attr_list=
);
=20=20=20=20=20
/* Here we ask the database for the requested attributes */
=20=20=20=20=20
- handle_query((database_query_struct*) db_hdl);
+ handle_query(&db_hdl->db);
=20=20=20=20=20
D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
free(db_hdl);
@@ -551,7 +552,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -563,7 +564,7 @@
{
D_REC(FNC"Incorrect packet: Incorrect length field or whole packet was=
not received\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20=20=20
@@ -609,7 +610,7 @@
else
{
D_REC(FNC"Unknown UUID size 0x%02x\n",data[cur_pos]);
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
}
@@ -623,7 +624,7 @@
{
D_REC(FNC"Incorrect packet: Data Element Sequence expected\n");
/* Send an error msg with error code Invalid request syntax */
- send_error_rsp(sdp_con_id, trans_id, 3);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_REQUEST_SYNTAX);
return;
}
=20
@@ -674,13 +675,13 @@
if (len < cur_pos)
{
D_ERR(__FUNCTION__", packet len shorter than actual packet lengthlen:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
else if (len > cur_pos)
{
D_ERR(__FUNCTION__", packet len longer than actual packet length len:%=
d cur_pos:%d\n", len, cur_pos);
- send_error_rsp(sdp_con_id, trans_id, 4);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
=20=20=20
@@ -692,9 +693,14 @@
}
else
{
- tmp_len =3D sizeof(service_search_attr_struct) + attr_list_pos * 4;
+ tmp_len =3D sizeof(service_search_attr_struct) + attr_list_pos * sizeo=
f *attr_list;
=20=09
- db_hdl =3D (service_search_attr_struct*) malloc(tmp_len);
+ if (!(db_hdl =3D malloc(tmp_len))) {
+ D_ERR(__FUNCTION__ ": malloc failed to allocate %d bytes!\n", =
tmp_len);
+ send_error_rsp(sdp_con_id, trans_id, SDP_INSUFFICIENT_RESOURCE=
S);
+ return;
+ }
+
D_MEM("---> malloc%d %d bytes at 0x%08x\n",malloc_dbg++, tmp_len, (int=
) db_hdl);
=20=20=20=20=20
db_hdl->db.sdp_con_id =3D sdp_con_id;
@@ -703,12 +709,12 @@
=20=20=20=20=20
db_hdl->max_attr_byte_cnt =3D max_attr_cnt;
db_hdl->service_class_cnt =3D service_search_uuid_cnt;
- memcpy(db_hdl->service_class_list, service_search_uuid, service_search=
_uuid_cnt * 4);
+ memcpy(db_hdl->service_class_list, service_search_uuid, service_search=
_uuid_cnt * sizeof *service_search_uuid);
db_hdl->attr_cnt =3D attr_list_pos;
- memcpy(db_hdl->attr_list, attr_list, attr_list_pos * 4);
+ memcpy(db_hdl->attr_list, attr_list, attr_list_pos * sizeof *attr_list=
);
=20=20=20=20=20
/* Here we ask the database for the requested attributes */
- handle_query((database_query_struct*) db_hdl);
+ handle_query(&db_hdl->db);
=20
D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
free(db_hdl);
@@ -748,8 +754,8 @@
unsigned char sdp_data[7];
unsigned short pdu_len;
=20
- /* Since we not send any error information the pdu length is just the si=
ze
- of the error code length, whoch is two bytes */
+ /* Since we do not send any error information, the pdu length is just the
+ size of the error code length, which is two bytes */
=20
pdu_len =3D 2;
=20=20=20
@@ -794,7 +800,7 @@
return 16;
case 5:
*new_pos =3D 2;
- return *(data + 1);
+ return data[1];
case 6:
*new_pos =3D 3;
return CHAR2INT16(data[1], data[2]);
@@ -808,22 +814,20 @@
void
write2stack(int sdp_con_id, char *data, int len)
{
- data_struct *db_hdl;
- int send_len;
+ data_struct db_hdl;
+ struct iovec vec[2];
=20
D_XMIT("write2stack: writing %d bytes to sdp_con_id %d\n", len,sdp_con_i=
d);
=20=20=20
- send_len =3D sizeof(data_struct) + len;
- db_hdl =3D (data_struct*) malloc(send_len);
- D_MEM("---> malloc%d %d bytes at 0x%08x\n",malloc_dbg++, send_len, (int)=
db_hdl);
+ db_hdl.sdp_con_id =3D sdp_con_id;
+ db_hdl.len =3D len;
=20=20=20
- db_hdl->sdp_con_id =3D sdp_con_id;
- db_hdl->len =3D len;
- memcpy(db_hdl->data, data, len);
+ vec[0].iov_base =3D &db_hdl;
+ vec[0].iov_len =3D sizeof db_hdl;
+ vec[1].iov_base =3D data;
+ vec[1].iov_len =3D len;
=20=20=20
- write(stack_if_fd, (char*) db_hdl, send_len);
- D_MEM("<--- free%d 0x%08x\n",malloc_dbg--, (int) db_hdl);
- free(db_hdl);
+ writev(stack_if_fd, vec, 2);
}
=20
#ifndef BTD_USERSTACK
@@ -949,6 +953,8 @@
exit(1);
}
=20=20=20
+ syslog(LOG_INFO, "SDP Server starting");=20=20
+
xml_file =3D (argc >=3D 2 ? argv[1] : SDP_XML_FILE);
proc_file =3D (argc >=3D 3 ? argv[2] : SDP_PROC_FILE);
=20=20=20
--- sdp_parser.h 2001/03/04 15:46:08 1.3
+++ sdp_parser.h 2001/03/24 21:11:38 1.3.2.1
@@ -70,12 +70,18 @@
((unsigned int)((c1) & 0xff) << 8) + \
(unsigned int)((c0) &0xff))
=20
+#define SDP_INVALID_SDP_VERSION 0x0001
+#define SDP_INVALID_SERVICE_RECORD_HANDLE 0x0002
+#define SDP_INVALID_REQUEST_SYNTAX 0x0003
+#define SDP_INVALID_PDU_SIZE 0x0004
+#define SDP_INVALID_CONTINUATION_STATE 0x0005
+#define SDP_INSUFFICIENT_RESOURCES 0x0006
+
/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
typedef struct data_struct {
unsigned int sdp_con_id;
int len;
- unsigned char data[0];
} data_struct;
=20
/****************** EXPORTED FUNCTION DECLARATION SECTION ****************=
***/
|
|
From: Peter K. <pk...@us...> - 2001-03-26 13:48:44
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_parser.c 1.16 1.17=20=20=20=20=20=20=20=20=20=20=20=20
sdp_server.c 1.21 1.22=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Replaced -=3D 1 and +=3D 1 with -- and ++, and some other minor clean-up.
The diff of the modified file(s):
--- sdp_parser.c 2001/03/26 12:25:24 1.16
+++ sdp_parser.c 2001/03/26 13:48:28 1.17
@@ -304,7 +304,7 @@
service_search_uuid[i] =3D CHAR2INT16(data[cur_pos + 1],
data[cur_pos + 2]);
D_MISC("Found UUID16 0x%04x", service_search_uuid[i]);=20
- i +=3D 1;
+ i++;
tmp_pos +=3D 3;
cur_pos +=3D 3;
}
@@ -314,7 +314,7 @@
service_search_uuid[i] =3D CHAR2INT16(data[cur_pos + 1],
data[cur_pos + 2]);
D_MISC("Found UUID32 0x%08x", service_search_uuid[i]);=20
- i +=3D 1;
+ i++;
tmp_pos +=3D 5;
cur_pos +=3D 3;
}
@@ -324,7 +324,7 @@
service_search_uuid[i] =3D CHAR2INT16(data[cur_pos + 1],
data[cur_pos + 2]);
D_MISC("Got Service class 0x%08x", service_search_uuid[i]);
- i +=3D 1;
+ i++;
tmp_pos +=3D 17;
cur_pos +=3D 15;
}
@@ -341,10 +341,8 @@
max_rec_cnt =3D CHAR2INT16(data[cur_pos], data[cur_pos + 1]);
D_MISC("max_rec_cnt: %d", max_rec_cnt);
cur_pos +=3D 2;
-
- cont_state_len =3D data[cur_pos];
- cur_pos +=3D 1;
=20=20=20
+ cont_state_len =3D data[cur_pos++];
=20
if (len < cur_pos)
{
@@ -451,7 +449,7 @@
attr_list[attr_list_pos] =3D CHAR2INT32(data[cur_pos], data[cur_pos =
+ 1], data[cur_pos + 2], data[cur_pos + 3]);
D_MISC("Found range of attributes: 0x%08x", attr_list[attr_list_pos]=
);=20
cur_pos +=3D 4;
- attr_list_pos +=3D 1;
+ attr_list_pos++;
}
else
{
@@ -461,13 +459,13 @@
attr_list[attr_list_pos] |=3D attr_list[attr_list_pos] << 16;
D_MISC("Found single attributes: 0x%04x", attr_list[attr_list_pos]);=
=20
cur_pos +=3D 2;
- attr_list_pos +=3D 1;
+ attr_list_pos++;
}
des_len -=3D (*new_pos + tmp_len);
}
=20
- cont_state_len =3D data[cur_pos];
- cur_pos +=3D 1 + cont_state_len;
+ cont_state_len =3D data[cur_pos++];
+ cur_pos +=3D cont_state_len;
=20
if (len < cur_pos)
{
@@ -568,7 +566,7 @@
service_search_uuid[i] =3D CHAR2INT16(data[cur_pos + 1],
data[cur_pos + 2]);
D_MISC("Got Service class 0x%04x", service_search_uuid[i]);
- i +=3D 1;
+ i++;
tmp_pos +=3D 3;
cur_pos +=3D 3;
}
@@ -578,7 +576,7 @@
service_search_uuid[i] =3D CHAR2INT16(data[cur_pos + 1],
data[cur_pos + 2]);
D_MISC("Got Service class 0x%08x", service_search_uuid[i]);
- i +=3D 1;
+ i++;
tmp_pos +=3D 5;
cur_pos +=3D 3;
}
@@ -588,7 +586,7 @@
service_search_uuid[i] =3D CHAR2INT16(data[cur_pos + 1],
data[cur_pos + 2]);
D_MISC("Got Service class 0x%08x", service_search_uuid[i]);
- i +=3D 1;
+ i++;
tmp_pos +=3D 17;
cur_pos +=3D 15;
}
@@ -636,7 +634,7 @@
data[cur_pos + 3]);
D_MISC("Found range of attributes: 0x%08x", attr_list[attr_list_pos]=
);=20
cur_pos +=3D 4;
- attr_list_pos +=3D 1;
+ attr_list_pos++;
}
else
{
@@ -647,13 +645,13 @@
D_MISC("Found single attributes: 0x%04x",
(attr_list[attr_list_pos]) & 0xffff);=20
cur_pos +=3D 2;
- attr_list_pos +=3D 1;
+ attr_list_pos++;
}
des_len -=3D (*new_pos + tmp_len);
}
=20
- cont_state_len =3D data[cur_pos];
- cur_pos +=3D 1 + cont_state_len;
+ cont_state_len =3D data[cur_pos++];
+ cur_pos +=3D cont_state_len;
=20
if (len < cur_pos)
{
--- sdp_server.c 2001/03/26 12:58:25 1.21
+++ sdp_server.c 2001/03/26 13:48:28 1.22
@@ -198,8 +198,8 @@
int
get_err(void)
{
- int tmp;
- tmp =3D parse_err;
+ int tmp =3D parse_err;
+
parse_err =3D 0;
return tmp;
}
@@ -208,13 +208,12 @@
start_xml_parser(XML_Parser p, int fd)
{
void *buf;
+ int len;
=20
lseek(fd, 0, SEEK_SET);
=20=20=20=20=20=20=20
- for (;;)
+ do
{
- int len;
-
buf =3D XML_GetBuffer(p, BUFFSIZE);
if (buf =3D=3D NULL)
{
@@ -238,10 +237,8 @@
XML_ErrorString(XML_GetErrorCode(p)));
fprintf(stderr, "len:%d\n",len);
break;
- }
- if (len =3D=3D 0)
- break;
}
+ } while (len);
}
=20
unsigned char*
@@ -579,9 +576,8 @@
/* Lists all attributes registerd in the database */
attr_lst =3D get_all_attributes(fd);
=20=20=20
- return_sequence[0] =3D DES_HDR;
- return_sequence[1] =3D 0;
- pos +=3D 2;
+ return_sequence[pos++] =3D DES_HDR;
+ return_sequence[pos++] =3D 0;
=20=20=20
/* Find the first attribute in the range */
while ((i < attr_lst[0]) && (attr_lst[i] < (attr_id_code >> 16)))
@@ -743,7 +739,7 @@
if (strcmp(el, search_struct->service_class) =3D=3D 0)
{
S_FNC("Found service class %s", el);
- search_struct->service_class_found +=3D 1;
+ search_struct->service_class_found++;
}
if (search_struct->service_class_found)
{
@@ -800,7 +796,7 @@
list */
else if (search_struct->attr2get > 0)
{
- search_struct->attr2get -=3D 1;
+ search_struct->attr2get--;
=20
if (attr[0] && attr[1] &&
(strcmp(attr[0], "type") =3D=3D 0) && (strcmp(attr[1], "DES") =
=3D=3D 0))
@@ -840,7 +836,7 @@
if (strcmp(el, search_hdl->service_class) =3D=3D 0)
{
S_FNC("Found %s", el);
- search_hdl->service_class_found -=3D 1;
+ search_hdl->service_class_found--;
}
/* If we have found the attribute name end tag, there are no more attrib=
utes
to find */
@@ -869,17 +865,19 @@
int i =3D 0;
=20
if (len <=3D 0)
+ {
return;
+ }
=20=20=20
- while (i < len)
+ while (i < len && !FIRST_VALID_CHAR(s[i]))
{
- if (FIRST_VALID_CHAR(s[i]))
- break;
i++;
}
=20
if (i =3D=3D len)
+ {
return;
+ }
=20
if ((search_hdl->service_class_found) && (search_hdl->attribute_name_fou=
nd))
{
@@ -901,11 +899,10 @@
sprintf(search_hdl->attrlist + search_hdl->attrlist_index,
"%01x%01x" , s[i] / 16, s[i] % 16);
search_hdl->attrlist_index +=3D 2;
- search_hdl->des_len[0] +=3D1;
+ search_hdl->des_len[0]++;
}
=20=20=20=20=20
- strncpy(search_hdl->attrlist + search_hdl->attrlist_index, "\0", 1);
- search_hdl->attrlist_index +=3D 1;
+ search_hdl->attrlist[search_hdl->attrlist_index++] =3D '\0';
}
}
=20
@@ -1120,8 +1117,8 @@
memcpy(search_hdl->search_val, &attr_cnt, 4);
for (i =3D 0; attr[i]; i +=3D 2)
{
- unsigned int tmp;
- tmp =3D (unsigned int)strtol(attr[i + 1], NULL, 16);=20
+ unsigned int tmp =3D strtoul(attr[i + 1], NULL, 16);=20
+
memcpy(search_hdl->search_val + 4 +(i * 2), &tmp ,4);
S_FNC("Attribute %d found", tmp);
}=20
@@ -1185,7 +1182,7 @@
=20
if (rec_hdl !=3D NO_REC_HDL)
{
- rec_hdl_cnt +=3D 1;
+ rec_hdl_cnt++;
}
=20
rec_hdl_list =3D get_more_rec_hdl(db_hdl->service_class_list[0], xml_fd);
@@ -1199,7 +1196,7 @@
D_REC("Got Record handle: 0x%08x", rec_hdl_list[i]);
if (rec_hdl =3D=3D rec_hdl_list[i])
{
- rec_hdl_cnt -=3D 1;
+ rec_hdl_cnt--;
rec_hdl =3D NO_REC_HDL;
}
i++;
@@ -1210,33 +1207,29 @@
rsp_pkt_len =3D SDP_HDR_SIZE;=20=20
=20=20=20
/* Set the total service record count */
- rsp_pkt[rsp_pkt_len] =3D SHORT2CHAR_MS(rec_hdl_cnt);
- rsp_pkt[rsp_pkt_len + 1] =3D SHORT2CHAR_LS(rec_hdl_cnt);
- rsp_pkt_len +=3D 2;
+ rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_MS(rec_hdl_cnt);
+ rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_LS(rec_hdl_cnt);
=20=20=20
/* Set the current service record count */
- rsp_pkt[rsp_pkt_len] =3D SHORT2CHAR_MS(rec_hdl_cnt);
- rsp_pkt[rsp_pkt_len + 1] =3D SHORT2CHAR_LS(rec_hdl_cnt);
- rsp_pkt_len +=3D 2;
+ rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_MS(rec_hdl_cnt);
+ rsp_pkt[rsp_pkt_len++] =3D SHORT2CHAR_LS(rec_hdl_cnt);
=20=20=20
if (rec_hdl !=3D NO_REC_HDL)
{
- rsp_pkt[rsp_pkt_len] =3D (rec_hdl >> 24) & 0xff;
- rsp_pkt[rsp_pkt_len + 1] =3D (rec_hdl >> 16) & 0xff;
- rsp_pkt[rsp_pkt_len + 2] =3D (rec_hdl >> 8) & 0xff;
- rsp_pkt[rsp_pkt_len + 3] =3D rec_hdl & 0xff;
- rsp_pkt_len +=3D 4;
+ rsp_pkt[rsp_pkt_len++] =3D (rec_hdl >> 24) & 0xff;
+ rsp_pkt[rsp_pkt_len++] =3D (rec_hdl >> 16) & 0xff;
+ rsp_pkt[rsp_pkt_len++] =3D (rec_hdl >> 8) & 0xff;
+ rsp_pkt[rsp_pkt_len++] =3D rec_hdl & 0xff;
}
=20
if (rec_hdl_list)
{
for (i =3D 0; rec_hdl_list[i] !=3D NO_REC_HDL; i++)
{
- rsp_pkt[rsp_pkt_len] =3D (rec_hdl_list[i] >> 24) & 0xff;
- rsp_pkt[rsp_pkt_len + 1] =3D (rec_hdl_list[i] >> 16) & 0xff;
- rsp_pkt[rsp_pkt_len + 2] =3D (rec_hdl_list[i] >> 8) & 0xff;
- rsp_pkt[rsp_pkt_len + 3] =3D rec_hdl_list[i] & 0xff;
- rsp_pkt_len +=3D 4;
+ rsp_pkt[rsp_pkt_len++] =3D (rec_hdl_list[i] >> 24) & 0xff;
+ rsp_pkt[rsp_pkt_len++] =3D (rec_hdl_list[i] >> 16) & 0xff;
+ rsp_pkt[rsp_pkt_len++] =3D (rec_hdl_list[i] >> 8) & 0xff;
+ rsp_pkt[rsp_pkt_len++] =3D rec_hdl_list[i] & 0xff;
}
D_MEM("<--- free%d 0x%8p", --malloc_dbg, rec_hdl_list);
free(rec_hdl_list);
@@ -1260,9 +1253,9 @@
/* Skip the sdp header and the attribute byte count field */
rsp_pkt_len =3D SDP_HDR_SIZE + 2;
=20
- rsp_pkt[rsp_pkt_len] =3D DES_HDR;
- des_len_pos =3D rsp_pkt_len + 1;
- rsp_pkt_len +=3D 2;
+ rsp_pkt[rsp_pkt_len++] =3D DES_HDR;
+ des_len_pos =3D rsp_pkt_len;
+ rsp_pkt_len++;
=20=20=20
for (i =3D 0; i < db_hdl->attr_cnt; i++)
{
@@ -1348,9 +1341,9 @@
/* Skip the sdp header and the attribute byte count field */
rsp_pkt_len =3D SDP_HDR_SIZE + 2;
=20
- rsp_pkt[rsp_pkt_len] =3D DES_HDR_2B;
- des_len_pos =3D rsp_pkt_len + 1;
- rsp_pkt_len +=3D 3;
+ rsp_pkt[rsp_pkt_len++] =3D DES_HDR_2B;
+ des_len_pos =3D rsp_pkt_len;
+ rsp_pkt_len +=3D 2;
=20
if (!rec_hdl_cnt) {
rec_hdl_cnt =3D 1;
@@ -1421,7 +1414,7 @@
int cur_rec_cnt;
int cnt_len;
=20
- cur_rec_cnt =3D CHAR2INT16(pkt[7], pkt[8]);
+ cur_rec_cnt =3D CHAR2INT16(pkt[SDP_HDR_SIZE+2], pkt[SDP_HDR_SIZE+3]);
=20
if (cur_rec_cnt > max_rec_cnt)
{
@@ -1444,23 +1437,20 @@
cont_state_buf =3D malloc(sizeof(cont_state_struct) + cnt_len);
D_MEM("---> malloc%d %ld bytes at 0x%8p", malloc_dbg++, sizeof(cont_st=
ate_struct) + cnt_len, cont_state_buf);
=20
- cont_state_buf->pdu =3D pkt[0];
- D_MISC("PDU: 0x%02x", pkt[0]);
+ cont_state_buf->pdu =3D pkt[SDP_HDR_TYPE];
+ D_MISC("PDU: 0x%02x", cont_state_buf->pdu);
=20=20=20=20=20
cont_state_buf->len =3D cnt_len;
memcpy(cont_state_buf->data, pkt + len, cnt_len);
=20=20=20=20=20
len =3D SDP_HDR_SIZE + 2 + 2 + (max_rec_cnt * 4);
=20
- pkt[len] =3D 1;
- len +=3D 1;
- pkt[len] =3D 0;
- len +=3D 1;
+ pkt[len++] =3D 1;
+ pkt[len++] =3D 0;
}
else
{
- pkt[len] =3D 0;
- len +=3D 1;
+ pkt[len++] =3D 0;
}
=20=20=20
/* Change the length field */
@@ -1498,8 +1488,8 @@
cont_state_buf =3D malloc(sizeof(cont_state_struct) + cont_len);
D_MEM("---> malloc%d %ld bytes at 0x%8p", malloc_dbg++, sizeof(cont_st=
ate_struct) + cont_len , cont_state_buf);
=20
- cont_state_buf->pdu =3D pkt[0];
- D_MISC("PDU: 0x%02x", pkt[0]);
+ cont_state_buf->pdu =3D pkt[SDP_HDR_TYPE];
+ D_MISC("PDU: 0x%02x", cont_state_buf->pdu);
=20
cont_state_buf->len =3D cont_len;
memcpy(cont_state_buf->data, pkt + len, cont_len);
@@ -1507,16 +1497,13 @@
pkt[SDP_HDR_SIZE] =3D SHORT2CHAR_MS(max_attr_len);
pkt[SDP_HDR_SIZE+1] =3D SHORT2CHAR_LS(max_attr_len);
=20=20=20=20=20
- pkt[len] =3D 1;
- len +=3D 1;
- pkt[len] =3D 0;
- len +=3D 1;
+ pkt[len++] =3D 1;
+ pkt[len++] =3D 0;
}
else
{
S_FNC("No continuation State set");
- pkt[len] =3D 0;
- len +=3D 1;
+ pkt[len++] =3D 0;
}
=20=20=20
/* Change the length field */
@@ -1538,9 +1525,7 @@
if (!cont_state_buf) {
send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_CONTINUATION_STATE);
}
- else
- {
- if ((max_rec_cnt * 4) >=3D cont_state_buf->len)
+ else if ((max_rec_cnt * 4) >=3D cont_state_buf->len)
{
/* Allocate space for the SDP header, the attribute byte count field,
the attributes and the continuation state field */
@@ -1582,7 +1567,6 @@
send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_SDP_VERSION);
}
}
-}
=20
void
send_cont_state_attr_rsp(int len, unsigned char *info, int max_attr_cnt,
|
|
From: Peter K. <pk...@us...> - 2001-03-26 15:52:28
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_server.c 1.23 1.24=20=20=20=20=20=20=20=20=20=20=20=20
sdp_server.h 1.9 1.10=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* hdl_list_len and hdl_list_max (formerly block_len) now counts the
number of entries in the hdl_list in the rec_hdl_search_struct.
* Use realloc() instead of malloc() + memcpy() to add space to the
hdl_list in the rec_hdl_search_struct.
The diff of the modified file(s):
--- sdp_server.c 2001/03/26 14:02:09 1.23
+++ sdp_server.c 2001/03/26 15:52:26 1.24
@@ -287,7 +287,7 @@
strcpy(tmp_list + tmp_len, value_string + value_string_pos + 2);
tmp_len +=3D strlen(value_string + value_string_pos) - 2;
=20
- /* If we found a data element sequens header we need to remember that
+ /* If we found a data element sequence header we need to remember th=
at
position so we can fill in the length field later */=20=20=20=20=
=20=20
if (strncmp(value_string + value_string_pos, S_DES_HDR, strlen(S_DES=
_HDR)) =3D=3D 0)
{
@@ -296,8 +296,8 @@
i =3D (int) strtol(value_string + value_string_pos + strlen(S_DES_=
HDR),
NULL, 16);
=20
- /* Now we found a data element sequens header inside another
- data element sequense */
+ /* Now we found a data element sequence header inside another
+ data element sequence */
if (des_pos[i])
{
sprintf(c_des_len[i], "%02x", des_len[i]);
@@ -444,7 +444,7 @@
if ((s_hdl->tmp_hdl) && (strcmp(el, s_hdl->uuid) =3D=3D 0))
{
if ((s_hdl->hdl_list_len > 0) &&
- (s_hdl->tmp_hdl =3D=3D s_hdl->hdl_list[(s_hdl->hdl_list_len / U32_=
SIZE) - 1]))
+ (s_hdl->tmp_hdl =3D=3D s_hdl->hdl_list[s_hdl->hdl_list_len - 1]))
{
S_FNC("%s is present in record handle 0x%08x, but already found",
s_hdl->uuid, s_hdl->tmp_hdl);
@@ -458,23 +458,16 @@
necessary allocate new space for both the old and the new record
handles */
=20
- if (s_hdl->hdl_list_len >=3D s_hdl->block_len)
+ if (s_hdl->hdl_list_len >=3D s_hdl->hdl_list_max)
{
- tmp =3D s_hdl->hdl_list;
- s_hdl->block_len =3D s_hdl->hdl_list_len + s_hdl->block_len * 2;
- s_hdl->hdl_list =3D malloc(s_hdl->block_len);
- D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, s_hdl->bloc=
k_len, s_hdl->hdl_list);
+ s_hdl->hdl_list_max +=3D 16;
+ tmp =3D realloc(s_hdl->hdl_list, s_hdl->hdl_list_max * sizeof *s_h=
dl->hdl_list);
+ D_MEM("---> realloc%d %ld bytes at 0x%8p", malloc_dbg++, s_hdl->hd=
l_list_max * sizeof *s_hdl->hdl_list, tmp);
=20
- memcpy(s_hdl->hdl_list, tmp, s_hdl->hdl_list_len);
- if (tmp)
- {
- D_MEM("<--- free%d 0x%8p", --malloc_dbg, tmp);
- free(tmp);
- }
+ s_hdl->hdl_list =3D tmp;
}
=20=20=20=20=20
- s_hdl->hdl_list[s_hdl->hdl_list_len/sizeof(unsigned int)] =3D s_hdl-=
>tmp_hdl;
- s_hdl->hdl_list_len +=3D sizeof(unsigned int);
+ s_hdl->hdl_list[s_hdl->hdl_list_len++] =3D s_hdl->tmp_hdl;
}
}
}
@@ -490,7 +483,6 @@
rec_hdl_search_struct s_hdl;
char tmp_ch[12];
unsigned int *tmp;
- unsigned int tmp_len;
=20=20=20
XML_Parser p;
=20
@@ -514,8 +506,9 @@
}
=20
s_hdl.hdl_list_len =3D 0;
- s_hdl.block_len =3D 16 * sizeof(unsigned int);
- s_hdl.hdl_list =3D malloc(s_hdl.block_len);
+ s_hdl.hdl_list_max =3D 16;
+ s_hdl.hdl_list =3D malloc(s_hdl.hdl_list_max * sizeof *s_hdl.hdl_list);
+ D_MEM("---> malloc%d %ld bytes at 0x%8p", malloc_dbg++, s_hdl.hdl_list_m=
ax * sizeof *s_hdl.hdl_list, s_hdl.hdl_list);
=20=20=20
p =3D XML_ParserCreate(NULL);
XML_SetElementHandler(p, get_more_rec_hdl_start, get_more_rec_hdl_end);
@@ -525,24 +518,16 @@
start_xml_parser(p, fd);
XML_ParserFree(p);
=20
- if (s_hdl.hdl_list_len >=3D s_hdl.block_len)
+ if (s_hdl.hdl_list_len >=3D s_hdl.hdl_list_max)
{
- tmp =3D s_hdl.hdl_list;
- tmp_len =3D s_hdl.hdl_list_len + sizeof(unsigned int);
- s_hdl.block_len +=3D 1;
+ s_hdl.hdl_list_max =3D s_hdl.hdl_list_len + 1;
=20=20=20=20=20
- s_hdl.hdl_list =3D malloc(tmp_len);
- D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, tmp_len, s_hdl.=
hdl_list);
+ tmp =3D realloc(s_hdl.hdl_list, s_hdl.hdl_list_max * sizeof *s_hdl.hdl=
_list);
+ D_MEM("---> realloc%d %ld bytes at 0x%8p", malloc_dbg++, s_hdl.hdl_lis=
t_max * sizeof *s_hdl.hdl_list, tmp);
=20=20=20=20=20
- memcpy(s_hdl.hdl_list, tmp, s_hdl.hdl_list_len);
- if (tmp)
- {
- D_MEM("<--- free%d 0x%8p", --malloc_dbg, tmp);
- free(tmp);
- }
+ s_hdl.hdl_list =3D tmp;
}
- s_hdl.hdl_list[s_hdl.hdl_list_len / sizeof(unsigned int)] =3D NO_REC_HDL;
- s_hdl.hdl_list_len +=3D sizeof(unsigned int);
+ s_hdl.hdl_list[s_hdl.hdl_list_len++] =3D NO_REC_HDL;
=20=20=20
return s_hdl.hdl_list;
}
@@ -559,7 +544,6 @@
return_sequence =3D malloc(256);
D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, 256, return_seque=
nce);
=20=20=20
-=20=20
D_ATTR("A range of attributes was requested 0x%04x - 0x%04x",
(attr_id_code >> 16), (attr_id_code & 0xffff));
=20
@@ -774,7 +758,7 @@
}
}
}
- /* This is when we found a data element sequense, we here browses
+ /* This is when we found a data element sequence, we here browses
through all the attributes in the sequence and copies them into our
list */
else if (search_struct->attr2get > 0)
@@ -1276,7 +1260,7 @@
rsp_pkt[SDP_HDR_SIZE+1] =3D SHORT2CHAR_LS(rsp_pkt_len - SDP_HDR_SIZE - 2=
);
=20
/* The length of the attribute list is the length of the attribute byte
- count minus the size of the data element sequens header */
+ count minus the size of the data element sequence header */
rsp_pkt[des_len_pos] =3D rsp_pkt_len - SDP_HDR_SIZE - 2 - 2;
=20=20=20
set_sdp_hdr(rsp_pkt, SDP_SERVICEATTR_RSP, db_hdl->db.trans_id,
--- sdp_server.h 2001/03/26 12:25:24 1.9
+++ sdp_server.h 2001/03/26 15:52:26 1.10
@@ -73,8 +73,6 @@
=20
#define NO_REC_HDL 1
=20
-#define U32_SIZE sizeof(unsigned int)
-
#define SDP_ERROR_RSP 1
#define SDP_SERVICESEARCH_REQ 2
#define SDP_SERVICESEARCH_RSP 3
@@ -90,7 +88,7 @@
char *uuid;
unsigned int tmp_hdl;
unsigned int hdl_list_len;
- unsigned int block_len;
+ unsigned int hdl_list_max;
unsigned int *hdl_list;
} rec_hdl_search_struct;
=20
|
|
From: Mattias A. <mat...@us...> - 2001-04-17 12:43:39
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_parser.c 1.17 1.18=20=20=20=20=20=20=20=20=20=20=20=20
sdp_server.c 1.26 1.27=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
changed syslog priority
The diff of the modified file(s):
--- sdp_parser.c 2001/03/26 13:48:28 1.17
+++ sdp_parser.c 2001/04/17 12:43:39 1.18
@@ -71,31 +71,31 @@
#endif
=20
#if SDP_DEBUG_XMIT
-#define D_XMIT(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_XMIT(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_XMIT(fmt...)
#endif
=20
#if SDP_DEBUG_REC
-#define D_REC(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_REC(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_REC(fmt...)
#endif
=20
#if SDP_DEBUG_MISC
-#define D_MISC(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_MISC(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_MISC(fmt...)
#endif
=20
#if SDP_DEBUG_MEM
-#define D_MEM(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_MEM(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_MEM(fmt...)
#endif
=20
#if SDP_DEBUG_PROC
-#define D_PROC(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_PROC(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_PROC(fmt...)
#endif
@@ -163,6 +163,7 @@
int sdp_con_id;
data_struct *db_hdl;
=20
+ D_REC("%d bytes",len);
PRINT_DATA(__FUNCTION__, data, len);
=20
db_hdl =3D (data_struct*)data;
@@ -347,6 +348,7 @@
if (len < cur_pos)
{
D_ERR("Packet length (%d) shorter than actual packet length (%d)", len=
, cur_pos);
+
send_error_rsp(sdp_con_id, trans_id, SDP_INVALID_PDU_SIZE);
return;
}
@@ -819,7 +821,7 @@
}
else if (len =3D=3D 0)
{
- syslog(LOG_DEBUG, "No data was read");
+ syslog(LOG_INFO, "No data was read");
}
else
{
--- sdp_server.c 2001/03/27 18:12:47 1.26
+++ sdp_server.c 2001/04/17 12:43:39 1.27
@@ -77,37 +77,37 @@
#define SDP_DEBUG_PRINT_DATA 0
=20
#if SDP_DEBUG_SUBFNC
-#define S_FNC(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define S_FNC(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define S_FNC(fmt...)
#endif
=20
#if SDP_DEBUG_INCOMING
-#define D_REC(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_REC(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_REC(fmt...)
#endif
=20
#if SDP_DEBUG_MISC
-#define D_MISC(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_MISC(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_MISC(fmt...)
#endif
=20
#if SDP_DEBUG_GET_ATTRIBUTES
-#define D_ATTR(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_ATTR(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_ATTR(fmt...)
#endif
=20
#if SDP_DEBUG_GET_RECORD_HDL
-#define D_RHDL(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_RHDL(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_RHDL(fmt...)
#endif
=20
#if SDP_DEBUG_MEM
-#define D_MEM(fmt...) syslog(LOG_DEBUG, __FUNCTION__ ": " fmt)
+#define D_MEM(fmt...) syslog(LOG_INFO, __FUNCTION__ ": " fmt)
#else
#define D_MEM(fmt...)
#endif
@@ -165,21 +165,21 @@
int t, offs =3D 0;
char tmp[100];
=20
- syslog(LOG_DEBUG, "%s (%d):", message, len);
+ syslog(LOG_INFO, "%s (%d):", message, len);
=20
for (t =3D 0; t < len; t++)=20
{
offs +=3D sprintf(tmp + offs, " 0x%02x", (unsigned int)buf[t]);
if (!((t+1) % 8))
{
- syslog(LOG_DEBUG, tmp);
+ syslog(LOG_INFO, tmp);
offs =3D 0;
}
}
=20
if (offs)
{
- syslog(LOG_DEBUG, tmp);
+ syslog(LOG_INFO, tmp);
}
}
=20
|
|
From: Anders J. <and...@us...> - 2003-11-04 10:59:39
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Tag Comment
---- ----------- ----------- --- -------
Makefile 1.13 1.14=20=20=20=20=20=20=20=20=20=20=20=20=20=20
sdp_server.c 1.33 1.34=20=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Created OpenBT library from common files in experimental.
* Removed experimental, BluetoothPN and btd. Usermode stack will not be=20
supported from now on.
* Moved applications to utils-directory.
* Removed warnings.
The diff of the modified file(s):
--- Makefile 2002/09/27 12:59:03 1.13
+++ Makefile 2003/11/04 10:59:38 1.14
@@ -22,7 +22,7 @@ SRCS =3D sdp_server.c sdp_parser.c
=20
CFLAGS +=3D -I$(INCDIR) -MMD
LDFLAGS +=3D -L$(LIBDIR)
-LDLIBS +=3D -lxmlparse -lxmltok
+LDLIBS +=3D -lexpat
=20
all: $(PROGS)
=20
--- sdp_server.c 2003/03/29 18:44:56 1.33
+++ sdp_server.c 2003/11/04 10:59:38 1.34
@@ -46,7 +46,7 @@
#include <syslog.h>
#include <unistd.h>
=20
-#include <xmlparse.h>
+#include <expat.h>
=20
#include "sdp_server.h"
#include "sdp_parser.h"
@@ -812,7 +812,7 @@ get_attribute_list(int fd, unsigned int=20
=20
if (search_struct.attribute_name =3D=3D NULL)
{
- fprintf(stderr, __FUNCTION__ ": Didn't find service attribute id name =
for uuid 0x%04x\n", attr_id_code);
+ fprintf(stderr, "%s: Didn't find service attribute id name for uuid 0x=
%04x\n", __FUNCTION__, attr_id_code);
return NULL;
}
=20=20=20
@@ -823,7 +823,7 @@ get_attribute_list(int fd, unsigned int=20
=20=20=20
if (search_struct.service_class =3D=3D NULL)
{
- fprintf(stderr, __FUNCTION__ ": Didn't find service class name for Rec=
ordHandle 0x%08x\n", record_handle);
+ fprintf(stderr, "%s: Didn't find service class name for RecordHandle 0=
x%08x\n", __FUNCTION__, record_handle);
=20
set_err(SDP_INVALID_SERVICE_RECORD_HANDLE);
D_MEM("<--- free%d 0x%8p", --malloc_dbg, search_struct.attribute_name);
@@ -1108,7 +1108,7 @@ get_from_xml(int fd, char *tag, char *at
{=20=20=20=20
if (set_value !=3D -1)
{
- fprintf(stderr, __FUNCTION__ ": Error more than one attribute =3D=3D=
NULL\n");
+ fprintf(stderr, "%s: Error more than one attribute =3D=3D NULL\n", _=
_FUNCTION__);
return NULL;
}
=20
@@ -1120,7 +1120,7 @@ get_from_xml(int fd, char *tag, char *at
{
if (set_value !=3D -1)
{
- fprintf(stderr, __FUNCTION__ ": Error more than one attribute =3D=3D=
NULL\n");
+ fprintf(stderr, "%s: Error more than one attribute =3D=3D NULL\n", _=
_FUNCTION__);
return NULL;
}
=20
@@ -1630,11 +1630,11 @@ handle_service_search_attr_req(service_s
}
if (tmp_ptr)
{=20=20=20
- printf(__FUNCTION__ ": Copying %d bytes to rsp_pkt\n", tmp_ptr[1]);
+ printf("%s: Copying %d bytes to rsp_pkt\n", __FUNCTION__, tmp_ptr=
[1]);
memcpy(rsp_pkt + rsp_pkt_len + tmp_len, tmp_ptr + 2, tmp_ptr[1]);
tmp_len +=3D tmp_ptr[1];
=20
- printf(__FUNCTION__ ": list_len: %d\n", tmp_len);
+ printf("%s: list_len: %d\n", __FUNCTION__, tmp_len);
=20
D_MEM("<--- free%d tmp_ptr 0x%8p", --malloc_dbg, tmp_ptr);
free(tmp_ptr);
|