• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (C) 2016 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _CHRE_WWAN_H_
19 #define _CHRE_WWAN_H_
20 
21 /**
22  * @file
23  * Wireless Wide Area Network (WWAN, i.e. mobile/cellular network) API relevant
24  * for querying cell tower identity and associated information that can be
25  * useful in determining location.
26  *
27  * Based on Android N RIL definitions (located at this path as of the time of
28  * this comment: hardware/ril/include/telephony/ril.h), version 12. Refer to
29  * that file and associated documentation for futher details.
30  *
31  * In general, the parts of this API that are taken from the RIL follow the
32  * field naming conventions established in that interface rather than the CHRE
33  * API conventions, in order to avoid confusion and enable code re-use where
34  * applicable. Note that structure names include the chreWwan* prefix rather
35  * than RIL_*, but field names are the same. If necessary to enable code
36  * sharing, it is recommended to create typedefs that map from the CHRE
37  * structures to the associated RIL type names, for example "typedef struct
38  * chreWwanCellIdentityGsm RIL_CellIdentityGsm_v12", etc.
39  */
40 
41 #include <chre/common.h>
42 
43 #include <stdbool.h>
44 #include <stdint.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /**
51  * The set of flags returned by chreWwanGetCapabilities().
52  * @defgroup CHRE_WWAN_CAPABILITIES
53  * @{
54  */
55 
56 //! No WWAN APIs are supported
57 #define CHRE_WWAN_CAPABILITIES_NONE  UINT32_C(0)
58 
59 //! Current cell information can be queried via chreWwanGetCellInfoAsync()
60 #define CHRE_WWAN_GET_CELL_INFO      UINT32_C(1 << 0)
61 
62 /** @} */
63 
64 /**
65  * Produce an event ID in the block of IDs reserved for WWAN
66  * @param offset  Index into WWAN event ID block; valid range [0,15]
67  */
68 #define CHRE_WWAN_EVENT_ID(offset)  (CHRE_EVENT_WWAN_FIRST_EVENT + (offset))
69 
70 /**
71  * nanoappHandleEvent argument: struct chreWwanCellInfoResult
72  *
73  * Provides the result of an asynchronous request for cell info sent via
74  * chreWwanGetCellInfoAsync().
75  */
76 #define CHRE_EVENT_WWAN_CELL_INFO_RESULT  CHRE_WWAN_EVENT_ID(0)
77 
78 // NOTE: Do not add new events with ID > 15; only values 0-15 are reserved
79 // (see chre/event.h)
80 
81 /**
82  * The current version of struct chreWwanCellInfoResult associated with this
83  * API definition.
84  */
85 #define CHRE_WWAN_CELL_INFO_RESULT_VERSION  UINT8_C(1)
86 
87 //! Reference: RIL_CellIdentityGsm_v12
88 struct chreWwanCellIdentityGsm {
89     //! 3-digit Mobile Country Code, 0..999, INT32_MAX if unknown
90     int32_t mcc;
91 
92     //! 2 or 3-digit Mobile Network Code, 0..999, INT32_MAX if unknown
93     int32_t mnc;
94 
95     //! 16-bit Location Area Code, 0..65535, INT32_MAX if unknown
96     int32_t lac;
97 
98     //! 16-bit GSM Cell Identity described in TS 27.007, 0..65535,
99     //! INT32_MAX if unknown
100     int32_t cid;
101 
102     //! 16-bit GSM Absolute RF channel number, INT32_MAX if unknown
103     int32_t arfcn;
104 
105     //! 6-bit Base Station Identity Code, UINT8_MAX if unknown
106     uint8_t bsic;
107 
108     //! Reserved for future use; must be set to 0
109     uint8_t reserved[3];
110 };
111 
112 //! Reference: RIL_CellIdentityWcdma_v12
113 struct chreWwanCellIdentityWcdma {
114     //! 3-digit Mobile Country Code, 0..999, INT32_MAX if unknown
115     int32_t mcc;
116 
117     //! 2 or 3-digit Mobile Network Code, 0..999, INT32_MAX if unknown
118     int32_t mnc;
119 
120     //! 16-bit Location Area Code, 0..65535, INT32_MAX if unknown
121     int32_t lac;
122 
123     //! 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455,
124     //! INT32_MAX if unknown
125     int32_t cid;
126 
127     //! 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511,
128     //! INT32_MAX if unknown
129     int32_t psc;
130 
131     //! 16-bit UMTS Absolute RF Channel Number, INT32_MAX if unknown
132     int32_t uarfcn;
133 };
134 
135 //! Reference: RIL_CellIdentityCdma
136 struct chreWwanCellIdentityCdma {
137     //! Network Id 0..65535, INT32_MAX if unknown
138     int32_t networkId;
139 
140     //! CDMA System Id 0..32767, INT32_MAX if unknown
141     int32_t systemId;
142 
143     //! Base Station Id 0..65535, INT32_MAX if unknown
144     int32_t basestationId;
145 
146     //! Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
147     //! It is represented in units of 0.25 seconds and ranges from -2592000
148     //! to 2592000, both values inclusive (corresponding to a range of -180
149     //! to +180 degrees). INT32_MAX if unknown
150     int32_t longitude;
151 
152     //! Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
153     //! It is represented in units of 0.25 seconds and ranges from -1296000
154     //! to 1296000, both values inclusive (corresponding to a range of -90
155     //! to +90 degrees). INT32_MAX if unknown
156     int32_t latitude;
157 };
158 
159 //! Reference: RIL_CellIdentityLte_v12
160 struct chreWwanCellIdentityLte {
161     //! 3-digit Mobile Country Code, 0..999, INT32_MAX if unknown
162     int32_t mcc;
163 
164     //! 2 or 3-digit Mobile Network Code, 0..999, INT32_MAX if unknown
165     int32_t mnc;
166 
167     //! 28-bit Cell Identity described in TS ???, INT32_MAX if unknown
168     int32_t ci;
169 
170     //! physical cell id 0..503, INT32_MAX if unknown
171     int32_t pci;
172 
173     //! 16-bit tracking area code, INT32_MAX if unknown
174     int32_t tac;
175 
176     //! 18-bit LTE Absolute RF Channel Number, INT32_MAX if unknown
177     int32_t earfcn;
178 };
179 
180 //! Reference: RIL_CellIdentityTdscdma
181 struct chreWwanCellIdentityTdscdma {
182     //! 3-digit Mobile Country Code, 0..999, INT32_MAX if unknown
183     int32_t mcc;
184 
185     //! 2 or 3-digit Mobile Network Code, 0..999, INT32_MAX if unknown
186     int32_t mnc;
187 
188     //! 16-bit Location Area Code, 0..65535, INT32_MAX if unknown
189     int32_t lac;
190 
191     //! 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455,
192     //! INT32_MAX if unknown
193     int32_t cid;
194 
195     //! 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT32_MAX if
196     //! unknown
197     int32_t cpid;
198 };
199 
200 //! Reference: RIL_GSM_SignalStrength_v12
201 struct chreWwanSignalStrengthGsm {
202     //! Valid values are (0-31, 99) as defined in TS 27.007 8.5
203     int32_t signalStrength;
204 
205     //! bit error rate (0-7, 99) as defined in TS 27.007 8.5
206     int32_t bitErrorRate;
207 
208     //! Timing Advance in bit periods. 1 bit period = 48.13 us. INT32_MAX
209     //! denotes invalid value
210     int32_t timingAdvance;
211 };
212 
213 //! Reference: RIL_SignalStrengthWcdma
214 struct chreWwanSignalStrengthWcdma {
215     //! Valid values are (0-31, 99) as defined in TS 27.007 8.5
216     int32_t signalStrength;
217 
218     //! bit error rate (0-7, 99) as defined in TS 27.007 8.5
219     int32_t bitErrorRate;
220 };
221 
222 //! Reference: RIL_CDMA_SignalStrength
223 struct chreWwanSignalStrengthCdma {
224     //! Valid values are positive integers.  This value is the actual RSSI value
225     //! multiplied by -1.  Example: If the actual RSSI is -75, then this
226     //! response value will be 75.
227     int32_t dbm;
228 
229     //! Valid values are positive integers.  This value is the actual Ec/Io
230     //! multiplied by -10.  Example: If the actual Ec/Io is -12.5 dB, then this
231     //! response value will be 125.
232     int32_t ecio;
233 };
234 
235 //! Reference: RIL_EVDO_SignalStrength
236 struct chreWwanSignalStrengthEvdo {
237     //! Valid values are positive integers.  This value is the actual RSSI value
238     //! multiplied by -1.  Example: If the actual RSSI is -75, then this
239     //! response value will be 75.
240     int32_t dbm;
241 
242     //! Valid values are positive integers.  This value is the actual Ec/Io
243     //! multiplied by -10.  Example: If the actual Ec/Io is -12.5 dB, then this
244     //! response value will be 125.
245     int32_t ecio;
246 
247     //! Valid values are 0-8.  8 is the highest signal to noise ratio.
248     int32_t signalNoiseRatio;
249 };
250 
251 //! Reference: RIL_LTE_SignalStrength_v8
252 struct chreWwanSignalStrengthLte {
253     //! Valid values are (0-31, 99) as defined in TS 27.007 8.5
254     int32_t signalStrength;
255 
256     //! The current Reference Signal Receive Power in dBm multipled by -1.
257     //! Range: 44 to 140 dBm
258     //! INT32_MAX: 0x7FFFFFFF denotes invalid value.
259     //! Reference: 3GPP TS 36.133 9.1.4
260     int32_t rsrp;
261 
262     //! The current Reference Signal Receive Quality in dB multiplied by -1.
263     //! Range: 20 to 3 dB.
264     //! INT32_MAX: 0x7FFFFFFF denotes invalid value.
265     //! Reference: 3GPP TS 36.133 9.1.7
266     int32_t rsrq;
267 
268     //! The current reference signal signal-to-noise ratio in 0.1 dB units.
269     //! Range: -200 to +300 (-200 = -20.0 dB, +300 = 30dB).
270     //! INT32_MAX : 0x7FFFFFFF denotes invalid value.
271     //! Reference: 3GPP TS 36.101 8.1.1
272     int32_t rssnr;
273 
274     //! The current Channel Quality Indicator.
275     //! Range: 0 to 15.
276     //! INT32_MAX : 0x7FFFFFFF denotes invalid value.
277     //! Reference: 3GPP TS 36.101 9.2, 9.3, A.4
278     int32_t cqi;
279 
280     //! timing advance in micro seconds for a one way trip from cell to device.
281     //! Approximate distance can be calculated using 300m/us * timingAdvance.
282     //! Range: 0 to 0x7FFFFFFE
283     //! INT32_MAX : 0x7FFFFFFF denotes invalid value.
284     //! Reference: 3GPP 36.321 section 6.1.3.5
285     //! also: http://www.cellular-planningoptimization.com/2010/02/timing-advance-with-calculation.html
286     int32_t timingAdvance;
287 };
288 
289 //! Reference: RIL_TD_SCDMA_SignalStrength
290 struct chreWwanSignalStrengthTdscdma {
291     //! The Received Signal Code Power in dBm multipled by -1.
292     //! Range : 25 to 120
293     //! INT32_MAX: 0x7FFFFFFF denotes invalid value.
294     //! Reference: 3GPP TS 25.123, section 9.1.1.1
295     int32_t rscp;
296 };
297 
298 //! Reference: RIL_CellInfoGsm_v12
299 struct chreWwanCellInfoGsm {
300     struct chreWwanCellIdentityGsm    cellIdentityGsm;
301     struct chreWwanSignalStrengthGsm  signalStrengthGsm;
302 };
303 
304 //! Reference: RIL_CellInfoWcdma_v12
305 struct chreWwanCellInfoWcdma {
306     struct chreWwanCellIdentityWcdma    cellIdentityWcdma;
307     struct chreWwanSignalStrengthWcdma  signalStrengthWcdma;
308 };
309 
310 //! Reference: RIL_CellInfoCdma
311 struct chreWwanCellInfoCdma {
312     struct chreWwanCellIdentityCdma    cellIdentityCdma;
313     struct chreWwanSignalStrengthCdma  signalStrengthCdma;
314     struct chreWwanSignalStrengthEvdo  signalStrengthEvdo;
315 };
316 
317 //! Reference: RIL_CellInfoLte_v12
318 struct chreWwanCellInfoLte {
319     struct chreWwanCellIdentityLte    cellIdentityLte;
320     struct chreWwanSignalStrengthLte  signalStrengthLte;
321 };
322 
323 //! Reference: RIL_CellInfoTdscdma
324 struct chreWwanCellInfoTdscdma {
325     struct chreWwanCellIdentityTdscdma    cellIdentityTdscdma;
326     struct chreWwanSignalStrengthTdscdma  signalStrengthTdscdma;
327 };
328 
329 //! Reference: RIL_CellInfoType
330 enum chreWwanCellInfoType {
331     CHRE_WWAN_CELL_INFO_TYPE_GSM      = 1,
332     CHRE_WWAN_CELL_INFO_TYPE_CDMA     = 2,
333     CHRE_WWAN_CELL_INFO_TYPE_LTE      = 3,
334     CHRE_WWAN_CELL_INFO_TYPE_WCDMA    = 4,
335     CHRE_WWAN_CELL_INFO_TYPE_TD_SCDMA = 5,
336 };
337 
338 //! Reference: RIL_TimeStampType
339 enum chreWwanCellTimeStampType {
340     CHRE_WWAN_CELL_TIMESTAMP_TYPE_UNKNOWN  = 0,
341     CHRE_WWAN_CELL_TIMESTAMP_TYPE_ANTENNA  = 1,
342     CHRE_WWAN_CELL_TIMESTAMP_TYPE_MODEM    = 2,
343     CHRE_WWAN_CELL_TIMESTAMP_TYPE_OEM_RIL  = 3,
344     CHRE_WWAN_CELL_TIMESTAMP_TYPE_JAVA_RIL = 4,
345 };
346 
347 //! Reference: RIL_CellInfo_v12
348 struct chreWwanCellInfo {
349     //! Timestamp in nanoseconds; must be in the same time base as chreGetTime()
350     uint64_t timeStamp;
351 
352     //! A value from enum {@link #CellInfoType} indicating the radio access
353     //! technology of the cell, and which field in union CellInfo can be used
354     //! to retrieve additional information
355     uint8_t cellInfoType;
356 
357     //! A value from value from enum {@link #CellTimeStampType} that identifies
358     //! the source of the value in timeStamp. This is typically set to
359     //! CHRE_WWAN_CELL_TIMESTAMP_TYPE_OEM_RIL, and indicates the time given by
360     //! chreGetTime() that an intermediate module received the data from the
361     //! modem and forwarded it to the requesting CHRE client.
362     uint8_t timeStampType;
363 
364     //! !0 if this cell is registered, 0 if not registered
365     uint8_t registered;
366 
367     //! Reserved for future use; must be set to 0
368     uint8_t reserved;
369 
370     //! The value in cellInfoType indicates which field in this union is valid
371     union {
372         struct chreWwanCellInfoGsm     gsm;
373         struct chreWwanCellInfoCdma    cdma;
374         struct chreWwanCellInfoLte     lte;
375         struct chreWwanCellInfoWcdma   wcdma;
376         struct chreWwanCellInfoTdscdma tdscdma;
377     } CellInfo;
378 
379     //! Additional bytes reserved for future use; must be set to 0
380     uint8_t reserved2[4];
381 };
382 
383 /**
384  * Data structure provided with events of type CHRE_EVENT_WWAN_CELL_INFO_RESULT.
385  */
386 struct chreWwanCellInfoResult {
387     //! Indicates the version of the structure, for compatibility purposes.
388     //! Clients do not normally need to worry about this field; the CHRE
389     //! implementation guarantees that the client only receives the structure
390     //! version it expects.
391     uint8_t version;
392 
393     //! Populated with a value from enum {@link #chreError}, indicating whether
394     //! the request failed, and if so, provides the cause of the failure
395     uint8_t errorCode;
396 
397     //! The number of valid entries in cells[]
398     uint8_t cellInfoCount;
399 
400     //! Reserved for future use; must be set to 0
401     uint8_t reserved;
402 
403     //! Set to the cookie parameter given to chreWwanGetCellInfoAsync()
404     const void *cookie;
405 
406     //! Pointer to an array of cellInfoCount elements containing information
407     //! about serving and neighbor cells
408     const struct chreWwanCellInfo *cells;
409 };
410 
411 
412 /**
413  * Retrieves a set of flags indicating the WWAN features supported by the
414  * current CHRE implementation. The value returned by this function must be
415  * consistent for the entire duration of the Nanoapp's execution.
416  *
417  * The client must allow for more flags to be set in this response than it knows
418  * about, for example if the implementation supports a newer version of the API
419  * than the client was compiled against.
420  *
421  * @return A bitmask with zero or more CHRE_WWAN_CAPABILITIES_* flags set
422  *
423  * @since v1.1
424  */
425 uint32_t chreWwanGetCapabilities(void);
426 
427 /**
428  * Query information about the current serving cell and its neighbors. This does
429  * not perform a network scan, but should return state from the current network
430  * registration data stored in the cellular modem. This is effectively the same
431  * as a request for RIL_REQUEST_GET_CELL_INFO_LIST in the RIL.
432  *
433  * The requested cellular information is returned asynchronously via
434  * CHRE_EVENT_WWAN_CELL_INFO_RESULT. The implementation must send this event,
435  * either with successful data or an error status, within
436  * CHRE_ASYNC_RESULT_TIMEOUT_NS.
437  *
438  * @param cookie An opaque value that will be included in the chreAsyncResult
439  *        sent in relation to this request.
440  *
441  * @return true if the request was accepted for processing, false otherwise
442  *
443  * @since v1.1
444  */
445 bool chreWwanGetCellInfoAsync(const void *cookie);
446 
447 
448 #ifdef __cplusplus
449 }
450 #endif
451 
452 #endif  /* _CHRE_WWAN_H_ */
453