1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "adapter_bt_utils.h"
17 
18 OhosStatusToSoftBus BleStatus[] = {
19     {OHOS_BT_STATUS_SUCCESS,            SOFTBUS_BT_STATUS_SUCCESS},
20     {OHOS_BT_STATUS_FAIL,               SOFTBUS_BT_STATUS_FAIL},
21     {OHOS_BT_STATUS_NOT_READY,          SOFTBUS_BT_STATUS_NOT_READY},
22     {OHOS_BT_STATUS_NOMEM,              SOFTBUS_BT_STATUS_NOMEM},
23     {OHOS_BT_STATUS_BUSY,               SOFTBUS_BT_STATUS_BUSY},
24     {OHOS_BT_STATUS_DONE,               SOFTBUS_BT_STATUS_DONE},
25     {OHOS_BT_STATUS_UNSUPPORTED,        SOFTBUS_BT_STATUS_UNSUPPORTED},
26     {OHOS_BT_STATUS_PARM_INVALID,       SOFTBUS_BT_STATUS_PARM_INVALID},
27     {OHOS_BT_STATUS_UNHANDLED,          SOFTBUS_BT_STATUS_UNHANDLED},
28     {OHOS_BT_STATUS_AUTH_FAILURE,       SOFTBUS_BT_STATUS_AUTH_FAILURE},
29     {OHOS_BT_STATUS_RMT_DEV_DOWN,       SOFTBUS_BT_STATUS_RMT_DEV_DOWN},
30     {OHOS_BT_STATUS_AUTH_REJECTED,      SOFTBUS_BT_STATUS_AUTH_REJECTED},
31 };
32 
BleOhosStatusToSoftBus(BtStatus btStatus)33 int32_t BleOhosStatusToSoftBus(BtStatus btStatus)
34 {
35     int32_t status = OHOS_BT_STATUS_FAIL;
36     const int len = sizeof(BleStatus) / sizeof(BleStatus[0]);
37     OhosStatusToSoftBus *ptr = BleStatus;
38 
39     if (btStatus >= len) {
40         return status;
41     }
42 
43     return (ptr + btStatus)->softBusBtStatus;
44 }