Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / ble / BleError.cpp
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 #include <support/ErrorStr.h>
34
35 namespace chip {
36 namespace Ble {
37
38 /**
39  * Register a text error formatter for BLE Layer errors.
40  */
41 void RegisterLayerErrorFormatter()
42 {
43     static ErrorFormatter sBleLayerErrorFormatter = { FormatLayerError, nullptr };
44
45     RegisterErrorFormatter(&sBleLayerErrorFormatter);
46 }
47
48 bool FormatLayerError(char * buf, uint16_t bufSize, int32_t err)
49 {
50     const char * desc = nullptr;
51
52     if (err < BLE_ERROR_MIN || err > BLE_ERROR_MAX)
53     {
54         return false;
55     }
56
57 #if !CHIP_CONFIG_SHORT_ERROR_STR
58     switch (err)
59     {
60     case BLE_ERROR_BAD_ARGS:
61         desc = "Bad arguments";
62         break;
63     case BLE_ERROR_INCORRECT_STATE:
64         desc = "Incorrect state";
65         break;
66     case BLE_ERROR_NO_ENDPOINTS:
67         desc = "No more BLE endpoints";
68         break;
69     case BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK:
70         desc = "No chip over BLE connection received callback set";
71         break;
72     case BLE_ERROR_CENTRAL_UNSUBSCRIBED:
73         desc = "BLE central unsubscribed";
74         break;
75     case BLE_ERROR_GATT_SUBSCRIBE_FAILED:
76         desc = "GATT subscribe operation failed";
77         break;
78     case BLE_ERROR_GATT_UNSUBSCRIBE_FAILED:
79         desc = "GATT unsubscribe operation failed";
80         break;
81     case BLE_ERROR_GATT_WRITE_FAILED:
82         desc = "GATT write characteristic operation failed";
83         break;
84     case BLE_ERROR_GATT_INDICATE_FAILED:
85         desc = "GATT indicate characteristic operation failed";
86         break;
87     case BLE_ERROR_NOT_IMPLEMENTED:
88         desc = "Not implemented";
89         break;
90     case BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT:
91         desc = "BLE transport protocol fired abort";
92         break;
93     case BLE_ERROR_REMOTE_DEVICE_DISCONNECTED:
94         desc = "Remote device closed BLE connection";
95         break;
96     case BLE_ERROR_APP_CLOSED_CONNECTION:
97         desc = "Application closed BLE connection";
98         break;
99     case BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG:
100         desc = "Outbound message too big";
101         break;
102     case BLE_ERROR_NOT_CHIP_DEVICE:
103         desc = "BLE device doesn't seem to support chip";
104         break;
105     case BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS:
106         desc = "Incompatible BLE transport protocol versions";
107         break;
108     case BLE_ERROR_NO_MEMORY:
109         desc = "No memory";
110         break;
111     case BLE_ERROR_MESSAGE_INCOMPLETE:
112         desc = "Message incomplete";
113         break;
114     case BLE_ERROR_INVALID_FRAGMENT_SIZE:
115         desc = "Invalid fragment size";
116         break;
117     case BLE_ERROR_START_TIMER_FAILED:
118         desc = "Start timer failed";
119         break;
120     case BLE_ERROR_CONNECT_TIMED_OUT:
121         desc = "Connect handshake timed out";
122         break;
123     case BLE_ERROR_RECEIVE_TIMED_OUT:
124         desc = "Receive handshake timed out";
125         break;
126     case BLE_ERROR_INVALID_MESSAGE:
127         desc = "Invalid message";
128         break;
129     case BLE_ERROR_FRAGMENT_ACK_TIMED_OUT:
130         desc = "Message fragment acknowledgement timed out";
131         break;
132     case BLE_ERROR_KEEP_ALIVE_TIMED_OUT:
133         desc = "Keep-alive receipt timed out";
134         break;
135     case BLE_ERROR_NO_CONNECT_COMPLETE_CALLBACK:
136         desc = "Missing required callback";
137         break;
138     case BLE_ERROR_INVALID_ACK:
139         desc = "Received invalid BLE transport protocol fragment acknowledgement";
140         break;
141     case BLE_ERROR_REASSEMBLER_MISSING_DATA:
142         desc = "BLE message reassembler did not receive enough data";
143         break;
144     case BLE_ERROR_INVALID_BTP_HEADER_FLAGS:
145         desc = "Received invalid BLE transport protocol header flags";
146         break;
147     case BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER:
148         desc = "Received invalid BLE transport protocol sequence number";
149         break;
150     case BLE_ERROR_REASSEMBLER_INCORRECT_STATE:
151         desc = "BLE message reassembler received packet in incorrect state";
152         break;
153     case BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG:
154         desc = "Message received by BLE message reassembler was too large";
155         break;
156     }
157 #endif // !CHIP_CONFIG_SHORT_ERROR_STR
158
159     FormatError(buf, bufSize, "Ble", err, desc);
160
161     return true;
162 }
163
164 } /* namespace Ble */
165 } /* namespace chip */
166
167 #endif // CONFIG_NETWORK_LAYER_BLE