1 /**
2 * Copyright (C) 2020 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 <stdbool.h>
18 #include <stdint.h>
19
20 #include "chpp/common/wwan.h"
21 #include "chpp/services/wwan.h"
22 #include "chre/pal/wwan.h"
23
24 static const struct chrePalSystemApi *gSystemApi;
25 static const struct chrePalWwanCallbacks *gCallbacks;
26
wwanPalOpen(const struct chrePalSystemApi * systemApi,const struct chrePalWwanCallbacks * callbacks)27 static bool wwanPalOpen(const struct chrePalSystemApi *systemApi,
28 const struct chrePalWwanCallbacks *callbacks) {
29 gSystemApi = systemApi;
30 gCallbacks = callbacks;
31
32 return true;
33 }
34
wwanPalClose(void)35 static void wwanPalClose(void) {}
36
wwanPalGetCapabilities(void)37 static uint32_t wwanPalGetCapabilities(void) {
38 return CHRE_WWAN_GET_CELL_INFO;
39 }
40
wwanPalRequestCellInfo(void)41 static bool wwanPalRequestCellInfo(void) {
42 struct chreWwanCellInfoResult *result =
43 gSystemApi->memoryAlloc(sizeof(struct chreWwanCellInfoResult));
44 CHPP_NOT_NULL(result);
45
46 // TODO: <populate result>
47
48 if (result->cellInfoCount > 0) {
49 result->cells = gSystemApi->memoryAlloc(result->cellInfoCount *
50 sizeof(struct chreWwanCellInfo));
51 CHPP_NOT_NULL(cells);
52 }
53
54 // TODO: <populate cells>
55
56 gCallbacks->cellInfoResultCallback(result);
57
58 return true; // If successful
59 }
60
wwanPalReleaseCellInfoResult(struct chreWwanCellInfoResult * result)61 static void wwanPalReleaseCellInfoResult(
62 struct chreWwanCellInfoResult *result) {
63 gSystemApi->memoryFree(CHPP_CONST_CAST_POINTER(result->cells));
64 gSystemApi->memoryFree(result);
65 }
66
67 #ifdef CHPP_SERVICE_ENABLED_WWAN
chrePalWwanGetApi(uint32_t requestedApiVersion)68 const struct chrePalWwanApi *chrePalWwanGetApi(uint32_t requestedApiVersion) {
69 static const struct chrePalWwanApi api = {
70 .moduleVersion = CHPP_PAL_WWAN_API_VERSION,
71 .open = wwanPalOpen,
72 .close = wwanPalClose,
73 .getCapabilities = wwanPalGetCapabilities,
74 .requestCellInfo = wwanPalRequestCellInfo,
75 .releaseCellInfoResult = wwanPalReleaseCellInfoResult,
76 };
77
78 CHPP_STATIC_ASSERT(
79 CHRE_PAL_WWAN_API_CURRENT_VERSION == CHPP_PAL_WWAN_API_VERSION,
80 "A newer CHRE PAL API version is available. Please update.");
81
82 if (!CHRE_PAL_VERSIONS_ARE_COMPATIBLE(api.moduleVersion,
83 requestedApiVersion)) {
84 return NULL;
85 } else {
86 return &api;
87 }
88 }
89 #endif
90