Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2012 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 __BEGIN_DECLS
     20 
     21 #define BTSOCK_FLAG_ENCRYPT 1
     22 #define BTSOCK_FLAG_AUTH (1 << 1)
     23 #define BTSOCK_FLAG_NO_SDP (1 << 2)
     24 #define BTSOCK_FLAG_AUTH_MITM (1 << 3)
     25 #define BTSOCK_FLAG_AUTH_16_DIGIT (1 << 4)
     26 #define BTSOCK_FLAG_LE_COC (1 << 5)
     27 
     28 typedef enum {
     29   BTSOCK_RFCOMM = 1,
     30   BTSOCK_SCO = 2,
     31   BTSOCK_L2CAP = 3,
     32   BTSOCK_L2CAP_LE = 4
     33 } btsock_type_t;
     34 
     35 /** Represents the standard BT SOCKET interface. */
     36 typedef struct {
     37   short size;
     38   RawAddress bd_addr;
     39   int channel;
     40   int status;
     41 
     42   // The writer must make writes using a buffer of this maximum size
     43   // to avoid loosing data. (L2CAP only)
     44   unsigned short max_tx_packet_size;
     45 
     46   // The reader must read using a buffer of at least this size to avoid
     47   // loosing data. (L2CAP only)
     48   unsigned short max_rx_packet_size;
     49 } __attribute__((packed)) sock_connect_signal_t;
     50 
     51 typedef struct {
     52   /** set to size of this struct*/
     53   size_t size;
     54 
     55   /**
     56    * Listen to a RFCOMM UUID or channel. It returns the socket fd from which
     57    * btsock_connect_signal can be read out when a remote device connected.
     58    * If neither a UUID nor a channel is provided, a channel will be allocated
     59    * and a service record can be created providing the channel number to
     60    * create_sdp_record(...) in bt_sdp.
     61    * The callingUid is the UID of the application which is requesting the
     62    * socket. This is used for traffic accounting purposes.
     63    */
     64   bt_status_t (*listen)(btsock_type_t type, const char* service_name,
     65                         const bluetooth::Uuid* service_uuid, int channel,
     66                         int* sock_fd, int flags, int callingUid);
     67 
     68   /**
     69    * Connect to a RFCOMM UUID channel of remote device, It returns the socket fd
     70    * from which the btsock_connect_signal and a new socket fd to be accepted can
     71    * be read out when connected. The callingUid is the UID of the application
     72    * which is requesting the socket. This is used for traffic accounting
     73    * purposes.
     74    */
     75   bt_status_t (*connect)(const RawAddress* bd_addr, btsock_type_t type,
     76                          const bluetooth::Uuid* uuid, int channel, int* sock_fd,
     77                          int flags, int callingUid);
     78 
     79   /**
     80    * Set the LE Data Length value to this connected peer to the
     81    * maximum supported by this BT controller. This command
     82    * suggests to the BT controller to set its maximum transmission
     83    * packet size.
     84    */
     85   void (*request_max_tx_data_length)(const RawAddress& bd_addr);
     86 
     87 } btsock_interface_t;
     88 
     89 __END_DECLS
     90