3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Google LLC.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file contains functions for working with BLE Layer errors.
26 #include <ble/BleConfig.h>
28 #if CONFIG_NETWORK_LAYER_BLE
30 #include <ble/BleError.h>
31 #include <ble/BleLayer.h>
33 #include <support/ErrorStr.h>
39 * Register a text error formatter for BLE Layer errors.
41 void RegisterLayerErrorFormatter()
43 static ErrorFormatter sBleLayerErrorFormatter = { FormatLayerError, nullptr };
45 RegisterErrorFormatter(&sBleLayerErrorFormatter);
48 bool FormatLayerError(char * buf, uint16_t bufSize, int32_t err)
50 const char * desc = nullptr;
52 if (err < BLE_ERROR_MIN || err > BLE_ERROR_MAX)
57 #if !CHIP_CONFIG_SHORT_ERROR_STR
60 case BLE_ERROR_BAD_ARGS:
61 desc = "Bad arguments";
63 case BLE_ERROR_INCORRECT_STATE:
64 desc = "Incorrect state";
66 case BLE_ERROR_NO_ENDPOINTS:
67 desc = "No more BLE endpoints";
69 case BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK:
70 desc = "No chip over BLE connection received callback set";
72 case BLE_ERROR_CENTRAL_UNSUBSCRIBED:
73 desc = "BLE central unsubscribed";
75 case BLE_ERROR_GATT_SUBSCRIBE_FAILED:
76 desc = "GATT subscribe operation failed";
78 case BLE_ERROR_GATT_UNSUBSCRIBE_FAILED:
79 desc = "GATT unsubscribe operation failed";
81 case BLE_ERROR_GATT_WRITE_FAILED:
82 desc = "GATT write characteristic operation failed";
84 case BLE_ERROR_GATT_INDICATE_FAILED:
85 desc = "GATT indicate characteristic operation failed";
87 case BLE_ERROR_NOT_IMPLEMENTED:
88 desc = "Not implemented";
90 case BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT:
91 desc = "BLE transport protocol fired abort";
93 case BLE_ERROR_REMOTE_DEVICE_DISCONNECTED:
94 desc = "Remote device closed BLE connection";
96 case BLE_ERROR_APP_CLOSED_CONNECTION:
97 desc = "Application closed BLE connection";
99 case BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG:
100 desc = "Outbound message too big";
102 case BLE_ERROR_NOT_CHIP_DEVICE:
103 desc = "BLE device doesn't seem to support chip";
105 case BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS:
106 desc = "Incompatible BLE transport protocol versions";
108 case BLE_ERROR_NO_MEMORY:
111 case BLE_ERROR_MESSAGE_INCOMPLETE:
112 desc = "Message incomplete";
114 case BLE_ERROR_INVALID_FRAGMENT_SIZE:
115 desc = "Invalid fragment size";
117 case BLE_ERROR_START_TIMER_FAILED:
118 desc = "Start timer failed";
120 case BLE_ERROR_CONNECT_TIMED_OUT:
121 desc = "Connect handshake timed out";
123 case BLE_ERROR_RECEIVE_TIMED_OUT:
124 desc = "Receive handshake timed out";
126 case BLE_ERROR_INVALID_MESSAGE:
127 desc = "Invalid message";
129 case BLE_ERROR_FRAGMENT_ACK_TIMED_OUT:
130 desc = "Message fragment acknowledgement timed out";
132 case BLE_ERROR_KEEP_ALIVE_TIMED_OUT:
133 desc = "Keep-alive receipt timed out";
135 case BLE_ERROR_NO_CONNECT_COMPLETE_CALLBACK:
136 desc = "Missing required callback";
138 case BLE_ERROR_INVALID_ACK:
139 desc = "Received invalid BLE transport protocol fragment acknowledgement";
141 case BLE_ERROR_REASSEMBLER_MISSING_DATA:
142 desc = "BLE message reassembler did not receive enough data";
144 case BLE_ERROR_INVALID_BTP_HEADER_FLAGS:
145 desc = "Received invalid BLE transport protocol header flags";
147 case BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER:
148 desc = "Received invalid BLE transport protocol sequence number";
150 case BLE_ERROR_REASSEMBLER_INCORRECT_STATE:
151 desc = "BLE message reassembler received packet in incorrect state";
153 case BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG:
154 desc = "Message received by BLE message reassembler was too large";
157 #endif // !CHIP_CONFIG_SHORT_ERROR_STR
159 FormatError(buf, bufSize, "Ble", err, desc);
164 } /* namespace Ble */
165 } /* namespace chip */
167 #endif // CONFIG_NETWORK_LAYER_BLE