Do not tread 128-bit UUID as int128. Provide separate macros to get/put

128-bit UUID libsdp(3). Fix 128-bit UUID printing in sdpcontrol(8).

MFC after:	3 days
This commit is contained in:
Maksim Yevmenkin 2005-05-27 19:11:33 +00:00
parent 2e631cd2fa
commit 43d33de948
4 changed files with 117 additions and 36 deletions

View File

@ -34,11 +34,13 @@
.Nm SDP_GET32 ,
.Nm SDP_GET64 ,
.Nm SDP_GET128 ,
.Nm SDP_GET_UUID128 ,
.Nm SDP_PUT8 ,
.Nm SDP_PUT16 ,
.Nm SDP_PUT32 ,
.Nm SDP_PUT64 ,
.Nm SDP_PUT128 ,
.Nm SDP_PUT_UUID128 ,
.Nm sdp_open ,
.Nm sdp_open_local ,
.Nm sdp_close ,
@ -57,11 +59,13 @@
.Fn SDP_GET32 "l" "cp"
.Fn SDP_GET64 "l" "cp"
.Fn SDP_GET128 "l" "cp"
.Fn SDP_GET_UUID128 "l" "cp"
.Fn SDP_PUT8 "b" "cp"
.Fn SDP_PUT16 "s" "cp"
.Fn SDP_PUT32 "l" "cp"
.Fn SDP_PUT64 "l" "cp"
.Fn SDP_PUT128 "l" "cp"
.Fn SDP_PUT_UUID128 "l" "cp"
.Ft "void *"
.Fn sdp_open "bdaddr_t const *l" "bdaddr_t const *r"
.Ft "void *"
@ -117,6 +121,14 @@ into the buffer pointed by
pointer.
The pointer is automatically advanced.
.Pp
.Fn SDP_GET_UUID128
and
.Fn SDP_PUT_UUID128
macros are used to get and put 128-bit UUID into the buffer pointed by
.Fa cp
pointer.
The pointer is automatically advanced.
.Pp
The
.Fn sdp_open
and
@ -359,7 +371,7 @@ sdp_attr_t proto = { SDP_ATTR_INVALID,0,sizeof(buffer),buffer };
if ((ss = sdp_open(NG_HCI_BDADDR_ANY, remote)) == NULL)
/* exit ENOMEM */
if (sdp_error(ss) != 0)
/* exit spd_error(ss) */
/* exit sdp_error(ss) */
if (sdp_search(ss, 1, &serv, 1, &attr, 1, &proto) != 0)
/* exit sdp_error(ss) */

View File

@ -360,9 +360,31 @@ typedef struct sdp_attr * sdp_attr_p;
(l)->b[3] = *t_cp++; \
(l)->b[2] = *t_cp++; \
(l)->b[1] = *t_cp++; \
(l)->b[0] = *t_cp++; \
(cp) += 16; \
}
#else /* BYTE_ORDER != LITTLE_ENDIAN */
#define SDP_GET_UUID128(l, cp) { \
register uint8_t *t_cp = (uint8_t *)(cp); \
(l)->b[0] = *t_cp++; \
(l)->b[1] = *t_cp++; \
(l)->b[2] = *t_cp++; \
(l)->b[3] = *t_cp++; \
(l)->b[4] = *t_cp++; \
(l)->b[5] = *t_cp++; \
(l)->b[6] = *t_cp++; \
(l)->b[7] = *t_cp++; \
(l)->b[8] = *t_cp++; \
(l)->b[9] = *t_cp++; \
(l)->b[10] = *t_cp++; \
(l)->b[11] = *t_cp++; \
(l)->b[12] = *t_cp++; \
(l)->b[13] = *t_cp++; \
(l)->b[14] = *t_cp++; \
(l)->b[15] = *t_cp++; \
(cp) += 16; \
}
#elif BYTE_ORDER == BIG_ENDIAN
#define SDP_GET128(l, cp) { \
register uint8_t *t_cp = (uint8_t *)(cp); \
(l)->b[0] = *t_cp++; \
@ -383,6 +405,10 @@ typedef struct sdp_attr * sdp_attr_p;
(l)->b[15] = *t_cp++; \
(cp) += 16; \
}
#define SDP_GET_UUID128(l, cp) SDP_GET128(l, cp)
#else
#error "Unsupported BYTE_ORDER"
#endif /* BYTE_ORDER */
#define SDP_PUT8(b, cp) { \
@ -445,7 +471,28 @@ typedef struct sdp_attr * sdp_attr_p;
*t_cp = (l)->b[0]; \
(cp) += 16; \
}
#else /* BYTE_ORDER != LITTLE_ENDIAN */
#define SDP_PUT_UUID128(l, cp) { \
register uint8_t *t_cp = (uint8_t *)(cp); \
*t_cp++ = (l)->b[0]; \
*t_cp++ = (l)->b[1]; \
*t_cp++ = (l)->b[2]; \
*t_cp++ = (l)->b[3]; \
*t_cp++ = (l)->b[4]; \
*t_cp++ = (l)->b[5]; \
*t_cp++ = (l)->b[6]; \
*t_cp++ = (l)->b[7]; \
*t_cp++ = (l)->b[8]; \
*t_cp++ = (l)->b[9]; \
*t_cp++ = (l)->b[10]; \
*t_cp++ = (l)->b[11]; \
*t_cp++ = (l)->b[12]; \
*t_cp++ = (l)->b[13]; \
*t_cp++ = (l)->b[14]; \
*t_cp = (l)->b[15]; \
(cp) += 16; \
}
#elif BYTE_ORDER == BIG_ENDIAN
#define SDP_PUT128(l, cp) { \
register uint8_t *t_cp = (uint8_t *)(cp); \
*t_cp++ = (l)->b[0]; \
@ -466,6 +513,10 @@ typedef struct sdp_attr * sdp_attr_p;
*t_cp = (l)->b[15]; \
(cp) += 16; \
}
#define SDP_PUT_UUID128(l, cp) SDP_PUT128(l, cp)
#else
#error "Unsupported BYTE_ORDER"
#endif /* BYTE_ORDER */
void * sdp_open (bdaddr_t const *l, bdaddr_t const *r);

