159078Smdodd/*
259078Smdodd * dun.c
359078Smdodd *
432801Sjulian * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
559078Smdodd * All rights reserved.
659078Smdodd *
759078Smdodd * Redistribution and use in source and binary forms, with or without
832801Sjulian * modification, are permitted provided that the following conditions
932801Sjulian * are met:
1032801Sjulian * 1. Redistributions of source code must retain the above copyright
1132801Sjulian *    notice, this list of conditions and the following disclaimer.
1259078Smdodd * 2. Redistributions in binary form must reproduce the above copyright
1332801Sjulian *    notice, this list of conditions and the following disclaimer in the
1432801Sjulian *    documentation and/or other materials provided with the distribution.
1532801Sjulian *
1632801Sjulian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1732801Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1832801Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1932801Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2059078Smdodd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2159078Smdodd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2232801Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2332801Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2432801Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2532801Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2632801Sjulian * SUCH DAMAGE.
2732801Sjulian *
2832801Sjulian * $Id: dun.c,v 1.5 2004/01/13 01:54:39 max Exp $
2932801Sjulian * $FreeBSD: releng/10.2/usr.sbin/bluetooth/sdpd/dun.c 124758 2004-01-20 20:48:26Z emax $
30119418Sobrien */
31119418Sobrien
32119418Sobrien#include <sys/queue.h>
3332801Sjulian#include <bluetooth.h>
3432801Sjulian#include <sdp.h>
3532801Sjulian#include <string.h>
3659078Smdodd#include "profile.h"
37117126Sscottl#include "provider.h"
38117126Sscottl
3959078Smdoddstatic int32_t
4032801Sjuliandun_profile_create_service_class_id_list(
4139234Sgibbs		uint8_t *buf, uint8_t const * const eob,
4259078Smdodd		uint8_t const *data, uint32_t datalen)
4359078Smdodd{
4439234Sgibbs	static uint16_t	service_classes[] = {
45119277Simp		SDP_SERVICE_CLASS_DIALUP_NETWORKING
46119277Simp	};
4759078Smdodd
4839234Sgibbs	return (common_profile_create_service_class_id_list(
4939234Sgibbs			buf, eob,
5039234Sgibbs			(uint8_t const *) service_classes,
5132801Sjulian			sizeof(service_classes)));
5259078Smdodd}
5359078Smdodd
5432801Sjulianstatic int32_t
55119690Sjhbdun_profile_create_bluetooth_profile_descriptor_list(
56119690Sjhb		uint8_t *buf, uint8_t const * const eob,
5732801Sjulian		uint8_t const *data, uint32_t datalen)
5859078Smdodd{
5932801Sjulian	static uint16_t	profile_descriptor_list[] = {
6059078Smdodd		SDP_SERVICE_CLASS_DIALUP_NETWORKING,
6159078Smdodd		0x0100
6232801Sjulian	};
6359078Smdodd
6459078Smdodd	return (common_profile_create_bluetooth_profile_descriptor_list(
6559078Smdodd			buf, eob,
6659078Smdodd			(uint8_t const *) profile_descriptor_list,
6759078Smdodd			sizeof(profile_descriptor_list)));
6859078Smdodd}
69143161Simp
7059078Smdoddstatic int32_t
7159078Smdodddun_profile_create_service_name(
7259078Smdodd		uint8_t *buf, uint8_t const * const eob,
7332801Sjulian		uint8_t const *data, uint32_t datalen)
7459078Smdodd{
7559078Smdodd	static char	service_name[] = "DialUp networking";
7632801Sjulian
7759078Smdodd	return (common_profile_create_string8(
7859078Smdodd			buf, eob,
7932801Sjulian			(uint8_t const *) service_name, strlen(service_name)));
80112780Smdodd}
81170872Sscottl
82241593Sjhbstatic int32_t
83112780Smdodddun_profile_create_protocol_descriptor_list(
8459078Smdodd		uint8_t *buf, uint8_t const * const eob,
85254263Sscottl		uint8_t const *data, uint32_t datalen)
86254263Sscottl{
87254263Sscottl	provider_p		provider = (provider_p) data;
88254263Sscottl	sdp_dun_profile_p	dun = (sdp_dun_profile_p) provider->data;
8932801Sjulian
90254263Sscottl	return (rfcomm_profile_create_protocol_descriptor_list(
91112780Smdodd			buf, eob,
92112780Smdodd			(uint8_t const *) &dun->server_channel, 1));
93127135Snjl}
94127135Snjl
9559078Smdoddstatic int32_t
9632801Sjuliandun_profile_create_audio_feedback_support(
97112780Smdodd		uint8_t *buf, uint8_t const * const eob,
9859078Smdodd		uint8_t const *data, uint32_t datalen)
9959078Smdodd{
10059078Smdodd	provider_p		provider = (provider_p) data;
10159078Smdodd	sdp_dun_profile_p	dun = (sdp_dun_profile_p) provider->data;
102112780Smdodd
10332801Sjulian	if (buf + 2 > eob)
104112780Smdodd		return (-1);
105127135Snjl
106127135Snjl	SDP_PUT8(SDP_DATA_BOOL, buf);
107112780Smdodd	SDP_PUT8(dun->audio_feedback_support, buf);
10859078Smdodd
10959078Smdodd	return (2);
11059078Smdodd}
11159078Smdodd
11232801Sjulianstatic attr_t	dun_profile_attrs[] = {
11359078Smdodd	{ SDP_ATTR_SERVICE_RECORD_HANDLE,
114241593Sjhb	  common_profile_create_service_record_handle },
11532801Sjulian	{ SDP_ATTR_SERVICE_CLASS_ID_LIST,
116112780Smdodd	  dun_profile_create_service_class_id_list },
11732801Sjulian	{ SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
11859078Smdodd	  dun_profile_create_bluetooth_profile_descriptor_list },
11959078Smdodd	{ SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST,
12032801Sjulian	  common_profile_create_language_base_attribute_id_list },
12159078Smdodd	{ SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET,
12259078Smdodd	  dun_profile_create_service_name },
12339234Sgibbs	{ SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
12432801Sjulian	  dun_profile_create_protocol_descriptor_list },
12539234Sgibbs	{ SDP_ATTR_AUDIO_FEEDBACK_SUPPORT,
126232854Sscottl	  dun_profile_create_audio_feedback_support },
12759078Smdodd	{ 0, NULL } /* end entry */
12859078Smdodd};
12959078Smdodd
13059078Smdoddprofile_t	dun_profile_descriptor = {
13159078Smdodd	SDP_SERVICE_CLASS_DIALUP_NETWORKING,
13259078Smdodd	sizeof(sdp_dun_profile_t),
13359078Smdodd	common_profile_server_channel_valid,
134104710Speter	(attr_t const * const) &dun_profile_attrs
13559078Smdodd};
13659078Smdodd
137241593Sjhb