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 *
.Fn sdp_open "bdaddr_t const *l" "bdaddr_t const *r"
.Ft void *
.Fn sdp_open_local "void"
.Fn sdp_open_local "char const *control"
.Ft int32_t
.Fn sdp_close "void *xs"
.Ft int32_t
@ -134,7 +134,13 @@ Remote BD_ADDR can not be
.Dv NG_HCI_BDADDR_ANY .
The
.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
The
.Fn sdp_close

View File

@ -469,7 +469,7 @@ typedef struct sdp_attr * sdp_attr_p;
#endif /* BYTE_ORDER */
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_error (void *xs);

View File

@ -102,7 +102,7 @@ sdp_open(bdaddr_t const *l, bdaddr_t const *r)
}
void *
sdp_open_local(void)
sdp_open_local(char const *control)
{
sdp_session_p ss = NULL;
struct sockaddr_un sa;
@ -116,9 +116,12 @@ sdp_open_local(void)
goto fail;
}
if (control == NULL)
control = SDP_LOCAL_PATH;
sa.sun_len = sizeof(sa);
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) {
ss->error = errno;

View File

@ -30,18 +30,25 @@
.Os
.Sh NAME
.Nm spdcontrol
.Nd SDP configuration utility
.Nd SDP query utility
.Sh SYNOPSIS
.Nm
.Op Fl h
.Fl h
.Nm
.Fl a Ar BD_ADDR
.Ar command
.Op Ar parameters ...
.Nm
.Fl l
.Op Fl c Ar path
.Ar command
.Op Ar parameters ...
.Sh DESCRIPTION
The
.Nm
utility connects to the remote device with the specified BD_ADDR and attempts
to send query via Service Discovery Protocol (SDP).
utility attempts to query specified Service Discovery Protocol (SDP) server.
Remote SDP servers are identified by their BD_ADDRs.
Connection to the local SDP server is made via control socket.
The
.Nm
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.
Example:
.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
Display usage message and exit.
.It Fl l
Query the local SDP server via the control socket.
.It Ar command
One of the supported commands (see below).
Special command
@ -75,13 +88,13 @@ are:
.It Cm Search
.El
.Sh CAVEAT
Currently, the
The
.Nm
utility only implements client side functionality.
.Pp
The
.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
.It
Service Record Handle

View File

@ -41,7 +41,8 @@
#include "sdpcontrol.h"
/* 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 *,
struct sdp_command *);
static void print_sdp_command (struct sdp_command *);
@ -51,15 +52,16 @@ static void usage (void);
int
main(int argc, char *argv[])
{
int n;
bdaddr_t bdaddr;
char const *control = SDP_LOCAL_PATH;
int n, local;
bdaddr_t bdaddr;
memset(&bdaddr, 0, sizeof(bdaddr));
/* Process command line arguments */
while ((n = getopt(argc, argv, "a:h")) != -1) {
while ((n = getopt(argc, argv, "a:c:lh")) != -1) {
switch (n) {
case 'a':
case 'a': /* bdaddr */
if (!bt_aton(optarg, &bdaddr)) {
struct hostent *he = NULL;
@ -70,6 +72,14 @@ main(int argc, char *argv[])
}
break;
case 'c': /* control socket */
control = optarg;
break;
case 'l': /* local sdpd */
local = 1;
break;
case 'h':
default:
usage();
@ -83,12 +93,13 @@ main(int argc, char *argv[])
if (*argv == NULL)
usage();
return (do_sdp_command(&bdaddr, argc, argv));
return (do_sdp_command(&bdaddr, control, local, argc, argv));
}
/* Execute commands */
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];
struct sdp_command *c = NULL;
@ -120,12 +131,16 @@ do_sdp_command(bdaddr_p bdaddr, int argc, char **argv)
}
if (!help) {
if (memcmp(bdaddr, NG_HCI_BDADDR_ANY, sizeof(*bdaddr)) == 0)
usage();
if (!local) {
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");
if (sdp_error(xs) == 0)
e = (c->handler)(xs, -- argc, ++ argv);
else
@ -190,8 +205,14 @@ print_sdp_command(struct sdp_command *category)
static void
usage(void)
{
fprintf(stdout, "Usage: sdpcontrol -a BD_ADDR [-h] " \
"cmd [p1] [..]]\n");
fprintf(stderr,
"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);
} /* usage */

View File

@ -37,7 +37,7 @@
#include "sdpcontrol.h"
/* 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_SERVICE_RECORD_HANDLE),
@ -53,7 +53,7 @@ static u_int32_t attrs[] =
/* Buffer for the attributes */
#define NRECS 25 /* request this much records from the SDP server */
#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 */
static sdp_attr_t values[NRECS * attrs_len];
@ -70,9 +70,9 @@ static sdp_attr_t values[NRECS * attrs_len];
*/
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) {
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);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(u_int32_t *)&uuid.b[0],
*(u_int16_t *)&uuid.b[4],
*(u_int16_t *)&uuid.b[6],
*(u_int16_t *)&uuid.b[8],
*(u_int16_t *)&uuid.b[10],
*(u_int32_t *)&uuid.b[12]);
*(uint32_t *)&uuid.b[0],
*(uint16_t *)&uuid.b[4],
*(uint16_t *)&uuid.b[6],
*(uint16_t *)&uuid.b[8],
*(uint16_t *)&uuid.b[10],
*(uint32_t *)&uuid.b[12]);
} break;
default:
@ -153,7 +153,7 @@ print_service_class_id_list(u_int8_t const *start, u_int8_t const *end)
*/
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 {
uint8_t uint8;
@ -162,7 +162,7 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
uint64_t uint64;
int128_t int128;
} value;
u_int32_t type, len, param;
uint32_t type, len, param;
/* Get Protocol UUID */
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:
SDP_GET128(&value.int128, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(u_int32_t *)&value.int128.b[0],
*(u_int16_t *)&value.int128.b[4],
*(u_int16_t *)&value.int128.b[6],
*(u_int16_t *)&value.int128.b[8],
*(u_int16_t *)&value.int128.b[10],
*(u_int32_t *)&value.int128.b[12]);
*(uint32_t *)&value.int128.b[0],
*(uint16_t *)&value.int128.b[4],
*(uint16_t *)&value.int128.b[6],
*(uint16_t *)&value.int128.b[8],
*(uint16_t *)&value.int128.b[10],
*(uint32_t *)&value.int128.b[12]);
break;
default:
@ -238,12 +238,12 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
case SDP_DATA_UUID128:
SDP_GET128(&value.int128, start);
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],
*(u_int16_t *)&value.int128.b[4],
*(u_int16_t *)&value.int128.b[6],
*(u_int16_t *)&value.int128.b[8],
*(u_int16_t *)&value.int128.b[10],
*(u_int32_t *)&value.int128.b[12]);
*(uint32_t *)&value.int128.b[0],
*(uint16_t *)&value.int128.b[4],
*(uint16_t *)&value.int128.b[6],
*(uint16_t *)&value.int128.b[8],
*(uint16_t *)&value.int128.b[10],
*(uint32_t *)&value.int128.b[12]);
break;
case SDP_DATA_STR8:
@ -301,9 +301,9 @@ print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
} /* print_protocol_descriptor */
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) {
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
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) {
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);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ",
*(u_int32_t *)&uuid.b[0],
*(u_int16_t *)&uuid.b[4],
*(u_int16_t *)&uuid.b[6],
*(u_int16_t *)&uuid.b[8],
*(u_int16_t *)&uuid.b[10],
*(u_int32_t *)&uuid.b[12]);
*(uint32_t *)&uuid.b[0],
*(uint16_t *)&uuid.b[4],
*(uint16_t *)&uuid.b[6],
*(uint16_t *)&uuid.b[8],
*(uint16_t *)&uuid.b[10],
*(uint32_t *)&uuid.b[12]);
} break;
default:
@ -485,7 +485,7 @@ do_sdp_search(void *xs, int argc, char **argv)
{
char *ep = NULL;
int32_t n, type, value;
u_int16_t service;
uint16_t service;
/* Parse command line arguments */
switch (argc) {
@ -570,7 +570,7 @@ do_sdp_search(void *xs, int argc, char **argv)
/* NOT REACHED */
}
} else
service = (u_int16_t) n;
service = (uint16_t) n;
break;
default: