The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2014 Google, Inc. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
Marie Janssen | 49120dc | 2015-07-07 16:47:20 -0700 | [diff] [blame] | 19 | #define LOG_TAG "bt_btif_sock" |
| 20 | |
Myles Watson | b793f4f | 2017-02-28 11:05:52 -0800 | [diff] [blame] | 21 | #include <atomic> |
| 22 | |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 23 | #include <base/logging.h> |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 24 | |
Jack He | 83f8683 | 2019-02-06 20:24:24 -0800 | [diff] [blame] | 25 | #include <frameworks/base/core/proto/android/bluetooth/enums.pb.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 | #include <hardware/bluetooth.h> |
| 27 | #include <hardware/bt_sock.h> |
| 28 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 29 | #include "bta_api.h" |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 30 | #include "btif_common.h" |
Jakub Pawlowski | 3118cdc | 2019-08-05 20:28:22 +0200 | [diff] [blame] | 31 | #include "btif_config.h" |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 32 | #include "btif_sock_l2cap.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 33 | #include "btif_sock_rfc.h" |
Ian McKellar | e93ac12 | 2013-11-07 16:30:05 -0800 | [diff] [blame] | 34 | #include "btif_sock_sco.h" |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 35 | #include "btif_sock_sdp.h" |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 36 | #include "btif_sock_thread.h" |
Adam Lesinski | 0620f97 | 2015-12-02 22:15:08 -0800 | [diff] [blame] | 37 | #include "btif_uid.h" |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 38 | #include "btif_util.h" |
Jack He | 83f8683 | 2019-02-06 20:24:24 -0800 | [diff] [blame] | 39 | #include "common/metrics.h" |
Stanley Tng | 70bebaf | 2018-01-22 17:08:03 -0800 | [diff] [blame] | 40 | #include "device/include/controller.h" |
Sharvil Nanavati | 0f9b91e | 2015-03-12 15:42:50 -0700 | [diff] [blame] | 41 | #include "osi/include/thread.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 43 | using bluetooth::Uuid; |
| 44 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 45 | static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 46 | const Uuid* uuid, int channel, int* sock_fd, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 47 | int flags, int app_uid); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 48 | static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 49 | const Uuid* uuid, int channel, int* sock_fd, |
| 50 | int flags, int app_uid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 51 | |
Stanley Tng | 70bebaf | 2018-01-22 17:08:03 -0800 | [diff] [blame] | 52 | static void btsock_request_max_tx_data_length(const RawAddress& bd_addr); |
| 53 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 54 | static void btsock_signaled(int fd, int type, int flags, uint32_t user_id); |
| 55 | |
Myles Watson | b793f4f | 2017-02-28 11:05:52 -0800 | [diff] [blame] | 56 | static std::atomic_int thread_handle{-1}; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 57 | static thread_t* thread; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 58 | |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 59 | const btsock_interface_t* btif_sock_get_interface(void) { |
Stanley Tng | 70bebaf | 2018-01-22 17:08:03 -0800 | [diff] [blame] | 60 | static btsock_interface_t interface = { |
| 61 | sizeof(interface), btsock_listen, /* listen */ |
| 62 | btsock_connect, /* connect */ |
| 63 | btsock_request_max_tx_data_length /* request_max_tx_data_length */ |
| 64 | }; |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 65 | |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 66 | return &interface; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Adam Lesinski | 0620f97 | 2015-12-02 22:15:08 -0800 | [diff] [blame] | 69 | bt_status_t btif_sock_init(uid_set_t* uid_set) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 70 | CHECK(thread_handle == -1); |
| 71 | CHECK(thread == NULL); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 72 | |
Jakub Pawlowski | 713993d | 2016-04-21 13:16:45 -0700 | [diff] [blame] | 73 | bt_status_t status; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 74 | btsock_thread_init(); |
| 75 | thread_handle = btsock_thread_create(btsock_signaled, NULL); |
| 76 | if (thread_handle == -1) { |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 77 | LOG_ERROR(LOG_TAG, "%s unable to create btsock_thread.", __func__); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 78 | goto error; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Jakub Pawlowski | 713993d | 2016-04-21 13:16:45 -0700 | [diff] [blame] | 81 | status = btsock_rfc_init(thread_handle, uid_set); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 82 | if (status != BT_STATUS_SUCCESS) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 83 | LOG_ERROR(LOG_TAG, "%s error initializing RFCOMM sockets: %d", __func__, |
| 84 | status); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 85 | goto error; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Adam Lesinski | 0620f97 | 2015-12-02 22:15:08 -0800 | [diff] [blame] | 88 | status = btsock_l2cap_init(thread_handle, uid_set); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 89 | if (status != BT_STATUS_SUCCESS) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 90 | LOG_ERROR(LOG_TAG, "%s error initializing L2CAP sockets: %d", __func__, |
| 91 | status); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 92 | goto error; |
| 93 | } |
| 94 | |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 95 | thread = thread_new("btif_sock"); |
| 96 | if (!thread) { |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 97 | LOG_ERROR(LOG_TAG, "%s error creating new thread.", __func__); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 98 | btsock_rfc_cleanup(); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 99 | goto error; |
| 100 | } |
| 101 | |
| 102 | status = btsock_sco_init(thread); |
| 103 | if (status != BT_STATUS_SUCCESS) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 104 | LOG_ERROR(LOG_TAG, "%s error initializing SCO sockets: %d", __func__, |
| 105 | status); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 106 | btsock_rfc_cleanup(); |
| 107 | goto error; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return BT_STATUS_SUCCESS; |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 111 | |
| 112 | error:; |
| 113 | thread_free(thread); |
| 114 | thread = NULL; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 115 | if (thread_handle != -1) btsock_thread_exit(thread_handle); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 116 | thread_handle = -1; |
Adam Lesinski | 0620f97 | 2015-12-02 22:15:08 -0800 | [diff] [blame] | 117 | uid_set = NULL; |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 118 | return BT_STATUS_FAIL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 119 | } |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 120 | |
| 121 | void btif_sock_cleanup(void) { |
Myles Watson | b793f4f | 2017-02-28 11:05:52 -0800 | [diff] [blame] | 122 | int saved_handle = thread_handle; |
| 123 | if (std::atomic_exchange(&thread_handle, -1) == -1) return; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 124 | |
Myles Watson | b793f4f | 2017-02-28 11:05:52 -0800 | [diff] [blame] | 125 | btsock_thread_exit(saved_handle); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 126 | btsock_rfc_cleanup(); |
| 127 | btsock_sco_cleanup(); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 128 | btsock_l2cap_cleanup(); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 129 | thread_free(thread); |
Sharvil Nanavati | c8aaee2 | 2014-08-21 18:17:19 -0700 | [diff] [blame] | 130 | thread = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | } |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 132 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 133 | static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 134 | const Uuid* service_uuid, int channel, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 135 | int* sock_fd, int flags, int app_uid) { |
| 136 | if ((flags & BTSOCK_FLAG_NO_SDP) == 0) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 137 | CHECK(sock_fd != NULL); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 138 | } |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 139 | |
| 140 | *sock_fd = INVALID_FD; |
| 141 | bt_status_t status = BT_STATUS_FAIL; |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 142 | int original_channel = channel; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 143 | |
Jack He | 83f8683 | 2019-02-06 20:24:24 -0800 | [diff] [blame] | 144 | bluetooth::common::LogSocketConnectionState( |
| 145 | RawAddress::kEmpty, 0, type, |
| 146 | android::bluetooth::SocketConnectionstateEnum:: |
| 147 | SOCKET_CONNECTION_STATE_LISTENING, |
| 148 | 0, 0, app_uid, channel, android::bluetooth::SOCKET_ROLE_LISTEN); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 149 | switch (type) { |
| 150 | case BTSOCK_RFCOMM: |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 151 | status = btsock_rfc_listen(service_name, service_uuid, channel, sock_fd, |
| 152 | flags, app_uid); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 153 | break; |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 154 | case BTSOCK_L2CAP: |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 155 | status = |
| 156 | btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 157 | break; |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 158 | case BTSOCK_L2CAP_LE: |
| 159 | if (flags & BTSOCK_FLAG_NO_SDP) { |
Stanley Tng | a34e9b4 | 2018-01-05 09:25:11 -0800 | [diff] [blame] | 160 | /* Set channel to zero so that it will be assigned */ |
| 161 | channel = 0; |
| 162 | } else if (channel <= 0) { |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 163 | LOG_ERROR(LOG_TAG, "%s: type BTSOCK_L2CAP_LE: invalid channel=%d", |
| 164 | __func__, channel); |
| 165 | break; |
| 166 | } |
Stanley Tng | a34e9b4 | 2018-01-05 09:25:11 -0800 | [diff] [blame] | 167 | flags |= BTSOCK_FLAG_LE_COC; |
| 168 | LOG_DEBUG( |
| 169 | LOG_TAG, |
| 170 | "%s: type=BTSOCK_L2CAP_LE, channel=0x%x, original=0x%x, flags=0x%x", |
| 171 | __func__, channel, original_channel, flags); |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 172 | status = |
| 173 | btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid); |
| 174 | break; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 175 | case BTSOCK_SCO: |
| 176 | status = btsock_sco_listen(sock_fd, flags); |
| 177 | break; |
| 178 | |
| 179 | default: |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 180 | LOG_ERROR(LOG_TAG, "%s unknown/unsupported socket type: %d", __func__, |
| 181 | type); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 182 | status = BT_STATUS_UNSUPPORTED; |
| 183 | break; |
| 184 | } |
Jack He | 83f8683 | 2019-02-06 20:24:24 -0800 | [diff] [blame] | 185 | if (status != BT_STATUS_SUCCESS) { |
| 186 | bluetooth::common::LogSocketConnectionState( |
| 187 | RawAddress::kEmpty, 0, type, |
| 188 | android::bluetooth::SocketConnectionstateEnum:: |
| 189 | SOCKET_CONNECTION_STATE_DISCONNECTED, |
| 190 | 0, 0, app_uid, channel, android::bluetooth::SOCKET_ROLE_LISTEN); |
| 191 | } |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 192 | return status; |
| 193 | } |
| 194 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 195 | static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 196 | const Uuid* uuid, int channel, int* sock_fd, |
| 197 | int flags, int app_uid) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 198 | CHECK(bd_addr != NULL); |
| 199 | CHECK(sock_fd != NULL); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 200 | |
| 201 | *sock_fd = INVALID_FD; |
| 202 | bt_status_t status = BT_STATUS_FAIL; |
| 203 | |
Jack He | 83f8683 | 2019-02-06 20:24:24 -0800 | [diff] [blame] | 204 | bluetooth::common::LogSocketConnectionState( |
| 205 | *bd_addr, 0, type, |
| 206 | android::bluetooth::SocketConnectionstateEnum:: |
| 207 | SOCKET_CONNECTION_STATE_CONNECTING, |
| 208 | 0, 0, app_uid, channel, android::bluetooth::SOCKET_ROLE_CONNECTION); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 209 | switch (type) { |
| 210 | case BTSOCK_RFCOMM: |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 211 | status = |
| 212 | btsock_rfc_connect(bd_addr, uuid, channel, sock_fd, flags, app_uid); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 213 | break; |
| 214 | |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 215 | case BTSOCK_L2CAP: |
Adam Lesinski | 0620f97 | 2015-12-02 22:15:08 -0800 | [diff] [blame] | 216 | status = btsock_l2cap_connect(bd_addr, channel, sock_fd, flags, app_uid); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 217 | break; |
| 218 | |
Jakub Pawlowski | 3118cdc | 2019-08-05 20:28:22 +0200 | [diff] [blame] | 219 | case BTSOCK_L2CAP_LE: { |
Stanley Tng | a34e9b4 | 2018-01-05 09:25:11 -0800 | [diff] [blame] | 220 | flags |= BTSOCK_FLAG_LE_COC; |
Jakub Pawlowski | 3118cdc | 2019-08-05 20:28:22 +0200 | [diff] [blame] | 221 | |
| 222 | // Ensure device is in inquiry database |
| 223 | int addr_type = 0; |
| 224 | int device_type = 0; |
| 225 | |
| 226 | if (btif_get_address_type(*bd_addr, &addr_type) && |
| 227 | btif_get_device_type(*bd_addr, &device_type) && |
| 228 | device_type != BT_DEVICE_TYPE_BREDR) { |
| 229 | BTA_DmAddBleDevice(*bd_addr, addr_type, device_type); |
| 230 | } |
| 231 | |
Stanley Tng | a34e9b4 | 2018-01-05 09:25:11 -0800 | [diff] [blame] | 232 | LOG_DEBUG(LOG_TAG, "%s: type=BTSOCK_L2CAP_LE, channel=0x%x, flags=0x%x", |
| 233 | __func__, channel, flags); |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 234 | status = btsock_l2cap_connect(bd_addr, channel, sock_fd, flags, app_uid); |
| 235 | break; |
Jakub Pawlowski | 3118cdc | 2019-08-05 20:28:22 +0200 | [diff] [blame] | 236 | } |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 237 | |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 238 | case BTSOCK_SCO: |
| 239 | status = btsock_sco_connect(bd_addr, sock_fd, flags); |
| 240 | break; |
| 241 | |
| 242 | default: |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 243 | LOG_ERROR(LOG_TAG, "%s unknown/unsupported socket type: %d", __func__, |
| 244 | type); |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 245 | status = BT_STATUS_UNSUPPORTED; |
| 246 | break; |
| 247 | } |
Jack He | 83f8683 | 2019-02-06 20:24:24 -0800 | [diff] [blame] | 248 | if (status != BT_STATUS_SUCCESS) { |
| 249 | bluetooth::common::LogSocketConnectionState( |
| 250 | *bd_addr, 0, type, |
| 251 | android::bluetooth::SocketConnectionstateEnum:: |
| 252 | SOCKET_CONNECTION_STATE_DISCONNECTED, |
| 253 | 0, 0, app_uid, channel, android::bluetooth::SOCKET_ROLE_CONNECTION); |
| 254 | } |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 255 | return status; |
| 256 | } |
| 257 | |
Stanley Tng | 70bebaf | 2018-01-22 17:08:03 -0800 | [diff] [blame] | 258 | static void btsock_request_max_tx_data_length(const RawAddress& remote_device) { |
| 259 | const controller_t* controller = controller_get_interface(); |
| 260 | uint16_t max_len = controller->get_ble_maximum_tx_data_length(); |
| 261 | |
| 262 | DVLOG(2) << __func__ << ": max_len=" << max_len; |
| 263 | |
| 264 | BTA_DmBleSetDataLength(remote_device, max_len); |
| 265 | } |
| 266 | |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 267 | static void btsock_signaled(int fd, int type, int flags, uint32_t user_id) { |
| 268 | switch (type) { |
| 269 | case BTSOCK_RFCOMM: |
| 270 | btsock_rfc_signaled(fd, flags, user_id); |
| 271 | break; |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 272 | case BTSOCK_L2CAP: |
Stanley Tng | 49dd53c | 2017-12-20 09:38:30 -0800 | [diff] [blame] | 273 | case BTSOCK_L2CAP_LE: |
| 274 | /* Note: The caller may not distinguish between BTSOCK_L2CAP and |
| 275 | * BTSOCK_L2CAP_LE correctly */ |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 276 | btsock_l2cap_signaled(fd, flags, user_id); |
| 277 | break; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 278 | default: |
Hansong Zhang | a912f96 | 2018-11-15 15:37:12 -0800 | [diff] [blame] | 279 | LOG(FATAL) << "Invalid socket type! type=" << type << " fd=" << fd |
| 280 | << " flags=" << flags << " user_id=" << user_id; |
Sharvil Nanavati | fe4ec6b | 2014-08-21 13:17:43 -0700 | [diff] [blame] | 281 | break; |
| 282 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 283 | } |