Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2017 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 | #include "hci_protocol.h" |
| 18 | |
| 19 | #define LOG_TAG "android.hardware.bluetooth-hci-hci_protocol" |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 20 | #include <assert.h> |
Bailey Forrest | ba20404 | 2017-06-12 16:49:18 -0700 | [diff] [blame] | 21 | #include <errno.h> |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 22 | #include <fcntl.h> |
Steven Moreland | 96510c8 | 2017-04-11 12:22:27 -0700 | [diff] [blame] | 23 | #include <log/log.h> |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 24 | |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace bluetooth { |
| 28 | namespace hci { |
| 29 | |
| 30 | size_t HciProtocol::WriteSafely(int fd, const uint8_t* data, size_t length) { |
| 31 | size_t transmitted_length = 0; |
| 32 | while (length > 0) { |
| 33 | ssize_t ret = |
| 34 | TEMP_FAILURE_RETRY(write(fd, data + transmitted_length, length)); |
| 35 | |
| 36 | if (ret == -1) { |
| 37 | if (errno == EAGAIN) continue; |
| 38 | ALOGE("%s error writing to UART (%s)", __func__, strerror(errno)); |
| 39 | break; |
| 40 | |
| 41 | } else if (ret == 0) { |
| 42 | // Nothing written :( |
| 43 | ALOGE("%s zero bytes written - something went wrong...", __func__); |
| 44 | break; |
| 45 | } |
| 46 | |
| 47 | transmitted_length += ret; |
| 48 | length -= ret; |
| 49 | } |
| 50 | |
| 51 | return transmitted_length; |
| 52 | } |
| 53 | |
| 54 | } // namespace hci |
| 55 | } // namespace bluetooth |
| 56 | } // namespace hardware |
| 57 | } // namespace android |