1 /*
2 * Copyright (C) 2016 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 #include "chre_api/chre/wifi.h"
18
19 #include "chre/core/event_loop_manager.h"
20 #include "chre/util/macros.h"
21 #include "chre/util/system/napp_permissions.h"
22
23 using chre::EventLoopManager;
24 using chre::EventLoopManagerSingleton;
25 using chre::NanoappPermissions;
26
chreWifiGetCapabilities()27 DLL_EXPORT uint32_t chreWifiGetCapabilities() {
28 #ifdef CHRE_WIFI_SUPPORT_ENABLED
29 return chre::EventLoopManagerSingleton::get()
30 ->getWifiRequestManager()
31 .getCapabilities();
32 #else
33 return CHRE_WIFI_CAPABILITIES_NONE;
34 #endif // CHRE_WIFI_SUPPORT_ENABLED
35 }
36
chreWifiConfigureScanMonitorAsync(bool enable,const void * cookie)37 DLL_EXPORT bool chreWifiConfigureScanMonitorAsync(
38 [[maybe_unused]] bool enable, [[maybe_unused]] const void *cookie) {
39 #ifdef CHRE_WIFI_SUPPORT_ENABLED
40 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
41 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_WIFI) &&
42 EventLoopManagerSingleton::get()
43 ->getWifiRequestManager()
44 .configureScanMonitor(nanoapp, enable, cookie);
45 #else
46 return false;
47 #endif // CHRE_WIFI_SUPPORT_ENABLED
48 }
49
chreWifiRequestScanAsync(const struct chreWifiScanParams * params,const void * cookie)50 DLL_EXPORT bool chreWifiRequestScanAsync(
51 [[maybe_unused]] const struct chreWifiScanParams *params,
52 [[maybe_unused]] const void *cookie) {
53 #ifdef CHRE_WIFI_SUPPORT_ENABLED
54 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
55 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_WIFI) &&
56 EventLoopManagerSingleton::get()->getWifiRequestManager().requestScan(
57 nanoapp, params, cookie);
58 #else
59 return false;
60 #endif // CHRE_WIFI_SUPPORT_ENABLED
61 }
62
chreWifiRequestRangingAsync(const struct chreWifiRangingParams * params,const void * cookie)63 DLL_EXPORT bool chreWifiRequestRangingAsync(
64 [[maybe_unused]] const struct chreWifiRangingParams *params,
65 [[maybe_unused]] const void *cookie) {
66 #ifdef CHRE_WIFI_SUPPORT_ENABLED
67 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
68 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_WIFI) &&
69 EventLoopManagerSingleton::get()
70 ->getWifiRequestManager()
71 .requestRanging(chre::WifiRequestManager::RangingType::WIFI_AP,
72 nanoapp, params, cookie);
73 #else
74 return false;
75 #endif // CHRE_WIFI_SUPPORT_ENABLED
76 }
77
chreWifiNanSubscribe(struct chreWifiNanSubscribeConfig * config,const void * cookie)78 DLL_EXPORT bool chreWifiNanSubscribe(
79 [[maybe_unused]] struct chreWifiNanSubscribeConfig *config,
80 [[maybe_unused]] const void *cookie) {
81 #if defined(CHRE_WIFI_SUPPORT_ENABLED) && defined(CHRE_WIFI_NAN_SUPPORT_ENABLED)
82 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
83 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_WIFI) &&
84 EventLoopManagerSingleton::get()->getWifiRequestManager().nanSubscribe(
85 nanoapp, config, cookie);
86 #else
87 return false;
88 #endif // CHRE_WIFI_SUPPORT_ENABLED
89 }
90
chreWifiNanSubscribeCancel(uint32_t subscriptionId)91 DLL_EXPORT bool chreWifiNanSubscribeCancel(
92 [[maybe_unused]] uint32_t subscriptionId) {
93 #if defined(CHRE_WIFI_SUPPORT_ENABLED) && defined(CHRE_WIFI_NAN_SUPPORT_ENABLED)
94 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
95 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_WIFI) &&
96 EventLoopManagerSingleton::get()
97 ->getWifiRequestManager()
98 .nanSubscribeCancel(nanoapp, subscriptionId);
99 #else
100 return false;
101 #endif // CHRE_WIFI_SUPPORT_ENABLED
102 }
103
chreWifiNanRequestRangingAsync(const struct chreWifiNanRangingParams * params,const void * cookie)104 DLL_EXPORT bool chreWifiNanRequestRangingAsync(
105 [[maybe_unused]] const struct chreWifiNanRangingParams *params,
106 [[maybe_unused]] const void *cookie) {
107 #if defined(CHRE_WIFI_SUPPORT_ENABLED) && defined(CHRE_WIFI_NAN_SUPPORT_ENABLED)
108 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
109 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_WIFI) &&
110 EventLoopManagerSingleton::get()
111 ->getWifiRequestManager()
112 .requestRanging(chre::WifiRequestManager::RangingType::WIFI_AWARE,
113 nanoapp, params, cookie);
114 #else
115 return false;
116 #endif // CHRE_WIFI_SUPPORT_ENABLED
117 }
118
chreWifiNanGetCapabilities(struct chreWifiNanCapabilities * capabilities)119 DLL_EXPORT bool chreWifiNanGetCapabilities(
120 struct chreWifiNanCapabilities *capabilities) {
121 // Not implemented yet.
122 UNUSED_VAR(capabilities);
123 return false;
124 }
125