1177059Semax/*
2177059Semax * panu.c
3177059Semax */
4177059Semax
5177059Semax/*-
6177059Semax * Copyright (c) 2008 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7177059Semax * All rights reserved.
8177059Semax *
9177059Semax * Redistribution and use in source and binary forms, with or without
10177059Semax * modification, are permitted provided that the following conditions
11177059Semax * are met:
12177059Semax * 1. Redistributions of source code must retain the above copyright
13177059Semax *    notice, this list of conditions and the following disclaimer.
14177059Semax * 2. Redistributions in binary form must reproduce the above copyright
15177059Semax *    notice, this list of conditions and the following disclaimer in the
16177059Semax *    documentation and/or other materials provided with the distribution.
17177059Semax *
18177059Semax * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19177059Semax * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20177059Semax * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21177059Semax * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22177059Semax * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23177059Semax * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24177059Semax * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25177059Semax * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26177059Semax * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27177059Semax * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28177059Semax * SUCH DAMAGE.
29177059Semax *
30177059Semax * $Id: panu.c,v 1.1 2008/03/11 00:02:42 max Exp $
31177059Semax * $FreeBSD$
32177059Semax */
33177059Semax
34177059Semax#include <sys/queue.h>
35177059Semax#include <bluetooth.h>
36177059Semax#include <sdp.h>
37177059Semax#include <string.h>
38177059Semax#include "profile.h"
39177059Semax#include "provider.h"
40177059Semax
41177059Semaxstatic int32_t
42177059Semaxpanu_profile_create_service_class_id_list(
43177059Semax		uint8_t *buf, uint8_t const * const eob,
44177059Semax		uint8_t const *data, uint32_t datalen)
45177059Semax{
46177059Semax	static uint16_t	service_classes[] = {
47177059Semax		SDP_SERVICE_CLASS_PANU
48177059Semax	};
49177059Semax
50177059Semax	return (common_profile_create_service_class_id_list(
51177059Semax			buf, eob,
52177059Semax			(uint8_t const *) service_classes,
53177059Semax			sizeof(service_classes)));
54177059Semax}
55177059Semax
56177059Semaxstatic int32_t
57177059Semaxpanu_profile_create_bluetooth_profile_descriptor_list(
58177059Semax		uint8_t *buf, uint8_t const * const eob,
59177059Semax		uint8_t const *data, uint32_t datalen)
60177059Semax{
61177059Semax	static uint16_t	profile_descriptor_list[] = {
62177059Semax		SDP_SERVICE_CLASS_PANU,
63177059Semax		0x0100
64177059Semax	};
65177059Semax
66177059Semax	return (common_profile_create_bluetooth_profile_descriptor_list(
67177059Semax			buf, eob,
68177059Semax			(uint8_t const *) profile_descriptor_list,
69177059Semax			sizeof(profile_descriptor_list)));
70177059Semax}
71177059Semax
72177059Semaxstatic int32_t
73177059Semaxpanu_profile_create_service_name(
74177059Semax		uint8_t *buf, uint8_t const * const eob,
75177059Semax		uint8_t const *data, uint32_t datalen)
76177059Semax{
77177059Semax	static char	service_name[] = "Personal Ad-hoc User Service";
78177059Semax
79177059Semax	return (common_profile_create_string8(
80177059Semax			buf, eob,
81177059Semax			(uint8_t const *) service_name, strlen(service_name)));
82177059Semax}
83177059Semax
84177059Semaxstatic int32_t
85177059Semaxpanu_profile_create_service_description(
86177059Semax		uint8_t *buf, uint8_t const * const eob,
87177059Semax		uint8_t const *data, uint32_t datalen)
88177059Semax{
89177059Semax	static char	service_descr[] =
90177059Semax				"Personal Ad-hoc User Service";
91177059Semax
92177059Semax	return (common_profile_create_string8(
93177059Semax			buf, eob,
94177059Semax			(uint8_t const *) service_descr,
95177059Semax			strlen(service_descr)));
96177059Semax}
97177059Semax
98177059Semaxstatic int32_t
99177059Semaxpanu_profile_create_protocol_descriptor_list(
100177059Semax		uint8_t *buf, uint8_t const * const eob,
101177059Semax		uint8_t const *data, uint32_t datalen)
102177059Semax{
103177358Semax	provider_p		provider = (provider_p) data;
104177358Semax	sdp_panu_profile_p	panu = (sdp_panu_profile_p) provider->data;
105177358Semax
106177059Semax	return (bnep_profile_create_protocol_descriptor_list(
107177358Semax			buf, eob, (uint8_t const *) &panu->psm,
108177358Semax			sizeof(panu->psm)));
109177059Semax}
110177059Semax
111177358Semaxstatic int32_t
112177358Semaxpanu_profile_data_valid(uint8_t const *data, uint32_t datalen)
113177358Semax{
114177358Semax	sdp_panu_profile_p	panu = (sdp_panu_profile_p) data;
115177358Semax
116177358Semax	return ((panu->psm == 0)? 0 : 1);
117177358Semax}
118177358Semax
119177358Semaxstatic int32_t
120177358Semaxpanu_profile_create_service_availability(
121177358Semax		uint8_t *buf, uint8_t const * const eob,
122177358Semax		uint8_t const *data, uint32_t datalen)
123177358Semax{
124177358Semax	provider_p		provider = (provider_p) data;
125177358Semax	sdp_panu_profile_p	panu = (sdp_panu_profile_p) provider->data;
126177358Semax
127177358Semax	return (common_profile_create_service_availability( buf, eob,
128177358Semax			&panu->load_factor, 1));
129177358Semax}
130177358Semax
131177364Semaxstatic int32_t
132177364Semaxpanu_profile_create_security_description(
133177364Semax		uint8_t *buf, uint8_t const * const eob,
134177364Semax		uint8_t const *data, uint32_t datalen)
135177364Semax{
136177364Semax	provider_p		provider = (provider_p) data;
137177364Semax	sdp_panu_profile_p	panu = (sdp_panu_profile_p) provider->data;
138177364Semax
139177364Semax	return (bnep_profile_create_security_description(buf, eob,
140177364Semax			(uint8_t const *) &panu->security_description,
141177364Semax			sizeof(panu->security_description)));
142177364Semax}
143177364Semax
144177059Semaxstatic attr_t	panu_profile_attrs[] = {
145177059Semax	{ SDP_ATTR_SERVICE_RECORD_HANDLE,
146177059Semax	  common_profile_create_service_record_handle },
147177059Semax	{ SDP_ATTR_SERVICE_CLASS_ID_LIST,
148177059Semax	  panu_profile_create_service_class_id_list },
149177059Semax	{ SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
150177059Semax	  panu_profile_create_protocol_descriptor_list },
151177059Semax	{ SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST,
152177059Semax	  common_profile_create_language_base_attribute_id_list },
153177358Semax	{ SDP_ATTR_SERVICE_AVAILABILITY,
154177358Semax	  panu_profile_create_service_availability },
155177059Semax	{ SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
156177059Semax	  panu_profile_create_bluetooth_profile_descriptor_list },
157177059Semax	{ SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET,
158177059Semax	  panu_profile_create_service_name },
159177059Semax	{ SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET,
160177059Semax	  panu_profile_create_service_description },
161177364Semax	{ SDP_ATTR_SECURITY_DESCRIPTION,
162177364Semax	  panu_profile_create_security_description },
163177059Semax	{ 0, NULL } /* end entry */
164177059Semax};
165177059Semax
166177059Semaxprofile_t	panu_profile_descriptor = {
167177059Semax	SDP_SERVICE_CLASS_PANU,
168177059Semax	sizeof(sdp_panu_profile_t),
169177358Semax	panu_profile_data_valid,
170177059Semax	(attr_t const * const) &panu_profile_attrs
171177059Semax};
172177059Semax
173