Change sdp_open_local(3) API. It now takes a path to a control socket

Teach sdpcontrol(8) how to talk to the local SDP server
Update man pages
s/u_int/uint

Reviewed by:	imp (mentor), ru
This commit is contained in:
Maksim Yevmenkin 2004-01-09 22:44:28 +00:00
parent 91c9d24e52
commit a4b187fa33
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=124317
6 changed files with 103 additions and 60 deletions

View File

@ -73,7 +73,7 @@
.Ft void * .Ft void *
.Fn sdp_open "bdaddr_t const *l" "bdaddr_t const *r" .Fn sdp_open "bdaddr_t const *l" "bdaddr_t const *r"
.Ft void * .Ft void *
.Fn sdp_open_local "void" .Fn sdp_open_local "char const *control"
.Ft int32_t .Ft int32_t
.Fn sdp_close "void *xs" .Fn sdp_close "void *xs"
.Ft int32_t .Ft int32_t
@ -134,7 +134,13 @@ Remote BD_ADDR can not be
.Dv NG_HCI_BDADDR_ANY . .Dv NG_HCI_BDADDR_ANY .
The The
.Fn sdp_open_local .Fn sdp_open_local
function takes no arguments and opens a connection to a local SDP server. function takes path to the control socket and opens a connection to a local
SDP server.
If path to the control socket is
.Dv NULL
then default
.Pa /var/run/sdp
path will be used.
.Pp .Pp
The The
.Fn sdp_close .Fn sdp_close

View File

@ -469,7 +469,7 @@ typedef struct sdp_attr * sdp_attr_p;
#endif /* BYTE_ORDER */ #endif /* BYTE_ORDER */
void * sdp_open (bdaddr_t const *l, bdaddr_t const *r); void * sdp_open (bdaddr_t const *l, bdaddr_t const *r);
void * sdp_open_local (void); void * sdp_open_local (char const *control);
int32_t sdp_close (void *xs); int32_t sdp_close (void *xs);
int32_t sdp_error (void *xs); int32_t sdp_error (void *xs);

View File

