1f2505d70SMaksim Yevmenkin /* 2f2505d70SMaksim Yevmenkin * gn.c 3f2505d70SMaksim Yevmenkin */ 4f2505d70SMaksim Yevmenkin 5f2505d70SMaksim Yevmenkin /*- 6f2505d70SMaksim Yevmenkin * Copyright (c) 2008 Maksim Yevmenkin <m_evmenkin@yahoo.com> 7f2505d70SMaksim Yevmenkin * All rights reserved. 8f2505d70SMaksim Yevmenkin * 9f2505d70SMaksim Yevmenkin * Redistribution and use in source and binary forms, with or without 10f2505d70SMaksim Yevmenkin * modification, are permitted provided that the following conditions 11f2505d70SMaksim Yevmenkin * are met: 12f2505d70SMaksim Yevmenkin * 1. Redistributions of source code must retain the above copyright 13f2505d70SMaksim Yevmenkin * notice, this list of conditions and the following disclaimer. 14f2505d70SMaksim Yevmenkin * 2. Redistributions in binary form must reproduce the above copyright 15f2505d70SMaksim Yevmenkin * notice, this list of conditions and the following disclaimer in the 16f2505d70SMaksim Yevmenkin * documentation and/or other materials provided with the distribution. 17f2505d70SMaksim Yevmenkin * 18f2505d70SMaksim Yevmenkin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19f2505d70SMaksim Yevmenkin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20f2505d70SMaksim Yevmenkin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21f2505d70SMaksim Yevmenkin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22f2505d70SMaksim Yevmenkin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23f2505d70SMaksim Yevmenkin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24f2505d70SMaksim Yevmenkin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25f2505d70SMaksim Yevmenkin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26f2505d70SMaksim Yevmenkin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27f2505d70SMaksim Yevmenkin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28f2505d70SMaksim Yevmenkin * SUCH DAMAGE. 29f2505d70SMaksim Yevmenkin * 30f2505d70SMaksim Yevmenkin * $Id: gn.c,v 1.1 2008/03/11 00:02:42 max Exp $ 31f2505d70SMaksim Yevmenkin * $FreeBSD$ 32f2505d70SMaksim Yevmenkin */ 33f2505d70SMaksim Yevmenkin 34f2505d70SMaksim Yevmenkin #include <sys/queue.h> 35f2505d70SMaksim Yevmenkin #include <bluetooth.h> 36f2505d70SMaksim Yevmenkin #include <sdp.h> 37f2505d70SMaksim Yevmenkin #include <string.h> 38f2505d70SMaksim Yevmenkin #include "profile.h" 39f2505d70SMaksim Yevmenkin #include "provider.h" 40f2505d70SMaksim Yevmenkin 41f2505d70SMaksim Yevmenkin static int32_t 42f2505d70SMaksim Yevmenkin gn_profile_create_service_class_id_list( 43f2505d70SMaksim Yevmenkin uint8_t *buf, uint8_t const * const eob, 44f2505d70SMaksim Yevmenkin uint8_t const *data, uint32_t datalen) 45f2505d70SMaksim Yevmenkin { 46f2505d70SMaksim Yevmenkin static uint16_t service_classes[] = { 47f2505d70SMaksim Yevmenkin SDP_SERVICE_CLASS_GN 48f2505d70SMaksim Yevmenkin }; 49f2505d70SMaksim Yevmenkin 50f2505d70SMaksim Yevmenkin return (common_profile_create_service_class_id_list( 51f2505d70SMaksim Yevmenkin buf, eob, 52f2505d70SMaksim Yevmenkin (uint8_t const *) service_classes, 53f2505d70SMaksim Yevmenkin sizeof(service_classes))); 54f2505d70SMaksim Yevmenkin } 55f2505d70SMaksim Yevmenkin 56f2505d70SMaksim Yevmenkin static int32_t 57f2505d70SMaksim Yevmenkin gn_profile_create_bluetooth_profile_descriptor_list( 58f2505d70SMaksim Yevmenkin uint8_t *buf, uint8_t const * const eob, 59f2505d70SMaksim Yevmenkin uint8_t const *data, uint32_t datalen) 60f2505d70SMaksim Yevmenkin { 61f2505d70SMaksim Yevmenkin static uint16_t profile_descriptor_list[] = { 62f2505d70SMaksim Yevmenkin SDP_SERVICE_CLASS_GN, 63f2505d70SMaksim Yevmenkin 0x0100 64f2505d70SMaksim Yevmenkin }; 65f2505d70SMaksim Yevmenkin 66f2505d70SMaksim Yevmenkin return (common_profile_create_bluetooth_profile_descriptor_list( 67f2505d70SMaksim Yevmenkin buf, eob, 68f2505d70SMaksim Yevmenkin (uint8_t const *) profile_descriptor_list, 69f2505d70SMaksim Yevmenkin sizeof(profile_descriptor_list))); 70f2505d70SMaksim Yevmenkin } 71f2505d70SMaksim Yevmenkin 72f2505d70SMaksim Yevmenkin static int32_t 73f2505d70SMaksim Yevmenkin gn_profile_create_service_name( 74f2505d70SMaksim Yevmenkin uint8_t *buf, uint8_t const * const eob, 75f2505d70SMaksim Yevmenkin uint8_t const *data, uint32_t datalen) 76f2505d70SMaksim Yevmenkin { 77f2505d70SMaksim Yevmenkin static char service_name[] = "Group Ad-hoc Network"; 78f2505d70SMaksim Yevmenkin 79f2505d70SMaksim Yevmenkin return (common_profile_create_string8( 80f2505d70SMaksim Yevmenkin buf, eob, 81f2505d70SMaksim Yevmenkin (uint8_t const *) service_name, strlen(service_name))); 82f2505d70SMaksim Yevmenkin } 83f2505d70SMaksim Yevmenkin 84f2505d70SMaksim Yevmenkin static int32_t 85f2505d70SMaksim Yevmenkin gn_profile_create_service_description( 86f2505d70SMaksim Yevmenkin uint8_t *buf, uint8_t const * const eob, 87f2505d70SMaksim Yevmenkin uint8_t const *data, uint32_t datalen) 88f2505d70SMaksim Yevmenkin { 89f2505d70SMaksim Yevmenkin static char service_descr[] = 90f2505d70SMaksim Yevmenkin "Personal Group Ad-hoc Network Service"; 91f2505d70SMaksim Yevmenkin 92f2505d70SMaksim Yevmenkin return (common_profile_create_string8( 93f2505d70SMaksim Yevmenkin buf, eob, 94f2505d70SMaksim Yevmenkin (uint8_t const *) service_descr, 95f2505d70SMaksim Yevmenkin strlen(service_descr))); 96f2505d70SMaksim Yevmenkin } 97f2505d70SMaksim Yevmenkin 98f2505d70SMaksim Yevmenkin static int32_t 99f2505d70SMaksim Yevmenkin gn_profile_create_protocol_descriptor_list( 100f2505d70SMaksim Yevmenkin uint8_t *buf, uint8_t const * const eob, 101f2505d70SMaksim Yevmenkin uint8_t const *data, uint32_t datalen) 102f2505d70SMaksim Yevmenkin { 103f2505d70SMaksim Yevmenkin return (bnep_profile_create_protocol_descriptor_list( 104f2505d70SMaksim Yevmenkin buf, eob, NULL, 0)); 105f2505d70SMaksim Yevmenkin } 106f2505d70SMaksim Yevmenkin 107f2505d70SMaksim Yevmenkin static int32_t 108f2505d70SMaksim Yevmenkin gn_profile_create_security_description( 109f2505d70SMaksim Yevmenkin uint8_t *buf, uint8_t const * const eob, 110f2505d70SMaksim Yevmenkin uint8_t const *data, uint32_t datalen) 111f2505d70SMaksim Yevmenkin { 112f2505d70SMaksim Yevmenkin provider_p provider = (provider_p) data; 113f2505d70SMaksim Yevmenkin sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; 114f2505d70SMaksim Yevmenkin 115f2505d70SMaksim Yevmenkin return (bnep_profile_create_security_description(buf, eob, 116f2505d70SMaksim Yevmenkin (uint8_t const *) &gn->security_description, 117f2505d70SMaksim Yevmenkin sizeof(gn->security_description))); 118f2505d70SMaksim Yevmenkin } 119f2505d70SMaksim Yevmenkin 120f2505d70SMaksim Yevmenkin static attr_t gn_profile_attrs[] = { 121f2505d70SMaksim Yevmenkin { SDP_ATTR_SERVICE_RECORD_HANDLE, 122f2505d70SMaksim Yevmenkin common_profile_create_service_record_handle }, 123f2505d70SMaksim Yevmenkin { SDP_ATTR_SERVICE_CLASS_ID_LIST, 124f2505d70SMaksim Yevmenkin gn_profile_create_service_class_id_list }, 125f2505d70SMaksim Yevmenkin { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, 126f2505d70SMaksim Yevmenkin gn_profile_create_protocol_descriptor_list }, 127f2505d70SMaksim Yevmenkin { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, 128f2505d70SMaksim Yevmenkin common_profile_create_language_base_attribute_id_list }, 129f2505d70SMaksim Yevmenkin { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, 130f2505d70SMaksim Yevmenkin gn_profile_create_bluetooth_profile_descriptor_list }, 131f2505d70SMaksim Yevmenkin { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, 132f2505d70SMaksim Yevmenkin gn_profile_create_service_name }, 133f2505d70SMaksim Yevmenkin { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, 134f2505d70SMaksim Yevmenkin gn_profile_create_service_description }, 135f2505d70SMaksim Yevmenkin { SDP_ATTR_SECURITY_DESCRIPTION, 136f2505d70SMaksim Yevmenkin gn_profile_create_security_description }, 137f2505d70SMaksim Yevmenkin { 0, NULL } /* end entry */ 138f2505d70SMaksim Yevmenkin }; 139f2505d70SMaksim Yevmenkin 140f2505d70SMaksim Yevmenkin profile_t gn_profile_descriptor = { 141f2505d70SMaksim Yevmenkin SDP_SERVICE_CLASS_GN, 142f2505d70SMaksim Yevmenkin sizeof(sdp_gn_profile_t), 143f2505d70SMaksim Yevmenkin common_profile_always_valid, 144f2505d70SMaksim Yevmenkin (attr_t const * const) &gn_profile_attrs 145f2505d70SMaksim Yevmenkin }; 146f2505d70SMaksim Yevmenkin 147