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$ 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 42177059Semaxgn_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_GN 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 57177059Semaxgn_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_GN, 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 73177059Semaxgn_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[] = "Group Ad-hoc Network"; 78177059Semax 79177059Semax return (common_profile_create_string8( 80177059Semax buf, eob, 81177059Semax (uint8_t const *) service_name, strlen(service_name))); 82177059Semax} 83177059Semax 84177059Semaxstatic int32_t 85177059Semaxgn_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 Group Ad-hoc Network 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 99177059Semaxgn_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_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 105177358Semax 106177059Semax return (bnep_profile_create_protocol_descriptor_list( 107177358Semax buf, eob, (uint8_t const *) &gn->psm, 108177358Semax sizeof(gn->psm))); 109177059Semax} 110177059Semax 111177059Semaxstatic int32_t 112177059Semaxgn_profile_create_security_description( 113177059Semax uint8_t *buf, uint8_t const * const eob, 114177059Semax uint8_t const *data, uint32_t datalen) 115177059Semax{ 116177059Semax provider_p provider = (provider_p) data; 117177059Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 118177059Semax 119177059Semax return (bnep_profile_create_security_description(buf, eob, 120177059Semax (uint8_t const *) &gn->security_description, 121177059Semax sizeof(gn->security_description))); 122177059Semax} 123177059Semax 124177358Semaxstatic int32_t 125177358Semaxgn_profile_create_service_availability( 126177358Semax uint8_t *buf, uint8_t const * const eob, 127177358Semax uint8_t const *data, uint32_t datalen) 128177358Semax{ 129177358Semax provider_p provider = (provider_p) data; 130177358Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 131177358Semax 132177358Semax return (common_profile_create_service_availability(buf, eob, 133177358Semax &gn->load_factor, 1)); 134177358Semax} 135177358Semax 136177358Semaxstatic int32_t 137177358Semaxgn_profile_data_valid(uint8_t const *data, uint32_t datalen) 138177358Semax{ 139177358Semax sdp_gn_profile_p gn = (sdp_gn_profile_p) data; 140177358Semax 141177358Semax return ((gn->psm == 0)? 0 : 1); 142177358Semax} 143177358Semax 144177059Semaxstatic attr_t gn_profile_attrs[] = { 145177059Semax { SDP_ATTR_SERVICE_RECORD_HANDLE, 146177059Semax common_profile_create_service_record_handle }, 147177059Semax { SDP_ATTR_SERVICE_CLASS_ID_LIST, 148177059Semax gn_profile_create_service_class_id_list }, 149177059Semax { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, 150177059Semax gn_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 gn_profile_create_service_availability }, 155177059Semax { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, 156177059Semax gn_profile_create_bluetooth_profile_descriptor_list }, 157177059Semax { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, 158177059Semax gn_profile_create_service_name }, 159177059Semax { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, 160177059Semax gn_profile_create_service_description }, 161177059Semax { SDP_ATTR_SECURITY_DESCRIPTION, 162177059Semax gn_profile_create_security_description }, 163177059Semax { 0, NULL } /* end entry */ 164177059Semax}; 165177059Semax 166177059Semaxprofile_t gn_profile_descriptor = { 167177059Semax SDP_SERVICE_CLASS_GN, 168177059Semax sizeof(sdp_gn_profile_t), 169177358Semax gn_profile_data_valid, 170177059Semax (attr_t const * const) &gn_profile_attrs 171177059Semax}; 172177059Semax 173