blob: ce2a8f8b49a83bf8ba0d2875f804d08ec599cdcb [file] [log] [blame]
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file was automatically generated by chre_api_to_chpp.py
// Date: 2020-07-08 23:38:49 UTC
// Source: chre_api/include/chre_api/chre/wwan.h @ commit 3addfee7
// DO NOT modify this file directly, as those changes will be lost the next
// time the script is executed
#include "chpp/macros.h"
#include "chpp/memory.h"
#include "chpp/services/wwan_types.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
//! @return number of bytes required to represent the given
//! chreWwanCellInfoResult along with the CHPP header as
//! struct ChppWwanCellInfoResultWithHeader
static size_t chppWwanSizeOfCellInfoResultFromChre(
const struct chreWwanCellInfoResult *cellInfoResult) {
size_t encodedSize = sizeof(struct ChppWwanCellInfoResultWithHeader);
encodedSize +=
cellInfoResult->cellInfoCount * sizeof(struct ChppWwanCellInfo);
return encodedSize;
}
static void chppWwanConvertCellIdentityCdmaFromChre(
const struct chreWwanCellIdentityCdma *in,
struct ChppWwanCellIdentityCdma *out) {
out->networkId = in->networkId;
out->systemId = in->systemId;
out->basestationId = in->basestationId;
out->longitude = in->longitude;
out->latitude = in->latitude;
}
static void chppWwanConvertSignalStrengthCdmaFromChre(
const struct chreWwanSignalStrengthCdma *in,
struct ChppWwanSignalStrengthCdma *out) {
out->dbm = in->dbm;
out->ecio = in->ecio;
}
static void chppWwanConvertSignalStrengthEvdoFromChre(
const struct chreWwanSignalStrengthEvdo *in,
struct ChppWwanSignalStrengthEvdo *out) {
out->dbm = in->dbm;
out->ecio = in->ecio;
out->signalNoiseRatio = in->signalNoiseRatio;
}
static void chppWwanConvertCellInfoCdmaFromChre(
const struct chreWwanCellInfoCdma *in, struct ChppWwanCellInfoCdma *out) {
chppWwanConvertCellIdentityCdmaFromChre(&in->cellIdentityCdma,
&out->cellIdentityCdma);
chppWwanConvertSignalStrengthCdmaFromChre(&in->signalStrengthCdma,
&out->signalStrengthCdma);
chppWwanConvertSignalStrengthEvdoFromChre(&in->signalStrengthEvdo,
&out->signalStrengthEvdo);
}
static void chppWwanConvertCellIdentityGsmFromChre(
const struct chreWwanCellIdentityGsm *in,
struct ChppWwanCellIdentityGsm *out) {
out->mcc = in->mcc;
out->mnc = in->mnc;
out->lac = in->lac;
out->cid = in->cid;
out->arfcn = in->arfcn;
out->bsic = in->bsic;
memset(&out->reserved, 0, sizeof(out->reserved));
}
static void chppWwanConvertSignalStrengthGsmFromChre(
const struct chreWwanSignalStrengthGsm *in,
struct ChppWwanSignalStrengthGsm *out) {
out->signalStrength = in->signalStrength;
out->bitErrorRate = in->bitErrorRate;
out->timingAdvance = in->timingAdvance;
}
static void chppWwanConvertCellInfoGsmFromChre(
const struct chreWwanCellInfoGsm *in, struct ChppWwanCellInfoGsm *out) {
chppWwanConvertCellIdentityGsmFromChre(&in->cellIdentityGsm,
&out->cellIdentityGsm);
chppWwanConvertSignalStrengthGsmFromChre(&in->signalStrengthGsm,
&out->signalStrengthGsm);
}
static void chppWwanConvertCellIdentityLteFromChre(
const struct chreWwanCellIdentityLte *in,
struct ChppWwanCellIdentityLte *out) {
out->mcc = in->mcc;
out->mnc = in->mnc;
out->ci = in->ci;
out->pci = in->pci;
out->tac = in->tac;
out->earfcn = in->earfcn;
}
static void chppWwanConvertSignalStrengthLteFromChre(
const struct chreWwanSignalStrengthLte *in,
struct ChppWwanSignalStrengthLte *out) {
out->signalStrength = in->signalStrength;
out->rsrp = in->rsrp;
out->rsrq = in->rsrq;
out->rssnr = in->rssnr;
out->cqi = in->cqi;
out->timingAdvance = in->timingAdvance;
}
static void chppWwanConvertCellInfoLteFromChre(
const struct chreWwanCellInfoLte *in, struct ChppWwanCellInfoLte *out) {
chppWwanConvertCellIdentityLteFromChre(&in->cellIdentityLte,
&out->cellIdentityLte);
chppWwanConvertSignalStrengthLteFromChre(&in->signalStrengthLte,
&out->signalStrengthLte);
}
static void chppWwanConvertCellIdentityNrFromChre(
const struct chreWwanCellIdentityNr *in,
struct ChppWwanCellIdentityNr *out) {
out->mcc = in->mcc;
out->mnc = in->mnc;
out->nci0 = in->nci0;
out->nci1 = in->nci1;
out->pci = in->pci;
out->tac = in->tac;
out->nrarfcn = in->nrarfcn;
}
static void chppWwanConvertSignalStrengthNrFromChre(
const struct chreWwanSignalStrengthNr *in,
struct ChppWwanSignalStrengthNr *out) {
out->ssRsrp = in->ssRsrp;
out->ssRsrq = in->ssRsrq;
out->ssSinr = in->ssSinr;
out->csiRsrp = in->csiRsrp;
out->csiRsrq = in->csiRsrq;
out->csiSinr = in->csiSinr;
}
static void chppWwanConvertCellInfoNrFromChre(
const struct chreWwanCellInfoNr *in, struct ChppWwanCellInfoNr *out) {
chppWwanConvertCellIdentityNrFromChre(&in->cellIdentityNr,
&out->cellIdentityNr);
chppWwanConvertSignalStrengthNrFromChre(&in->signalStrengthNr,
&out->signalStrengthNr);
}
static void chppWwanConvertCellIdentityTdscdmaFromChre(
const struct chreWwanCellIdentityTdscdma *in,
struct ChppWwanCellIdentityTdscdma *out) {
out->mcc = in->mcc;
out->mnc = in->mnc;
out->lac = in->lac;
out->cid = in->cid;
out->cpid = in->cpid;
}
static void chppWwanConvertSignalStrengthTdscdmaFromChre(
const struct chreWwanSignalStrengthTdscdma *in,
struct ChppWwanSignalStrengthTdscdma *out) {
out->rscp = in->rscp;
}
static void chppWwanConvertCellInfoTdscdmaFromChre(
const struct chreWwanCellInfoTdscdma *in,
struct ChppWwanCellInfoTdscdma *out) {
chppWwanConvertCellIdentityTdscdmaFromChre(&in->cellIdentityTdscdma,
&out->cellIdentityTdscdma);
chppWwanConvertSignalStrengthTdscdmaFromChre(&in->signalStrengthTdscdma,
&out->signalStrengthTdscdma);
}
static void chppWwanConvertCellIdentityWcdmaFromChre(
const struct chreWwanCellIdentityWcdma *in,
struct ChppWwanCellIdentityWcdma *out) {
out->mcc = in->mcc;
out->mnc = in->mnc;
out->lac = in->lac;
out->cid = in->cid;
out->psc = in->psc;
out->uarfcn = in->uarfcn;
}
static void chppWwanConvertSignalStrengthWcdmaFromChre(
const struct chreWwanSignalStrengthWcdma *in,
struct ChppWwanSignalStrengthWcdma *out) {
out->signalStrength = in->signalStrength;
out->bitErrorRate = in->bitErrorRate;
}
static void chppWwanConvertCellInfoWcdmaFromChre(
const struct chreWwanCellInfoWcdma *in, struct ChppWwanCellInfoWcdma *out) {
chppWwanConvertCellIdentityWcdmaFromChre(&in->cellIdentityWcdma,
&out->cellIdentityWcdma);
chppWwanConvertSignalStrengthWcdmaFromChre(&in->signalStrengthWcdma,
&out->signalStrengthWcdma);
}
static void chppWwanConvertCellInfoFromChre(const struct chreWwanCellInfo *in,
struct ChppWwanCellInfo *out) {
out->timeStamp = in->timeStamp;
out->cellInfoType = in->cellInfoType;
out->timeStampType = in->timeStampType;
out->registered = in->registered;
out->reserved = 0;
memset(&out->CellInfo, 0, sizeof(out->CellInfo));
switch (in->cellInfoType) {
case CHRE_WWAN_CELL_INFO_TYPE_GSM:
chppWwanConvertCellInfoGsmFromChre(&in->CellInfo.gsm, &out->CellInfo.gsm);
break;
case CHRE_WWAN_CELL_INFO_TYPE_CDMA:
chppWwanConvertCellInfoCdmaFromChre(&in->CellInfo.cdma,
&out->CellInfo.cdma);
break;
case CHRE_WWAN_CELL_INFO_TYPE_LTE:
chppWwanConvertCellInfoLteFromChre(&in->CellInfo.lte, &out->CellInfo.lte);
break;
case CHRE_WWAN_CELL_INFO_TYPE_WCDMA:
chppWwanConvertCellInfoWcdmaFromChre(&in->CellInfo.wcdma,
&out->CellInfo.wcdma);
break;
case CHRE_WWAN_CELL_INFO_TYPE_TD_SCDMA:
chppWwanConvertCellInfoTdscdmaFromChre(&in->CellInfo.tdscdma,
&out->CellInfo.tdscdma);
break;
case CHRE_WWAN_CELL_INFO_TYPE_NR:
chppWwanConvertCellInfoNrFromChre(&in->CellInfo.nr, &out->CellInfo.nr);
break;
default:
CHPP_ASSERT(false);
}
}
static void chppWwanConvertCellInfoResultFromChre(
const struct chreWwanCellInfoResult *in, struct ChppWwanCellInfoResult *out,
uint8_t *payload, size_t payloadSize, uint16_t *vlaOffset) {
out->version = CHRE_WWAN_CELL_INFO_RESULT_VERSION;
out->errorCode = in->errorCode;
out->cellInfoCount = in->cellInfoCount;
out->reserved = 0;
out->cookie = 0;
struct ChppWwanCellInfo *cells =
(struct ChppWwanCellInfo *)&payload[*vlaOffset];
out->cells.length = in->cellInfoCount * sizeof(struct ChppWwanCellInfo);
CHPP_ASSERT(*vlaOffset + out->cells.length <= payloadSize);
if (out->cells.length > 0 && *vlaOffset + out->cells.length <= payloadSize) {
out->cells.offset = *vlaOffset;
*vlaOffset += out->cells.length;
for (size_t i = 0; i < in->cellInfoCount; i++) {
chppWwanConvertCellInfoFromChre(&in->cells[i], &cells[i]);
}
} else {
out->cells.offset = 0;
}
}
bool chppWwanCellInfoResultFromChre(
const struct chreWwanCellInfoResult *in,
struct ChppWwanCellInfoResultWithHeader **out, size_t *outSize) {
CHPP_NOT_NULL(out);
CHPP_NOT_NULL(outSize);
size_t payloadSize = chppWwanSizeOfCellInfoResultFromChre(in);
*out = chppMalloc(payloadSize);
if (*out != NULL) {
uint8_t *payload = (uint8_t *)&(*out)->payload;
uint16_t vlaOffset = sizeof(struct ChppWwanCellInfoResult);
chppWwanConvertCellInfoResultFromChre(in, &(*out)->payload, payload,
payloadSize, &vlaOffset);
*outSize = payloadSize;
return true;
}
return false;
}