Line data Source code
1 : /* 2 : * 3 : * Copyright (c) 2020 Project CHIP Authors 4 : * Copyright (c) 2019 Google LLC. 5 : * 6 : * Licensed under the Apache License, Version 2.0 (the "License"); 7 : * you may not use this file except in compliance with the License. 8 : * You may obtain a copy of the License at 9 : * 10 : * http://www.apache.org/licenses/LICENSE-2.0 11 : * 12 : * Unless required by applicable law or agreed to in writing, software 13 : * distributed under the License is distributed on an "AS IS" BASIS, 14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 : * See the License for the specific language governing permissions and 16 : * limitations under the License. 17 : */ 18 : 19 : /** 20 : * @file 21 : * This file contains functions for working with BLE Layer errors. 22 : */ 23 : 24 : #include <stddef.h> 25 : 26 : #include <ble/BleConfig.h> 27 : 28 : #if CONFIG_NETWORK_LAYER_BLE 29 : 30 : #include <ble/BleError.h> 31 : #include <ble/BleLayer.h> 32 : 33 : namespace chip { 34 : namespace Ble { 35 : 36 : /** 37 : * Register a text error formatter for BLE Layer errors. 38 : */ 39 41 : void RegisterLayerErrorFormatter() 40 : { 41 : static ErrorFormatter sBleLayerErrorFormatter = { FormatLayerError, nullptr }; 42 : 43 41 : RegisterErrorFormatter(&sBleLayerErrorFormatter); 44 41 : } 45 : 46 451 : bool FormatLayerError(char * buf, uint16_t bufSize, CHIP_ERROR err) 47 : { 48 451 : const char * desc = nullptr; 49 : 50 451 : if (!err.IsPart(ChipError::SdkPart::kBLE)) 51 : { 52 427 : return false; 53 : } 54 : 55 : #if !CHIP_CONFIG_SHORT_ERROR_STR 56 24 : switch (err.AsInteger()) 57 : { 58 1 : case BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK.AsInteger(): 59 1 : desc = "No chip over BLE connection received callback set"; 60 1 : break; 61 1 : case BLE_ERROR_CENTRAL_UNSUBSCRIBED.AsInteger(): 62 1 : desc = "BLE central unsubscribed"; 63 1 : break; 64 1 : case BLE_ERROR_GATT_SUBSCRIBE_FAILED.AsInteger(): 65 1 : desc = "GATT subscribe operation failed"; 66 1 : break; 67 1 : case BLE_ERROR_GATT_UNSUBSCRIBE_FAILED.AsInteger(): 68 1 : desc = "GATT unsubscribe operation failed"; 69 1 : break; 70 1 : case BLE_ERROR_GATT_WRITE_FAILED.AsInteger(): 71 1 : desc = "GATT write characteristic operation failed"; 72 1 : break; 73 1 : case BLE_ERROR_GATT_INDICATE_FAILED.AsInteger(): 74 1 : desc = "GATT indicate characteristic operation failed"; 75 1 : break; 76 1 : case BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT.AsInteger(): 77 1 : desc = "BLE transport protocol fired abort"; 78 1 : break; 79 1 : case BLE_ERROR_REMOTE_DEVICE_DISCONNECTED.AsInteger(): 80 1 : desc = "Remote device closed BLE connection"; 81 1 : break; 82 1 : case BLE_ERROR_APP_CLOSED_CONNECTION.AsInteger(): 83 1 : desc = "Application closed BLE connection"; 84 1 : break; 85 1 : case BLE_ERROR_NOT_CHIP_DEVICE.AsInteger(): 86 1 : desc = "BLE device doesn't seem to support chip"; 87 1 : break; 88 1 : case BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS.AsInteger(): 89 1 : desc = "Incompatible BLE transport protocol versions"; 90 1 : break; 91 1 : case BLE_ERROR_INVALID_FRAGMENT_SIZE.AsInteger(): 92 1 : desc = "Invalid fragment size"; 93 1 : break; 94 1 : case BLE_ERROR_START_TIMER_FAILED.AsInteger(): 95 1 : desc = "Start timer failed"; 96 1 : break; 97 1 : case BLE_ERROR_CONNECT_TIMED_OUT.AsInteger(): 98 1 : desc = "Connect handshake timed out"; 99 1 : break; 100 1 : case BLE_ERROR_RECEIVE_TIMED_OUT.AsInteger(): 101 1 : desc = "Receive handshake timed out"; 102 1 : break; 103 1 : case BLE_ERROR_INVALID_MESSAGE.AsInteger(): 104 1 : desc = "Invalid message"; 105 1 : break; 106 1 : case BLE_ERROR_FRAGMENT_ACK_TIMED_OUT.AsInteger(): 107 1 : desc = "Message fragment acknowledgement timed out"; 108 1 : break; 109 1 : case BLE_ERROR_KEEP_ALIVE_TIMED_OUT.AsInteger(): 110 1 : desc = "Keep-alive receipt timed out"; 111 1 : break; 112 1 : case BLE_ERROR_NO_CONNECT_COMPLETE_CALLBACK.AsInteger(): 113 1 : desc = "Missing required callback"; 114 1 : break; 115 1 : case BLE_ERROR_INVALID_ACK.AsInteger(): 116 1 : desc = "Received invalid BLE transport protocol fragment acknowledgement"; 117 1 : break; 118 1 : case BLE_ERROR_REASSEMBLER_MISSING_DATA.AsInteger(): 119 1 : desc = "BLE message reassembler did not receive enough data"; 120 1 : break; 121 1 : case BLE_ERROR_INVALID_BTP_HEADER_FLAGS.AsInteger(): 122 1 : desc = "Received invalid BLE transport protocol header flags"; 123 1 : break; 124 1 : case BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER.AsInteger(): 125 1 : desc = "Received invalid BLE transport protocol sequence number"; 126 1 : break; 127 1 : case BLE_ERROR_REASSEMBLER_INCORRECT_STATE.AsInteger(): 128 1 : desc = "BLE message reassembler received packet in incorrect state"; 129 1 : break; 130 : } 131 : #endif // !CHIP_CONFIG_SHORT_ERROR_STR 132 : 133 24 : FormatError(buf, bufSize, "Ble", err, desc); 134 : 135 24 : return true; 136 : } 137 : 138 : } /* namespace Ble */ 139 : } /* namespace chip */ 140 : 141 : #endif // CONFIG_NETWORK_LAYER_BLE