|
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 {
|