1177059Semax/* 2177059Semax * gn.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: gn.c,v 1.1 2008/03/11 00:02:42 max Exp $ 31177059Semax * $FreeBSD: releng/11.0/usr.sbin/bluetooth/sdpd/gn.c 281210 2015-04-07 16:48:23Z takawata $ 32177059Semax */ 33177059Semax 34177059Semax#include <sys/queue.h> 35281210Stakawata#define L2CAP_SOCKET_CHECKED 36177059Semax#include <bluetooth.h> 37177059Semax#include <sdp.h> 38177059Semax#include <string.h> 39177059Semax#include "profile.h" 40177059Semax#include "provider.h" 41177059Semax 42177059Semaxstatic int32_t 43177059Semaxgn_profile_create_service_class_id_list( 44177059Semax uint8_t *buf, uint8_t const * const eob, 45177059Semax uint8_t const *data, uint32_t datalen) 46177059Semax{ 47177059Semax static uint16_t service_classes[] = { 48177059Semax SDP_SERVICE_CLASS_GN 49177059Semax }; 50177059Semax 51177059Semax return (common_profile_create_service_class_id_list( 52177059Semax buf, eob, 53177059Semax (uint8_t const *) service_classes, 54177059Semax sizeof(service_classes))); 55177059Semax} 56177059Semax 57177059Semaxstatic int32_t 58177059Semaxgn_profile_create_bluetooth_profile_descriptor_list( 59177059Semax uint8_t *buf, uint8_t const * const eob, 60177059Semax uint8_t const *data, uint32_t datalen) 61177059Semax{ 62177059Semax static uint16_t profile_descriptor_list[] = { 63177059Semax SDP_SERVICE_CLASS_GN, 64177059Semax 0x0100 65177059Semax }; 66177059Semax 67177059Semax return (common_profile_create_bluetooth_profile_descriptor_list( 68177059Semax buf, eob, 69177059Semax (uint8_t const *) profile_descriptor_list, 70177059Semax sizeof(profile_descriptor_list))); 71177059Semax} 72177059Semax 73177059Semaxstatic int32_t 74177059Semaxgn_profile_create_service_name( 75177059Semax uint8_t *buf, uint8_t const * const eob, 76177059Semax uint8_t const *data, uint32_t datalen) 77177059Semax{ 78177059Semax static char service_name[] = "Group Ad-hoc Network"; 79177059Semax 80177059Semax return (common_profile_create_string8( 81177059Semax buf, eob, 82177059Semax (uint8_t const *) service_name, strlen(service_name))); 83177059Semax} 84177059Semax 85177059Semaxstatic int32_t 86177059Semaxgn_profile_create_service_description( 87177059Semax uint8_t *buf, uint8_t const * const eob, 88177059Semax uint8_t const *data, uint32_t datalen) 89177059Semax{ 90177059Semax static char service_descr[] = 91177059Semax "Personal Group Ad-hoc Network Service"; 92177059Semax 93177059Semax return (common_profile_create_string8( 94177059Semax buf, eob, 95177059Semax (uint8_t const *) service_descr, 96177059Semax strlen(service_descr))); 97177059Semax} 98177059Semax 99177059Semaxstatic int32_t 100177059Semaxgn_profile_create_protocol_descriptor_list( 101177059Semax uint8_t *buf, uint8_t const * const eob, 102177059Semax uint8_t const *data, uint32_t datalen) 103177059Semax{ 104177358Semax provider_p provider = (provider_p) data; 105177358Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 106177358Semax 107177059Semax return (bnep_profile_create_protocol_descriptor_list( 108177358Semax buf, eob, (uint8_t const *) &gn->psm, 109177358Semax sizeof(gn->psm))); 110177059Semax} 111177059Semax 112177059Semaxstatic int32_t 113177059Semaxgn_profile_create_security_description( 114177059Semax uint8_t *buf, uint8_t const * const eob, 115177059Semax uint8_t const *data, uint32_t datalen) 116177059Semax{ 117177059Semax provider_p provider = (provider_p) data; 118177059Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 119177059Semax 120177059Semax return (bnep_profile_create_security_description(buf, eob, 121177059Semax (uint8_t const *) &gn->security_description, 122177059Semax sizeof(gn->security_description))); 123177059Semax} 124177059Semax 125177358Semaxstatic int32_t 126177358Semaxgn_profile_create_service_availability( 127177358Semax uint8_t *buf, uint8_t const * const eob, 128177358Semax uint8_t const *data, uint32_t datalen) 129177358Semax{ 130177358Semax provider_p provider = (provider_p) data; 131177358Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 132177358Semax 133177358Semax return (common_profile_create_service_availability(buf, eob, 134177358Semax &gn->load_factor, 1)); 135177358Semax} 136177358Semax 137177358Semaxstatic int32_t 138177358Semaxgn_profile_data_valid(uint8_t const *data, uint32_t datalen) 139177358Semax{ 140177358Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) data; 141177358Semax 142177358Semax return ((gn->psm == 0)? 0 : 1); 143177358Semax} 144177358Semax 145177059Semaxstatic attr_t gn_profile_attrs[] = { 146177059Semax { SDP_ATTR_SERVICE_RECORD_HANDLE, 147177059Semax common_profile_create_service_record_handle }, 148177059Semax { SDP_ATTR_SERVICE_CLASS_ID_LIST, 149177059Semax gn_profile_create_service_class_id_list }, 150177059Semax { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, 151177059Semax gn_profile_create_protocol_descriptor_list }, 152177059Semax { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, 153177059Semax common_profile_create_language_base_attribute_id_list }, 154177358Semax { SDP_ATTR_SERVICE_AVAILABILITY, 155177358Semax gn_profile_create_service_availability }, 156177059Semax { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, 157177059Semax gn_profile_create_bluetooth_profile_descriptor_list }, 158177059Semax { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, 159177059Semax gn_profile_create_service_name }, 160177059Semax { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, 161177059Semax gn_profile_create_service_description }, 162177059Semax { SDP_ATTR_SECURITY_DESCRIPTION, 163177059Semax gn_profile_create_security_description }, 164177059Semax { 0, NULL } /* end entry */ 165177059Semax}; 166177059Semax 167177059Semaxprofile_t gn_profile_descriptor = { 168177059Semax SDP_SERVICE_CLASS_GN, 169177059Semax sizeof(sdp_gn_profile_t), 170177358Semax gn_profile_data_valid, 171177059Semax (attr_t const * const) &gn_profile_attrs 172177059Semax}; 173177059Semax 174