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