@ -102,7 +102,7 @@ sdp_open(bdaddr_t const *l, bdaddr_t const *r)
} }
void * void *
sdp_open_local(void) sdp_open_local(char const *control)
{ {
sdp_session_p ss = NULL; sdp_session_p ss = NULL;
struct sockaddr_un sa; struct sockaddr_un sa;
@ -116,9 +116,12 @@ sdp_open_local(void)
goto fail; goto fail;
} }
if (control == NULL)
control = SDP_LOCAL_PATH;
sa.sun_len = sizeof(sa); sa.sun_len = sizeof(sa);
sa.sun_family = AF_UNIX; sa.sun_family = AF_UNIX;
strlcpy(sa.sun_path, SDP_LOCAL_PATH, sizeof(sa.sun_path)); strlcpy(sa.sun_path, control, sizeof(sa.sun_path));
if (connect(ss->s, (struct sockaddr *) &sa, sizeof(sa)) < 0) { if (connect(ss->s, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
ss->error = errno; ss->error = errno;

View File

@ -30,18 +30,25 @@
.Os .Os
.Sh NAME .Sh NAME
.Nm spdcontrol .Nm spdcontrol
.Nd SDP configuration utility .Nd SDP query utility
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl h .Fl h
.Nm
.Fl a Ar BD_ADDR .Fl a Ar BD_ADDR
.Ar command .Ar command
.Op Ar parameters ... .Op Ar parameters ...
.Nm
.Fl l
.Op Fl c Ar path
.Ar command
.Op Ar parameters ...
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm
utility connects to the remote device with the specified BD_ADDR and attempts utility attempts to query specified Service Discovery Protocol (SDP) server.
to send query via Service Discovery Protocol (SDP). Remote SDP servers are identified by their BD_ADDRs.
Connection to the local SDP server is made via control socket.
The The
.Nm .Nm
utility will use Service Search Attribute Request and will print results to utility will use Service Search Attribute Request and will print results to
@ -53,8 +60,14 @@ The options are as follows:
Connect to the remote device with the specified BD_ADDR. Connect to the remote device with the specified BD_ADDR.
Example: Example:
.Fl a Li 00:01:02:03:04:05 . .Fl a Li 00:01:02:03:04:05 .
.It Fl c Ar path
Specify path to the control socket.
The default path is
.Pa /var/run/sdp .
.It Fl h .It Fl h
Display usage message and exit. Display usage message and exit.
.It Fl l
Query the local SDP server via the control socket.
.It Ar command .It Ar command
One of the supported commands (see below). One of the supported commands (see below).
Special command Special command
@ -75,13 +88,13 @@ are:
.It Cm Search .It Cm Search
.El .El
.Sh CAVEAT .Sh CAVEAT
Currently, the The
.Nm .Nm
utility only implements client side functionality. utility only implements client side functionality.
.Pp .Pp
The The
.Nm .Nm
utility only request the following attributes from the remote SDP server: utility only requests the following attributes from the SDP server:
.Bl -enum -offset indent -compact .Bl -enum -offset indent -compact
.It .It
Service Record Handle Service Record Handle

View File

@ -41,7 +41,8 @@
#include "sdpcontrol.h" #include "sdpcontrol.h"
/* Prototypes */ /* Prototypes */
static int do_sdp_command (bdaddr_p, int, char **); static int do_sdp_command (bdaddr_p, char const *, int,
int, char **);
static struct sdp_command * find_sdp_command (char const *, static struct sdp_command * find_sdp_command (char const *,
struct sdp_command *); struct sdp_command *);
static void print_sdp_command (struct sdp_command *); static void print_sdp_command (struct sdp_command *);
@ -51,15 +52,16 @@ static void usage (void);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int n; char const *control = SDP_LOCAL_PATH;
bdaddr_t bdaddr; int n, local;
bdaddr_t bdaddr;
memset(&bdaddr, 0, sizeof(bdaddr)); memset(&bdaddr, 0, sizeof(bdaddr));
/* Process command line arguments */ /* Process command line arguments */
while ((n = getopt(argc, argv, "a:h")) != -1) { while ((n = getopt(argc, argv, "a:c:lh")) != -1) {
switch (n) { switch (n) {
case 'a': case 'a': /* bdaddr */
if (!bt_aton(optarg, &bdaddr)) { if (!bt_aton(optarg, &bdaddr)) {
struct hostent *he = NULL; struct hostent *he = NULL;
@ -70,6 +72,14 @@ main(int argc, char *argv[])
} }
break; break;
case 'c': /* control socket */
control = optarg;
break;
case 'l': /* local sdpd */
local = 1;
break;
case 'h': case 'h':
default: default:
usage(); usage();
@ -83,12 +93,13 @@ main(int argc, char *argv[])
if (*argv == NULL) if (*argv == NULL)
usage(); usage();
return (do_sdp_command(&bdaddr, argc, argv)); return (do_sdp_command(&bdaddr, control, local, argc, argv));
} }
/* Execute commands */ /* Execute commands */
static int static int
do_sdp_command(bdaddr_p bdaddr, int argc, char **argv) do_sdp_command(bdaddr_p bdaddr, char const *control, int local,
int argc, char **argv)
{ {
char *cmd = argv[0]; char *cmd = argv[0];
struct sdp_command *c = NULL; struct sdp_command *c = NULL;
@ -120,12 +131,16 @@ do_sdp_command(bdaddr_p bdaddr, int argc, char **argv)
} }
if (!help) { if (!help) {
if (memcmp(bdaddr, NG_HCI_BDADDR_ANY, sizeof(*bdaddr)) == 0) if (!local) {
usage(); if (memcmp(bdaddr, NG_HCI_BDADDR_ANY, sizeof(*bdaddr)) == 0)
usage();
if ((xs = sdp_open(NG_HCI_BDADDR_ANY, bdaddr)) == NULL) xs = sdp_open(NG_HCI_BDADDR_ANY, bdaddr);
} else
xs = sdp_open_local(control);
if (xs == NULL)
errx(1, "Could not create SDP session object"); errx(1, "Could not create SDP session object");
if (sdp_error(xs) == 0) if (sdp_error(xs) == 0)
e = (c->handler)(xs, -- argc, ++ argv); e = (c->handler)(xs, -- argc, ++ argv);
else else
@ -190,8 +205,14 @@ print_sdp_command(struct sdp_command *category)
static void static void
usage(void) usage(void)
{ {
fprintf(stdout, "Usage: sdpcontrol -a BD_ADDR [-h] " \ fprintf(stderr,
"cmd [p1] [..]]\n"); "Usage: sdpcontrol options command\n" \
"Where options are:\n"
" -a bdaddr specify bdaddr\n" \
" -c path path to the control socket (default is %s)\n" \
" -h display usage and quit\n" \
" -l connect to the local SDP server via control socket\n" \
" command one of the supported commands\n", SDP_LOCAL_PATH);
exit(255); exit(255);
} /* usage */ } /* usage */

View File

@ -37,7 +37,7 @@
#include "sdpcontrol.h" #include "sdpcontrol.h"
/* List of the attributes we are looking for */ /* List of the attributes we are looking for */
static u_int32_t attrs[] = static uint32_t attrs[] =
{ {
SDP_ATTR_RANGE( SDP_ATTR_SERVICE_RECORD_HANDLE, SDP_ATTR_RANGE( SDP_ATTR_SERVICE_RECORD_HANDLE,
SDP_ATTR_SERVICE_RECORD_HANDLE), SDP_ATTR_SERVICE_RECORD_HANDLE),
@ -53,7 +53,7 @@ static u_int32_t attrs[] =
/* Buffer for the attributes */ /* Buffer for the attributes */
#define NRECS 25 /* request this much records from the SDP server */ #define NRECS 25 /* request this much records from the SDP server */
#define BSIZE 256 /* one attribute buffer size */ #define BSIZE 256 /* one attribute buffer size */
static u_int8_t buffer[NRECS * attrs_len][BSIZE]; static uint8_t buffer[NRECS * attrs_len][BSIZE];
/* SDP attributes */ /* SDP attributes */
static sdp_attr_t values[NRECS * attrs_len]; static sdp_attr_t values[NRECS * attrs_len];
@ -70,9 +70,9 @@ static sdp_attr_t values[NRECS * attrs_len];
*/ */
static void static void
print_service_class_id_list(u_int8_t const *start, u_int8_t const *end) print_service_class_id_list(uint8_t const *start, uint8_t const *end)
{ {
u_int32_t type, len, value; uint32_t type, len, value;
if (end - start < 2) { if (end - start < 2) {
fprintf(stderr, "Invalid Service Class ID List. " \ fprintf(stderr, "Invalid Service Class ID List. " \
@ -120,12 +120,12 @@ print_service_class_id_list(u_int8_t const *start, u_int8_t const *end)
SDP_GET128(&uuid, start); SDP_GET128(&uuid, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n", fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(u_int32_t *)&uuid.b[0], *(uint32_t *)&uuid.b[0],
*(u_int16_t *)&uuid.b[4], *(uint16_t *)&uuid.b[4],
*(u_int16_t *)&uuid.b[6], *(uint16_t *)&uuid.b[6],
*(u_int16_t *)&uuid.b[8], *(uint16_t *)&uuid.b[8],
*(u_int16_t *)&uuid.b[10], *(uint16_t *)&uuid.b[10],
*(u_int32_t *)&uuid.b[12]); *(uint32_t *)&uuid.b[12]);
} break; } break;
default: default:
@ -153,7 +153,7 @@ print_service_class_id_list(u_int8_t const *start, u_int8_t const *end)
*/ */
static void static void
print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end) print_protocol_descriptor(uint8_t const *start, uint8_t const *end)
{ {
union { union {
uint8_t uint8; uint8_t uint8;
@ -162,7 +162,7 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
uint64_t uint64; uint64_t uint64;
int128_t int128; int128_t int128;
} value; } value;
u_int32_t type, len, param; uint32_t type, len, param;
/* Get Protocol UUID */ /* Get Protocol UUID */
SDP_GET8(type, start); SDP_GET8(type, start);
@ -181,12 +181,12 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
case SDP_DATA_UUID128: case SDP_DATA_UUID128:
SDP_GET128(&value.int128, start); SDP_GET128(&value.int128, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n", fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(u_int32_t *)&value.int128.b[0], *(uint32_t *)&value.int128.b[0],
*(u_int16_t *)&value.int128.b[4], *(uint16_t *)&value.int128.b[4],
*(u_int16_t *)&value.int128.b[6], *(uint16_t *)&value.int128.b[6],
*(u_int16_t *)&value.int128.b[8], *(uint16_t *)&value.int128.b[8],
*(u_int16_t *)&value.int128.b[10], *(uint16_t *)&value.int128.b[10],
*(u_int32_t *)&value.int128.b[12]); *(uint32_t *)&value.int128.b[12]);
break; break;
default: default:
@ -238,12 +238,12 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
case SDP_DATA_UUID128: case SDP_DATA_UUID128:
SDP_GET128(&value.int128, start); SDP_GET128(&value.int128, start);
fprintf(stdout, "u/int/uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n", fprintf(stdout, "u/int/uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(u_int32_t *)&value.int128.b[0], *(uint32_t *)&value.int128.b[0],
*(u_int16_t *)&value.int128.b[4], *(uint16_t *)&value.int128.b[4],
*(u_int16_t *)&value.int128.b[6], *(uint16_t *)&value.int128.b[6],
*(u_int16_t *)&value.int128.b[8], *(uint16_t *)&value.int128.b[8],
*(u_int16_t *)&value.int128.b[10], *(uint16_t *)&value.int128.b[10],
*(u_int32_t *)&value.int128.b[12]); *(uint32_t *)&value.int128.b[12]);
break; break;
case SDP_DATA_STR8: case SDP_DATA_STR8:
@ -301,9 +301,9 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
} /* print_protocol_descriptor */ } /* print_protocol_descriptor */
static void static void
print_protocol_descriptor_list(u_int8_t const *start, u_int8_t const *end) print_protocol_descriptor_list(uint8_t const *start, uint8_t const *end)
{ {
u_int32_t type, len; uint32_t type, len;
if (end - start < 2) { if (end - start < 2) {
fprintf(stderr, "Invalid Protocol Descriptor List. " \ fprintf(stderr, "Invalid Protocol Descriptor List. " \
@ -375,9 +375,9 @@ print_protocol_descriptor_list(u_int8_t const *start, u_int8_t const *end)
*/ */
static void static void
print_bluetooth_profile_descriptor_list(u_int8_t const *start, u_int8_t const *end) print_bluetooth_profile_descriptor_list(uint8_t const *start, uint8_t const *end)
{ {
u_int32_t type, len, value; uint32_t type, len, value;
if (end - start < 2) { if (end - start < 2) {
fprintf(stderr, "Invalid Bluetooth Profile Descriptor List. " \ fprintf(stderr, "Invalid Bluetooth Profile Descriptor List. " \
@ -448,12 +448,12 @@ print_bluetooth_profile_descriptor_list(u_int8_t const *start, u_int8_t const *e
SDP_GET128(&uuid, start); SDP_GET128(&uuid, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ", fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ",
*(u_int32_t *)&uuid.b[0], *(uint32_t *)&uuid.b[0],
*(u_int16_t *)&uuid.b[4], *(uint16_t *)&uuid.b[4],
*(u_int16_t *)&uuid.b[6], *(uint16_t *)&uuid.b[6],
*(u_int16_t *)&uuid.b[8], *(uint16_t *)&uuid.b[8],
*(u_int16_t *)&uuid.b[10], *(uint16_t *)&uuid.b[10],
*(u_int32_t *)&uuid.b[12]); *(uint32_t *)&uuid.b[12]);
} break; } break;
default: default:
@ -485,7 +485,7 @@ do_sdp_search(void *xs, int argc, char **argv)
{ {
char *ep = NULL; char *ep = NULL;
int32_t n, type, value; int32_t n, type, value;
u_int16_t service; uint16_t service;
/* Parse command line arguments */ /* Parse command line arguments */
switch (argc) { switch (argc) {
@ -570,7 +570,7 @@ do_sdp_search(void *xs, int argc, char **argv)
/* NOT REACHED */ /* NOT REACHED */
} }
} else } else
service = (u_int16_t) n; service = (uint16_t) n;
break; break;
default: default: