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