View File

@ -29,6 +29,7 @@
* $FreeBSD$
*/
#include <netinet/in.h>
#include <bluetooth.h>
#include <stdio.h>
#include <sdp.h>
@ -317,17 +318,25 @@ sdp_print(uint32_t level, uint8_t const *start, uint8_t const *end)
case SDP_DATA_UINT128:
case SDP_DATA_INT128:
case SDP_DATA_UUID128:
SDP_GET128(&value.int128, start);
printf("int128/uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
printf("u/int128 %#8.8x%8.8x%8.8x%8.8x\n",
*(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[4],
*(uint32_t *)&value.int128.b[8],
*(uint32_t *)&value.int128.b[12]);
break;
case SDP_DATA_UUID128:
SDP_GET_UUID128(&value.int128, start);
printf("uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
ntohl(*(uint32_t *)&value.int128.b[0]),
ntohs(*(uint16_t *)&value.int128.b[4]),
ntohs(*(uint16_t *)&value.int128.b[6]),
ntohs(*(uint16_t *)&value.int128.b[8]),
ntohs(*(uint16_t *)&value.int128.b[10]),
ntohl(*(uint32_t *)&value.int128.b[12]));
break;
case SDP_DATA_INT8:
SDP_GET8(value.int8, start);
printf("int8 %d\n", value.int8);

View File

@ -29,6 +29,7 @@
* $FreeBSD$
*/
#include <netinet/in.h>
#include <bluetooth.h>
#include <ctype.h>
#include <sdp.h>
@ -118,14 +119,14 @@ print_service_class_id_list(uint8_t const *start, uint8_t const *end)
case SDP_DATA_UUID128: {
int128_t uuid;
SDP_GET128(&uuid, start);
SDP_GET_UUID128(&uuid, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(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]);
ntohl(*(uint32_t *)&uuid.b[0]),
ntohs(*(uint16_t *)&uuid.b[4]),
ntohs(*(uint16_t *)&uuid.b[6]),
ntohs(*(uint16_t *)&uuid.b[8]),
ntohs(*(uint16_t *)&uuid.b[10]),
ntohl(*(uint32_t *)&uuid.b[12]));
} break;
default:
@ -179,14 +180,14 @@ print_protocol_descriptor(uint8_t const *start, uint8_t const *end)
break;
case SDP_DATA_UUID128:
SDP_GET128(&value.int128, start);
SDP_GET_UUID128(&value.int128, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
*(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]);
ntohl(*(uint32_t *)&value.int128.b[0]),
ntohs(*(uint16_t *)&value.int128.b[4]),
ntohs(*(uint16_t *)&value.int128.b[6]),
ntohs(*(uint16_t *)&value.int128.b[8]),
ntohs(*(uint16_t *)&value.int128.b[10]),
ntohl(*(uint32_t *)&value.int128.b[12]));
break;
default:
@ -235,17 +236,25 @@ print_protocol_descriptor(uint8_t const *start, uint8_t const *end)
case SDP_DATA_UINT128:
case SDP_DATA_INT128:
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",
fprintf(stdout, "u/int128 %#8.8x%8.8x%8.8x%8.8x\n",
*(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[4],
*(uint32_t *)&value.int128.b[8],
*(uint32_t *)&value.int128.b[12]);
break;
case SDP_DATA_UUID128:
SDP_GET_UUID128(&value.int128, start);
fprintf(stdout, "uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
ntohl(*(uint32_t *)&value.int128.b[0]),
ntohs(*(uint16_t *)&value.int128.b[4]),
ntohs(*(uint16_t *)&value.int128.b[6]),
ntohs(*(uint16_t *)&value.int128.b[8]),
ntohs(*(uint16_t *)&value.int128.b[10]),
ntohl(*(uint32_t *)&value.int128.b[12]));
break;
case SDP_DATA_STR8:
case SDP_DATA_URL8:
SDP_GET8(len, start);
@ -446,14 +455,14 @@ print_bluetooth_profile_descriptor_list(uint8_t const *start, uint8_t const *end
case SDP_DATA_UUID128: {
int128_t uuid;
SDP_GET128(&uuid, start);
SDP_GET_UUID128(&uuid, start);
fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ",
*(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]);
ntohl(*(uint32_t *)&uuid.b[0]),
ntohs(*(uint16_t *)&uuid.b[4]),
ntohs(*(uint16_t *)&uuid.b[6]),
ntohs(*(uint16_t *)&uuid.b[8]),
ntohs(*(uint16_t *)&uuid.b[10]),
ntohl(*(uint32_t *)&uuid.b[12]));
} break;
default: