1 /*
2  * Copyright 2023 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 
18 #define LOG_TAG "sec_interf"
19 
20 #include <bluetooth/log.h>
21 
22 #include "stack/btm/btm_dev.h"
23 #include "stack/btm/btm_sec.h"
24 #include "stack/btm/btm_sec_cb.h"
25 #include "stack/include/btm_ble_sec_api.h"
26 #include "stack/include/btm_sec_api.h"
27 #include "stack/include/security_client_callbacks.h"
28 #include "types/bt_transport.h"
29 
30 using namespace bluetooth;
31 
BTM_SecConfirmReqReply(tBTM_STATUS res,tBT_TRANSPORT transport,const RawAddress bd_addr)32 static void BTM_SecConfirmReqReply(tBTM_STATUS res, tBT_TRANSPORT transport,
33                                    const RawAddress bd_addr) {
34   if (transport == BT_TRANSPORT_BR_EDR) {
35     BTM_ConfirmReqReply(res, bd_addr);
36   } else if (transport == BT_TRANSPORT_LE) {
37     BTM_BleConfirmReply(bd_addr, res);
38   } else {
39     log::error("Unexpected transport:{}", transport);
40   }
41 }
42 
43 static SecurityClientInterface security = {
44         .BTM_Sec_Init = BTM_Sec_Init,
45         .BTM_Sec_Free = BTM_Sec_Free,
46         .BTM_SecRegister = BTM_SecRegister,
47 
48         .BTM_BleLoadLocalKeys = BTM_BleLoadLocalKeys,
49 
50         .BTM_SecAddDevice = BTM_SecAddDevice,
51         .BTM_SecAddBleDevice = BTM_SecAddBleDevice,
52         .BTM_SecDeleteDevice = BTM_SecDeleteDevice,
53         .BTM_SecAddBleKey = BTM_SecAddBleKey,
54         .BTM_SecClearSecurityFlags = BTM_SecClearSecurityFlags,
55         .BTM_SetEncryption = BTM_SetEncryption,
56         .BTM_IsEncrypted = BTM_IsEncrypted,
57         .BTM_SecIsSecurityPending = BTM_SecIsSecurityPending,
58         .BTM_IsLinkKeyKnown = BTM_IsLinkKeyKnown,
59 
60         .BTM_SetSecurityLevel = BTM_SetSecurityLevel,
61         .BTM_SecClrService = BTM_SecClrService,
62         .BTM_SecClrServiceByPsm = BTM_SecClrServiceByPsm,
63 
64         .BTM_SecBond = BTM_SecBond,
65         .BTM_SecBondCancel = BTM_SecBondCancel,
66         .BTM_RemoteOobDataReply = BTM_RemoteOobDataReply,
67         .BTM_PINCodeReply = BTM_PINCodeReply,
68         .BTM_SecConfirmReqReply = BTM_SecConfirmReqReply,
69         .BTM_BleSirkConfirmDeviceReply = BTM_BleSirkConfirmDeviceReply,
70         .BTM_BlePasskeyReply = BTM_BlePasskeyReply,
71 
72         .BTM_GetSecurityMode = BTM_GetSecurityMode,
73 
74         .BTM_SecReadDevName = BTM_SecReadDevName,
75         .BTM_SecReadDevClass = BTM_SecReadDevClass,
76 };
77 
get_security_client_interface()78 const SecurityClientInterface& get_security_client_interface() { return security; }
79