Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #pragma once
     18 
     19 #include "bluetooth.h"
     20 
     21 #define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15
     22 
     23 __BEGIN_DECLS
     24 
     25 /**
     26  * These events are handled by the state machine
     27  */
     28 typedef enum {
     29   SDP_TYPE_RAW,         // Used to carry raw SDP search data for unknown UUIDs
     30   SDP_TYPE_MAP_MAS,     // Message Access Profile - Server
     31   SDP_TYPE_MAP_MNS,     // Message Access Profile - Client (Notification Server)
     32   SDP_TYPE_PBAP_PSE,    // Phone Book Profile - Server
     33   SDP_TYPE_PBAP_PCE,    // Phone Book Profile - Client
     34   SDP_TYPE_OPP_SERVER,  // Object Push Profile
     35   SDP_TYPE_SAP_SERVER   // SIM Access Profile
     36 } bluetooth_sdp_types;
     37 
     38 typedef struct _bluetooth_sdp_hdr {
     39   bluetooth_sdp_types type;
     40   bluetooth::Uuid uuid;
     41   uint32_t service_name_length;
     42   char* service_name;
     43   int32_t rfcomm_channel_number;
     44   int32_t l2cap_psm;
     45   int32_t profile_version;
     46 } bluetooth_sdp_hdr;
     47 
     48 /**
     49  * Some signals need additional pointers, hence we introduce a
     50  * generic way to handle these pointers.
     51  */
     52 typedef struct _bluetooth_sdp_hdr_overlay {
     53   bluetooth_sdp_types type;
     54   bluetooth::Uuid uuid;
     55   uint32_t service_name_length;
     56   char* service_name;
     57   int32_t rfcomm_channel_number;
     58   int32_t l2cap_psm;
     59   int32_t profile_version;
     60 
     61   // User pointers, only used for some signals - see bluetooth_sdp_ops_record
     62   int user1_ptr_len;
     63   uint8_t* user1_ptr;
     64   int user2_ptr_len;
     65   uint8_t* user2_ptr;
     66 } bluetooth_sdp_hdr_overlay;
     67 
     68 typedef struct _bluetooth_sdp_mas_record {
     69   bluetooth_sdp_hdr_overlay hdr;
     70   uint32_t mas_instance_id;
     71   uint32_t supported_features;
     72   uint32_t supported_message_types;
     73 } bluetooth_sdp_mas_record;
     74 
     75 typedef struct _bluetooth_sdp_mns_record {
     76   bluetooth_sdp_hdr_overlay hdr;
     77   uint32_t supported_features;
     78 } bluetooth_sdp_mns_record;
     79 
     80 typedef struct _bluetooth_sdp_pse_record {
     81   bluetooth_sdp_hdr_overlay hdr;
     82   uint32_t supported_features;
     83   uint32_t supported_repositories;
     84 } bluetooth_sdp_pse_record;
     85 
     86 typedef struct _bluetooth_sdp_pce_record {
     87   bluetooth_sdp_hdr_overlay hdr;
     88 } bluetooth_sdp_pce_record;
     89 
     90 typedef struct _bluetooth_sdp_ops_record {
     91   bluetooth_sdp_hdr_overlay hdr;
     92   int supported_formats_list_len;
     93   uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
     94 } bluetooth_sdp_ops_record;
     95 
     96 typedef struct _bluetooth_sdp_sap_record {
     97   bluetooth_sdp_hdr_overlay hdr;
     98 } bluetooth_sdp_sap_record;
     99 
    100 typedef union {
    101   bluetooth_sdp_hdr_overlay hdr;
    102   bluetooth_sdp_mas_record mas;
    103   bluetooth_sdp_mns_record mns;
    104   bluetooth_sdp_pse_record pse;
    105   bluetooth_sdp_pce_record pce;
    106   bluetooth_sdp_ops_record ops;
    107   bluetooth_sdp_sap_record sap;
    108 } bluetooth_sdp_record;
    109 
    110 /** Callback for SDP search */
    111 typedef void (*btsdp_search_callback)(bt_status_t status,
    112                                       const RawAddress& bd_addr,
    113                                       const bluetooth::Uuid& uuid,
    114                                       int num_records,
    115                                       bluetooth_sdp_record* records);
    116 
    117 typedef struct {
    118   /** Set to sizeof(btsdp_callbacks_t) */
    119   size_t size;
    120   btsdp_search_callback sdp_search_cb;
    121 } btsdp_callbacks_t;
    122 
    123 typedef struct {
    124   /** Set to size of this struct */
    125   size_t size;
    126 
    127   /** Register BT SDP search callbacks */
    128   bt_status_t (*init)(btsdp_callbacks_t* callbacks);
    129 
    130   /** Unregister BT SDP */
    131   bt_status_t (*deinit)();
    132 
    133   /** Search for SDP records with specific uuid on remote device */
    134   bt_status_t (*sdp_search)(RawAddress* bd_addr, const bluetooth::Uuid& uuid);
    135 
    136   /**
    137    * Use listen in the socket interface to create rfcomm and/or l2cap PSM
    138    * channels, (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP
    139    * flag in flags). Then use createSdpRecord to create the SDP record
    140    * associated with the rfcomm/l2cap channels.
    141    *
    142    * Returns a handle to the SDP record, which can be parsed to
    143    * remove_sdp_record.
    144    *
    145    * record           (in) The SDP record to create
    146    * record_handle    (out)The corresponding record handle will be written to
    147    * this pointer.
    148    */
    149   bt_status_t (*create_sdp_record)(bluetooth_sdp_record* record,
    150                                    int* record_handle);
    151 
    152   /** Remove a SDP record created by createSdpRecord */
    153   bt_status_t (*remove_sdp_record)(int sdp_handle);
    154 } btsdp_interface_t;
    155 
    156 __END_DECLS
    157