commit b141465131601ad3760e696050b3f3a881b11183 Author: PythonLimited Date: Tue Mar 19 17:28:47 2019 +0100 treble bringup diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..a38db64 --- /dev/null +++ b/Android.bp @@ -0,0 +1,3 @@ +subdirs = [ + "sensors", +] diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..e89f340 --- /dev/null +++ b/Android.mk @@ -0,0 +1,253 @@ +# Copyright (C) 2014 The CyanogenMod 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. + +LOCAL_PATH := $(call my-dir) + +ifeq ($(BOARD_VENDOR),samsung) +ifeq ($(TARGET_BOARD_PLATFORM),msm8226) + +include $(call all-subdir-makefiles,$(LOCAL_PATH)) + +ADSP_IMAGES := \ + adsp.b00 adsp.b01 adsp.b02 adsp.b03 adsp.b04 adsp.b05 adsp.b06 \ + adsp.b08 adsp.b09 adsp.b10 adsp.b11 adsp.b12 adsp.b13 adsp.mdt + +ADSP_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(ADSP_IMAGES))) +$(ADSP_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "ADSP firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware-modem/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(ADSP_SYMLINKS) + +FIRMWARE_CMNLIB_IMAGES := \ + cmnlib.b00 cmnlib.b01 cmnlib.b02 cmnlib.b03 cmnlib.mdt + +FIRMWARE_CMNLIB_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(FIRMWARE_CMNLIB_IMAGES))) +$(FIRMWARE_CMNLIB_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "CMNLIB Firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(FIRMWARE_CMNLIB_SYMLINKS) + +ISDB_IMAGES := \ + isdbtmm.b00 isdbtmm.b01 isdbtmm.b02 isdbtmm.b03 isdbtmm.mdt + +ISDB_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(ISDB_IMAGES))) +$(ISDB_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "ISDB firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(ISDB_SYMLINKS) + +KM_IMAGES := \ + keymaster.b00 keymaster.b01 keymaster.b02 keymaster.b03 keymaster.mdt + +KM_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR)/firmware/keymaster/,$(notdir $(KM_IMAGES))) +$(KM_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Keymaster firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/keymaste$(suffix $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(KM_SYMLINKS) + +MBA_IMAGES := \ + mba.b00 mba.mdt + +MBA_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(MBA_IMAGES))) +$(MBA_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "MBA firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware-modem/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(MBA_SYMLINKS) + +MC_IMAGES := \ + mc_v2.b00 mc_v2.b01 mc_v2.b02 mc_v2.b03 mc_v2.mdt + +MC_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(MC_IMAGES))) +$(MC_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Mobicore firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(MC_SYMLINKS) + +MODEM_IMAGES := \ + modem.b00 modem.b01 modem.b02 modem.b03 modem.b04 modem.b05 \ + modem.b06 modem.b08 modem.b09 modem.b10 modem.b11 modem.b13 \ + modem.b14 modem.b15 modem.b16 modem.b17 modem.b18 modem.b19 \ + modem.b20 modem.b21 modem.b22 modem.b23 modem.b24 modem.b25 \ + modem.b26 modem.b27 modem.b28 modem.b29 modem.mdt + +MODEM_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(MODEM_IMAGES))) +$(MODEM_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Modem firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware-modem/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(MODEM_SYMLINKS) + +PROV_IMAGES := \ + prov.b00 prov.b01 prov.b02 prov.b03 prov.mtd \ + +PROV_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(PROV_IMAGES))) +$(PROV_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Prov firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(PROV_SYMLINKS) + +SECSTOR_IMAGES := \ + sec_stor.b00 sec_stor.b01 sec_stor.b02 sec_stor.b03 sec_stor.mdt + +SECSTOR_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(SECSTOR_IMAGES))) +$(SECSTOR_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Secstor firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(SECSTOR_SYMLINKS) + +SKM_IMAGES := \ + skm.b00 skm.b01 skm.b02 skm.b03 skm.mdt + +SKM_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(SKM_IMAGES))) +$(SKM_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "SKM firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(SKM_SYMLINKS) + +SKMM_TA_IMAGES := \ + skmm_ta.b00 skmm_ta.b01 skmm_ta.b02 skmm_ta.b03 skmm_ta.mdt + +SKMM_TA_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(SKMM_TA_IMAGES))) +$(SKMM_TA_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "SKMM firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(SKMM_TA_SYMLINKS) + +SSHDCPAP_IMAGES := \ + sshdcpap.b00 sshdcpap.b01 sshdcpap.b02 sshdcpap.b03 sshdcpap.mdt + +SSHDCPAP_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(SSHDCPAP_IMAGES))) +$(SSHDCPAP_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "SSHDCPAP firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(SSHDCPAP_SYMLINKS) + +TBASE_IMAGES := \ + tbase300.b00 tbase300.b01 tbase300.b02 tbase300.b03 tbase300.mdt + +SSHDCPAP_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(SSHDCPAP_IMAGES))) +$(TBASE_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "SSHDCPAP firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(TBASE_SYMLINKS) + +TZPR_IMAGES := \ + tzpr25.b00 tzpr25.b01 tzpr25.b02 tzpr25.b03 tzpr25.mdt + +TZPR_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(TZPR_IMAGES))) +$(TZPR_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "TZPR firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(TZPR_SYMLINKS) + +TZ_CCM_IMAGES := \ + tz_ccm.b00 tz_ccm.b01 tz_ccm.b02 tz_ccm.b03 tz_ccm.mdt + +TZ_CCM_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(TZ_CCM_IMAGES))) +$(TZ_CCM_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "TZ_CCM firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(TZ_CCM_SYMLINKS) + +VENUS_IMAGES := \ + venus.b00 venus.b01 venus.b02 venus.b03 venus.b04 venus.mdt + +VENUS_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(VENUS_IMAGES))) +$(VENUS_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Venus firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(VENUS_SYMLINKS) + +WCNSS_IMAGES := \ + wcnss.b00 wcnss.b01 wcnss.b02 wcnss.b04 wcnss.b06 \ + wcnss.b07 wcnss.b08 wcnss.b09 wcnss.mdt + +WCNSS_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR_ETC)/firmware/,$(notdir $(WCNSS_IMAGES))) +$(WCNSS_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "WCNSS firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(WCNSS_SYMLINKS) + +WV_IMAGES := \ + widevine.b00 widevine.b01 widevine.b02 widevine.b03 widevine.mdt + +WV_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR)/firmware/,$(notdir $(WV_IMAGES))) +$(WV_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Widevine firmware link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf /firmware/image/$(notdir $@) $@ + +ALL_DEFAULT_INSTALLED_MODULES += $(WV_SYMLINKS) + +# Create links for audcal data files +$(shell mkdir -p $(TARGET_OUT_VENDOR_ETC)/firmware/wcd9306; \ + ln -sf /data/misc/audio/wcd9320_anc.bin \ + $(TARGET_OUT_VENDOR_ETC)/firmware/wcd9306/wcd9306_anc.bin; \ + ln -sf /data/misc/audio/mbhc.bin \ + $(TARGET_OUT_VENDOR_ETC)/firmware/wcd9306/wcd9306_mbhc.bin) + + +endif +endif diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk new file mode 100644 index 0000000..8d9db0c --- /dev/null +++ b/BoardConfigCommon.mk @@ -0,0 +1,59 @@ +# Copyright (C) 2014 The CyanogenMod 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. + +# Inherit from qcom-common +-include device/samsung/qcom-common/BoardConfigCommon.mk + +#-include vendor/qcom/proprietary/common/msm8226/BoardConfigVendor.mk + +VENDOR_PATH := device/samsung/msm8226-common + +#QC_PROP_ROOT := vendor/qcom/proprietary +#PROTOBUF_SUPPORTED := true + +include device/samsung/msm8226-common/board/*.mk + +TARGET_SPECIFIC_HEADER_PATH := $(VENDOR_PATH)/include + +# CMHW +BOARD_HARDWARE_CLASS += $(VENDOR_PATH)/cmhw + +# Filesystem +TARGET_FS_CONFIG_GEN := device/samsung/msm8226-common/config.fs + +# QCOM hardware +BOARD_USES_QCOM_HARDWARE := true +TARGET_POWERHAL_VARIANT := qcom +BOARD_USES_QC_TIME_SERVICES := true + +#HIDL +DEVICE_MANIFEST_FILE := $(VENDOR_PATH)/manifest.xml +DEVICE_MATRIX_FILE := $(VENDOR_PATH)/compatibility_matrix.xml + +TARGET_PROVIDES_LIBLIGHT := true + +# Fonts +EXTENDED_FONT_FOOTPRINT := true + +# FMRadio +AUDIO_FEATURE_ENABLED_FM := true +TARGET_QCOM_NO_FM_FIRMWARE := true +BOARD_HAVE_QCOM_FM := true + +# Properites +BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true +TARGET_VENDOR_PROP += $(VENDOR_PATH)/vendor.prop + +# SELinux +include device/qcom/sepolicy/sepolicy.mk diff --git a/board/art.mk b/board/art.mk new file mode 100644 index 0000000..a01cb4c --- /dev/null +++ b/board/art.mk @@ -0,0 +1,3 @@ +# ART +WITH_DEXPREOPT := true +WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true diff --git a/board/audio.mk b/board/audio.mk new file mode 100644 index 0000000..7e1d697 --- /dev/null +++ b/board/audio.mk @@ -0,0 +1,5 @@ +# Audio +#AUDIO_FEATURE_ENABLED_LOW_LATENCY_CAPTURE := true +BOARD_USES_ALSA_AUDIO := true +#USE_CUSTOM_AUDIO_POLICY := 1 +#USE_XML_AUDIO_POLICY_CONF := 1 diff --git a/board/bluetooth.mk b/board/bluetooth.mk new file mode 100644 index 0000000..a185be0 --- /dev/null +++ b/board/bluetooth.mk @@ -0,0 +1,5 @@ +# Bluetooth +BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := $(LOCAL_PATH)/bluetooth +BOARD_HAVE_BLUETOOTH := true +BOARD_HAVE_BLUETOOTH_QCOM := true +BLUETOOTH_HCI_USE_MCT := true diff --git a/board/bootloader.mk b/board/bootloader.mk new file mode 100644 index 0000000..c3c2646 --- /dev/null +++ b/board/bootloader.mk @@ -0,0 +1,2 @@ +# Bootloader +TARGET_BOOTLOADER_BOARD_NAME := MSM8226 diff --git a/board/camera.mk b/board/camera.mk new file mode 100644 index 0000000..be1e509 --- /dev/null +++ b/board/camera.mk @@ -0,0 +1,6 @@ +# Camera +USE_DEVICE_SPECIFIC_CAMERA := true +TARGET_HAS_LEGACY_CAMERA_HAL1 := true +TARGET_USES_NON_TREBLE_CAMERA := true +TARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS := true +TARGET_NEEDS_LEGACY_CAMERA_HAL1_DYN_NATIVE_HANDLE := true diff --git a/board/charger.mk b/board/charger.mk new file mode 100644 index 0000000..79a4787 --- /dev/null +++ b/board/charger.mk @@ -0,0 +1,6 @@ +# Charger +BOARD_BATTERY_DEVICE_NAME := "battery" +BOARD_CHARGING_CMDLINE_NAME := "androidboot.mode" +BOARD_CHARGING_CMDLINE_VALUE := "charger" +BOARD_CHARGER_ENABLE_SUSPEND := true +BOARD_CHARGER_SHOW_PERCENTAGE := true diff --git a/board/dexpreopt.mk b/board/dexpreopt.mk new file mode 100644 index 0000000..8c09c4c --- /dev/null +++ b/board/dexpreopt.mk @@ -0,0 +1,6 @@ +# Basic dexpreopt +ifeq ($(HOST_OS),linux) + #We need this otherwise WIFI causes a bootloop on each connect! + WITH_DEXPREOPT := true + +endif diff --git a/board/display.mk b/board/display.mk new file mode 100644 index 0000000..c47a90e --- /dev/null +++ b/board/display.mk @@ -0,0 +1,13 @@ +# Display +NUM_FRAMEBUFFER_SURFACE_BUFFERS := 3 +OVERRIDE_RS_DRIVER := libRSDriver_adreno.so + +# Shader cache config options +# Maximum size of the GLES Shaders that can be cached for reuse. +# Increase the size if shaders of size greater than 12KB are used. +MAX_EGL_CACHE_KEY_SIZE := 12*1024 + +# Maximum GLES shader cache size for each app to store the compiled shader +# binaries. Decrease the size if RAM or Flash Storage size is a limitation +# of the device. +MAX_EGL_CACHE_SIZE := 2048*1024 diff --git a/board/fm.mk b/board/fm.mk new file mode 100644 index 0000000..9d91525 --- /dev/null +++ b/board/fm.mk @@ -0,0 +1,4 @@ +# FM +AUDIO_FEATURE_ENABLED_FM := true +TARGET_QCOM_NO_FM_FIRMWARE := true + diff --git a/board/gpu.mk b/board/gpu.mk new file mode 100644 index 0000000..bce0b97 --- /dev/null +++ b/board/gpu.mk @@ -0,0 +1,3 @@ +# GPU +TARGET_BOARD_PLATFORM := msm8226 +TARGET_BOARD_PLATFORM_GPU := qcom-adreno305 diff --git a/board/init.mk b/board/init.mk new file mode 100644 index 0000000..f5977dc --- /dev/null +++ b/board/init.mk @@ -0,0 +1,2 @@ +# Init +TARGET_INIT_VENDOR_LIB := libinit_msm diff --git a/board/kernel.mk b/board/kernel.mk new file mode 100644 index 0000000..c43e4ce --- /dev/null +++ b/board/kernel.mk @@ -0,0 +1,3 @@ +# Architecture +TARGET_CPU_MEMCPY_BASE_OPT_DISABLE := true +TARGET_CPU_VARIANT := krait diff --git a/board/memory.mk b/board/memory.mk new file mode 100644 index 0000000..72eb3ec --- /dev/null +++ b/board/memory.mk @@ -0,0 +1,2 @@ +# Memory +MALLOC_SVELTE := true diff --git a/board/partitions.mk b/board/partitions.mk new file mode 100644 index 0000000..8d87197 --- /dev/null +++ b/board/partitions.mk @@ -0,0 +1,5 @@ +# Partitions and Vold +BOARD_VOLD_EMMC_SHARES_DEV_MAJOR := true +TARGET_USERIMAGES_USE_EXT4 := true +TARGET_USE_CUSTOM_LUN_FILE_PATH := /sys/devices/platform/msm_hsusb/gadget/lun%d/file + diff --git a/board/radio.mk b/board/radio.mk new file mode 100644 index 0000000..b580a93 --- /dev/null +++ b/board/radio.mk @@ -0,0 +1,3 @@ +# Radio +BOARD_PROVIDES_LIBRIL := true +TARGET_RIL_VARIANT := caf diff --git a/board/treble.mk b/board/treble.mk new file mode 100644 index 0000000..f2423e2 --- /dev/null +++ b/board/treble.mk @@ -0,0 +1,8 @@ +# Treble +PRODUCT_SHIPPING_API_LEVEL := 19 +PRODUCT_FULL_TREBLE_OVERRIDE := true +PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE := 27 +BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true + +BOARD_VNDK_RUNTIME_DISABLE := true +BOARD_VNDK_VERSION := current diff --git a/board/wifi.mk b/board/wifi.mk new file mode 100644 index 0000000..fdb11cf --- /dev/null +++ b/board/wifi.mk @@ -0,0 +1,14 @@ +# Wifi +BOARD_HAS_QCOM_WLAN := true +BOARD_HAS_QCOM_WLAN_SDK := true +BOARD_WLAN_DEVICE := qcwcn +BOARD_HOSTAPD_DRIVER := NL80211 +BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE) +BOARD_WPA_SUPPLICANT_DRIVER := NL80211 +BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE) +TARGET_PROVIDES_WCNSS_QMI := true +TARGET_USES_QCOM_WCNSS_QMI := true +TARGET_USES_WCNSS_CTRL := true +WPA_SUPPLICANT_VERSION := VER_0_8_X +WIFI_DRIVER_FW_PATH_STA := "sta" +WIFI_DRIVER_FW_PATH_AP := "ap" diff --git a/cmhw/org/lineageos/hardware/KeyDisabler.java b/cmhw/org/lineageos/hardware/KeyDisabler.java new file mode 100644 index 0000000..9e7365e --- /dev/null +++ b/cmhw/org/lineageos/hardware/KeyDisabler.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 The CyanogenMod 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. + */ + +package org.lineageos.hardware; + +import org.lineageos.internal.util.FileUtils; + +/* + * Disable capacitive keys + * + * This is intended for use on devices in which the capacitive keys + * can be fully disabled for replacement with a soft navbar. You + * really should not be using this on a device with mechanical or + * otherwise visible-when-inactive keys + */ + +public class KeyDisabler { + + private static final String KEYDISABLER_PATH = "/sys/class/sec/sec_touchkey/keypad_enable"; + /* + * All HAF classes should export this boolean. + * Real implementations must, of course, return true + */ + + public static boolean isSupported() { + return FileUtils.isFileWritable(KEYDISABLER_PATH); + } + + /* + * Are the keys currently blocked? + */ + + public static boolean isActive() { + return FileUtils.readOneLine(KEYDISABLER_PATH).equals("0"); + } + + /* + * Disable capacitive keys + */ + + public static boolean setActive(boolean state) { + return FileUtils.writeLine(KEYDISABLER_PATH, state ? "0" : "1"); + } +} diff --git a/compatibility_matrix.xml b/compatibility_matrix.xml new file mode 100644 index 0000000..1dcaa97 --- /dev/null +++ b/compatibility_matrix.xml @@ -0,0 +1,86 @@ + + + android.frameworks.displayservice + 1.0 + + IDisplayService + default + + + + android.frameworks.schedulerservice + 1.0 + + ISchedulingPolicyService + default + + + + android.frameworks.sensorservice + 1.0 + + ISensorManager + default + + + + android.hardware.graphics.composer + 2.1 + + IComposer + vr + + + + android.hidl.allocator + 1.0 + + IAllocator + ashmem + + + + android.hidl.manager + 1.1 + + IServiceManager + default + + + + android.hidl.memory + 1.0 + + IMapper + ashmem + + + + android.hidl.token + 1.0 + + ITokenManager + default + + + + android.system.net.netd + 1.0 + + INetd + default + + + + android.system.wifi.keystore + 1.0 + + IKeystore + default + + + + netutils-wrapper + 1.0 + + diff --git a/config.fs b/config.fs new file mode 100644 index 0000000..14d23f5 --- /dev/null +++ b/config.fs @@ -0,0 +1,8 @@ +[AID_QCOM_DIAG] +value:2950 + +[AID_RFS] +value:2951 + +[AID_RFS_SHARED] +value:2952 diff --git a/configs/_hals.conf b/configs/_hals.conf new file mode 100644 index 0000000..e40e35d --- /dev/null +++ b/configs/_hals.conf @@ -0,0 +1 @@ +sensors.vendor.msm8226.so diff --git a/configs/media_codecs.xml b/configs/media_codecs.xml new file mode 100644 index 0000000..f169b2d --- /dev/null +++ b/configs/media_codecs.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/configs/media_codecs_performance.xml b/configs/media_codecs_performance.xml new file mode 100644 index 0000000..2382a53 --- /dev/null +++ b/configs/media_codecs_performance.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/device-vendor-s3ve3g.mk b/device-vendor-s3ve3g.mk new file mode 100644 index 0000000..3fdb94e --- /dev/null +++ b/device-vendor-s3ve3g.mk @@ -0,0 +1,4 @@ +ifeq ($(QC_COMPILE), true) +QC_PROP_ROOT := vendor/qcom/proprietary +PROTOBUF_SUPPORTED := true +endif diff --git a/gps/Android.mk b/gps/Android.mk new file mode 100644 index 0000000..37483e0 --- /dev/null +++ b/gps/Android.mk @@ -0,0 +1,17 @@ +# +# Copyright (C) 2017 The LineageOS 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. +# + +include $(call first-makefiles-under,$(call my-dir)) diff --git a/gps/Makefile.am b/gps/Makefile.am new file mode 100644 index 0000000..f374a5c --- /dev/null +++ b/gps/Makefile.am @@ -0,0 +1,10 @@ +# Makefile.am - Automake script for gps loc_api +# + +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = utils loc_api/libloc_api_50001 loc_api/loc_api_v02 + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = loc-api.pc +EXTRA_DIST = $(pkgconfig_DATA) diff --git a/gps/configure.ac b/gps/configure.ac new file mode 100644 index 0000000..dca18a1 --- /dev/null +++ b/gps/configure.ac @@ -0,0 +1,85 @@ +# configure.ac -- Autoconf script for gps loc_api +# +# Process this file with autoconf to produce a configure script + +# Requires autoconf tool later than 2.61 +AC_PREREQ(2.61) +# Initialize the gps loc_api package version 1.0.0 +AC_INIT([loc-api],1.0.0) +# Does not strictly follow GNU Coding standards +AM_INIT_AUTOMAKE([foreign]) +# Disables auto rebuilding of configure, Makefile.ins +AM_MAINTAINER_MODE +# Verifies the --srcdir is correct by checking for the path +AC_CONFIG_SRCDIR([utils/loc_cfg.cpp]) +# defines some macros variable to be included by source +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +# Checks for libraries. +PKG_CHECK_MODULES([QMIF], [qmi-framework]) +AC_SUBST([QMIF_CFLAGS]) +AC_SUBST([QMIF_LIBS]) + +AC_ARG_WITH([libhardware_includes], + AC_HELP_STRING([--with-libhardware-includes=@<:@dir@:>@], + [Specify the location of the libhardware headers]), + [libhardware_incdir=$withval], + with_libhardware_includes=no) + +if test "x$with_libhardware_includes" != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${libhardware_incdir}" +fi + +AC_ARG_WITH([core_includes], + AC_HELP_STRING([--with-core-includes=@<:@dir@:>@], + [Specify the location of the core headers]), + [core_incdir=$withval], + with_core_includes=no) + +if test "x$with_core_includes" != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${core_incdir}" +fi + +AC_SUBST([CPPFLAGS]) + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +AC_CONFIG_FILES([ \ + Makefile \ + utils/Makefile \ + loc_api/libloc_api_50001/Makefile \ + loc_api/loc_api_v02/Makefile \ + loc-api.pc \ + ]) + +AC_OUTPUT diff --git a/gps/core/Android.mk b/gps/core/Android.mk new file mode 100644 index 0000000..4105615 --- /dev/null +++ b/gps/core/Android.mk @@ -0,0 +1,42 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libloc_core +LOCAL_MODULE_OWNER := qcom +LOCAL_PROPRIETARY_MODULE := true + +LOCAL_MODULE_TAGS := optional + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libutils \ + libcutils \ + libgps.utils \ + libdl \ + libhardware + +LOCAL_SRC_FILES += \ + LocApiBase.cpp \ + LocAdapterBase.cpp \ + ContextBase.cpp \ + LocDualContext.cpp \ + loc_core_log.cpp + +LOCAL_CFLAGS += \ + -fno-short-enums \ + -D_ANDROID_ \ + -Wno-unused-parameter + +LOCAL_C_INCLUDES:= \ + $(TARGET_OUT_HEADERS)/gps.utils \ + $(TARGET_OUT_HEADERS)/libflp + +LOCAL_HEADER_LIBRARIES := libgps.utils_headers + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libloc_core_headers +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) +include $(BUILD_HEADER_LIBRARY) diff --git a/gps/core/ContextBase.cpp b/gps/core/ContextBase.cpp new file mode 100644 index 0000000..9f6c4aa --- /dev/null +++ b/gps/core/ContextBase.cpp @@ -0,0 +1,114 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_CtxBase" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +LBSProxyBase* ContextBase::getLBSProxy(const char* libName) +{ + LBSProxyBase* proxy = NULL; + LOC_LOGD("%s:%d]: getLBSProxy libname: %s\n", __func__, __LINE__, libName); + void* lib = dlopen(libName, RTLD_NOW); + + if ((void*)NULL != lib) { + getLBSProxy_t* getter = (getLBSProxy_t*)dlsym(lib, "getLBSProxy"); + if (NULL != getter) { + proxy = (*getter)(); + } + } + if (NULL == proxy) { + proxy = new LBSProxyBase(); + } + LOC_LOGD("%s:%d]: Exiting\n", __func__, __LINE__); + return proxy; +} + +LocApiBase* ContextBase::createLocApi(LOC_API_ADAPTER_EVENT_MASK_T exMask) +{ + LocApiBase* locApi = NULL; + + // first if can not be MPQ + if (TARGET_MPQ != loc_get_target()) { + if (NULL == (locApi = mLBSProxy->getLocApi(mMsgTask, exMask, this))) { + void *handle = NULL; + //try to see if LocApiV02 is present + if((handle = dlopen("libloc_api_v02.so", RTLD_NOW)) != NULL) { + LOC_LOGD("%s:%d]: libloc_api_v02.so is present", __func__, __LINE__); + getLocApi_t* getter = (getLocApi_t*)dlsym(handle, "getLocApi"); + if(getter != NULL) { + LOC_LOGD("%s:%d]: getter is not NULL for LocApiV02", __func__, __LINE__); + locApi = (*getter)(mMsgTask, exMask, this); + } + } + // only RPC is the option now + else { + LOC_LOGD("%s:%d]: libloc_api_v02.so is NOT present. Trying RPC", + __func__, __LINE__); + handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW); + if (NULL != handle) { + getLocApi_t* getter = (getLocApi_t*)dlsym(handle, "getLocApi"); + if (NULL != getter) { + LOC_LOGD("%s:%d]: getter is not NULL in RPC", __func__, __LINE__); + locApi = (*getter)(mMsgTask, exMask, this); + } + } + } + } + } + + // locApi could still be NULL at this time + // we would then create a dummy one + if (NULL == locApi) { + locApi = new LocApiBase(mMsgTask, exMask, this); + } + + return locApi; +} + +ContextBase::ContextBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + const char* libName) : + mLBSProxy(getLBSProxy(libName)), + mMsgTask(msgTask), + mLocApi(createLocApi(exMask)), + mLocApiProxy(mLocApi->getLocApiProxy()) +{ +} + +} diff --git a/gps/core/ContextBase.h b/gps/core/ContextBase.h new file mode 100644 index 0000000..fe0b860 --- /dev/null +++ b/gps/core/ContextBase.h @@ -0,0 +1,74 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_CONTEXT_BASE__ +#define __LOC_CONTEXT_BASE__ + +#include +#include +#include +#include +#include + +namespace loc_core { + +class LocAdapterBase; + +class ContextBase { + static LBSProxyBase* getLBSProxy(const char* libName); + LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask); +protected: + const LBSProxyBase* mLBSProxy; + const MsgTask* mMsgTask; + LocApiBase* mLocApi; + LocApiProxyBase *mLocApiProxy; +public: + ContextBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + const char* libName); + inline virtual ~ContextBase() { delete mLocApi; delete mLBSProxy; } + + inline const MsgTask* getMsgTask() { return mMsgTask; } + inline LocApiBase* getLocApi() { return mLocApi; } + inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; } + inline bool hasAgpsExtendedCapabilities() { return mLBSProxy->hasAgpsExtendedCapabilities(); } + inline bool hasCPIExtendedCapabilities() { return mLBSProxy->hasCPIExtendedCapabilities(); } + inline void modemPowerVote(bool power) const { return mLBSProxy->modemPowerVote(power); } + inline void requestUlp(LocAdapterBase* adapter, + unsigned long capabilities) { + mLBSProxy->requestUlp(adapter, capabilities); + } + inline IzatDevId_t getIzatDevId() const { + return mLBSProxy->getIzatDevId(); + } + inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); } +}; + +} // namespace loc_core + +#endif //__LOC_CONTEXT_BASE__ diff --git a/gps/core/LBSProxyBase.h b/gps/core/LBSProxyBase.h new file mode 100644 index 0000000..b3736c2 --- /dev/null +++ b/gps/core/LBSProxyBase.h @@ -0,0 +1,79 @@ +/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef IZAT_PROXY_BASE_H +#define IZAT_PROXY_BASE_H +#include +#include + +namespace loc_core { + +class LocApiBase; +class LocAdapterBase; +class ContextBase; + +class LBSProxyBase { + friend class ContextBase; + inline virtual LocApiBase* + getLocApi(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + ContextBase* context) const { + + (void)msgTask; + (void)exMask; + (void)context; + return NULL; + } +protected: + inline LBSProxyBase() {} +public: + inline virtual ~LBSProxyBase() {} + inline virtual void requestUlp(LocAdapterBase* adapter, + unsigned long capabilities) const { + + (void)adapter; + (void)capabilities; + } + inline virtual bool hasAgpsExtendedCapabilities() const { return false; } + inline virtual bool hasCPIExtendedCapabilities() const { return false; } + inline virtual void modemPowerVote(bool power) const { + + (void)power; + } + virtual void injectFeatureConfig(ContextBase* context) const { + + (void)context; + } + inline virtual IzatDevId_t getIzatDevId() const { return 0; } +}; + +typedef LBSProxyBase* (getLBSProxy_t)(); + +} // namespace loc_core + +#endif // IZAT_PROXY_BASE_H diff --git a/gps/core/LocAdapterBase.cpp b/gps/core/LocAdapterBase.cpp new file mode 100644 index 0000000..8348efa --- /dev/null +++ b/gps/core/LocAdapterBase.cpp @@ -0,0 +1,142 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_LocAdapterBase" + +#include +#include +#include +#include +#include + +namespace loc_core { + +// This is the top level class, so the constructor will +// always gets called. Here we prepare for the default. +// But if getLocApi(targetEnumType target) is overriden, +// the right locApi should get created. +LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context, LocAdapterProxyBase *adapterProxyBase) : + mEvtMask(mask), mContext(context), + mLocApi(context->getLocApi()), mLocAdapterProxyBase(adapterProxyBase), + mMsgTask(context->getMsgTask()) +{ + mLocApi->addAdapter(this); +} + +void LocAdapterBase::handleEngineUpEvent() +{ + if (mLocAdapterProxyBase) { + mLocAdapterProxyBase->handleEngineUpEvent(); + } +} + +void LocAdapterBase::handleEngineDownEvent() +{ + if (mLocAdapterProxyBase) { + mLocAdapterProxyBase->handleEngineDownEvent(); + } +} + +void LocAdapterBase:: + reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) { + if (mLocAdapterProxyBase == NULL || + !mLocAdapterProxyBase->reportPosition(location, + locationExtended, + status, + loc_technology_mask)) { + DEFAULT_IMPL() + } +} + +void LocAdapterBase:: + reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) +DEFAULT_IMPL() + + +void LocAdapterBase:: + reportStatus(GpsStatusValue status) +DEFAULT_IMPL() + + +void LocAdapterBase:: + reportNmea(const char* nmea, int length) +DEFAULT_IMPL() + +bool LocAdapterBase:: + reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestXtraData() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestTime() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestLocation() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestATL(int connHandle, AGpsType agps_type) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + releaseATL(int connHandle) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestSuplES(int connHandle) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportDataCallOpened() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportDataCallClosed() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestNiNotify(GpsNiNotification ¬ify, const void* data) +DEFAULT_IMPL(false) + +void LocAdapterBase:: + reportGpsMeasurementData(GpsData &gpsMeasurementData) +DEFAULT_IMPL() +} // namespace loc_core diff --git a/gps/core/LocAdapterBase.h b/gps/core/LocAdapterBase.h new file mode 100644 index 0000000..40783df --- /dev/null +++ b/gps/core/LocAdapterBase.h @@ -0,0 +1,125 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_API_ADAPTER_BASE_H +#define LOC_API_ADAPTER_BASE_H + +#include +#include +#include + +namespace loc_core { + +class LocAdapterProxyBase; + +class LocAdapterBase { +protected: + LOC_API_ADAPTER_EVENT_MASK_T mEvtMask; + ContextBase* mContext; + LocApiBase* mLocApi; + LocAdapterProxyBase* mLocAdapterProxyBase; + const MsgTask* mMsgTask; + + inline LocAdapterBase(const MsgTask* msgTask) : + mEvtMask(0), mContext(NULL), mLocApi(NULL), + mLocAdapterProxyBase(NULL), mMsgTask(msgTask) {} +public: + inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); } + LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context, LocAdapterProxyBase *adapterProxyBase = NULL); + inline LOC_API_ADAPTER_EVENT_MASK_T + checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const { + return mEvtMask & mask; + } + + inline LOC_API_ADAPTER_EVENT_MASK_T getEvtMask() const { + return mEvtMask; + } + + inline void sendMsg(const LocMsg* msg) const { + mMsgTask->sendMsg(msg); + } + + inline void sendMsg(const LocMsg* msg) { + mMsgTask->sendMsg(msg); + } + + inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled) + { + mEvtMask = + isEnabled == LOC_REGISTRATION_MASK_ENABLED ? (mEvtMask|event):(mEvtMask&~event); + + mLocApi->updateEvtMask(); + } + + // This will be overridden by the individual adapters + // if necessary. + inline virtual void setUlpProxy(UlpProxyBase* ulp) { + + (void)ulp; + } + virtual void handleEngineUpEvent(); + virtual void handleEngineDownEvent(); + inline virtual void setPositionModeInt(LocPosMode& posMode) { + + (void)posMode; + } + virtual void startFixInt() {} + virtual void stopFixInt() {} + virtual void getZppInt() {} + virtual void reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + virtual void reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt); + virtual void reportStatus(GpsStatusValue status); + virtual void reportNmea(const char* nmea, int length); + virtual bool reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + virtual bool requestXtraData(); + virtual bool requestTime(); + virtual bool requestLocation(); + virtual bool requestATL(int connHandle, AGpsType agps_type); + virtual bool releaseATL(int connHandle); + virtual bool requestSuplES(int connHandle); + virtual bool reportDataCallOpened(); + virtual bool reportDataCallClosed(); + virtual bool requestNiNotify(GpsNiNotification ¬ify, + const void* data); + inline virtual bool isInSession() { return false; } + ContextBase* getContext() const { return mContext; } + virtual void reportGpsMeasurementData(GpsData &gpsMeasurementData); +}; + +} // namespace loc_core + +#endif //LOC_API_ADAPTER_BASE_H diff --git a/gps/core/LocAdapterProxyBase.h b/gps/core/LocAdapterProxyBase.h new file mode 100644 index 0000000..11859de --- /dev/null +++ b/gps/core/LocAdapterProxyBase.h @@ -0,0 +1,75 @@ +/* Copyright (c) 2014 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ADAPTER_PROXY_BASE_H +#define LOC_ADAPTER_PROXY_BASE_H + +#include +#include + +namespace loc_core { + +class LocAdapterProxyBase { +private: + LocAdapterBase *mLocAdapterBase; +protected: + inline LocAdapterProxyBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context): + mLocAdapterBase(new LocAdapterBase(mask, context, this)) { + } + inline virtual ~LocAdapterProxyBase() { + delete mLocAdapterBase; + } + ContextBase* getContext() const { + return mLocAdapterBase->getContext(); + } + inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled) { + mLocAdapterBase->updateEvtMask(event,isEnabled); + } + +public: + inline virtual void handleEngineUpEvent() {}; + inline virtual void handleEngineDownEvent() {}; + inline virtual bool reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) { + + (void)location; + (void)locationExtended; + (void)status; + (void)loc_technology_mask; + return false; + } +}; + +} // namespace loc_core + +#endif //LOC_ADAPTER_PROXY_BASE_H diff --git a/gps/core/LocApiBase.cpp b/gps/core/LocApiBase.cpp new file mode 100644 index 0000000..1278155 --- /dev/null +++ b/gps/core/LocApiBase.cpp @@ -0,0 +1,553 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_LocApiBase" + +#include +#include +#include +#include +#include + +namespace loc_core { + +#define TO_ALL_LOCADAPTERS(call) TO_ALL_ADAPTERS(mLocAdapters, (call)) +#define TO_1ST_HANDLING_LOCADAPTERS(call) TO_1ST_HANDLING_ADAPTER(mLocAdapters, (call)) + +int hexcode(char *hexstring, int string_size, + const char *data, int data_size) +{ + int i; + for (i = 0; i < data_size; i++) + { + char ch = data[i]; + if (i*2 + 3 <= string_size) + { + snprintf(&hexstring[i*2], 3, "%02X", ch); + } + else { + break; + } + } + return i; +} + +int decodeAddress(char *addr_string, int string_size, + const char *data, int data_size) +{ + const char addr_prefix = 0x91; + int i, idxOutput = 0; + + if (!data || !addr_string) { return 0; } + + if (data[0] != addr_prefix) + { + LOC_LOGW("decodeAddress: address prefix is not 0x%x but 0x%x", addr_prefix, data[0]); + addr_string[0] = '\0'; + return 0; // prefix not correct + } + + for (i = 1; i < data_size; i++) + { + unsigned char ch = data[i], low = ch & 0x0F, hi = ch >> 4; + if (low <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = low + '0'; } + if (hi <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = hi + '0'; } + } + + addr_string[idxOutput] = '\0'; // Terminates the string + + return idxOutput; +} + +struct LocSsrMsg : public LocMsg { + LocApiBase* mLocApi; + inline LocSsrMsg(LocApiBase* locApi) : + LocMsg(), mLocApi(locApi) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->close(); + mLocApi->open(mLocApi->getEvtMask()); + } + inline void locallog() { + LOC_LOGV("LocSsrMsg"); + } + inline virtual void log() { + locallog(); + } +}; + +struct LocOpenMsg : public LocMsg { + LocApiBase* mLocApi; + LOC_API_ADAPTER_EVENT_MASK_T mMask; + inline LocOpenMsg(LocApiBase* locApi, + LOC_API_ADAPTER_EVENT_MASK_T mask) : + LocMsg(), mLocApi(locApi), mMask(mask) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->open(mMask); + } + inline void locallog() { + LOC_LOGV("%s:%d]: LocOpen Mask: %x\n", + __func__, __LINE__, mMask); + } + inline virtual void log() { + locallog(); + } +}; + +LocApiBase::LocApiBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T excludedMask, + ContextBase* context) : + mExcludedMask(excludedMask), mMsgTask(msgTask), + mMask(0), mSupportedMsg(0), mContext(context) +{ + memset(mLocAdapters, 0, sizeof(mLocAdapters)); +} + +LOC_API_ADAPTER_EVENT_MASK_T LocApiBase::getEvtMask() +{ + LOC_API_ADAPTER_EVENT_MASK_T mask = 0; + + TO_ALL_LOCADAPTERS(mask |= mLocAdapters[i]->getEvtMask()); + + return mask & ~mExcludedMask; +} + +bool LocApiBase::isInSession() +{ + bool inSession = false; + + for (int i = 0; + !inSession && i < MAX_ADAPTERS && NULL != mLocAdapters[i]; + i++) { + inSession = mLocAdapters[i]->isInSession(); + } + + return inSession; +} + +void LocApiBase::addAdapter(LocAdapterBase* adapter) +{ + for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) { + if (mLocAdapters[i] == NULL) { + mLocAdapters[i] = adapter; + mMsgTask->sendMsg(new LocOpenMsg(this, + (adapter->getEvtMask()))); + break; + } + } +} + +void LocApiBase::removeAdapter(LocAdapterBase* adapter) +{ + for (int i = 0; + i < MAX_ADAPTERS && NULL != mLocAdapters[i]; + i++) { + if (mLocAdapters[i] == adapter) { + mLocAdapters[i] = NULL; + + // shift the rest of the adapters up so that the pointers + // in the array do not have holes. This should be more + // performant, because the array maintenance is much much + // less frequent than event handlings, which need to linear + // search all the adapters + int j = i; + while (++i < MAX_ADAPTERS && mLocAdapters[i] != NULL); + + // i would be MAX_ADAPTERS or point to a NULL + i--; + // i now should point to a none NULL adapter within valid + // range although i could be equal to j, but it won't hurt. + // No need to check it, as it gains nothing. + mLocAdapters[j] = mLocAdapters[i]; + // this makes sure that we exit the for loop + mLocAdapters[i] = NULL; + + // if we have an empty list of adapters + if (0 == i) { + close(); + } else { + // else we need to remove the bit + mMsgTask->sendMsg(new LocOpenMsg(this, getEvtMask())); + } + } + } +} + +void LocApiBase::updateEvtMask() +{ + mMsgTask->sendMsg(new LocOpenMsg(this, getEvtMask())); +} + +void LocApiBase::handleEngineUpEvent() +{ + // This will take care of renegotiating the loc handle + mMsgTask->sendMsg(new LocSsrMsg(this)); + + LocDualContext::injectFeatureConfig(mContext); + + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineUpEvent()); +} + +void LocApiBase::handleEngineDownEvent() +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent()); +} + +void LocApiBase::reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) +{ + // print the location info before delivering + LOC_LOGV("flags: %d\n source: %d\n latitude: %f\n longitude: %f\n " + "altitude: %f\n speed: %f\n bearing: %f\n accuracy: %f\n " + "timestamp: %lld\n rawDataSize: %d\n rawData: %p\n " + "Session status: %d\n Technology mask: %u", + location.gpsLocation.flags, location.position_source, + location.gpsLocation.latitude, location.gpsLocation.longitude, + location.gpsLocation.altitude, location.gpsLocation.speed, + location.gpsLocation.bearing, location.gpsLocation.accuracy, + location.gpsLocation.timestamp, location.rawDataSize, + location.rawData, status, loc_technology_mask); + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportPosition(location, + locationExtended, + locationExt, + status, + loc_technology_mask) + ); +} + +void LocApiBase::reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) +{ + // print the SV info before delivering + LOC_LOGV("num sv: %d\n ephemeris mask: %dxn almanac mask: %x\n gps/glo/bds in use" + " mask: %x/%x/%x\n sv: prn snr elevation azimuth", + svStatus.num_svs, svStatus.ephemeris_mask, + svStatus.almanac_mask, svStatus.gps_used_in_fix_mask, + svStatus.glo_used_in_fix_mask, svStatus.bds_used_in_fix_mask); + for (int i = 0; i < svStatus.num_svs && i < GPS_MAX_SVS; i++) { + LOC_LOGV(" %d: %d %f %f %f", + i, + svStatus.sv_list[i].prn, + svStatus.sv_list[i].snr, + svStatus.sv_list[i].elevation, + svStatus.sv_list[i].azimuth); + } + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportSv(svStatus, + locationExtended, + svExt) + ); +} + +void LocApiBase::reportStatus(GpsStatusValue status) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportStatus(status)); +} + +void LocApiBase::reportNmea(const char* nmea, int length) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmea(nmea, length)); +} + +void LocApiBase::reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportXtraServer(url1, url2, url3, maxlength)); + +} + +void LocApiBase::requestXtraData() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestXtraData()); +} + +void LocApiBase::requestTime() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestTime()); +} + +void LocApiBase::requestLocation() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestLocation()); +} + +void LocApiBase::requestATL(int connHandle, AGpsType agps_type) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestATL(connHandle, agps_type)); +} + +void LocApiBase::releaseATL(int connHandle) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->releaseATL(connHandle)); +} + +void LocApiBase::requestSuplES(int connHandle) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestSuplES(connHandle)); +} + +void LocApiBase::reportDataCallOpened() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallOpened()); +} + +void LocApiBase::reportDataCallClosed() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallClosed()); +} + +void LocApiBase::requestNiNotify(GpsNiNotification ¬ify, const void* data) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotify(notify, data)); +} + +void LocApiBase::saveSupportedMsgList(uint64_t supportedMsgList) +{ + mSupportedMsg = supportedMsgList; +} + +void* LocApiBase :: getSibling() + DEFAULT_IMPL(NULL) + +LocApiProxyBase* LocApiBase :: getLocApiProxy() + DEFAULT_IMPL(NULL) + +void LocApiBase::reportGpsMeasurementData(GpsData &gpsMeasurementData) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGpsMeasurementData(gpsMeasurementData)); +} + +enum loc_api_adapter_err LocApiBase:: + open(LOC_API_ADAPTER_EVENT_MASK_T mask) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + close() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + startFix(const LocPosMode& posMode) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + stopFix() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + deleteAidingData(GpsAidingData f) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + enableData(int enable) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setAPN(char* apn, int len) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + injectPosition(double latitude, double longitude, float accuracy) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setTime(GpsUtcTime time, int64_t timeReference, int uncertainty) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setXtraData(char* data, int length) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + requestXtraServer() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + atlOpenStatus(int handle, int is_succ, char* apn, + AGpsBearerType bear, AGpsType agpsType) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + atlCloseStatus(int handle, int is_succ) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setPositionMode(const LocPosMode& posMode) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setServer(const char* url, int len) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setServer(unsigned int ip, int port, + LocServerType type) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + informNiResponse(GpsUserResponseType userResponse, + const void* passThroughData) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSUPLVersion(uint32_t version) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setLPPConfig(uint32_t profile) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorControlConfig(int sensorUsage, + int sensorProvider) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, + float gyroBiasVarianceRandomWalk, + bool accelBiasVarianceRandomWalk_valid, + float accelBiasVarianceRandomWalk, + bool angleBiasVarianceRandomWalk_valid, + float angleBiasVarianceRandomWalk, + bool rateBiasVarianceRandomWalk_valid, + float rateBiasVarianceRandomWalk, + bool velocityBiasVarianceRandomWalk_valid, + float velocityBiasVarianceRandomWalk) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorPerfControlConfig(int controlMode, + int accelSamplesPerBatch, + int accelBatchesPerSec, + int gyroSamplesPerBatch, + int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, + int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, + int gyroBatchesPerSecHigh, + int algorithmConfig) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setExtPowerConfig(int isBatteryCharging) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setAGLONASSProtocol(unsigned long aGlonassProtocol) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + getWwanZppFix(GpsLocation& zppLoc) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + getBestAvailableZppFix(GpsLocation& zppLoc) +{ + memset(&zppLoc, 0, sizeof(zppLoc)); + DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) +} + +enum loc_api_adapter_err LocApiBase:: + getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask) +{ + memset(&zppLoc, 0, sizeof(zppLoc)); + memset(&tech_mask, 0, sizeof(tech_mask)); + DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) +} + +int LocApiBase:: + initDataServiceClient() +DEFAULT_IMPL(-1) + +int LocApiBase:: + openAndStartDataCall() +DEFAULT_IMPL(-1) + +void LocApiBase:: + stopDataCall() +DEFAULT_IMPL() + +void LocApiBase:: + closeDataCall() +DEFAULT_IMPL() + +int LocApiBase:: + setGpsLock(LOC_GPS_LOCK_MASK lock) +DEFAULT_IMPL(-1) + +void LocApiBase:: + installAGpsCert(const DerEncodedCertificate* pData, + size_t length, + uint32_t slotBitMask) +DEFAULT_IMPL() + +int LocApiBase:: + getGpsLock() +DEFAULT_IMPL(-1) + +enum loc_api_adapter_err LocApiBase:: + setXtraVersionCheck(enum xtra_version_check check) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +int LocApiBase:: + updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled) +DEFAULT_IMPL(-1) + +bool LocApiBase:: + gnssConstellationConfig() +DEFAULT_IMPL(false) + +} // namespace loc_core diff --git a/gps/core/LocApiBase.h b/gps/core/LocApiBase.h new file mode 100644 index 0000000..64bb0f9 --- /dev/null +++ b/gps/core/LocApiBase.h @@ -0,0 +1,267 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_API_BASE_H +#define LOC_API_BASE_H + +#include +#include +#include +#include +#include + +namespace loc_core { +class ContextBase; + +int hexcode(char *hexstring, int string_size, + const char *data, int data_size); +int decodeAddress(char *addr_string, int string_size, + const char *data, int data_size); + +#define MAX_ADAPTERS 10 + +#define TO_ALL_ADAPTERS(adapters, call) \ + for (int i = 0; i < MAX_ADAPTERS && NULL != (adapters)[i]; i++) { \ + call; \ + } + +#define TO_1ST_HANDLING_ADAPTER(adapters, call) \ + for (int i = 0; i sendMsg(msg); + } + + void addAdapter(LocAdapterBase* adapter); + void removeAdapter(LocAdapterBase* adapter); + + // upward calls + void handleEngineUpEvent(); + void handleEngineDownEvent(); + void reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask = + LOC_POS_TECH_MASK_DEFAULT); + void reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt); + void reportStatus(GpsStatusValue status); + void reportNmea(const char* nmea, int length); + void reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + void requestXtraData(); + void requestTime(); + void requestLocation(); + void requestATL(int connHandle, AGpsType agps_type); + void releaseATL(int connHandle); + void requestSuplES(int connHandle); + void reportDataCallOpened(); + void reportDataCallClosed(); + void requestNiNotify(GpsNiNotification ¬ify, const void* data); + void saveSupportedMsgList(uint64_t supportedMsgList); + void reportGpsMeasurementData(GpsData &gpsMeasurementData); + + // downward calls + // All below functions are to be defined by adapter specific modules: + // RPC, QMI, etc. The default implementation is empty. + + virtual void* getSibling(); + virtual LocApiProxyBase* getLocApiProxy(); + virtual enum loc_api_adapter_err + startFix(const LocPosMode& posMode); + virtual enum loc_api_adapter_err + stopFix(); + virtual enum loc_api_adapter_err + deleteAidingData(GpsAidingData f); + virtual enum loc_api_adapter_err + enableData(int enable); + virtual enum loc_api_adapter_err + setAPN(char* apn, int len); + virtual enum loc_api_adapter_err + injectPosition(double latitude, double longitude, float accuracy); + virtual enum loc_api_adapter_err + setTime(GpsUtcTime time, int64_t timeReference, int uncertainty); + virtual enum loc_api_adapter_err + setXtraData(char* data, int length); + virtual enum loc_api_adapter_err + requestXtraServer(); + virtual enum loc_api_adapter_err + atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType); + virtual enum loc_api_adapter_err + atlCloseStatus(int handle, int is_succ); + virtual enum loc_api_adapter_err + setPositionMode(const LocPosMode& posMode); + virtual enum loc_api_adapter_err + setServer(const char* url, int len); + virtual enum loc_api_adapter_err + setServer(unsigned int ip, int port, + LocServerType type); + virtual enum loc_api_adapter_err + informNiResponse(GpsUserResponseType userResponse, const void* passThroughData); + virtual enum loc_api_adapter_err + setSUPLVersion(uint32_t version); + virtual enum loc_api_adapter_err + setLPPConfig(uint32_t profile); + virtual enum loc_api_adapter_err + setSensorControlConfig(int sensorUsage, int sensorProvider); + virtual enum loc_api_adapter_err + setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, + float gyroBiasVarianceRandomWalk, + bool accelBiasVarianceRandomWalk_valid, + float accelBiasVarianceRandomWalk, + bool angleBiasVarianceRandomWalk_valid, + float angleBiasVarianceRandomWalk, + bool rateBiasVarianceRandomWalk_valid, + float rateBiasVarianceRandomWalk, + bool velocityBiasVarianceRandomWalk_valid, + float velocityBiasVarianceRandomWalk); + virtual enum loc_api_adapter_err + setSensorPerfControlConfig(int controlMode, + int accelSamplesPerBatch, + int accelBatchesPerSec, + int gyroSamplesPerBatch, + int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, + int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, + int gyroBatchesPerSecHigh, + int algorithmConfig); + virtual enum loc_api_adapter_err + setExtPowerConfig(int isBatteryCharging); + virtual enum loc_api_adapter_err + setAGLONASSProtocol(unsigned long aGlonassProtocol); + virtual enum loc_api_adapter_err + getWwanZppFix(GpsLocation & zppLoc); + virtual enum loc_api_adapter_err + getBestAvailableZppFix(GpsLocation & zppLoc); + virtual enum loc_api_adapter_err + getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask); + virtual int initDataServiceClient(); + virtual int openAndStartDataCall(); + virtual void stopDataCall(); + virtual void closeDataCall(); + virtual void installAGpsCert(const DerEncodedCertificate* pData, + size_t length, + uint32_t slotBitMask); + inline virtual void setInSession(bool inSession) { + + (void)inSession; + } + inline bool isMessageSupported (LocCheckingMessagesID msgID) const { + + // confirm if msgID is not larger than the number of bits in + // mSupportedMsg + if ((uint64_t)msgID > (sizeof(mSupportedMsg) << 3)) { + return false; + } else { + uint32_t messageChecker = 1 << msgID; + return (messageChecker & mSupportedMsg) == messageChecker; + } + } + void updateEvtMask(); + + /*Values for lock + 1 = Do not lock any position sessions + 2 = Lock MI position sessions + 3 = Lock MT position sessions + 4 = Lock all position sessions + */ + virtual int setGpsLock(LOC_GPS_LOCK_MASK lock); + /* + Returns + Current value of GPS Lock on success + -1 on failure + */ + virtual int getGpsLock(void); + + virtual enum loc_api_adapter_err setXtraVersionCheck(enum xtra_version_check check); + + /* + Update gps reporting events + */ + virtual int updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled); + /* + Check if the modem support the service + */ + virtual bool gnssConstellationConfig(); +}; + +typedef LocApiBase* (getLocApi_t)(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + ContextBase *context); + +} // namespace loc_core + +#endif //LOC_API_BASE_H diff --git a/gps/core/LocDualContext.cpp b/gps/core/LocDualContext.cpp new file mode 100644 index 0000000..578421c --- /dev/null +++ b/gps/core/LocDualContext.cpp @@ -0,0 +1,147 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_DualCtx" + +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +// nothing exclude for foreground +const LOC_API_ADAPTER_EVENT_MASK_T +LocDualContext::mFgExclMask = 0; +// excluded events for background clients +const LOC_API_ADAPTER_EVENT_MASK_T +LocDualContext::mBgExclMask = + (LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | + LOC_API_ADAPTER_BIT_SATELLITE_REPORT | + LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | + LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT | + LOC_API_ADAPTER_BIT_IOCTL_REPORT | + LOC_API_ADAPTER_BIT_STATUS_REPORT | + LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT | + LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT); + +const MsgTask* LocDualContext::mMsgTask = NULL; +ContextBase* LocDualContext::mFgContext = NULL; +ContextBase* LocDualContext::mBgContext = NULL; +ContextBase* LocDualContext::mInjectContext = NULL; +// the name must be shorter than 15 chars +const char* LocDualContext::mLocationHalName = "Loc_hal_worker"; +const char* LocDualContext::mLBSLibName = "liblbs_core.so"; + +pthread_mutex_t LocDualContext::mGetLocContextMutex = PTHREAD_MUTEX_INITIALIZER; + +const MsgTask* LocDualContext::getMsgTask(LocThread::tCreate tCreator, + const char* name, bool joinable) +{ + if (NULL == mMsgTask) { + mMsgTask = new MsgTask(tCreator, name, joinable); + } + return mMsgTask; +} + +inline +const MsgTask* LocDualContext::getMsgTask(const char* name, bool joinable) { + return getMsgTask((LocThread::tCreate)NULL, name, joinable); +} + +ContextBase* LocDualContext::getLocFgContext(LocThread::tCreate tCreator, + LocMsg* firstMsg, const char* name, bool joinable) +{ + pthread_mutex_lock(&LocDualContext::mGetLocContextMutex); + LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__); + if (NULL == mFgContext) { + LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__); + const MsgTask* msgTask = getMsgTask(tCreator, name, joinable); + mFgContext = new LocDualContext(msgTask, + mFgExclMask); + } + if(NULL == mInjectContext) { + LOC_LOGD("%s:%d]: mInjectContext is FgContext", __func__, __LINE__); + mInjectContext = mFgContext; + injectFeatureConfig(mInjectContext); + } + pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex); + + if (firstMsg) { + mFgContext->sendMsg(firstMsg); + } + + return mFgContext; +} + +ContextBase* LocDualContext::getLocBgContext(LocThread::tCreate tCreator, + LocMsg* firstMsg, const char* name, bool joinable) +{ + pthread_mutex_lock(&LocDualContext::mGetLocContextMutex); + LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__); + if (NULL == mBgContext) { + LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__); + const MsgTask* msgTask = getMsgTask(tCreator, name, joinable); + mBgContext = new LocDualContext(msgTask, + mBgExclMask); + } + if(NULL == mInjectContext) { + LOC_LOGD("%s:%d]: mInjectContext is BgContext", __func__, __LINE__); + mInjectContext = mBgContext; + injectFeatureConfig(mInjectContext); + } + pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex); + + if (firstMsg) { + mBgContext->sendMsg(firstMsg); + } + + return mBgContext; +} + +void LocDualContext :: injectFeatureConfig(ContextBase *curContext) +{ + LOC_LOGD("%s:%d]: Enter", __func__, __LINE__); + if(curContext == mInjectContext) { + LOC_LOGD("%s:%d]: Calling LBSProxy (%p) to inject feature config", + __func__, __LINE__, ((LocDualContext *)mInjectContext)->mLBSProxy); + ((LocDualContext *)mInjectContext)->mLBSProxy->injectFeatureConfig(curContext); + } + LOC_LOGD("%s:%d]: Exit", __func__, __LINE__); +} + +LocDualContext::LocDualContext(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask) : + ContextBase(msgTask, exMask, mLBSLibName) +{ +} + +} diff --git a/gps/core/LocDualContext.h b/gps/core/LocDualContext.h new file mode 100644 index 0000000..ce77a1a --- /dev/null +++ b/gps/core/LocDualContext.h @@ -0,0 +1,76 @@ +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_ENG_CONTEXT__ +#define __LOC_ENG_CONTEXT__ + +#include +#include +#include +#include + +namespace loc_core { + +class LocDualContext : public ContextBase { + static const MsgTask* mMsgTask; + static ContextBase* mFgContext; + static ContextBase* mBgContext; + static ContextBase* mInjectContext; + static const MsgTask* getMsgTask(LocThread::tCreate tCreator, + const char* name, bool joinable = true); + static const MsgTask* getMsgTask(const char* name, bool joinable = true); + static pthread_mutex_t mGetLocContextMutex; + +protected: + LocDualContext(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask); + inline virtual ~LocDualContext() {} + +public: + static const char* mLBSLibName; + static const LOC_API_ADAPTER_EVENT_MASK_T mFgExclMask; + static const LOC_API_ADAPTER_EVENT_MASK_T mBgExclMask; + static const char* mLocationHalName; + + static ContextBase* getLocFgContext(LocThread::tCreate tCreator, LocMsg* firstMsg, + const char* name, bool joinable = true); + inline static ContextBase* getLocFgContext(const char* name, bool joinable = true) { + return getLocFgContext(NULL, NULL, name, joinable); + } + static ContextBase* getLocBgContext(LocThread::tCreate tCreator, LocMsg* firstMsg, + const char* name, bool joinable = true); + inline static ContextBase* getLocBgContext(const char* name, bool joinable = true) { + return getLocBgContext(NULL, NULL, name, joinable); + } + + static void injectFeatureConfig(ContextBase *context); +}; + +} + +#endif //__LOC_ENG_CONTEXT__ diff --git a/gps/core/UlpProxyBase.h b/gps/core/UlpProxyBase.h new file mode 100644 index 0000000..79b5248 --- /dev/null +++ b/gps/core/UlpProxyBase.h @@ -0,0 +1,107 @@ +/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ULP_PROXY_BASE_H +#define ULP_PROXY_BASE_H + +#include + +struct FlpExtLocation_s; +struct FlpExtBatchOptions; + +namespace loc_core { + +class LocAdapterBase; + +class UlpProxyBase { +public: + LocPosMode mPosMode; + bool mFixSet; + inline UlpProxyBase() { + mPosMode.mode = LOC_POSITION_MODE_INVALID; + mFixSet = false; + } + inline virtual ~UlpProxyBase() {} + inline virtual bool sendStartFix() { mFixSet = true; return false; } + inline virtual bool sendStopFix() { mFixSet = false; return false; } + inline virtual bool sendFixMode(LocPosMode ¶ms) { + mPosMode = params; + return false; + } + + inline virtual bool reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) { + (void)location; + (void)locationExtended; + (void)locationExt; + (void)status; + (void)loc_technology_mask; + return false; + } + inline virtual bool reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) { + (void)svStatus; + (void)locationExtended; + (void)svExt; + return false; + } + inline virtual bool reportStatus(GpsStatusValue status) { + + (void)status; + return false; + } + inline virtual void setAdapter(LocAdapterBase* adapter) { + + (void)adapter; + } + inline virtual void setCapabilities(unsigned long capabilities) { + + (void)capabilities; + } + inline virtual bool reportBatchingSession(FlpExtBatchOptions &options, + bool active) { + + (void)options; + (void)active; + return false; + } + inline virtual bool reportPositions(const struct FlpExtLocation_s* locations, + int32_t number_of_locations) { + (void)locations; + (void)number_of_locations; + return false; + } +}; + +} // namespace loc_core + +#endif // ULP_PROXY_BASE_H diff --git a/gps/core/gps_extended.h b/gps/core/gps_extended.h new file mode 100644 index 0000000..88b0415 --- /dev/null +++ b/gps/core/gps_extended.h @@ -0,0 +1,92 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GPS_EXTENDED_H +#define GPS_EXTENDED_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +struct LocPosMode +{ + LocPositionMode mode; + GpsPositionRecurrence recurrence; + uint32_t min_interval; + uint32_t preferred_accuracy; + uint32_t preferred_time; + char credentials[14]; + char provider[8]; + LocPosMode(LocPositionMode m, GpsPositionRecurrence recr, + uint32_t gap, uint32_t accu, uint32_t time, + const char* cred, const char* prov) : + mode(m), recurrence(recr), + min_interval(gap < MIN_POSSIBLE_FIX_INTERVAL ? MIN_POSSIBLE_FIX_INTERVAL : gap), + preferred_accuracy(accu), preferred_time(time) { + memset(credentials, 0, sizeof(credentials)); + memset(provider, 0, sizeof(provider)); + if (NULL != cred) { + memcpy(credentials, cred, sizeof(credentials)-1); + } + if (NULL != prov) { + memcpy(provider, prov, sizeof(provider)-1); + } + } + + inline LocPosMode() : + mode(LOC_POSITION_MODE_MS_BASED), + recurrence(GPS_POSITION_RECURRENCE_PERIODIC), + min_interval(MIN_POSSIBLE_FIX_INTERVAL), + preferred_accuracy(50), preferred_time(120000) { + memset(credentials, 0, sizeof(credentials)); + memset(provider, 0, sizeof(provider)); + } + + inline bool equals(const LocPosMode &anotherMode) const + { + return anotherMode.mode == mode && + anotherMode.recurrence == recurrence && + anotherMode.min_interval == min_interval && + anotherMode.preferred_accuracy == preferred_accuracy && + anotherMode.preferred_time == preferred_time && + !strncmp(anotherMode.credentials, credentials, sizeof(credentials)-1) && + !strncmp(anotherMode.provider, provider, sizeof(provider)-1); + } + + void logv() const; +}; + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GPS_EXTENDED_H */ + diff --git a/gps/core/gps_extended_c.h b/gps/core/gps_extended_c.h new file mode 100644 index 0000000..8e3966a --- /dev/null +++ b/gps/core/gps_extended_c.h @@ -0,0 +1,437 @@ +/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GPS_EXTENDED_C_H +#define GPS_EXTENDED_C_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include +#include +#include +#include + +/** Location has valid source information. */ +#define LOCATION_HAS_SOURCE_INFO 0x0020 +/** GpsLocation has valid "is indoor?" flag */ +#define GPS_LOCATION_HAS_IS_INDOOR 0x0040 +/** GpsLocation has valid floor number */ +#define GPS_LOCATION_HAS_FLOOR_NUMBER 0x0080 +/** GpsLocation has valid map URL*/ +#define GPS_LOCATION_HAS_MAP_URL 0x0100 +/** GpsLocation has valid map index */ +#define GPS_LOCATION_HAS_MAP_INDEX 0x0200 + +/** Sizes for indoor fields */ +#define GPS_LOCATION_MAP_URL_SIZE 400 +#define GPS_LOCATION_MAP_INDEX_SIZE 16 + +/** Position source is ULP */ +#define ULP_LOCATION_IS_FROM_HYBRID 0x0001 +/** Position source is GNSS only */ +#define ULP_LOCATION_IS_FROM_GNSS 0x0002 +/** Position source is ZPP only */ +#define ULP_LOCATION_IS_FROM_ZPP 0x0004 +/** Position is from a Geofence Breach Event */ +#define ULP_LOCATION_IS_FROM_GEOFENCE 0X0008 +/** Position is from Hardware FLP */ +#define ULP_LOCATION_IS_FROM_HW_FLP 0x0010 +/** Position is from NLP */ +#define ULP_LOCATION_IS_FROM_NLP 0x0020 +/** Position is from PIP */ +#define ULP_LOCATION_IS_FROM_PIP 0x0040 + +#define ULP_MIN_INTERVAL_INVALID 0xffffffff + +/*Emergency SUPL*/ +#define GPS_NI_TYPE_EMERGENCY_SUPL 4 + +#define AGPS_CERTIFICATE_MAX_LENGTH 2000 +#define AGPS_CERTIFICATE_MAX_SLOTS 10 + +enum loc_registration_mask_status { + LOC_REGISTRATION_MASK_ENABLED, + LOC_REGISTRATION_MASK_DISABLED +}; + +typedef struct { + /** set to sizeof(UlpLocation) */ + size_t size; + GpsLocation gpsLocation; + /* Provider indicator for HYBRID or GPS */ + uint16_t position_source; + /*allows HAL to pass additional information related to the location */ + int rawDataSize; /* in # of bytes */ + void * rawData; + bool is_indoor; + float floor_number; + char map_url[GPS_LOCATION_MAP_URL_SIZE]; + unsigned char map_index[GPS_LOCATION_MAP_INDEX_SIZE]; +} UlpLocation; + +/** AGPS type */ +typedef int16_t AGpsExtType; +#define AGPS_TYPE_INVALID -1 +#define AGPS_TYPE_ANY 0 +#define AGPS_TYPE_SUPL 1 +#define AGPS_TYPE_C2K 2 +#define AGPS_TYPE_WWAN_ANY 3 +#define AGPS_TYPE_WIFI 4 +#define AGPS_TYPE_SUPL_ES 5 + +/** SSID length */ +#define SSID_BUF_SIZE (32+1) + +typedef int16_t AGpsBearerType; +#define AGPS_APN_BEARER_INVALID -1 +#define AGPS_APN_BEARER_IPV4 0 +#define AGPS_APN_BEARER_IPV6 1 +#define AGPS_APN_BEARER_IPV4V6 2 + +/** GPS extended callback structure. */ +typedef struct { + /** set to sizeof(GpsCallbacks) */ + size_t size; + gps_set_capabilities set_capabilities_cb; + gps_acquire_wakelock acquire_wakelock_cb; + gps_release_wakelock release_wakelock_cb; + gps_create_thread create_thread_cb; + gps_request_utc_time request_utc_time_cb; +} GpsExtCallbacks; + +/** Callback to report the xtra server url to the client. + * The client should use this url when downloading xtra unless overwritten + * in the gps.conf file + */ +typedef void (* report_xtra_server)(const char*, const char*, const char*); + +/** Callback structure for the XTRA interface. */ +typedef struct { + gps_xtra_download_request download_request_cb; + gps_create_thread create_thread_cb; + report_xtra_server report_xtra_server_cb; +} GpsXtraExtCallbacks; + +/** Represents the status of AGPS. */ +typedef struct { + /** set to sizeof(AGpsExtStatus) */ + size_t size; + + AGpsExtType type; + AGpsStatusValue status; + uint32_t ipv4_addr; + struct sockaddr_storage addr; + char ssid[SSID_BUF_SIZE]; + char password[SSID_BUF_SIZE]; +} AGpsExtStatus; + +/** Callback with AGPS status information. + * Can only be called from a thread created by create_thread_cb. + */ +typedef void (* agps_status_extended)(AGpsExtStatus* status); + +/** Callback structure for the AGPS interface. */ +typedef struct { + agps_status_extended status_cb; + gps_create_thread create_thread_cb; +} AGpsExtCallbacks; + + +/** GPS NI callback structure. */ +typedef struct +{ + /** + * Sends the notification request from HAL to GPSLocationProvider. + */ + gps_ni_notify_callback notify_cb; + gps_create_thread create_thread_cb; +} GpsNiExtCallbacks; + +typedef enum loc_server_type { + LOC_AGPS_CDMA_PDE_SERVER, + LOC_AGPS_CUSTOM_PDE_SERVER, + LOC_AGPS_MPC_SERVER, + LOC_AGPS_SUPL_SERVER +} LocServerType; + +typedef enum loc_position_mode_type { + LOC_POSITION_MODE_INVALID = -1, + LOC_POSITION_MODE_STANDALONE = 0, + LOC_POSITION_MODE_MS_BASED, + LOC_POSITION_MODE_MS_ASSISTED, + LOC_POSITION_MODE_RESERVED_1, + LOC_POSITION_MODE_RESERVED_2, + LOC_POSITION_MODE_RESERVED_3, + LOC_POSITION_MODE_RESERVED_4, + LOC_POSITION_MODE_RESERVED_5 + +} LocPositionMode; + +#define MIN_POSSIBLE_FIX_INTERVAL 1000 /* msec */ + +/** Flags to indicate which values are valid in a GpsLocationExtended. */ +typedef uint16_t GpsLocationExtendedFlags; +/** GpsLocationExtended has valid pdop, hdop, vdop. */ +#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001 +/** GpsLocationExtended has valid altitude mean sea level. */ +#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002 +/** UlpLocation has valid magnetic deviation. */ +#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004 +/** UlpLocation has valid mode indicator. */ +#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008 +/** GpsLocationExtended has valid vertical uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010 +/** GpsLocationExtended has valid speed uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020 +/** GpsLocationExtended has valid heading uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_BEARING_UNC 0x0040 +/** GpsLocationExtended has valid horizontal reliability */ +#define GPS_LOCATION_EXTENDED_HAS_HOR_RELIABILITY 0x0080 +/** GpsLocationExtended has valid vertical reliability */ +#define GPS_LOCATION_EXTENDED_HAS_VERT_RELIABILITY 0x0100 + +typedef enum { + LOC_RELIABILITY_NOT_SET = 0, + LOC_RELIABILITY_VERY_LOW = 1, + LOC_RELIABILITY_LOW = 2, + LOC_RELIABILITY_MEDIUM = 3, + LOC_RELIABILITY_HIGH = 4 +}LocReliability; + +/** Represents gps location extended. */ +typedef struct { + /** set to sizeof(GpsLocationExtended) */ + size_t size; + /** Contains GpsLocationExtendedFlags bits. */ + uint16_t flags; + /** Contains the Altitude wrt mean sea level */ + float altitudeMeanSeaLevel; + /** Contains Position Dilusion of Precision. */ + float pdop; + /** Contains Horizontal Dilusion of Precision. */ + float hdop; + /** Contains Vertical Dilusion of Precision. */ + float vdop; + /** Contains Magnetic Deviation. */ + float magneticDeviation; + /** vertical uncertainty in meters */ + float vert_unc; + /** speed uncertainty in m/s */ + float speed_unc; + /** heading uncertainty in degrees (0 to 359.999) */ + float bearing_unc; + /** horizontal reliability. */ + LocReliability horizontal_reliability; + /** vertical reliability. */ + LocReliability vertical_reliability; +} GpsLocationExtended; + +/** Represents SV status. */ +typedef struct { + /** set to sizeof(HaxxSvStatus) */ + size_t size; + + /** Number of SVs currently visible. */ + int num_svs; + + /** Contains an array of SV information. */ + GpsSvInfo sv_list[GPS_MAX_SVS]; + + /** Represents a bit mask indicating which SVs + * have ephemeris data. + */ + uint32_t ephemeris_mask; + + /** Represents a bit mask indicating which SVs + * have almanac data. + */ + uint32_t almanac_mask; + + /** + * Represents a bit mask indicating which GPS SVs + * were used for computing the most recent position fix. + */ + uint32_t gps_used_in_fix_mask; + + /** + * Represents a bit mask indicating which GLONASS SVs + * were used for computing the most recent position fix. + */ + uint32_t glo_used_in_fix_mask; + + /** + * Represents a bit mask indicating which BDS SVs + * were used for computing the most recent position fix. + */ + uint64_t bds_used_in_fix_mask; + +} HaxxSvStatus; + +enum loc_sess_status { + LOC_SESS_SUCCESS, + LOC_SESS_INTERMEDIATE, + LOC_SESS_FAILURE +}; + +typedef uint32_t LocPosTechMask; +#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000) +#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001) +#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002) +#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004) +#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008) +#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010) +#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020) +#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040) +#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080) + +typedef enum { + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + LOC_ENG_IF_REQUEST_SENDER_ID_MODEM, + LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN +} loc_if_req_sender_id_e_type; + + +#define smaller_of(a, b) (((a) > (b)) ? (b) : (a)) +#define MAX_APN_LEN 100 + +// This will be overridden by the individual adapters +// if necessary. +#define DEFAULT_IMPL(rtv) \ +{ \ + LOC_LOGD("%s: default implementation invoked", __func__); \ + return rtv; \ +} + +enum loc_api_adapter_err { + LOC_API_ADAPTER_ERR_SUCCESS = 0, + LOC_API_ADAPTER_ERR_GENERAL_FAILURE = 1, + LOC_API_ADAPTER_ERR_UNSUPPORTED = 2, + LOC_API_ADAPTER_ERR_INVALID_HANDLE = 4, + LOC_API_ADAPTER_ERR_INVALID_PARAMETER = 5, + LOC_API_ADAPTER_ERR_ENGINE_BUSY = 6, + LOC_API_ADAPTER_ERR_PHONE_OFFLINE = 7, + LOC_API_ADAPTER_ERR_TIMEOUT = 8, + LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9, + LOC_API_ADAPTER_ERR_INTERNAL = 10, + + /* equating engine down to phone offline, as they are the same errror */ + LOC_API_ADAPTER_ERR_ENGINE_DOWN = LOC_API_ADAPTER_ERR_PHONE_OFFLINE, + LOC_API_ADAPTER_ERR_FAILURE = 101, + LOC_API_ADAPTER_ERR_UNKNOWN +}; + +enum loc_api_adapter_event_index { + LOC_API_ADAPTER_REPORT_POSITION = 0, // Position report comes in loc_parsed_position_s_type + LOC_API_ADAPTER_REPORT_SATELLITE, // Satellite in view report + LOC_API_ADAPTER_REPORT_NMEA_1HZ, // NMEA report at 1HZ rate + LOC_API_ADAPTER_REPORT_NMEA_POSITION, // NMEA report at position report rate + LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY, // NI notification/verification request + LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA, // Assistance data, eg: time, predicted orbits request + LOC_API_ADAPTER_REQUEST_LOCATION_SERVER, // Request for location server + LOC_API_ADAPTER_REPORT_IOCTL, // Callback report for loc_ioctl + LOC_API_ADAPTER_REPORT_STATUS, // Misc status report: eg, engine state + LOC_API_ADAPTER_REQUEST_WIFI, // + LOC_API_ADAPTER_SENSOR_STATUS, // + LOC_API_ADAPTER_REQUEST_TIME_SYNC, // + LOC_API_ADAPTER_REPORT_SPI, // + LOC_API_ADAPTER_REPORT_NI_GEOFENCE, // + LOC_API_ADAPTER_GEOFENCE_GEN_ALERT, // + LOC_API_ADAPTER_REPORT_GENFENCE_BREACH, // + LOC_API_ADAPTER_PEDOMETER_CTRL, // + LOC_API_ADAPTER_MOTION_CTRL, // + LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA, // Wifi ap data + LOC_API_ADAPTER_BATCH_FULL, // Batching on full + LOC_API_ADAPTER_BATCHED_POSITION_REPORT, // Batching on fix + LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT, // + LOC_API_ADAPTER_GDT_UPLOAD_BEGIN_REQ, // GDT upload start request + LOC_API_ADAPTER_GDT_UPLOAD_END_REQ, // GDT upload end request + LOC_API_ADAPTER_GNSS_MEASUREMENT, // GNSS Measurement report + LOC_API_ADAPTER_REQUEST_TIMEZONE, // Timezone injection request + LOC_API_ADAPTER_REPORT_GENFENCE_DWELL_REPORT, // Geofence dwell report + LOC_API_ADAPTER_EVENT_MAX +}; + +#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT (1< +#include +#include + +void LocPosMode::logv() const +{ + LOC_LOGV ("Position mode: %s\n Position recurrence: %s\n " + "min interval: %d\n preferred accuracy: %d\n " + "preferred time: %d\n credentials: %s provider: %s", + loc_get_position_mode_name(mode), + loc_get_position_recurrence_name(recurrence), + min_interval, + preferred_accuracy, + preferred_time, + credentials, + provider); +} + +/* GPS status names */ +static const loc_name_val_s_type gps_status_name[] = +{ + NAME_VAL( GPS_STATUS_NONE ), + NAME_VAL( GPS_STATUS_SESSION_BEGIN ), + NAME_VAL( GPS_STATUS_SESSION_END ), + NAME_VAL( GPS_STATUS_ENGINE_ON ), + NAME_VAL( GPS_STATUS_ENGINE_OFF ), +}; +static const int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type); + +/* Find Android GPS status name */ +const char* loc_get_gps_status_name(GpsStatusValue gps_status) +{ + return loc_get_name_from_val(gps_status_name, gps_status_num, + (long) gps_status); +} + + + +static const loc_name_val_s_type loc_eng_position_modes[] = +{ + NAME_VAL( LOC_POSITION_MODE_STANDALONE ), + NAME_VAL( LOC_POSITION_MODE_MS_BASED ), + NAME_VAL( LOC_POSITION_MODE_MS_ASSISTED ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_1 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_2 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_3 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_5 ) +}; +static const int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type); + +const char* loc_get_position_mode_name(GpsPositionMode mode) +{ + return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode); +} + + + +static const loc_name_val_s_type loc_eng_position_recurrences[] = +{ + NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ), + NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE ) +}; +static const int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type); + +const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur) +{ + return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur); +} + + + +static const loc_name_val_s_type loc_eng_aiding_data_bits[] = +{ + NAME_VAL( GPS_DELETE_EPHEMERIS ), + NAME_VAL( GPS_DELETE_ALMANAC ), + NAME_VAL( GPS_DELETE_POSITION ), + NAME_VAL( GPS_DELETE_TIME ), + NAME_VAL( GPS_DELETE_IONO ), + NAME_VAL( GPS_DELETE_UTC ), + NAME_VAL( GPS_DELETE_HEALTH ), + NAME_VAL( GPS_DELETE_SVDIR ), + NAME_VAL( GPS_DELETE_SVSTEER ), + NAME_VAL( GPS_DELETE_SADATA ), + NAME_VAL( GPS_DELETE_RTI ), + NAME_VAL( GPS_DELETE_CELLDB_INFO ), + NAME_VAL( GPS_DELETE_ALL) +}; +static const int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type); + +const char* loc_get_aiding_data_mask_names(GpsAidingData data) +{ + return NULL; +} + + +static const loc_name_val_s_type loc_eng_agps_types[] = +{ + NAME_VAL( AGPS_TYPE_INVALID ), + NAME_VAL( AGPS_TYPE_ANY ), + NAME_VAL( AGPS_TYPE_SUPL ), + NAME_VAL( AGPS_TYPE_C2K ), + NAME_VAL( AGPS_TYPE_WWAN_ANY ) +}; +static const int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_agps_type_name(AGpsType type) +{ + return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type); +} + + +static const loc_name_val_s_type loc_eng_ni_types[] = +{ + NAME_VAL( GPS_NI_TYPE_VOICE ), + NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ), + NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE ), + NAME_VAL( GPS_NI_TYPE_EMERGENCY_SUPL ) +}; +static const int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_ni_type_name(GpsNiType type) +{ + return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type); +} + + +static const loc_name_val_s_type loc_eng_ni_responses[] = +{ + NAME_VAL( GPS_NI_RESPONSE_ACCEPT ), + NAME_VAL( GPS_NI_RESPONSE_DENY ), + NAME_VAL( GPS_NI_RESPONSE_DENY ) +}; +static const int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type); + +const char* loc_get_ni_response_name(GpsUserResponseType response) +{ + return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response); +} + + +static const loc_name_val_s_type loc_eng_ni_encodings[] = +{ + NAME_VAL( GPS_ENC_NONE ), + NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ), + NAME_VAL( GPS_ENC_SUPL_UTF8 ), + NAME_VAL( GPS_ENC_SUPL_UCS2 ), + NAME_VAL( GPS_ENC_UNKNOWN ) +}; +static const int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type); + +const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding) +{ + return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding); +} + +static const loc_name_val_s_type loc_eng_agps_bears[] = +{ + NAME_VAL( AGPS_APN_BEARER_INVALID ), + NAME_VAL( AGPS_APN_BEARER_IPV4 ), + NAME_VAL( AGPS_APN_BEARER_IPV6 ), + NAME_VAL( AGPS_APN_BEARER_IPV4V6 ) +}; +static const int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type); + +const char* loc_get_agps_bear_name(AGpsBearerType bearer) +{ + return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer); +} + +static const loc_name_val_s_type loc_eng_server_types[] = +{ + NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ), + NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ), + NAME_VAL( LOC_AGPS_MPC_SERVER ), + NAME_VAL( LOC_AGPS_SUPL_SERVER ) +}; +static const int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_server_type_name(LocServerType type) +{ + return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type); +} + +static const loc_name_val_s_type loc_eng_position_sess_status_types[] = +{ + NAME_VAL( LOC_SESS_SUCCESS ), + NAME_VAL( LOC_SESS_INTERMEDIATE ), + NAME_VAL( LOC_SESS_FAILURE ) +}; +static const int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_position_sess_status_name(enum loc_sess_status status) +{ + return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status); +} + +static const loc_name_val_s_type loc_eng_agps_status_names[] = +{ + NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ), + NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ), + NAME_VAL( GPS_AGPS_DATA_CONNECTED ), + NAME_VAL( GPS_AGPS_DATA_CONN_DONE ), + NAME_VAL( GPS_AGPS_DATA_CONN_FAILED ) +}; +static const int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type); + +const char* loc_get_agps_status_name(AGpsStatusValue status) +{ + return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status); +} diff --git a/gps/core/loc_core_log.h b/gps/core/loc_core_log.h new file mode 100644 index 0000000..8a1825a --- /dev/null +++ b/gps/core/loc_core_log.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_CORE_LOG_H +#define LOC_CORE_LOG_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include + +const char* loc_get_gps_status_name(GpsStatusValue gps_status); +const char* loc_get_position_mode_name(GpsPositionMode mode); +const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur); +const char* loc_get_aiding_data_mask_names(GpsAidingData data); +const char* loc_get_agps_type_name(AGpsType type); +const char* loc_get_ni_type_name(GpsNiType type); +const char* loc_get_ni_response_name(GpsUserResponseType response); +const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding); +const char* loc_get_agps_bear_name(AGpsBearerType bear); +const char* loc_get_server_type_name(LocServerType type); +const char* loc_get_position_sess_status_name(enum loc_sess_status status); +const char* loc_get_agps_status_name(AGpsStatusValue status); + +#ifdef __cplusplus +} +#endif + +#endif /* LOC_CORE_LOG_H */ diff --git a/gps/etc/flp.conf b/gps/etc/flp.conf new file mode 100755 index 0000000..7d6002f --- /dev/null +++ b/gps/etc/flp.conf @@ -0,0 +1,60 @@ +################################### +##### FLP settings ##### +################################### + +################################### +# FLP BATCHING SIZE +################################### +# The number of batched locations +# requested to modem. The desired number +# defined below may not be satisfied, as +# the modem can only return the number +# of batched locations that can be allocated, +# which is limited by memory. The default +# batch size defined as 20 as below. +BATCH_SIZE=20 + +################################### +# FLP BATCHING SESSION TIMEOUT +################################### +# Duration with which batch session timeout +# happens in milliseconds. If not specified +# or set to zero, batching session timeout +# defaults to 20 seconds by the modem. +# BATCH_SESSION_TIMEOUT=20000 + +################################### +# FLP CAPABILITIES BIT MASK +################################### +# GEOFENCE = 0x01 +# BATCHING = 0x02 +# default = GEOFENCE | BATCHING +CAPABILITIES=0x03 + +################################### +# FLP BATCHING ACCURACY +################################### +# Set to one of the defined values below +# to define the accuracy of batching. +# If not specified, accuracy defaults +# to LOW. +# FLP BATCHING ACCURACY values: +# Low accuracy = 0 +# Medium accuracy = 1 +# High accuracy = 2 +ACCURACY=0 + +################################### +# FLP GEOFENCE RESPONSIVENESS +################################### +# If set to one of the defined values below, +# it will override the responsiveness for +# FLP geofence, which implements the fused +# location API. If not set to a value defined +# below, which is default, it will not +# override the responsivness. +# FLP_GEOFENCE_RESPONSIVENESS_OVERRIDE Values: +# 1: LOW responsiveness +# 2: MEDIUM responsiveness +# 3: HIGH responsiveness +FLP_GEOFENCE_RESPONSIVENESS_OVERRIDE = 0 diff --git a/gps/etc/gps.conf b/gps/etc/gps.conf new file mode 100755 index 0000000..c09390b --- /dev/null +++ b/gps/etc/gps.conf @@ -0,0 +1,117 @@ +#URLs from which to download XTRA data +#XTRA_SERVER_1=https://xtrapath1.izatcloud.net/xtra3grc.bin +#XTRA_SERVER_2=https://xtrapath2.izatcloud.net/xtra3grc.bin +#XTRA_SERVER_3=https://xtrapath3.izatcloud.net/xtra3grc.bin + +#Version check for XTRA +#DISABLE = 0 +#AUTO = 1 +#XTRA2 = 2 +#XTRA3 = 3 +XTRA_VERSION_CHECK=1 + +# Error Estimate +# _SET = 1 +# _CLEAR = 0 +ERR_ESTIMATE=0 + +#Test +# NTP_SERVER=time.gpsonextra.net +#Asia +# NTP_SERVER=asia.pool.ntp.org +#Europe +# NTP_SERVER=europe.pool.ntp.org +#North America +#NTP_SERVER=north-america.pool.ntp.org +NTP_SERVER=time.izatcloud.net + +# DEBUG LEVELS: 0 - none, 1 - Error, 2 - Warning, 3 - Info +# 4 - Debug, 5 - Verbose +# If DEBUG_LEVEL is commented, Android's logging levels will be used +DEBUG_LEVEL = 2 + +# Intermediate position report, 1=enable, 0=disable +INTERMEDIATE_POS=0 + +# Below bit mask configures how GPS functionalities +# should be locked when user turns off GPS on Settings +# Set bit 0x1 if MO GPS functionalities are to be locked +# Set bit 0x2 if NI GPS functionalities are to be locked +# default - non is locked for backward compatibility +# GPS_LOCK = 3 + +# supl version 2.0 +SUPL_VER=0x20000 + +# Emergency SUPL, 1=enable, 0=disable +SUPL_ES=1 + +#Choose PDN for Emergency SUPL +#1 - Use emergency PDN +#0 - Use regular SUPL PDN for Emergency SUPL +USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL=1 + +#SUPL_MODE is a bit mask set in config.xml per carrier by default. +#If it is uncommented here, this value will overwrite the value from +#config.xml. +#MSA=0X2 +#MSB=0X1 +#SUPL_MODE=3 + +# GPS Capabilities bit mask +# SCHEDULING = 0x01 +# MSB = 0x02 +# MSA = 0x04 +# ON_DEMAND_TIME = 0x10 +# GEOFENCE = 0x20 +# default = ON_DEMAND_TIME | MSA | MSB | SCHEDULING | GEOFENCE +CAPABILITIES=0x31 + +# Accuracy threshold for intermediate positions +# less accurate positions are ignored, 0 for passing all positions +ACCURACY_THRES=5000 + +################################ +##### AGPS server settings ##### +################################ + +# FOR SUPL SUPPORT, set the following +SUPL_HOST=supl.google.com +SUPL_PORT=7276 + +# FOR C2K PDE SUPPORT, set the following +# C2K_HOST=c2k.pde.com or IP +# C2K_PORT=1234 + +# Bitmask of slots that are available +# for write/install to, where 1s indicate writable, +# and the default value is 0 where no slots +# are writable. For example, AGPS_CERT_WRITABLE_MASK +# of b1000001010 makes 3 slots available +# and the remaining 7 slots unwritable. +#AGPS_CERT_WRITABLE_MASK=0 + +#################################### +# LTE Positioning Profile Settings +#################################### +# 0: Enable RRLP on LTE(Default) +# 1: Enable LPP_User_Plane on LTE +# 2: Enable LPP_Control_Plane +# 3: Enable both LPP_User_Plane and LPP_Control_Plane +LPP_PROFILE = 0 + +################################ +# EXTRA SETTINGS +################################ +# NMEA provider (1=Modem Processor, 0=Application Processor) +NMEA_PROVIDER=1 +# Mark if it is a SGLTE target (1=SGLTE, 0=nonSGLTE) +SGLTE_TARGET=0 + +################################################## +# Select Positioning Protocol on A-GLONASS system +################################################## +# 0x1: RRC CPlane +# 0x2: RRLP UPlane +# 0x4: LLP Uplane +A_GLONASS_POS_PROTOCOL_SELECT = 15 diff --git a/gps/etc/izat.conf b/gps/etc/izat.conf new file mode 100755 index 0000000..129328a --- /dev/null +++ b/gps/etc/izat.conf @@ -0,0 +1,209 @@ +######################################### +# Log verbosity control for izat modules +######################################### +# OFF = 0, ERROR = 1, WARNING = 2, INFO = 3, DEBUG = 4, VERBOSE = 5 +IZAT_DEBUG_LEVEL = 2 + +######################################## +# NLP/WIFI positioning options bit mask +######################################## +# Enable NLP fixes for WIPER/ODCPI feature => WIPER = 0x1 +# Enable free wifi scan injections for GEOFENCE => FREE_WIFI = 0x2 +# Enable SUPL2 MLD wifi => SUPL_WIFI = 0x4 +# Enable Attached Wifi AP info injection for GEOFENCE => FREE_AP_INFO = 0x8 +# default = WIPER | FREE_WIFI | SUPL_WIFI | FREE_AP_INFO +NLP_WIFI_LISTENER_MODE = 15 + +################################################## +# Select WIFI Wait Timeout value in seconds for SUPL +################################################## +WIFI_WAIT_TIMEOUT_SELECT = 0 + +################################ +# NLP Settings +################################ +# NLP_MODE 1: GNP Only, 2: QNP Only, 3: Combo +# NLP_TOLERANCE_TIME_FIRST: Time in ms used in Combo mode +# to determine how much Tolerance for first position +# NLP_TOLERANCE_TIME_AFTER: Time in ms used in Combo mode +# to determine how much Tolerance for positions after first +# NLP_THRESHOLD: Sets how many failures needed before +# switching preferred NLP in Combo mode +# NLP_ACCURACY_MULTIPLE: Determines how far off the accuracy +# must be, in multiples, between two NLP location reports to +# be considered much worse accuracy. Used in switching logic +# NLP COMBO MODE USES QNP WITH NO EULA CONSENT: Determines +# whether or not to still send network location requests to +# QNP when the EULA is not consented to by the user. QNP can +# still return ZPP locations or injected locations even +# without EULA consent, but the uncertainty can be high. +NLP_MODE = 3 +NLP_TOLERANCE_TIME_FIRST = 5000 +NLP_TOLERANCE_TIME_AFTER = 20000 +NLP_THRESHOLD = 3 +NLP_ACCURACY_MULTIPLE = 2 +NLP_COMBO_MODE_USES_QNP_WITH_NO_EULA_CONSENT = 1 + +# Threshold period for ZPP triggers +ZPP_TRIGGER_THRESHOLD=30000 + +################################### +# GEOFENCE SERVICES +################################### +# If set to one of the defined values below, it will override +# the responsiveness for geofence services, which implements +# the Proximity Alert API. If not set to a value defined below, +# which is default, it will not override the responsivness. +# The geofence HAL API is unaffected by this value. +# GEOFENCE_SERVICES_RESPONSIVENESS_OVERRIDE Values: +# 1: LOW responsiveness +# 2: MEDIUM responsiveness +# 3: HIGH responsiveness +GEOFENCE_SERVICES_RESPONSIVENESS_OVERRIDE = 0 + +##################################### +# IZAT PREMIUM FEATURE SETTINGS +##################################### +#Possible states of a feature: +#DISABLED +#BASIC +#PREMIUM + +#GTP_CELL_PROC valid options: +# AP +# MODEM +GTP_CELL_PROC=MODEM + +#GTP_CELL valid modes: +# DISABLED +# BASIC +GTP_CELL=BASIC + +#GTP_WIFI valid modes: +# DISABLED +# BASIC +GTP_WIFI=DISABLED + +#GTP_WAA valid modes: +# DISABLED +# BASIC +GTP_WAA=DISABLED + +#SAP valid modes: +# DISABLED +# BASIC +# PREMIUM +SAP=BASIC + +#PIP valid modes: +# DISABLED +# PREMIUM +PIP=DISABLED + +#ODCPI valid modes: +#DISABLED +#BASIC +ODCPI=BASIC + +#FREE_WIFI_SCAN_INJECT valid modes: +#DISABLED +#BASIC +FREE_WIFI_SCAN_INJECT=BASIC + +#SUPL_WIFI valid modes: +#DISABLED +#BASIC +SUPL_WIFI=BASIC + +#WIFI_SUPPLICANT_INFO valid modes: +#DISABLED +#BASIC +WIFI_SUPPLICANT_INFO=BASIC + +##################################### +# Location process launcher settings +##################################### + +#Values for PROCESS_STATE: +# ENABLED +# DISABLED + +#FEATURE MASKS: +# GTP-WIFI 0X03 +# GTP-AP-CELL 0X0c +# GTP-MP-CELL 0xc00 +# GTP-WAA 0X300 +# SAP 0Xc0 +# ODCPI 0x1000 +# FREE_WIFI_SCAN_INJECT 0x2000 +# SUPL_WIFI 0x4000 +# WIFI_SUPPLICANT_INFO 0x8000 + +#Values for PLATFORMS can be: +#1. Any valid values obtained from ro.board.platform separated by single space. For example: msm8960 msm8226 +#2. all -> for All platforms + +#Values for BASEBAND can be: +#1. Any valid values obtained from ro.baseband separated by single space. For example: sglte sglte2 +#2. all -> for all basebands + +PROCESS_NAME=/system/bin/gpsone_daemon +PROCESS_ARGUMENT= +PROCESS_STATE=ENABLED +PROCESS_GROUPS=inet net_raw +PREMIUM_FEATURE=0 +IZAT_FEATURE_MASK=0 +PLATFORMS=msm7630_fusion +BASEBAND=svlte2a sglte sglte2 +LEAN_TARGETS=DISABLED + +PROCESS_NAME=/system/bin/lowi-server +PROCESS_ARGUMENT= +PROCESS_STATE=ENABLED +PROCESS_GROUPS=gps net_admin wifi inet oem_2950 net_raw +PREMIUM_FEATURE=0 +IZAT_FEATURE_MASK=0xf303 +PLATFORMS=all +BASEBAND=all +LEAN_TARGETS=DISABLED + +PROCESS_NAME=/system/bin/quipc_igsn +PROCESS_STATE=ENABLED +PROCESS_GROUPS=inet gps oem_2950 +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0x30 +PLATFORMS=all +BASEBAND=all + +PROCESS_NAME=/system/bin/quipc_main +PROCESS_STATE=ENABLED +PROCESS_GROUPS=gps net_admin wifi inet oem_2950 +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0x30 +PLATFORMS=all +BASEBAND=all + +PROCESS_NAME=/system/bin/xtwifi-inet-agent +PROCESS_STATE=ENABLED +PROCESS_GROUPS=inet gps +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0x0f +PLATFORMS=all +BASEBAND=all + +PROCESS_NAME=/system/bin/xtwifi-client +PROCESS_ARGUMENT= +PROCESS_STATE=ENABLED +PROCESS_GROUPS=net_admin wifi inet gps +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0x30f +PLATFORMS=all +BASEBAND=all + +PROCESS_NAME=/system/vendor/bin/slim_ap_daemon +PROCESS_STATE=ENABLED +PROCESS_GROUPS=gps net_raw misc qcom_oncrpc oem_2950 +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0xf0 +PLATFORMS=all +BASEBAND=all diff --git a/gps/etc/sap.conf b/gps/etc/sap.conf new file mode 100755 index 0000000..b556dff --- /dev/null +++ b/gps/etc/sap.conf @@ -0,0 +1,44 @@ +################################ +# Sensor Settings +################################ +#The following parameters are optional. +#Internal defaults support MEMS sensors +#native to most handset devices. +#Device specific sensor characterization +#for improved performance is possible as +#described in SAP application notes. +#GYRO_BIAS_RANDOM_WALK= +#ACCEL_RANDOM_WALK_SPECTRAL_DENSITY= +#ANGLE_RANDOM_WALK_SPECTRAL_DENSITY= +#RATE_RANDOM_WALK_SPECTRAL_DENSITY= +#VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY= + +# Sensor Sampling Rate Parameters for Low-Data Rate Filter (should be greater than 0) +# used in loc_eng_reinit +SENSOR_ACCEL_BATCHES_PER_SEC=2 +SENSOR_ACCEL_SAMPLES_PER_BATCH=5 +SENSOR_GYRO_BATCHES_PER_SEC=2 +SENSOR_GYRO_SAMPLES_PER_BATCH=5 +# Sensor Sampling Rate Parameters for High-Data Rate Filter (should be greater than 0) +SENSOR_ACCEL_BATCHES_PER_SEC_HIGH=4 +SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH=25 +SENSOR_GYRO_BATCHES_PER_SEC_HIGH=4 +SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH=25 + +# Sensor Control Mode (0=AUTO, 1=FORCE_ON) +# used in loc_eng_reinit +SENSOR_CONTROL_MODE=0 + +# Enable or Disable Sensors for GPS use (0=Enable, 1=Disable) +# used in loc_eng_reinit +SENSOR_USAGE=0 + +# Choose GSIFF sensor provider (1=Snapdragon Sensors Core, 2=Android NDK) +SENSOR_PROVIDER=1 + +# Bit mask used to define which sensor algorithms are used. +# Setting each bit has the following definition: +# 0x1 - DISABLE_INS_POSITIONING_FILTER +# 0x0 - ENABLE_INS_POSITIONING_FILTER +SENSOR_ALGORITHM_CONFIG_MASK=0x0 + diff --git a/gps/loc-api.pc.in b/gps/loc-api.pc.in new file mode 100644 index 0000000..3b4f81b --- /dev/null +++ b/gps/loc-api.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: loc-api +Description: Qualcomm GPS Location API +Version: @VERSION@ +Libs: -L${libdir} -lgps_utils_so -lloc_adapter_so -lloc_eng_so -lgps_default_so -lloc_api +Cflags: -I${includedir}/loc-api/libloc_api_50001 -I${includedir}/loc-api/utils -I${includedir}/ -I${includedir}/loc-api diff --git a/gps/loc_api/libloc_api_50001/Android.mk b/gps/loc_api/libloc_api_50001/Android.mk new file mode 100644 index 0000000..9f6c49e --- /dev/null +++ b/gps/loc_api/libloc_api_50001/Android.mk @@ -0,0 +1,94 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libloc_eng +LOCAL_MODULE_OWNER := qcom +LOCAL_PROPRIETARY_MODULE := true + +LOCAL_MODULE_TAGS := optional + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libcutils \ + libdl \ + liblog \ + libloc_core \ + libgps.utils \ + libhardware + +LOCAL_SRC_FILES += \ + loc_eng.cpp \ + loc_eng_agps.cpp \ + loc_eng_xtra.cpp \ + loc_eng_ni.cpp \ + loc_eng_log.cpp \ + loc_eng_nmea.cpp \ + LocEngAdapter.cpp + +LOCAL_SRC_FILES += \ + loc_eng_dmn_conn.cpp \ + loc_eng_dmn_conn_handler.cpp \ + loc_eng_dmn_conn_thread_helper.c \ + loc_eng_dmn_conn_glue_msg.c \ + loc_eng_dmn_conn_glue_pipe.c + +LOCAL_CFLAGS += \ + -fno-short-enums \ + -D_ANDROID_ \ + -Wno-unused-parameter + +LOCAL_C_INCLUDES:= \ + $(TARGET_OUT_HEADERS)/gps.utils \ + $(TARGET_OUT_HEADERS)/libloc_core \ + $(LOCAL_PATH) \ + $(TARGET_OUT_HEADERS)/libflp + +LOCAL_HEADER_LIBRARIES := libgps.utils_headers libloc_core_headers + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libloc_eng_headers +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) +include $(BUILD_HEADER_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_MODULE := gps.$(TARGET_BOARD_PLATFORM) +LOCAL_MODULE_OWNER := qcom +LOCAL_PROPRIETARY_MODULE := true + +LOCAL_MODULE_TAGS := optional + +## Libs +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libcutils \ + liblog \ + libloc_eng \ + libloc_core \ + libgps.utils \ + libdl \ + libhardware + +LOCAL_SRC_FILES += \ + loc.cpp \ + gps.c + +LOCAL_CFLAGS += \ + -fno-short-enums \ + -D_ANDROID_ \ + -Wno-unused-parameter + +## Includes +LOCAL_C_INCLUDES:= \ + $(TARGET_OUT_HEADERS)/gps.utils \ + $(TARGET_OUT_HEADERS)/libloc_core \ + $(TARGET_OUT_HEADERS)/libflp + +LOCAL_MODULE_RELATIVE_PATH := hw + +LOCAL_HEADER_LIBRARIES := libgps.utils_headers libloc_core_headers + +include $(BUILD_SHARED_LIBRARY) diff --git a/gps/loc_api/libloc_api_50001/LocEngAdapter.cpp b/gps/loc_api/libloc_api_50001/LocEngAdapter.cpp new file mode 100644 index 0000000..f8c103a --- /dev/null +++ b/gps/loc_api/libloc_api_50001/LocEngAdapter.cpp @@ -0,0 +1,600 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_EngAdapter" + +#include +#include +#include +#include +#include +#include "loc_eng_msg.h" +#include "loc_log.h" + +#define CHIPSET_SERIAL_NUMBER_MAX_LEN 16 +#define USER_AGENT_MAX_LEN 512 + +using namespace loc_core; + +LocInternalAdapter::LocInternalAdapter(LocEngAdapter* adapter) : + LocAdapterBase(adapter->getMsgTask()), + mLocEngAdapter(adapter) +{ +} +void LocInternalAdapter::setPositionModeInt(LocPosMode& posMode) { + sendMsg(new LocEngPositionMode(mLocEngAdapter, posMode)); +} +void LocInternalAdapter::startFixInt() { + sendMsg(new LocEngStartFix(mLocEngAdapter)); +} +void LocInternalAdapter::stopFixInt() { + sendMsg(new LocEngStopFix(mLocEngAdapter)); +} +void LocInternalAdapter::getZppInt() { + sendMsg(new LocEngGetZpp(mLocEngAdapter)); +} + +LocEngAdapter::LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask, + void* owner, ContextBase* context, + LocThread::tCreate tCreator) : + LocAdapterBase(mask, + //Get the AFW context if VzW context has not already been intialized in + //loc_ext + context == NULL? + LocDualContext::getLocFgContext(tCreator, + NULL, + LocDualContext::mLocationHalName, + false) + :context), + mOwner(owner), mInternalAdapter(new LocInternalAdapter(this)), + mUlp(new UlpProxyBase()), mNavigating(false), + mSupportsAgpsRequests(false), + mSupportsPositionInjection(false), + mSupportsTimeInjection(false), + mPowerVote(0) +{ + memset(&mFixCriteria, 0, sizeof(mFixCriteria)); + mFixCriteria.mode = LOC_POSITION_MODE_INVALID; + LOC_LOGD("LocEngAdapter created"); +} + +inline +LocEngAdapter::~LocEngAdapter() +{ + delete mInternalAdapter; + LOC_LOGV("LocEngAdapter deleted"); +} + +void LocEngAdapter::setXtraUserAgent() { + struct LocSetXtraUserAgent : public LocMsg { + const ContextBase* const mContext; + inline LocSetXtraUserAgent(ContextBase* context) : + LocMsg(), mContext(context) { + } + virtual void proc() const { + char release[PROPERTY_VALUE_MAX]; + char manufacture[PROPERTY_VALUE_MAX]; + char model[PROPERTY_VALUE_MAX]; + char board[PROPERTY_VALUE_MAX]; + char brand[PROPERTY_VALUE_MAX]; + char chipsetsn[CHIPSET_SERIAL_NUMBER_MAX_LEN]; + char userAgent[USER_AGENT_MAX_LEN]; + const char defVal[] = "-"; + + property_get("ro.build.version.release", release, defVal); + property_get("ro.product.manufacturer", manufacture, defVal); + property_get("ro.product.model", model, defVal); + property_get("ro.product.board", board, defVal); + property_get("ro.product.brand", brand, defVal); + getChipsetSerialNo(chipsetsn, sizeof(chipsetsn), defVal); + + encodeInPlace(release, PROPERTY_VALUE_MAX); + encodeInPlace(manufacture, PROPERTY_VALUE_MAX); + encodeInPlace(model, PROPERTY_VALUE_MAX); + encodeInPlace(board, PROPERTY_VALUE_MAX); + encodeInPlace(brand, PROPERTY_VALUE_MAX); + + snprintf(userAgent, sizeof(userAgent), "A/%s/%s/%s/%s/-/QCX3/s%u/-/%s/-/%s/-/-/-", + release, manufacture, model, board, + mContext->getIzatDevId(), chipsetsn, brand); + + for (int i = 0; i < sizeof(userAgent) && userAgent[i]; i++) { + if (' ' == userAgent[i]) userAgent[i] = '#'; + } + + saveUserAgentString(userAgent, strlen(userAgent)); + LOC_LOGV("%s] UserAgent %s", __func__, userAgent); + } + + void saveUserAgentString(const char* data, const int len) const { + const char XTRA_FOLDER[] = "/data/misc/location/xtra"; + const char USER_AGENT_FILE[] = "/data/misc/location/xtra/useragent.txt"; + + if (data == NULL || len < 1) { + LOC_LOGE("%s:%d]: invalid input data = %p len = %d", __func__, __LINE__, data, len); + return; + } + + struct stat s; + int err = stat(XTRA_FOLDER, &s); + if (err < 0) { + if (ENOENT == errno) { + if (mkdir(XTRA_FOLDER, 0700) < 0) { + LOC_LOGE("%s:%d]: make XTRA_FOLDER failed", __func__, __LINE__); + return; + } + } else { + LOC_LOGE("%s:%d]: XTRA_FOLDER invalid", __func__, __LINE__); + return; + } + } + + FILE* file = fopen(USER_AGENT_FILE, "wt"); + if (file == NULL) { + LOC_LOGE("%s:%d]: open USER_AGENT_FILE failed", __func__, __LINE__); + return; + } + + size_t written = fwrite(data, 1, len, file); + fclose(file); + file = NULL; + + // set file permission + chmod(USER_AGENT_FILE, 0600); + + if (written != len) { + LOC_LOGE("%s:%d]: write USER_AGENT_FILE failed", __func__, __LINE__); + } + } + + void getChipsetSerialNo(char buf[], int buflen, const char def[]) const { + const char SOC_SERIAL_NUMBER[] = "/sys/devices/soc0/serial_number"; + + FILE* file = fopen(SOC_SERIAL_NUMBER, "rt"); + if (file == NULL) { + // use default upon unreadable file + strlcpy(buf, def, buflen); + + } else { + size_t size = fread(buf, 1, buflen - 1, file); + if (size == 0) { + // use default upon empty file + strlcpy(buf, def, buflen); + + } else { + buf[size] = '\0'; + } + + fclose(file); + + // remove trailing spaces + char *s; + s = buf + strlen(buf); + while (--s >= buf) { + if (!isspace(*s)) break; + *s = 0; + } + } + + return; + } + + /** + * encode the given string value such that all separator characters ('/','+','|','%') + * in the string are repaced by their corresponding encodings (%2F","%2B","%7C", "%25") + */ + static void encodeInPlace(char value[], const int size) { + char buffer[size]; + + struct ENCODE { + const char ch; + const char *code; + }; + + const ENCODE encodings[] = { {'/', "%2F"}, {'+', "%2B"}, {'|', "%7C",}, {'%', "%25"} }; + const int nencodings = (int)sizeof(encodings) / sizeof(encodings[0]); + + int inpos = 0, outpos = 0; + while(value[inpos] != '\0' && outpos < size - 1) { + // check if escaped character + int escchar = 0; + while(escchar < nencodings && encodings[escchar].ch != value[inpos]) { + escchar++; + } + + if (escchar == nencodings) { + // non escaped character + buffer[outpos++] = value[inpos++]; + continue; + } + + // escaped character + int codepos = 0; + #define NUM_CHARS_IN_CODE 3 + + if (outpos + NUM_CHARS_IN_CODE >= size) { + // skip last character if there is insufficient space + break; + } + + while(outpos < size - 1 && codepos < NUM_CHARS_IN_CODE) { + buffer[outpos++] = encodings[escchar].code[codepos++]; + } + inpos++; + } + + // copy to ouput + value[outpos] = '\0'; + while(--outpos >= 0) { + value[outpos] = buffer[outpos]; + } + } + }; + + sendMsg(new LocSetXtraUserAgent(mContext)); +} + +void LocInternalAdapter::setUlpProxy(UlpProxyBase* ulp) { + struct LocSetUlpProxy : public LocMsg { + LocAdapterBase* mAdapter; + UlpProxyBase* mUlp; + inline LocSetUlpProxy(LocAdapterBase* adapter, UlpProxyBase* ulp) : + LocMsg(), mAdapter(adapter), mUlp(ulp) { + } + virtual void proc() const { + LOC_LOGV("%s] ulp %p adapter %p", __func__, + mUlp, mAdapter); + mAdapter->setUlpProxy(mUlp); + } + }; + + sendMsg(new LocSetUlpProxy(mLocEngAdapter, ulp)); +} + +void LocEngAdapter::setUlpProxy(UlpProxyBase* ulp) +{ + if (ulp == mUlp) { + //This takes care of the case when double initalization happens + //and we get the same object back for UlpProxyBase . Do nothing + return; + } + + LOC_LOGV("%s] %p", __func__, ulp); + if (NULL == ulp) { + LOC_LOGE("%s:%d]: ulp pointer is NULL", __func__, __LINE__); + ulp = new UlpProxyBase(); + } + + if (LOC_POSITION_MODE_INVALID != mUlp->mPosMode.mode) { + // need to send this mode and start msg to ULP + ulp->sendFixMode(mUlp->mPosMode); + } + + if(mUlp->mFixSet) { + ulp->sendStartFix(); + } + + delete mUlp; + mUlp = ulp; +} + +int LocEngAdapter::setGpsLockMsg(LOC_GPS_LOCK_MASK lockMask) +{ + struct LocEngAdapterGpsLock : public LocMsg { + LocEngAdapter* mAdapter; + LOC_GPS_LOCK_MASK mLockMask; + inline LocEngAdapterGpsLock(LocEngAdapter* adapter, LOC_GPS_LOCK_MASK lockMask) : + LocMsg(), mAdapter(adapter), mLockMask(lockMask) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setGpsLock(mLockMask); + } + inline void locallog() const { + LOC_LOGV("LocEngAdapterGpsLock - mLockMask: %x", mLockMask); + } + inline virtual void log() const { + locallog(); + } + }; + sendMsg(new LocEngAdapterGpsLock(this, lockMask)); + return 0; +} + +void LocEngAdapter::requestPowerVote() +{ + if (getPowerVoteRight()) { + /* Power voting without engine lock: + * 101: vote down, 102-104 - vote up + * These codes are used not to confuse with actual engine lock + * functionality, that can't be used in SSR scenario, as it + * conflicts with initialization sequence. + */ + bool powerUp = getPowerVote(); + LOC_LOGV("LocEngAdapterVotePower - Vote Power: %d", (int)powerUp); + setGpsLock(powerUp ? 103 : 101); + } +} + +void LocInternalAdapter::reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) +{ + sendMsg(new LocEngReportPosition(mLocEngAdapter, + location, + locationExtended, + locationExt, + status, + loc_technology_mask)); +} + + +void LocEngAdapter::reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) +{ + if (! mUlp->reportPosition(location, + locationExtended, + locationExt, + status, + loc_technology_mask )) { + mInternalAdapter->reportPosition(location, + locationExtended, + locationExt, + status, + loc_technology_mask); + } +} + +void LocInternalAdapter::reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt){ + sendMsg(new LocEngReportSv(mLocEngAdapter, svStatus, + locationExtended, svExt)); +} + +void LocEngAdapter::reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) +{ + + // We want to send SV info to ULP to help it in determining GNSS + // signal strength ULP will forward the SV reports to HAL without + // any modifications + if (! mUlp->reportSv(svStatus, locationExtended, svExt)) { + mInternalAdapter->reportSv(svStatus, locationExtended, svExt); + } +} + +void LocEngAdapter::setInSession(bool inSession) +{ + mNavigating = inSession; + mLocApi->setInSession(inSession); + if (!mNavigating) { + mFixCriteria.mode = LOC_POSITION_MODE_INVALID; + } +} + +void LocInternalAdapter::reportStatus(GpsStatusValue status) +{ + sendMsg(new LocEngReportStatus(mLocEngAdapter, status)); +} + +void LocEngAdapter::reportStatus(GpsStatusValue status) +{ + if (!mUlp->reportStatus(status)) { + mInternalAdapter->reportStatus(status); + } +} + +inline +void LocEngAdapter::reportNmea(const char* nmea, int length) +{ + sendMsg(new LocEngReportNmea(mOwner, nmea, length)); +} + +inline +bool LocEngAdapter::reportXtraServer(const char* url1, + const char* url2, + const char* url3, + const int maxlength) +{ + if (mSupportsAgpsRequests) { + sendMsg(new LocEngReportXtraServer(mOwner, url1, + url2, url3, maxlength)); + } + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::requestATL(int connHandle, AGpsType agps_type) +{ + if (mSupportsAgpsRequests) { + sendMsg(new LocEngRequestATL(mOwner, + connHandle, agps_type)); + } + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::releaseATL(int connHandle) +{ + if (mSupportsAgpsRequests) { + sendMsg(new LocEngReleaseATL(mOwner, connHandle)); + } + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::requestXtraData() +{ + if (mSupportsAgpsRequests) { + sendMsg(new LocEngRequestXtra(mOwner)); + } + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::requestTime() +{ + if (mSupportsAgpsRequests) { + sendMsg(new LocEngRequestTime(mOwner)); + } + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::requestNiNotify(GpsNiNotification ¬if, const void* data) +{ + if (mSupportsAgpsRequests) { + notif.size = sizeof(notif); + notif.timeout = LOC_NI_NO_RESPONSE_TIME; + + sendMsg(new LocEngRequestNi(mOwner, notif, data)); + } + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::requestSuplES(int connHandle) +{ + if (mSupportsAgpsRequests) + sendMsg(new LocEngRequestSuplEs(mOwner, connHandle)); + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::reportDataCallOpened() +{ + if(mSupportsAgpsRequests) + sendMsg(new LocEngSuplEsOpened(mOwner)); + return mSupportsAgpsRequests; +} + +inline +bool LocEngAdapter::reportDataCallClosed() +{ + if(mSupportsAgpsRequests) + sendMsg(new LocEngSuplEsClosed(mOwner)); + return mSupportsAgpsRequests; +} + +inline +void LocEngAdapter::handleEngineDownEvent() +{ + sendMsg(new LocEngDown(mOwner)); +} + +inline +void LocEngAdapter::handleEngineUpEvent() +{ + sendMsg(new LocEngUp(mOwner)); +} + +enum loc_api_adapter_err LocEngAdapter::setTime(GpsUtcTime time, + int64_t timeReference, + int uncertainty) +{ + loc_api_adapter_err result = LOC_API_ADAPTER_ERR_SUCCESS; + + LOC_LOGD("%s:%d]: mSupportsTimeInjection is %d", + __func__, __LINE__, mSupportsTimeInjection); + + if (mSupportsTimeInjection) { + LOC_LOGD("%s:%d]: Injecting time", __func__, __LINE__); + result = mLocApi->setTime(time, timeReference, uncertainty); + } else { + mSupportsTimeInjection = true; + } + return result; +} + +enum loc_api_adapter_err LocEngAdapter::setXtraVersionCheck(int check) +{ + enum loc_api_adapter_err ret; + ENTRY_LOG(); + enum xtra_version_check eCheck; + switch (check) { + case 0: + eCheck = DISABLED; + break; + case 1: + eCheck = AUTO; + break; + case 2: + eCheck = XTRA2; + break; + case 3: + eCheck = XTRA3; + break; + default: + eCheck = DISABLED; + } + ret = mLocApi->setXtraVersionCheck(eCheck); + EXIT_LOG(%d, ret); + return ret; +} + +void LocEngAdapter::reportGpsMeasurementData(GpsData &gpsMeasurementData) +{ + sendMsg(new LocEngReportGpsMeasurement(mOwner, + gpsMeasurementData)); +} + +/* + Update Registration Mask + */ +void LocEngAdapter::updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled) +{ + LOC_LOGD("entering %s", __func__); + int result = LOC_API_ADAPTER_ERR_FAILURE; + result = mLocApi->updateRegistrationMask(event, isEnabled); + if (result == LOC_API_ADAPTER_ERR_SUCCESS) { + LOC_LOGD("%s] update registration mask succeed.", __func__); + } else { + LOC_LOGE("%s] update registration mask failed.", __func__); + } +} + +/* + Set Gnss Constellation Config + */ +bool LocEngAdapter::gnssConstellationConfig() +{ + LOC_LOGD("entering %s", __func__); + bool result = false; + result = mLocApi->gnssConstellationConfig(); + return result; +} diff --git a/gps/loc_api/libloc_api_50001/LocEngAdapter.h b/gps/loc_api/libloc_api_50001/LocEngAdapter.h new file mode 100644 index 0000000..b58c8e7 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/LocEngAdapter.h @@ -0,0 +1,351 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_API_ENG_ADAPTER_H +#define LOC_API_ENG_ADAPTER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_URL_LEN 256 + +using namespace loc_core; + +class LocEngAdapter; + +class LocInternalAdapter : public LocAdapterBase { + LocEngAdapter* mLocEngAdapter; +public: + LocInternalAdapter(LocEngAdapter* adapter); + + virtual void reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + virtual void reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt); + virtual void reportStatus(GpsStatusValue status); + virtual void setPositionModeInt(LocPosMode& posMode); + virtual void startFixInt(); + virtual void stopFixInt(); + virtual void getZppInt(); + virtual void setUlpProxy(UlpProxyBase* ulp); +}; + +typedef void (*loc_msg_sender)(void* loc_eng_data_p, void* msgp); + +class LocEngAdapter : public LocAdapterBase { + void* mOwner; + LocInternalAdapter* mInternalAdapter; + UlpProxyBase* mUlp; + LocPosMode mFixCriteria; + bool mNavigating; + // mPowerVote is encoded as + // mPowerVote & 0x20 -- powerVoteRight + // mPowerVote & 0x10 -- power On / Off + unsigned int mPowerVote; + static const unsigned int POWER_VOTE_RIGHT = 0x20; + static const unsigned int POWER_VOTE_VALUE = 0x10; + +public: + bool mSupportsAgpsRequests; + bool mSupportsPositionInjection; + bool mSupportsTimeInjection; + + LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask, + void* owner, ContextBase* context, + LocThread::tCreate tCreator); + virtual ~LocEngAdapter(); + + virtual void setUlpProxy(UlpProxyBase* ulp); + void setXtraUserAgent(); + inline void requestUlp(unsigned long capabilities) { + mContext->requestUlp(mInternalAdapter, capabilities); + } + inline LocInternalAdapter* getInternalAdapter() { return mInternalAdapter; } + inline UlpProxyBase* getUlpProxy() { return mUlp; } + inline void* getOwner() { return mOwner; } + inline bool hasAgpsExtendedCapabilities() { + return mContext->hasAgpsExtendedCapabilities(); + } + inline bool hasCPIExtendedCapabilities() { + return mContext->hasCPIExtendedCapabilities(); + } + inline const MsgTask* getMsgTask() { return mMsgTask; } + + inline enum loc_api_adapter_err + startFix() + { + return mLocApi->startFix(mFixCriteria); + } + inline enum loc_api_adapter_err + stopFix() + { + return mLocApi->stopFix(); + } + inline enum loc_api_adapter_err + deleteAidingData(GpsAidingData f) + { + return mLocApi->deleteAidingData(f); + } + inline enum loc_api_adapter_err + enableData(int enable) + { + return mLocApi->enableData(enable); + } + inline enum loc_api_adapter_err + setAPN(char* apn, int len) + { + return mLocApi->setAPN(apn, len); + } + inline enum loc_api_adapter_err + injectPosition(double latitude, double longitude, float accuracy) + { + return mLocApi->injectPosition(latitude, longitude, accuracy); + } + inline enum loc_api_adapter_err + setXtraData(char* data, int length) + { + return mLocApi->setXtraData(data, length); + } + inline enum loc_api_adapter_err + requestXtraServer() + { + return mLocApi->requestXtraServer(); + } + inline enum loc_api_adapter_err + atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType) + { + return mLocApi->atlOpenStatus(handle, is_succ, apn, bearer, agpsType); + } + inline enum loc_api_adapter_err + atlCloseStatus(int handle, int is_succ) + { + return mLocApi->atlCloseStatus(handle, is_succ); + } + inline enum loc_api_adapter_err + setPositionMode(const LocPosMode *posMode) + { + if (NULL != posMode) { + mFixCriteria = *posMode; + } + return mLocApi->setPositionMode(mFixCriteria); + } + inline enum loc_api_adapter_err + setServer(const char* url, int len) + { + return mLocApi->setServer(url, len); + } + inline enum loc_api_adapter_err + setServer(unsigned int ip, int port, + LocServerType type) + { + return mLocApi->setServer(ip, port, type); + } + inline enum loc_api_adapter_err + informNiResponse(GpsUserResponseType userResponse, const void* passThroughData) + { + return mLocApi->informNiResponse(userResponse, passThroughData); + } + inline enum loc_api_adapter_err + setSUPLVersion(uint32_t version) + { + return mLocApi->setSUPLVersion(version); + } + inline enum loc_api_adapter_err + setLPPConfig(uint32_t profile) + { + return mLocApi->setLPPConfig(profile); + } + inline enum loc_api_adapter_err + setSensorControlConfig(int sensorUsage, int sensorProvider) + { + return mLocApi->setSensorControlConfig(sensorUsage, sensorProvider); + } + inline enum loc_api_adapter_err + setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk, + bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk, + bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk, + bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk, + bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk) + { + return mLocApi->setSensorProperties(gyroBiasVarianceRandomWalk_valid, gyroBiasVarianceRandomWalk, + accelBiasVarianceRandomWalk_valid, accelBiasVarianceRandomWalk, + angleBiasVarianceRandomWalk_valid, angleBiasVarianceRandomWalk, + rateBiasVarianceRandomWalk_valid, rateBiasVarianceRandomWalk, + velocityBiasVarianceRandomWalk_valid, velocityBiasVarianceRandomWalk); + } + inline virtual enum loc_api_adapter_err + setSensorPerfControlConfig(int controlMode, int accelSamplesPerBatch, int accelBatchesPerSec, + int gyroSamplesPerBatch, int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig) + { + return mLocApi->setSensorPerfControlConfig(controlMode, accelSamplesPerBatch, accelBatchesPerSec, + gyroSamplesPerBatch, gyroBatchesPerSec, + accelSamplesPerBatchHigh, accelBatchesPerSecHigh, + gyroSamplesPerBatchHigh, gyroBatchesPerSecHigh, + algorithmConfig); + } + inline virtual enum loc_api_adapter_err + setExtPowerConfig(int isBatteryCharging) + { + return mLocApi->setExtPowerConfig(isBatteryCharging); + } + inline virtual enum loc_api_adapter_err + setAGLONASSProtocol(unsigned long aGlonassProtocol) + { + return mLocApi->setAGLONASSProtocol(aGlonassProtocol); + } + inline virtual int initDataServiceClient() + { + return mLocApi->initDataServiceClient(); + } + inline virtual int openAndStartDataCall() + { + return mLocApi->openAndStartDataCall(); + } + inline virtual void stopDataCall() + { + mLocApi->stopDataCall(); + } + inline virtual void closeDataCall() + { + mLocApi->closeDataCall(); + } + inline enum loc_api_adapter_err + getZpp(GpsLocation &zppLoc, LocPosTechMask &tech_mask) + { + return mLocApi->getBestAvailableZppFix(zppLoc, tech_mask); + } + enum loc_api_adapter_err setTime(GpsUtcTime time, + int64_t timeReference, + int uncertainty); + enum loc_api_adapter_err setXtraVersionCheck(int check); + inline virtual void installAGpsCert(const DerEncodedCertificate* pData, + size_t length, + uint32_t slotBitMask) + { + mLocApi->installAGpsCert(pData, length, slotBitMask); + } + virtual void handleEngineDownEvent(); + virtual void handleEngineUpEvent(); + virtual void reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + virtual void reportSv(HaxxSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt); + virtual void reportStatus(GpsStatusValue status); + virtual void reportNmea(const char* nmea, int length); + virtual bool reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + virtual bool requestXtraData(); + virtual bool requestTime(); + virtual bool requestATL(int connHandle, AGpsType agps_type); + virtual bool releaseATL(int connHandle); + virtual bool requestNiNotify(GpsNiNotification ¬ify, const void* data); + virtual bool requestSuplES(int connHandle); + virtual bool reportDataCallOpened(); + virtual bool reportDataCallClosed(); + virtual void reportGpsMeasurementData(GpsData &gpsMeasurementData); + + inline const LocPosMode& getPositionMode() const + {return mFixCriteria;} + inline virtual bool isInSession() + { return mNavigating; } + void setInSession(bool inSession); + + // Permit/prohibit power voting + inline void setPowerVoteRight(bool powerVoteRight) { + mPowerVote = powerVoteRight ? (mPowerVote | POWER_VOTE_RIGHT) : + (mPowerVote & ~POWER_VOTE_RIGHT); + } + inline bool getPowerVoteRight() const { + return (mPowerVote & POWER_VOTE_RIGHT) != 0 ; + } + // Set the power voting up/down and do actual operation if permitted + inline void setPowerVote(bool powerOn) { + mPowerVote = powerOn ? (mPowerVote | POWER_VOTE_VALUE) : + (mPowerVote & ~POWER_VOTE_VALUE); + requestPowerVote(); + mContext->modemPowerVote(powerOn); + } + inline bool getPowerVote() const { + return (mPowerVote & POWER_VOTE_VALUE) != 0 ; + } + // Do power voting according to last settings if permitted + void requestPowerVote(); + + /*Values for lock + 1 = Do not lock any position sessions + 2 = Lock MI position sessions + 3 = Lock MT position sessions + 4 = Lock all position sessions + */ + inline int setGpsLock(LOC_GPS_LOCK_MASK lock) + { + return mLocApi->setGpsLock(lock); + } + + int setGpsLockMsg(LOC_GPS_LOCK_MASK lock); + + /* + Returns + Current value of GPS lock on success + -1 on failure + */ + inline int getGpsLock() + { + return mLocApi->getGpsLock(); + } + + /* + Update Registration Mask + */ + void updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled); + + /* + Set Gnss Constellation Config + */ + bool gnssConstellationConfig(); +}; + +#endif //LOC_API_ENG_ADAPTER_H diff --git a/gps/loc_api/libloc_api_50001/gps.c b/gps/loc_api/libloc_api_50001/gps.c new file mode 100644 index 0000000..29f20f4 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/gps.c @@ -0,0 +1,73 @@ +/* Copyright (c) 2011,2015 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include +#include + +extern const GpsInterface* get_gps_interface(); + +const GpsInterface* gps__get_gps_interface(struct gps_device_t* dev) +{ + return get_gps_interface(); +} + +static int open_gps(const struct hw_module_t* module, char const* name, + struct hw_device_t** device) +{ + struct gps_device_t *dev = (struct gps_device_t *) malloc(sizeof(struct gps_device_t)); + + if(dev == NULL) + return -1; + + memset(dev, 0, sizeof(*dev)); + + dev->common.tag = HARDWARE_DEVICE_TAG; + dev->common.version = 0; + dev->common.module = (struct hw_module_t*)module; + dev->get_gps_interface = gps__get_gps_interface; + + *device = (struct hw_device_t*)dev; + return 0; +} + +static struct hw_module_methods_t gps_module_methods = { + .open = open_gps +}; + +struct hw_module_t HAL_MODULE_INFO_SYM = { + .tag = HARDWARE_MODULE_TAG, + .module_api_version = 1, + .hal_api_version = 0, + .id = GPS_HARDWARE_MODULE_ID, + .name = "loc_api GPS Module", + .author = "Qualcomm USA, Inc.", + .methods = &gps_module_methods, +}; diff --git a/gps/loc_api/libloc_api_50001/loc.cpp b/gps/loc_api/libloc_api_50001/loc.cpp new file mode 100644 index 0000000..6a97709 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc.cpp @@ -0,0 +1,1077 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_afw" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace loc_core; + +#define LOC_PM_CLIENT_NAME "GPS" + +//Globals defns +static gps_location_callback gps_loc_cb = NULL; +static gps_sv_status_callback gps_sv_cb = NULL; + +static void local_loc_cb(UlpLocation* location, void* locExt); +static void local_sv_cb(GpsSvStatus* sv_status, void* svExt); + +static const GpsGeofencingInterface* get_geofence_interface(void); + +// Function declarations for sLocEngInterface +static int loc_init(GpsCallbacks* callbacks); +static int loc_start(); +static int loc_stop(); +static void loc_cleanup(); +static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty); +static int loc_inject_location(double latitude, double longitude, float accuracy); +static void loc_delete_aiding_data(GpsAidingData f); +static int loc_set_position_mode(GpsPositionMode mode, GpsPositionRecurrence recurrence, + uint32_t min_interval, uint32_t preferred_accuracy, + uint32_t preferred_time); +static const void* loc_get_extension(const char* name); +// Defines the GpsInterface in gps.h +static const GpsInterface sLocEngInterface = +{ + sizeof(GpsInterface), + loc_init, + loc_start, + loc_stop, + loc_cleanup, + loc_inject_time, + loc_inject_location, + loc_delete_aiding_data, + loc_set_position_mode, + loc_get_extension +}; + +// Function declarations for sLocEngAGpsInterface +static void loc_agps_init(AGpsCallbacks* callbacks); +static int loc_agps_open(const char* apn); +static int loc_agps_closed(); +static int loc_agps_open_failed(); +static int loc_agps_set_server(AGpsType type, const char *hostname, int port); +static int loc_agps_open_with_apniptype( const char* apn, ApnIpType apnIpType); + +static const AGpsInterface sLocEngAGpsInterface = +{ + sizeof(AGpsInterface), + loc_agps_init, + loc_agps_open, + loc_agps_closed, + loc_agps_open_failed, + loc_agps_set_server, + loc_agps_open_with_apniptype +}; + +static int loc_xtra_init(GpsXtraCallbacks* callbacks); +static int loc_xtra_inject_data(char* data, int length); + +static const GpsXtraInterface sLocEngXTRAInterface = +{ + sizeof(GpsXtraInterface), + loc_xtra_init, + loc_xtra_inject_data +}; + +static void loc_ni_init(GpsNiCallbacks *callbacks); +static void loc_ni_respond(int notif_id, GpsUserResponseType user_response); + +static const GpsNiInterface sLocEngNiInterface = +{ + sizeof(GpsNiInterface), + loc_ni_init, + loc_ni_respond, +}; + +static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks); +static void loc_gps_measurement_close(); + +static const GpsMeasurementInterface sLocEngGpsMeasurementInterface = +{ + sizeof(GpsMeasurementInterface), + loc_gps_measurement_init, + loc_gps_measurement_close +}; + +static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ); +static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct); +static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid); +static void loc_agps_ril_ni_message(uint8_t *msg, size_t len); +static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info); +static void loc_agps_ril_update_network_availability(int avaiable, const char* apn); + +static const AGpsRilInterface sLocEngAGpsRilInterface = +{ + sizeof(AGpsRilInterface), + loc_agps_ril_init, + loc_agps_ril_set_ref_location, + loc_agps_ril_set_set_id, + loc_agps_ril_ni_message, + loc_agps_ril_update_network_state, + loc_agps_ril_update_network_availability +}; + +static int loc_agps_install_certificates(const DerEncodedCertificate* certificates, + size_t length); +static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints, + size_t length); + +static const SuplCertificateInterface sLocEngAGpsCertInterface = +{ + sizeof(SuplCertificateInterface), + loc_agps_install_certificates, + loc_agps_revoke_certificates +}; + +static void loc_configuration_update(const char* config_data, int32_t length); + +static const GnssConfigurationInterface sLocEngConfigInterface = +{ + sizeof(GnssConfigurationInterface), + loc_configuration_update +}; + +static loc_eng_data_s_type loc_afw_data; +static int gss_fd = -1; +static int sGnssType = GNSS_UNKNOWN; +/*=========================================================================== +FUNCTION gps_get_hardware_interface + +DESCRIPTION + Returns the GPS hardware interaface based on LOC API + if GPS is enabled. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +const GpsInterface* gps_get_hardware_interface () +{ + ENTRY_LOG_CALLFLOW(); + const GpsInterface* ret_val; + + char propBuf[PROPERTY_VALUE_MAX]; + + loc_eng_read_config(); + + // check to see if GPS should be disabled + property_get("gps.disable", propBuf, ""); + if (propBuf[0] == '1') + { + LOC_LOGD("gps_get_interface returning NULL because gps.disable=1\n"); + ret_val = NULL; + } else { + ret_val = &sLocEngInterface; + } + + loc_eng_read_config(); + + EXIT_LOG(%p, ret_val); + return ret_val; +} + +// for gps.c +extern "C" const GpsInterface* get_gps_interface() +{ + unsigned int target = TARGET_DEFAULT; + loc_eng_read_config(); + + target = loc_get_target(); + LOC_LOGD("Target name check returned %s", loc_get_target_name(target)); + + sGnssType = getTargetGnssType(target); + switch (sGnssType) + { + case GNSS_GSS: + case GNSS_AUTO: + //APQ8064 + gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); + gss_fd = open("/dev/gss", O_RDONLY); + if (gss_fd < 0) { + LOC_LOGE("GSS open failed: %s\n", strerror(errno)); + } + else { + LOC_LOGD("GSS open success! CAPABILITIES %0lx\n", + gps_conf.CAPABILITIES); + } + break; + case GNSS_NONE: + //MPQ8064 + LOC_LOGE("No GPS HW on this target. Not returning interface."); + return NULL; + case GNSS_QCA1530: + // qca1530 chip is present + gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); + LOC_LOGD("qca1530 present: CAPABILITIES %0lx\n", gps_conf.CAPABILITIES); + break; + } + return &sLocEngInterface; +} + +/*=========================================================================== +FUNCTION loc_init + +DESCRIPTION + Initialize the location engine, this include setting up global datas + and registers location engien with loc api service. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/Ax + +===========================================================================*/ +static int loc_init(GpsCallbacks* callbacks) +{ + int retVal = -1; + ENTRY_LOG(); + LOC_API_ADAPTER_EVENT_MASK_T event; + + if (NULL == callbacks) { + LOC_LOGE("loc_init failed. cb = NULL\n"); + EXIT_LOG(%d, retVal); + return retVal; + } + + event = LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | + LOC_API_ADAPTER_BIT_SATELLITE_REPORT | + LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST | + LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST | + LOC_API_ADAPTER_BIT_IOCTL_REPORT | + LOC_API_ADAPTER_BIT_STATUS_REPORT | + LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | + LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST; + + LocCallbacks clientCallbacks = {local_loc_cb, /* location_cb */ + callbacks->status_cb, /* status_cb */ + local_sv_cb, /* sv_status_cb */ + callbacks->nmea_cb, /* nmea_cb */ + callbacks->set_capabilities_cb, /* set_capabilities_cb */ + callbacks->acquire_wakelock_cb, /* acquire_wakelock_cb */ + callbacks->release_wakelock_cb, /* release_wakelock_cb */ + callbacks->create_thread_cb, /* create_thread_cb */ + NULL, /* location_ext_parser */ + NULL, /* sv_ext_parser */ + callbacks->request_utc_time_cb, /* request_utc_time_cb */ + }; + + gps_loc_cb = callbacks->location_cb; + gps_sv_cb = callbacks->sv_status_cb; + + retVal = loc_eng_init(loc_afw_data, &clientCallbacks, event, NULL); + loc_afw_data.adapter->mSupportsAgpsRequests = !loc_afw_data.adapter->hasAgpsExtendedCapabilities(); + loc_afw_data.adapter->mSupportsPositionInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities(); + loc_afw_data.adapter->mSupportsTimeInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities(); + loc_afw_data.adapter->setGpsLockMsg(0); + loc_afw_data.adapter->requestUlp(getCarrierCapabilities()); + loc_afw_data.adapter->setXtraUserAgent(); + + if(retVal) { + LOC_LOGE("loc_eng_init() fail!"); + goto err; + } + + loc_afw_data.adapter->setPowerVoteRight(loc_get_target() == TARGET_QCA1530); + loc_afw_data.adapter->setPowerVote(true); + + LOC_LOGD("loc_eng_init() success!"); + +err: + EXIT_LOG(%d, retVal); + return retVal; +} + +/*=========================================================================== +FUNCTION loc_cleanup + +DESCRIPTION + Cleans location engine. The location client handle will be released. + +DEPENDENCIES + None + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_cleanup() +{ + ENTRY_LOG(); + + loc_afw_data.adapter->setPowerVote(false); + loc_afw_data.adapter->setGpsLockMsg(gps_conf.GPS_LOCK); + + loc_eng_cleanup(loc_afw_data); + gps_loc_cb = NULL; + gps_sv_cb = NULL; + + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_start + +DESCRIPTION + Starts the tracking session + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_start() +{ + ENTRY_LOG(); + int ret_val = loc_eng_start(loc_afw_data); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_stop + +DESCRIPTION + Stops the tracking session + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_stop() +{ + ENTRY_LOG(); + int ret_val = -1; + ret_val = loc_eng_stop(loc_afw_data); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_set_position_mode + +DESCRIPTION + Sets the mode and fix frequency for the tracking session. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_set_position_mode(GpsPositionMode mode, + GpsPositionRecurrence recurrence, + uint32_t min_interval, + uint32_t preferred_accuracy, + uint32_t preferred_time) +{ + ENTRY_LOG(); + int ret_val = -1; + LocPositionMode locMode; + switch (mode) { + case GPS_POSITION_MODE_MS_BASED: + locMode = LOC_POSITION_MODE_MS_BASED; + break; + case GPS_POSITION_MODE_MS_ASSISTED: + locMode = LOC_POSITION_MODE_MS_ASSISTED; + break; + default: + locMode = LOC_POSITION_MODE_STANDALONE; + break; + } + + LocPosMode params(locMode, recurrence, min_interval, + preferred_accuracy, preferred_time, NULL, NULL); + ret_val = loc_eng_set_position_mode(loc_afw_data, params); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_inject_time + +DESCRIPTION + This is used by Java native function to do time injection. + +DEPENDENCIES + None + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty) +{ + ENTRY_LOG(); + int ret_val = 0; + + ret_val = loc_eng_inject_time(loc_afw_data, time, + timeReference, uncertainty); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + + +/*=========================================================================== +FUNCTION loc_inject_location + +DESCRIPTION + This is used by Java native function to do location injection. + +DEPENDENCIES + None + +RETURN VALUE + 0 : Successful + error code : Failure + +SIDE EFFECTS + N/A +===========================================================================*/ +static int loc_inject_location(double latitude, double longitude, float accuracy) +{ + ENTRY_LOG(); + + int ret_val = 0; + ret_val = loc_eng_inject_location(loc_afw_data, latitude, longitude, accuracy); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + + +/*=========================================================================== +FUNCTION loc_delete_aiding_data + +DESCRIPTION + This is used by Java native function to delete the aiding data. The function + updates the global variable for the aiding data to be deleted. If the GPS + engine is off, the aiding data will be deleted. Otherwise, the actual action + will happen when gps engine is turned off. + +DEPENDENCIES + Assumes the aiding data type specified in GpsAidingData matches with + LOC API specification. + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_delete_aiding_data(GpsAidingData f) +{ + ENTRY_LOG(); + loc_eng_delete_aiding_data(loc_afw_data, f); + + EXIT_LOG(%s, VOID_RET); +} + +const GpsGeofencingInterface* get_geofence_interface(void) +{ + ENTRY_LOG(); + void *handle; + const char *error; + typedef const GpsGeofencingInterface* (*get_gps_geofence_interface_function) (void); + get_gps_geofence_interface_function get_gps_geofence_interface; + static const GpsGeofencingInterface* geofence_interface = NULL; + + dlerror(); /* Clear any existing error */ + + handle = dlopen ("libgeofence.so", RTLD_NOW); + + if (!handle) + { + if ((error = dlerror()) != NULL) { + LOC_LOGE ("%s, dlopen for libgeofence.so failed, error = %s\n", __func__, error); + } + goto exit; + } + dlerror(); /* Clear any existing error */ + get_gps_geofence_interface = (get_gps_geofence_interface_function)dlsym(handle, "gps_geofence_get_interface"); + if ((error = dlerror()) != NULL || NULL == get_gps_geofence_interface) { + LOC_LOGE ("%s, dlsym for get_gps_geofence_interface failed, error = %s\n", __func__, error); + goto exit; + } + + geofence_interface = get_gps_geofence_interface(); + +exit: + EXIT_LOG(%d, geofence_interface == NULL); + return geofence_interface; +} +/*=========================================================================== +FUNCTION loc_get_extension + +DESCRIPTION + Get the gps extension to support XTRA. + +DEPENDENCIES + N/A + +RETURN VALUE + The GPS extension interface. + +SIDE EFFECTS + N/A + +===========================================================================*/ +const void* loc_get_extension(const char* name) +{ + ENTRY_LOG(); + const void* ret_val = NULL; + + LOC_LOGD("%s:%d] For Interface = %s\n",__func__, __LINE__, name); + if (strcmp(name, GPS_XTRA_INTERFACE) == 0) + { + ret_val = &sLocEngXTRAInterface; + } + else if (strcmp(name, AGPS_INTERFACE) == 0) + { + ret_val = &sLocEngAGpsInterface; + } + else if (strcmp(name, GPS_NI_INTERFACE) == 0) + { + ret_val = &sLocEngNiInterface; + } + else if (strcmp(name, AGPS_RIL_INTERFACE) == 0) + { + char baseband[PROPERTY_VALUE_MAX]; + property_get("ro.baseband", baseband, "msm"); + if (strcmp(baseband, "csfb") == 0) + { + ret_val = &sLocEngAGpsRilInterface; + } + } + else if (strcmp(name, GPS_GEOFENCING_INTERFACE) == 0) + { + if ((gps_conf.CAPABILITIES | GPS_CAPABILITY_GEOFENCING) == gps_conf.CAPABILITIES ){ + ret_val = get_geofence_interface(); + } + } + else if (strcmp(name, SUPL_CERTIFICATE_INTERFACE) == 0) + { + ret_val = &sLocEngAGpsCertInterface; + } + else if (strcmp(name, GNSS_CONFIGURATION_INTERFACE) == 0) + { + ret_val = &sLocEngConfigInterface; + } + else if (strcmp(name, GPS_MEASUREMENT_INTERFACE) == 0) + { + ret_val = &sLocEngGpsMeasurementInterface; + } + else + { + LOC_LOGE ("get_extension: Invalid interface passed in\n"); + } + EXIT_LOG(%p, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_agps_init + +DESCRIPTION + Initialize the AGps interface. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_agps_init(AGpsCallbacks* callbacks) +{ + ENTRY_LOG(); + loc_eng_agps_init(loc_afw_data, (AGpsExtCallbacks*)callbacks); + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_agps_open + +DESCRIPTION + This function is called when on-demand data connection opening is successful. +It should inform ARM 9 about the data open result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_agps_open(const char* apn) +{ + ENTRY_LOG(); + AGpsType agpsType = AGPS_TYPE_SUPL; + AGpsBearerType bearerType = AGPS_APN_BEARER_IPV4; + int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_agps_open_with_apniptype + +DESCRIPTION + This function is called when on-demand data connection opening is successful. +It should inform ARM 9 about the data open result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_agps_open_with_apniptype(const char* apn, ApnIpType apnIpType) +{ + ENTRY_LOG(); + AGpsType agpsType = AGPS_TYPE_SUPL; + AGpsBearerType bearerType; + + switch (apnIpType) { + case APN_IP_IPV4: + bearerType = AGPS_APN_BEARER_IPV4; + break; + case APN_IP_IPV6: + bearerType = AGPS_APN_BEARER_IPV6; + break; + case APN_IP_IPV4V6: + bearerType = AGPS_APN_BEARER_IPV4V6; + break; + default: + bearerType = AGPS_APN_BEARER_IPV4; + break; + } + + int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_agps_closed + +DESCRIPTION + This function is called when on-demand data connection closing is done. +It should inform ARM 9 about the data close result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_agps_closed() +{ + ENTRY_LOG(); + AGpsType agpsType = AGPS_TYPE_SUPL; + int ret_val = loc_eng_agps_closed(loc_afw_data, agpsType); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_agps_open_failed + +DESCRIPTION + This function is called when on-demand data connection opening has failed. +It should inform ARM 9 about the data open result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_agps_open_failed() +{ + ENTRY_LOG(); + AGpsType agpsType = AGPS_TYPE_SUPL; + int ret_val = loc_eng_agps_open_failed(loc_afw_data, agpsType); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_agps_set_server + +DESCRIPTION + If loc_eng_set_server is called before loc_eng_init, it doesn't work. This + proxy buffers server settings and calls loc_eng_set_server when the client is + open. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_agps_set_server(AGpsType type, const char* hostname, int port) +{ + ENTRY_LOG(); + LocServerType serverType; + switch (type) { + case AGPS_TYPE_SUPL: + serverType = LOC_AGPS_SUPL_SERVER; + break; + case AGPS_TYPE_C2K: + serverType = LOC_AGPS_CDMA_PDE_SERVER; + break; + default: + serverType = LOC_AGPS_SUPL_SERVER; + } + int ret_val = loc_eng_set_server_proxy(loc_afw_data, serverType, hostname, port); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTIONf571 + loc_xtra_init + +DESCRIPTION + Initialize XTRA module. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_xtra_init(GpsXtraCallbacks* callbacks) +{ + ENTRY_LOG(); + GpsXtraExtCallbacks extCallbacks; + memset(&extCallbacks, 0, sizeof(extCallbacks)); + extCallbacks.download_request_cb = callbacks->download_request_cb; + int ret_val = loc_eng_xtra_init(loc_afw_data, &extCallbacks); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + + +/*=========================================================================== +FUNCTION loc_xtra_inject_data + +DESCRIPTION + Initialize XTRA module. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_xtra_inject_data(char* data, int length) +{ + ENTRY_LOG(); + int ret_val = -1; + if( (data != NULL) && ((unsigned int)length <= XTRA_DATA_MAX_SIZE)) + ret_val = loc_eng_xtra_inject_data(loc_afw_data, data, length); + else + LOC_LOGE("%s, Could not inject XTRA data. Buffer address: %p, length: %d", + __func__, data, length); + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_gps_measurement_init + +DESCRIPTION + This function initializes the gps measurement interface + +DEPENDENCIES + NONE + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks) +{ + ENTRY_LOG(); + int ret_val = loc_eng_gps_measurement_init(loc_afw_data, + callbacks); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_gps_measurement_close + +DESCRIPTION + This function closes the gps measurement interface + +DEPENDENCIES + NONE + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_gps_measurement_close() +{ + ENTRY_LOG(); + loc_eng_gps_measurement_close(loc_afw_data); + + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_ni_init + +DESCRIPTION + This function initializes the NI interface + +DEPENDENCIES + NONE + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_ni_init(GpsNiCallbacks *callbacks) +{ + ENTRY_LOG(); + loc_eng_ni_init(loc_afw_data,(GpsNiExtCallbacks*) callbacks); + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_ni_respond + +DESCRIPTION + This function sends an NI respond to the modem processor + +DEPENDENCIES + NONE + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_ni_respond(int notif_id, GpsUserResponseType user_response) +{ + ENTRY_LOG(); + loc_eng_ni_respond(loc_afw_data, notif_id, user_response); + EXIT_LOG(%s, VOID_RET); +} + +// Below stub functions are members of sLocEngAGpsRilInterface +static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ) {} +static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct) {} +static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid) {} +static void loc_agps_ril_ni_message(uint8_t *msg, size_t len) {} +static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info) {} + +/*=========================================================================== +FUNCTION loc_agps_ril_update_network_availability + +DESCRIPTION + Sets data call allow vs disallow flag to modem + This is the only member of sLocEngAGpsRilInterface implemented. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_agps_ril_update_network_availability(int available, const char* apn) +{ + ENTRY_LOG(); + loc_eng_agps_ril_update_network_availability(loc_afw_data, available, apn); + EXIT_LOG(%s, VOID_RET); +} + +static int loc_agps_install_certificates(const DerEncodedCertificate* certificates, + size_t length) +{ + ENTRY_LOG(); + int ret_val = loc_eng_agps_install_certificates(loc_afw_data, certificates, length); + EXIT_LOG(%d, ret_val); + return ret_val; +} +static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints, + size_t length) +{ + ENTRY_LOG(); + LOC_LOGE("%s:%d]: agps_revoke_certificates not supported"); + int ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; + EXIT_LOG(%d, ret_val); + return ret_val; +} + +static void loc_configuration_update(const char* config_data, int32_t length) +{ + ENTRY_LOG(); + loc_eng_configuration_update(loc_afw_data, config_data, length); + switch (sGnssType) + { + case GNSS_GSS: + case GNSS_AUTO: + case GNSS_QCA1530: + //APQ + gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); + break; + } + EXIT_LOG(%s, VOID_RET); +} + +static void local_loc_cb(UlpLocation* location, void* locExt) +{ + ENTRY_LOG(); + if (NULL != location) { + CALLBACK_LOG_CALLFLOW("location_cb - from", %d, location->position_source); + + if (NULL != gps_loc_cb) { + gps_loc_cb(&location->gpsLocation); + } + } + EXIT_LOG(%s, VOID_RET); +} + +static void local_sv_cb(GpsSvStatus* sv_status, void* svExt) +{ + ENTRY_LOG(); + if (NULL != gps_sv_cb) { + CALLBACK_LOG_CALLFLOW("sv_status_cb -", %d, sv_status->num_svs); + gps_sv_cb(sv_status); + } + EXIT_LOG(%s, VOID_RET); +} + diff --git a/gps/loc_api/libloc_api_50001/loc.h b/gps/loc_api/libloc_api_50001/loc.h new file mode 100644 index 0000000..e56fdcf --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2011,2014 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_H__ +#define __LOC_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include +#include +#include + +#define XTRA_DATA_MAX_SIZE 100000 /*bytes*/ + +typedef void (*loc_location_cb_ext) (UlpLocation* location, void* locExt); +typedef void (*loc_sv_status_cb_ext) (GpsSvStatus* sv_status, void* svExt); +typedef void* (*loc_ext_parser)(void* data); + +typedef struct { + loc_location_cb_ext location_cb; + gps_status_callback status_cb; + loc_sv_status_cb_ext sv_status_cb; + gps_nmea_callback nmea_cb; + gps_set_capabilities set_capabilities_cb; + gps_acquire_wakelock acquire_wakelock_cb; + gps_release_wakelock release_wakelock_cb; + gps_create_thread create_thread_cb; + loc_ext_parser location_ext_parser; + loc_ext_parser sv_ext_parser; + gps_request_utc_time request_utc_time_cb; +} LocCallbacks; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif //__LOC_H__ diff --git a/gps/loc_api/libloc_api_50001/loc_eng.cpp b/gps/loc_api/libloc_api_50001/loc_eng.cpp new file mode 100644 index 0000000..52dc6c5 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng.cpp @@ -0,0 +1,2999 @@ +/* Copyright (c) 2009-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_eng" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* struct sockaddr_in */ +#include +#include +#include +#include +#include +#include + +#include +#ifndef USE_GLIB +#include +#include +#endif /* USE_GLIB */ + +#ifdef USE_GLIB +#include +#include +#endif /* USE_GLIB */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include "log_util.h" +#include "platform_lib_includes.h" +#include "loc_core_log.h" +#include "loc_eng_log.h" + +#define SUCCESS TRUE +#define FAILURE FALSE + +#ifndef GPS_CONF_FILE +#define GPS_CONF_FILE "/etc/gps.conf" //??? platform independent +#endif + +#ifndef SAP_CONF_FILE +#define SAP_CONF_FILE "/etc/sap.conf" +#endif + +#define XTRA1_GPSONEXTRA "xtra1.gpsonextra.net" + +using namespace loc_core; + +boolean configAlreadyRead = false; +unsigned int agpsStatus = 0; +loc_gps_cfg_s_type gps_conf; +loc_sap_cfg_s_type sap_conf; + +/* Parameter spec table */ +static const loc_param_s_type gps_conf_table[] = +{ + {"GPS_LOCK", &gps_conf.GPS_LOCK, NULL, 'n'}, + {"SUPL_VER", &gps_conf.SUPL_VER, NULL, 'n'}, + {"LPP_PROFILE", &gps_conf.LPP_PROFILE, NULL, 'n'}, + {"A_GLONASS_POS_PROTOCOL_SELECT", &gps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'}, + {"AGPS_CERT_WRITABLE_MASK", &gps_conf.AGPS_CERT_WRITABLE_MASK, NULL, 'n'}, + {"SUPL_MODE", &gps_conf.SUPL_MODE, NULL, 'n'}, + {"INTERMEDIATE_POS", &gps_conf.INTERMEDIATE_POS, NULL, 'n'}, + {"ACCURACY_THRES", &gps_conf.ACCURACY_THRES, NULL, 'n'}, + {"NMEA_PROVIDER", &gps_conf.NMEA_PROVIDER, NULL, 'n'}, + {"CAPABILITIES", &gps_conf.CAPABILITIES, NULL, 'n'}, + {"XTRA_VERSION_CHECK", &gps_conf.XTRA_VERSION_CHECK, NULL, 'n'}, + {"XTRA_SERVER_1", &gps_conf.XTRA_SERVER_1, NULL, 's'}, + {"XTRA_SERVER_2", &gps_conf.XTRA_SERVER_2, NULL, 's'}, + {"XTRA_SERVER_3", &gps_conf.XTRA_SERVER_3, NULL, 's'}, + {"USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL", &gps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL, NULL, 'n'}, +}; + +static const loc_param_s_type sap_conf_table[] = +{ + {"GYRO_BIAS_RANDOM_WALK", &sap_conf.GYRO_BIAS_RANDOM_WALK, &sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'}, + {"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"ANGLE_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"RATE_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"SENSOR_ACCEL_BATCHES_PER_SEC", &sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, NULL, 'n'}, + {"SENSOR_ACCEL_SAMPLES_PER_BATCH", &sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, NULL, 'n'}, + {"SENSOR_GYRO_BATCHES_PER_SEC", &sap_conf.SENSOR_GYRO_BATCHES_PER_SEC, NULL, 'n'}, + {"SENSOR_GYRO_SAMPLES_PER_BATCH", &sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, NULL, 'n'}, + {"SENSOR_ACCEL_BATCHES_PER_SEC_HIGH", &sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, NULL, 'n'}, + {"SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH", &sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, NULL, 'n'}, + {"SENSOR_GYRO_BATCHES_PER_SEC_HIGH", &sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, NULL, 'n'}, + {"SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH", &sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, NULL, 'n'}, + {"SENSOR_CONTROL_MODE", &sap_conf.SENSOR_CONTROL_MODE, NULL, 'n'}, + {"SENSOR_USAGE", &sap_conf.SENSOR_USAGE, NULL, 'n'}, + {"SENSOR_ALGORITHM_CONFIG_MASK", &sap_conf.SENSOR_ALGORITHM_CONFIG_MASK, NULL, 'n'}, + {"SENSOR_PROVIDER", &sap_conf.SENSOR_PROVIDER, NULL, 'n'} +}; + +static void loc_default_parameters(void) +{ + /*Defaults for gps.conf*/ + gps_conf.INTERMEDIATE_POS = 0; + gps_conf.ACCURACY_THRES = 0; + gps_conf.NMEA_PROVIDER = 0; + gps_conf.GPS_LOCK = 0; + gps_conf.SUPL_VER = 0x10000; + gps_conf.SUPL_MODE = 0x3; + gps_conf.CAPABILITIES = 0x7; + /* LTE Positioning Profile configuration is disable by default*/ + gps_conf.LPP_PROFILE = 0; + /*By default no positioning protocol is selected on A-GLONASS system*/ + gps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0; + /*XTRA version check is disabled by default*/ + gps_conf.XTRA_VERSION_CHECK=0; + /*Use emergency PDN by default*/ + gps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = 1; + + /*Defaults for sap.conf*/ + sap_conf.GYRO_BIAS_RANDOM_WALK = 0; + sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC = 2; + sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH = 5; + sap_conf.SENSOR_GYRO_BATCHES_PER_SEC = 2; + sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH = 5; + sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH = 4; + sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH = 25; + sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH = 4; + sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH = 25; + sap_conf.SENSOR_CONTROL_MODE = 0; /* AUTO */ + sap_conf.SENSOR_USAGE = 0; /* Enabled */ + sap_conf.SENSOR_ALGORITHM_CONFIG_MASK = 0; /* INS Disabled = FALSE*/ + /* Values MUST be set by OEMs in configuration for sensor-assisted + navigation to work. There are NO default values */ + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY = 0; + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY = 0; + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY = 0; + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY = 0; + sap_conf.GYRO_BIAS_RANDOM_WALK_VALID = 0; + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + /* default provider is SSC */ + sap_conf.SENSOR_PROVIDER = 1; + + /* None of the 10 slots for agps certificates are writable by default */ + gps_conf.AGPS_CERT_WRITABLE_MASK = 0; +} + +// 2nd half of init(), singled out for +// modem restart to use. +static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data); +static void loc_eng_agps_reinit(loc_eng_data_s_type &loc_eng_data); + +static int loc_eng_set_server(loc_eng_data_s_type &loc_eng_data, + LocServerType type, const char *hostname, int port); +// Internal functions +static void loc_inform_gps_status(loc_eng_data_s_type &loc_eng_data, + GpsStatusValue status); +static void loc_eng_report_status(loc_eng_data_s_type &loc_eng_data, + GpsStatusValue status); +static void loc_eng_process_conn_request(loc_eng_data_s_type &loc_eng_data, + int connHandle, AGpsType agps_type); +static void loc_eng_agps_close_status(loc_eng_data_s_type &loc_eng_data, int is_succ); +static void loc_eng_handle_engine_down(loc_eng_data_s_type &loc_eng_data) ; +static void loc_eng_handle_engine_up(loc_eng_data_s_type &loc_eng_data) ; + +static int loc_eng_start_handler(loc_eng_data_s_type &loc_eng_data); +static int loc_eng_stop_handler(loc_eng_data_s_type &loc_eng_data); +static int loc_eng_get_zpp_handler(loc_eng_data_s_type &loc_eng_data); +static void deleteAidingData(loc_eng_data_s_type &logEng); +static AgpsStateMachine* +getAgpsStateMachine(loc_eng_data_s_type& logEng, AGpsExtType agpsType); +static int dataCallCb(void *cb_data); +static void update_aiding_data_for_deletion(loc_eng_data_s_type& loc_eng_data) { + if (loc_eng_data.engine_status != GPS_STATUS_ENGINE_ON && + loc_eng_data.aiding_data_for_deletion != 0) + { + loc_eng_data.adapter->deleteAidingData(loc_eng_data.aiding_data_for_deletion); + loc_eng_data.aiding_data_for_deletion = 0; + } +} + +static void* noProc(void* data) +{ + return NULL; +} + +/********************************************************************* + * definitions of the static messages used in the file + *********************************************************************/ +// case LOC_ENG_MSG_REQUEST_NI: +LocEngRequestNi::LocEngRequestNi(void* locEng, + GpsNiNotification ¬if, + const void* data) : + LocMsg(), mLocEng(locEng), mNotify(notif), mPayload(data) { + locallog(); +} +void LocEngRequestNi::proc() const { + loc_eng_ni_request_handler(*((loc_eng_data_s_type*)mLocEng), + &mNotify, mPayload); +} +void LocEngRequestNi::locallog() const +{ + LOC_LOGV("id: %d\n type: %s\n flags: %d\n time out: %d\n " + "default response: %s\n requestor id encoding: %s\n" + " text encoding: %s\n passThroughData: %p", + mNotify.notification_id, + loc_get_ni_type_name(mNotify.ni_type), + mNotify.notify_flags, + mNotify.timeout, + loc_get_ni_response_name(mNotify.default_response), + loc_get_ni_encoding_name(mNotify.requestor_id_encoding), + loc_get_ni_encoding_name(mNotify.text_encoding), + mPayload); +} +inline void LocEngRequestNi::log() const { + locallog(); +} + +// case LOC_ENG_MSG_INFORM_NI_RESPONSE: +// in loc_eng_ni.cpp + +// case LOC_ENG_MSG_START_FIX: +LocEngStartFix::LocEngStartFix(LocEngAdapter* adapter) : + LocMsg(), mAdapter(adapter) +{ + locallog(); +} +inline void LocEngStartFix::proc() const +{ + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner(); + loc_eng_start_handler(*locEng); +} +inline void LocEngStartFix::locallog() const +{ + LOC_LOGV("LocEngStartFix"); +} +inline void LocEngStartFix::log() const +{ + locallog(); +} +void LocEngStartFix::send() const { + mAdapter->sendMsg(this); +} + +// case LOC_ENG_MSG_STOP_FIX: +LocEngStopFix::LocEngStopFix(LocEngAdapter* adapter) : + LocMsg(), mAdapter(adapter) +{ + locallog(); +} +inline void LocEngStopFix::proc() const +{ + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner(); + loc_eng_stop_handler(*locEng); +} +inline void LocEngStopFix::locallog() const +{ + LOC_LOGV("LocEngStopFix"); +} +inline void LocEngStopFix::log() const +{ + locallog(); +} +void LocEngStopFix::send() const { + mAdapter->sendMsg(this); +} + +// case LOC_ENG_MSG_SET_POSITION_MODE: +LocEngPositionMode::LocEngPositionMode(LocEngAdapter* adapter, + LocPosMode &mode) : + LocMsg(), mAdapter(adapter), mPosMode(mode) +{ + mPosMode.logv(); +} +inline void LocEngPositionMode::proc() const { + mAdapter->setPositionMode(&mPosMode); +} +inline void LocEngPositionMode::log() const { + mPosMode.logv(); +} +void LocEngPositionMode::send() const { + mAdapter->sendMsg(this); +} + +LocEngGetZpp::LocEngGetZpp(LocEngAdapter* adapter) : + LocMsg(), mAdapter(adapter) +{ + locallog(); +} +inline void LocEngGetZpp::proc() const +{ + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner(); + loc_eng_get_zpp_handler(*locEng); +} +inline void LocEngGetZpp::locallog() const +{ + LOC_LOGV("LocEngGetZpp"); +} +inline void LocEngGetZpp::log() const +{ + locallog(); +} +void LocEngGetZpp::send() const { + mAdapter->sendMsg(this); +} + +struct LocEngSetTime : public LocMsg { + LocEngAdapter* mAdapter; + const GpsUtcTime mTime; + const int64_t mTimeReference; + const int mUncertainty; + inline LocEngSetTime(LocEngAdapter* adapter, + GpsUtcTime t, int64_t tf, int unc) : + LocMsg(), mAdapter(adapter), + mTime(t), mTimeReference(tf), mUncertainty(unc) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setTime(mTime, mTimeReference, mUncertainty); + } + inline void locallog() const { + LOC_LOGV("time: %lld\n timeReference: %lld\n uncertainty: %d", + mTime, mTimeReference, mUncertainty); + } + inline virtual void log() const { + locallog(); + } +}; + + // case LOC_ENG_MSG_INJECT_LOCATION: +struct LocEngInjectLocation : public LocMsg { + LocEngAdapter* mAdapter; + const double mLatitude; + const double mLongitude; + const float mAccuracy; + inline LocEngInjectLocation(LocEngAdapter* adapter, + double lat, double lon, float accur) : + LocMsg(), mAdapter(adapter), + mLatitude(lat), mLongitude(lon), mAccuracy(accur) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->injectPosition(mLatitude, mLongitude, mAccuracy); + } + inline void locallog() const { + LOC_LOGV("latitude: %f\n longitude: %f\n accuracy: %f", + mLatitude, mLongitude, mAccuracy); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SERVER_IPV4: +struct LocEngSetServerIpv4 : public LocMsg { + LocEngAdapter* mAdapter; + const unsigned int mNlAddr; + const int mPort; + const LocServerType mServerType; + inline LocEngSetServerIpv4(LocEngAdapter* adapter, + unsigned int ip, + int port, + LocServerType type) : + LocMsg(), mAdapter(adapter), + mNlAddr(ip), mPort(port), mServerType(type) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setServer(mNlAddr, mPort, mServerType); + } + inline void locallog() const { + LOC_LOGV("LocEngSetServerIpv4 - addr: %x, port: %d, type: %s", + mNlAddr, mPort, loc_get_server_type_name(mServerType)); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SERVER_URL: +struct LocEngSetServerUrl : public LocMsg { + LocEngAdapter* mAdapter; + const int mLen; + char* mUrl; + inline LocEngSetServerUrl(LocEngAdapter* adapter, + char* urlString, + int url_len) : + LocMsg(), mAdapter(adapter), + mLen(url_len), mUrl(new char[mLen+1]) + { + memcpy((void*)mUrl, (void*)urlString, url_len); + mUrl[mLen] = 0; + locallog(); + } + inline ~LocEngSetServerUrl() + { + delete[] mUrl; + } + inline virtual void proc() const { + mAdapter->setServer(mUrl, mLen); + } + inline void locallog() const { + LOC_LOGV("LocEngSetServerUrl - url: %s", mUrl); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_A_GLONASS_PROTOCOL: +struct LocEngAGlonassProtocol : public LocMsg { + LocEngAdapter* mAdapter; + const unsigned long mAGlonassProtocl; + inline LocEngAGlonassProtocol(LocEngAdapter* adapter, + unsigned long protocol) : + LocMsg(), mAdapter(adapter), mAGlonassProtocl(protocol) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setAGLONASSProtocol(mAGlonassProtocl); + } + inline void locallog() const { + LOC_LOGV("A-GLONASS protocol: 0x%lx", mAGlonassProtocl); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SUPL_VERSION: +struct LocEngSuplVer : public LocMsg { + LocEngAdapter* mAdapter; + const int mSuplVer; + inline LocEngSuplVer(LocEngAdapter* adapter, + int suplVer) : + LocMsg(), mAdapter(adapter), mSuplVer(suplVer) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSUPLVersion(mSuplVer); + } + inline void locallog() const { + LOC_LOGV("SUPL Version: %d", mSuplVer); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocEngSuplMode : public LocMsg { + UlpProxyBase* mUlp; + + inline LocEngSuplMode(UlpProxyBase* ulp) : + LocMsg(), mUlp(ulp) + { + locallog(); + } + inline virtual void proc() const { + mUlp->setCapabilities(getCarrierCapabilities()); + } + inline void locallog() const { + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_LPP_CONFIG: +struct LocEngLppConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mLppConfig; + inline LocEngLppConfig(LocEngAdapter* adapter, + int lppConfig) : + LocMsg(), mAdapter(adapter), mLppConfig(lppConfig) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setLPPConfig(mLppConfig); + } + inline void locallog() const { + LOC_LOGV("LocEngLppConfig - profile: %d", mLppConfig); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SENSOR_CONTROL_CONFIG: +struct LocEngSensorControlConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mSensorsDisabled; + const int mSensorProvider; + inline LocEngSensorControlConfig(LocEngAdapter* adapter, + int sensorsDisabled, int sensorProvider) : + LocMsg(), mAdapter(adapter), mSensorsDisabled(sensorsDisabled), + mSensorProvider(sensorProvider) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSensorControlConfig(mSensorsDisabled, mSensorProvider); + } + inline void locallog() const { + LOC_LOGV("LocEngSensorControlConfig - Sensors Disabled: %d, Sensor Provider: %d", + mSensorsDisabled, mSensorProvider); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SENSOR_PROPERTIES: +struct LocEngSensorProperties : public LocMsg { + LocEngAdapter* mAdapter; + const bool mGyroBiasVarianceRandomWalkValid; + const float mGyroBiasVarianceRandomWalk; + const bool mAccelRandomWalkValid; + const float mAccelRandomWalk; + const bool mAngleRandomWalkValid; + const float mAngleRandomWalk; + const bool mRateRandomWalkValid; + const float mRateRandomWalk; + const bool mVelocityRandomWalkValid; + const float mVelocityRandomWalk; + inline LocEngSensorProperties(LocEngAdapter* adapter, + bool gyroBiasRandomWalk_valid, + float gyroBiasRandomWalk, + bool accelRandomWalk_valid, + float accelRandomWalk, + bool angleRandomWalk_valid, + float angleRandomWalk, + bool rateRandomWalk_valid, + float rateRandomWalk, + bool velocityRandomWalk_valid, + float velocityRandomWalk) : + LocMsg(), mAdapter(adapter), + mGyroBiasVarianceRandomWalkValid(gyroBiasRandomWalk_valid), + mGyroBiasVarianceRandomWalk(gyroBiasRandomWalk), + mAccelRandomWalkValid(accelRandomWalk_valid), + mAccelRandomWalk(accelRandomWalk), + mAngleRandomWalkValid(angleRandomWalk_valid), + mAngleRandomWalk(angleRandomWalk), + mRateRandomWalkValid(rateRandomWalk_valid), + mRateRandomWalk(rateRandomWalk), + mVelocityRandomWalkValid(velocityRandomWalk_valid), + mVelocityRandomWalk(velocityRandomWalk) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSensorProperties(mGyroBiasVarianceRandomWalkValid, + mGyroBiasVarianceRandomWalk, + mAccelRandomWalkValid, + mAccelRandomWalk, + mAngleRandomWalkValid, + mAngleRandomWalk, + mRateRandomWalkValid, + mRateRandomWalk, + mVelocityRandomWalkValid, + mVelocityRandomWalk); + } + inline void locallog() const { + LOC_LOGV("Sensor properties validity, Gyro Random walk: %d " + "Accel Random Walk: %d " + "Angle Random Walk: %d Rate Random Walk: %d " + "Velocity Random Walk: %d\n" + "Sensor properties, Gyro Random walk: %f " + "Accel Random Walk: %f " + "Angle Random Walk: %f Rate Random Walk: %f " + "Velocity Random Walk: %f", + mGyroBiasVarianceRandomWalkValid, + mAccelRandomWalkValid, + mAngleRandomWalkValid, + mRateRandomWalkValid, + mVelocityRandomWalkValid, + mGyroBiasVarianceRandomWalk, + mAccelRandomWalk, + mAngleRandomWalk, + mRateRandomWalk, + mVelocityRandomWalk + ); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SENSOR_PERF_CONTROL_CONFIG: +struct LocEngSensorPerfControlConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mControlMode; + const int mAccelSamplesPerBatch; + const int mAccelBatchesPerSec; + const int mGyroSamplesPerBatch; + const int mGyroBatchesPerSec; + const int mAccelSamplesPerBatchHigh; + const int mAccelBatchesPerSecHigh; + const int mGyroSamplesPerBatchHigh; + const int mGyroBatchesPerSecHigh; + const int mAlgorithmConfig; + inline LocEngSensorPerfControlConfig(LocEngAdapter* adapter, + int controlMode, + int accelSamplesPerBatch, + int accelBatchesPerSec, + int gyroSamplesPerBatch, + int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, + int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, + int gyroBatchesPerSecHigh, + int algorithmConfig) : + LocMsg(), mAdapter(adapter), + mControlMode(controlMode), + mAccelSamplesPerBatch(accelSamplesPerBatch), + mAccelBatchesPerSec(accelBatchesPerSec), + mGyroSamplesPerBatch(gyroSamplesPerBatch), + mGyroBatchesPerSec(gyroBatchesPerSec), + mAccelSamplesPerBatchHigh(accelSamplesPerBatchHigh), + mAccelBatchesPerSecHigh(accelBatchesPerSecHigh), + mGyroSamplesPerBatchHigh(gyroSamplesPerBatchHigh), + mGyroBatchesPerSecHigh(gyroBatchesPerSecHigh), + mAlgorithmConfig(algorithmConfig) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSensorPerfControlConfig(mControlMode, + mAccelSamplesPerBatch, + mAccelBatchesPerSec, + mGyroSamplesPerBatch, + mGyroBatchesPerSec, + mAccelSamplesPerBatchHigh, + mAccelBatchesPerSecHigh, + mGyroSamplesPerBatchHigh, + mGyroBatchesPerSecHigh, + mAlgorithmConfig); + } + inline void locallog() const { + LOC_LOGV("Sensor Perf Control Config (performanceControlMode)(%u) " + "accel(#smp,#batches) (%u,%u) " + "gyro(#smp,#batches) (%u,%u), " + "accel_high(#smp,#batches) (%u,%u) " + "gyro_high(#smp,#batches) (%u,%u), " + "algorithmConfig(%u)\n", + mControlMode, + mAccelSamplesPerBatch, mAccelBatchesPerSec, + mGyroSamplesPerBatch, mGyroBatchesPerSec, + mAccelSamplesPerBatchHigh, mAccelBatchesPerSecHigh, + mGyroSamplesPerBatchHigh, mGyroBatchesPerSecHigh, + mAlgorithmConfig); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_EXT_POWER_CONFIG: +struct LocEngExtPowerConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mIsBatteryCharging; + inline LocEngExtPowerConfig(LocEngAdapter* adapter, + int isBatteryCharging) : + LocMsg(), mAdapter(adapter), + mIsBatteryCharging(isBatteryCharging) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setExtPowerConfig(mIsBatteryCharging); + } + inline void locallog() const { + LOC_LOGV("LocEngExtPowerConfig - isBatteryCharging: %d", + mIsBatteryCharging); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_REPORT_POSITION: +LocEngReportPosition::LocEngReportPosition(LocAdapterBase* adapter, + UlpLocation &loc, + GpsLocationExtended &locExtended, + void* locExt, + enum loc_sess_status st, + LocPosTechMask technology) : + LocMsg(), mAdapter(adapter), mLocation(loc), + mLocationExtended(locExtended), + mLocationExt(((loc_eng_data_s_type*) + ((LocEngAdapter*) + (mAdapter))->getOwner())->location_ext_parser(locExt)), + mStatus(st), mTechMask(technology) +{ + locallog(); +} +void LocEngReportPosition::proc() const { + LocEngAdapter* adapter = (LocEngAdapter*)mAdapter; + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)adapter->getOwner(); + + if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION) { + bool reported = false; + if (locEng->location_cb != NULL) { + if (LOC_SESS_FAILURE == mStatus) { + // in case we want to handle the failure case + locEng->location_cb(NULL, NULL); + reported = true; + } + // what's in the else if is... (line by line) + // 1. this is a final fix; and + // 1.1 it is a Satellite fix; or + // 1.2 it is a sensor fix + // 2. (must be intermediate fix... implicit) + // 2.1 we accepte intermediate; and + // 2.2 it is NOT the case that + // 2.2.1 there is inaccuracy; and + // 2.2.2 we care about inaccuracy; and + // 2.2.3 the inaccuracy exceeds our tolerance + else if ((LOC_SESS_SUCCESS == mStatus && + ((LOC_POS_TECH_MASK_SATELLITE | + LOC_POS_TECH_MASK_SENSORS | + LOC_POS_TECH_MASK_HYBRID) & + mTechMask)) || + (LOC_SESS_INTERMEDIATE == locEng->intermediateFix && + !((mLocation.gpsLocation.flags & + GPS_LOCATION_HAS_ACCURACY) && + (gps_conf.ACCURACY_THRES != 0) && + (mLocation.gpsLocation.accuracy > + gps_conf.ACCURACY_THRES)))) { + locEng->location_cb((UlpLocation*)&(mLocation), + (void*)mLocationExt); + reported = true; + } + } + + // if we have reported this fix + if (reported && + // and if this is a singleshot + GPS_POSITION_RECURRENCE_SINGLE == + locEng->adapter->getPositionMode().recurrence) { + if (LOC_SESS_INTERMEDIATE == mStatus) { + // modem could be still working for a final fix, + // although we no longer need it. So stopFix(). + locEng->adapter->stopFix(); + } + // turn off the session flag. + locEng->adapter->setInSession(false); + } + + LOC_LOGV("LocEngReportPosition::proc() - generateNmea: %d, position source: %d, " + "engine_status: %d, isInSession: %d", + locEng->generateNmea, mLocation.position_source, + locEng->engine_status, locEng->adapter->isInSession()); + + if (locEng->generateNmea && + locEng->adapter->isInSession()) + { + unsigned char generate_nmea = reported && + (mStatus != LOC_SESS_FAILURE); + loc_eng_nmea_generate_pos(locEng, mLocation, mLocationExtended, + generate_nmea); + } + + // Free the allocated memory for rawData + UlpLocation* gp = (UlpLocation*)&(mLocation); + if (gp != NULL && gp->rawData != NULL) + { + delete (char*)gp->rawData; + gp->rawData = NULL; + gp->rawDataSize = 0; + } + } +} +void LocEngReportPosition::locallog() const { + LOC_LOGV("LocEngReportPosition"); +} +void LocEngReportPosition::log() const { + locallog(); +} +void LocEngReportPosition::send() const { + mAdapter->sendMsg(this); +} + + +// case LOC_ENG_MSG_REPORT_SV: +LocEngReportSv::LocEngReportSv(LocAdapterBase* adapter, + HaxxSvStatus &sv, + GpsLocationExtended &locExtended, + void* svExt) : + LocMsg(), mAdapter(adapter), mSvStatus(sv), + mLocationExtended(locExtended), + mSvExt(((loc_eng_data_s_type*) + ((LocEngAdapter*) + (mAdapter))->getOwner())->sv_ext_parser(svExt)) +{ + locallog(); +} +void LocEngReportSv::proc() const { + LocEngAdapter* adapter = (LocEngAdapter*)mAdapter; + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)adapter->getOwner(); + + if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION) + { + if (locEng->sv_status_cb != NULL) { + locEng->sv_status_cb((GpsSvStatus*)&(mSvStatus), + (void*)mSvExt); + } + + if (locEng->generateNmea) + { + loc_eng_nmea_generate_sv(locEng, mSvStatus, mLocationExtended); + } + } +} +void LocEngReportSv::locallog() const { + LOC_LOGV("%s:%d] LocEngReportSv",__func__, __LINE__); +} +inline void LocEngReportSv::log() const { + locallog(); +} +void LocEngReportSv::send() const { + mAdapter->sendMsg(this); +} + +// case LOC_ENG_MSG_REPORT_STATUS: +LocEngReportStatus::LocEngReportStatus(LocAdapterBase* adapter, + GpsStatusValue engineStatus) : + LocMsg(), mAdapter(adapter), mStatus(engineStatus) +{ + locallog(); +} +inline void LocEngReportStatus::proc() const +{ + LocEngAdapter* adapter = (LocEngAdapter*)mAdapter; + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)adapter->getOwner(); + + loc_eng_report_status(*locEng, mStatus); + update_aiding_data_for_deletion(*locEng); +} +inline void LocEngReportStatus::locallog() const { + LOC_LOGV("LocEngReportStatus"); +} +inline void LocEngReportStatus::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REPORT_NMEA: +LocEngReportNmea::LocEngReportNmea(void* locEng, + const char* data, int len) : + LocMsg(), mLocEng(locEng), mNmea(new char[len]), mLen(len) +{ + memcpy((void*)mNmea, (void*)data, len); + locallog(); +} +void LocEngReportNmea::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng; + + struct timeval tv; + gettimeofday(&tv, (struct timezone *) NULL); + int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000; + + if (locEng->nmea_cb != NULL) + locEng->nmea_cb(now, mNmea, mLen); +} +inline void LocEngReportNmea::locallog() const { + LOC_LOGV("LocEngReportNmea"); +} +inline void LocEngReportNmea::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REPORT_XTRA_SERVER: +LocEngReportXtraServer::LocEngReportXtraServer(void* locEng, + const char *url1, + const char *url2, + const char *url3, + const int maxlength) : + LocMsg(), mLocEng(locEng), mMaxLen(maxlength), + mServers(new char[3*(mMaxLen+1)]) +{ + char * cptr = mServers; + memset(mServers, 0, 3*(mMaxLen+1)); + + // Override modem URLs with uncommented gps.conf urls + if( gps_conf.XTRA_SERVER_1[0] != '\0' ) { + url1 = &gps_conf.XTRA_SERVER_1[0]; + } + if( gps_conf.XTRA_SERVER_2[0] != '\0' ) { + url2 = &gps_conf.XTRA_SERVER_2[0]; + } + if( gps_conf.XTRA_SERVER_3[0] != '\0' ) { + url3 = &gps_conf.XTRA_SERVER_3[0]; + } + // copy non xtra1.gpsonextra.net URLs into the forwarding buffer. + if( NULL == strcasestr(url1, XTRA1_GPSONEXTRA) ) { + strlcpy(cptr, url1, mMaxLen + 1); + cptr += mMaxLen + 1; + } + if( NULL == strcasestr(url2, XTRA1_GPSONEXTRA) ) { + strlcpy(cptr, url2, mMaxLen + 1); + cptr += mMaxLen + 1; + } + if( NULL == strcasestr(url3, XTRA1_GPSONEXTRA) ) { + strlcpy(cptr, url3, mMaxLen + 1); + } + locallog(); +} + +void LocEngReportXtraServer::proc() const { + loc_eng_xtra_data_s_type* locEngXtra = + &(((loc_eng_data_s_type*)mLocEng)->xtra_module_data); + + if (locEngXtra->report_xtra_server_cb != NULL) { + CALLBACK_LOG_CALLFLOW("report_xtra_server_cb", %s, mServers); + locEngXtra->report_xtra_server_cb(mServers, + &(mServers[mMaxLen+1]), + &(mServers[(mMaxLen+1)<<1])); + } else { + LOC_LOGE("Callback function for request xtra is NULL"); + } +} +inline void LocEngReportXtraServer::locallog() const { + LOC_LOGV("LocEngReportXtraServers: server1: %s\n server2: %s\n" + " server3: %s\n", + mServers, &mServers[mMaxLen+1], &mServers[(mMaxLen+1)<<1]); +} +inline void LocEngReportXtraServer::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_BIT: +// case LOC_ENG_MSG_RELEASE_BIT: +LocEngReqRelBIT::LocEngReqRelBIT(void* locEng, AGpsExtType type, + int ipv4, char* ipv6, bool isReq) : + LocMsg(), mLocEng(locEng), mType(type), mIPv4Addr(ipv4), + mIPv6Addr(ipv6 ? new char[16] : NULL), mIsReq(isReq) { + if (NULL != ipv6) + memcpy(mIPv6Addr, ipv6, 16); + locallog(); +} +inline LocEngReqRelBIT::~LocEngReqRelBIT() { + if (mIPv6Addr) { + delete[] mIPv6Addr; + } +} +void LocEngReqRelBIT::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + BITSubscriber s(getAgpsStateMachine(*locEng, mType), + mIPv4Addr, mIPv6Addr); + AgpsStateMachine* sm = (AgpsStateMachine*)s.mStateMachine; + + if (mIsReq) { + sm->subscribeRsrc((Subscriber*)&s); + } else { + sm->unsubscribeRsrc((Subscriber*)&s); + } +} +inline void LocEngReqRelBIT::locallog() const { + LOC_LOGV("LocEngRequestBIT - ipv4: %d.%d.%d.%d, ipv6: %s", + (unsigned char)mIPv4Addr, + (unsigned char)(mIPv4Addr>>8), + (unsigned char)(mIPv4Addr>>16), + (unsigned char)(mIPv4Addr>>24), + NULL != mIPv6Addr ? mIPv6Addr : ""); +} +inline void LocEngReqRelBIT::log() const { + locallog(); +} +void LocEngReqRelBIT::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_RELEASE_BIT: +struct LocEngReleaseBIT : public LocMsg { + const BITSubscriber mSubscriber; + inline LocEngReleaseBIT(const AgpsStateMachine* stateMachine, + unsigned int ipv4, char* ipv6) : + LocMsg(), + mSubscriber(stateMachine, ipv4, ipv6) + { + locallog(); + } + inline virtual void proc() const + { + AgpsStateMachine* sm = (AgpsStateMachine*)mSubscriber.mStateMachine; + sm->unsubscribeRsrc((Subscriber*)&mSubscriber); + } + inline void locallog() const { + LOC_LOGV("LocEngReleaseBIT - ipv4: %d.%d.%d.%d, ipv6: %s", + (unsigned char)(mSubscriber.ID>>24), + (unsigned char)(mSubscriber.ID>>16), + (unsigned char)(mSubscriber.ID>>8), + (unsigned char)mSubscriber.ID, + NULL != mSubscriber.mIPv6Addr ? mSubscriber.mIPv6Addr : ""); + } + virtual void log() const { + locallog(); + } +}; + +// LocEngSuplEsOpened +LocEngSuplEsOpened::LocEngSuplEsOpened(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +void LocEngSuplEsOpened::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + if (locEng->ds_nif) { + AgpsStateMachine* sm = locEng->ds_nif; + sm->onRsrcEvent(RSRC_GRANTED); + } +} +void LocEngSuplEsOpened::locallog() const { + LOC_LOGV("LocEngSuplEsOpened"); +} +void LocEngSuplEsOpened::log() const { + locallog(); +} + +// LocEngSuplEsClosed +LocEngSuplEsClosed::LocEngSuplEsClosed(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +void LocEngSuplEsClosed::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + if (locEng->ds_nif) { + AgpsStateMachine* sm = locEng->ds_nif; + sm->onRsrcEvent(RSRC_RELEASED); + } +} +void LocEngSuplEsClosed::locallog() const { + LOC_LOGV("LocEngSuplEsClosed"); +} +void LocEngSuplEsClosed::log() const { + locallog(); +} + + +// case LOC_ENG_MSG_REQUEST_SUPL_ES: +LocEngRequestSuplEs::LocEngRequestSuplEs(void* locEng, int id) : + LocMsg(), mLocEng(locEng), mID(id) { + locallog(); +} +void LocEngRequestSuplEs::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + if (locEng->ds_nif) { + AgpsStateMachine* sm = locEng->ds_nif; + DSSubscriber s(sm, mID); + sm->subscribeRsrc((Subscriber*)&s); + } + else if (locEng->agnss_nif) { + AgpsStateMachine *sm = locEng->agnss_nif; + ATLSubscriber s(mID, + sm, + locEng->adapter, + false); + sm->subscribeRsrc((Subscriber*)&s); + LOC_LOGD("%s:%d]: Using regular ATL for SUPL ES", __func__, __LINE__); + } + else { + locEng->adapter->atlOpenStatus(mID, 0, NULL, -1, -1); + } +} +inline void LocEngRequestSuplEs::locallog() const { + LOC_LOGV("LocEngRequestSuplEs"); +} +inline void LocEngRequestSuplEs::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_ATL: +LocEngRequestATL::LocEngRequestATL(void* locEng, int id, + AGpsExtType agps_type) : + LocMsg(), mLocEng(locEng), mID(id), mType(agps_type) { + locallog(); +} +void LocEngRequestATL::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + AgpsStateMachine* sm = (AgpsStateMachine*) + getAgpsStateMachine(*locEng, mType); + if (sm) { + ATLSubscriber s(mID, + sm, + locEng->adapter, + AGPS_TYPE_INVALID == mType); + sm->subscribeRsrc((Subscriber*)&s); + } else { + locEng->adapter->atlOpenStatus(mID, 0, NULL, -1, mType); + } +} +inline void LocEngRequestATL::locallog() const { + LOC_LOGV("LocEngRequestATL"); +} +inline void LocEngRequestATL::log() const { + locallog(); +} + +// case LOC_ENG_MSG_RELEASE_ATL: +LocEngReleaseATL::LocEngReleaseATL(void* locEng, int id) : + LocMsg(), mLocEng(locEng), mID(id) { + locallog(); +} +void LocEngReleaseATL::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + + if (locEng->agnss_nif) { + ATLSubscriber s1(mID, locEng->agnss_nif, locEng->adapter, false); + if (locEng->agnss_nif->unsubscribeRsrc((Subscriber*)&s1)) { + LOC_LOGD("%s:%d]: Unsubscribed from agnss_nif", + __func__, __LINE__); + return; + } + } + + if (locEng->internet_nif) { + ATLSubscriber s2(mID, locEng->internet_nif, locEng->adapter, false); + if (locEng->internet_nif->unsubscribeRsrc((Subscriber*)&s2)) { + LOC_LOGD("%s:%d]: Unsubscribed from internet_nif", + __func__, __LINE__); + return; + } + } + + if (locEng->ds_nif) { + DSSubscriber s3(locEng->ds_nif, mID); + if (locEng->ds_nif->unsubscribeRsrc((Subscriber*)&s3)) { + LOC_LOGD("%s:%d]: Unsubscribed from ds_nif", + __func__, __LINE__); + return; + } + } + + LOC_LOGW("%s:%d]: Could not release ATL. " + "No subscribers found\n", + __func__, __LINE__); + locEng->adapter->atlCloseStatus(mID, 0); +} +inline void LocEngReleaseATL::locallog() const { + LOC_LOGV("LocEngReleaseATL"); +} +inline void LocEngReleaseATL::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_WIFI: +// case LOC_ENG_MSG_RELEASE_WIFI: +LocEngReqRelWifi::LocEngReqRelWifi(void* locEng, AGpsExtType type, + loc_if_req_sender_id_e_type sender_id, + char* s, char* p, bool isReq) : + LocMsg(), mLocEng(locEng), mType(type), mSenderId(sender_id), + mSSID(NULL == s ? NULL : new char[SSID_BUF_SIZE]), + mPassword(NULL == p ? NULL : new char[SSID_BUF_SIZE]), + mIsReq(isReq) { + if (NULL != s) + strlcpy(mSSID, s, SSID_BUF_SIZE); + if (NULL != p) + strlcpy(mPassword, p, SSID_BUF_SIZE); + locallog(); +} +LocEngReqRelWifi::~LocEngReqRelWifi() { + if (NULL != mSSID) { + delete[] mSSID; + } + if (NULL != mPassword) { + delete[] mPassword; + } +} +void LocEngReqRelWifi::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + if (locEng->wifi_nif) { + WIFISubscriber s(locEng->wifi_nif, mSSID, mPassword, mSenderId); + if (mIsReq) { + locEng->wifi_nif->subscribeRsrc((Subscriber*)&s); + } else { + locEng->wifi_nif->unsubscribeRsrc((Subscriber*)&s); + } + } else { + locEng->adapter->atlOpenStatus(mSenderId, 0, NULL, -1, mType); + } +} +inline void LocEngReqRelWifi::locallog() const { + LOC_LOGV("%s - senderId: %d, ssid: %s, password: %s", + mIsReq ? "LocEngRequestWifi" : "LocEngReleaseWifi", + mSenderId, + NULL != mSSID ? mSSID : "", + NULL != mPassword ? mPassword : ""); +} +inline void LocEngReqRelWifi::log() const { + locallog(); +} +void LocEngReqRelWifi::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_REQUEST_XTRA_DATA: +LocEngRequestXtra::LocEngRequestXtra(void* locEng) : + mLocEng(locEng) { + locallog(); +} +void LocEngRequestXtra::proc() const +{ + loc_eng_xtra_data_s_type* locEngXtra = + &(((loc_eng_data_s_type*)mLocEng)->xtra_module_data); + + if (locEngXtra->download_request_cb != NULL) { + CALLBACK_LOG_CALLFLOW("download_request_cb", %p, mLocEng); + locEngXtra->download_request_cb(); + } else { + LOC_LOGE("Callback function for request xtra is NULL"); + } +} +inline void LocEngRequestXtra::locallog() const { + LOC_LOGV("LocEngReqXtra"); +} +inline void LocEngRequestXtra::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_TIME: +LocEngRequestTime::LocEngRequestTime(void* locEng) : + LocMsg(), mLocEng(locEng) +{ + locallog(); +} +void LocEngRequestTime::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + if (gps_conf.CAPABILITIES & GPS_CAPABILITY_ON_DEMAND_TIME) { + if (locEng->request_utc_time_cb != NULL) { + locEng->request_utc_time_cb(); + } else { + LOC_LOGE("Callback function for request time is NULL"); + } + } +} +inline void LocEngRequestTime::locallog() const { + LOC_LOGV("LocEngReqTime"); +} +inline void LocEngRequestTime::log() const { + locallog(); +} + +// case LOC_ENG_MSG_DELETE_AIDING_DATA: +struct LocEngDelAidData : public LocMsg { + loc_eng_data_s_type* mLocEng; + const GpsAidingData mType; + inline LocEngDelAidData(loc_eng_data_s_type* locEng, + GpsAidingData f) : + LocMsg(), mLocEng(locEng), mType(f) + { + locallog(); + } + inline virtual void proc() const { + mLocEng->aiding_data_for_deletion = mType; + update_aiding_data_for_deletion(*mLocEng); + } + inline void locallog() const { + LOC_LOGV("aiding data msak %d", mType); + } + virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ENABLE_DATA: +struct LocEngEnableData : public LocMsg { + LocEngAdapter* mAdapter; + const int mEnable; + char* mAPN; + const int mLen; + inline LocEngEnableData(LocEngAdapter* adapter, + const char* name, int len, int enable) : + LocMsg(), mAdapter(adapter), + mEnable(enable), mAPN(NULL), mLen(len) + { + if (NULL != name) { + mAPN = new char[len+1]; + memcpy((void*)mAPN, (void*)name, len); + mAPN[len] = 0; + } + locallog(); + } + inline ~LocEngEnableData() { + if (NULL != mAPN) { + delete[] mAPN; + } + } + inline virtual void proc() const { + mAdapter->enableData(mEnable); + if (NULL != mAPN) { + mAdapter->setAPN(mAPN, mLen); + } + } + inline void locallog() const { + LOC_LOGV("apn: %s\n enable: %d", + (NULL == mAPN) ? "NULL" : mAPN, mEnable); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_INJECT_XTRA_DATA: +// loc_eng_xtra.cpp + +// case LOC_ENG_MSG_SET_CAPABILITIES: +struct LocEngSetCapabilities : public LocMsg { + loc_eng_data_s_type* mLocEng; + inline LocEngSetCapabilities(loc_eng_data_s_type* locEng) : + LocMsg(), mLocEng(locEng) + { + locallog(); + } + inline virtual void proc() const { + if (NULL != mLocEng->set_capabilities_cb) { + LOC_LOGV("calling set_capabilities_cb 0x%x", + gps_conf.CAPABILITIES); + mLocEng->set_capabilities_cb(gps_conf.CAPABILITIES); + } else { + LOC_LOGV("set_capabilities_cb is NULL.\n"); + } + } + inline void locallog() const + { + LOC_LOGV("LocEngSetCapabilities"); + } + inline virtual void log() const + { + locallog(); + } +}; + +// case LOC_ENG_MSG_LOC_INIT: +struct LocEngInit : public LocMsg { + loc_eng_data_s_type* mLocEng; + inline LocEngInit(loc_eng_data_s_type* locEng) : + LocMsg(), mLocEng(locEng) + { + locallog(); + } + inline virtual void proc() const { + loc_eng_reinit(*mLocEng); + mLocEng->adapter->setGpsLock(1); + // set the capabilities + mLocEng->adapter->sendMsg(new LocEngSetCapabilities(mLocEng)); + } + inline void locallog() const + { + LOC_LOGV("LocEngInit"); + } + inline virtual void log() const + { + locallog(); + } +}; + +// case LOC_ENG_MSG_REQUEST_XTRA_SERVER: +// loc_eng_xtra.cpp + +// case LOC_ENG_MSG_ATL_OPEN_SUCCESS: +struct LocEngAtlOpenSuccess : public LocMsg { + AgpsStateMachine* mStateMachine; + const int mLen; + char* mAPN; + const AGpsBearerType mBearerType; + inline LocEngAtlOpenSuccess(AgpsStateMachine* statemachine, + const char* name, + int len, + AGpsBearerType btype) : + LocMsg(), + mStateMachine(statemachine), mLen(len), + mAPN(new char[len+1]), mBearerType(btype) + { + memcpy((void*)mAPN, (void*)name, len); + mAPN[len] = 0; + locallog(); + } + inline ~LocEngAtlOpenSuccess() + { + delete[] mAPN; + } + inline virtual void proc() const { + mStateMachine->setBearer(mBearerType); + mStateMachine->setAPN(mAPN, mLen); + mStateMachine->onRsrcEvent(RSRC_GRANTED); + } + inline void locallog() const { + LOC_LOGV("LocEngAtlOpenSuccess agps type: %s\n apn: %s\n" + " bearer type: %s", + loc_get_agps_type_name(mStateMachine->getType()), + mAPN, + loc_get_agps_bear_name(mBearerType)); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ATL_CLOSED: +struct LocEngAtlClosed : public LocMsg { + AgpsStateMachine* mStateMachine; + inline LocEngAtlClosed(AgpsStateMachine* statemachine) : + LocMsg(), mStateMachine(statemachine) { + locallog(); + } + inline virtual void proc() const { + mStateMachine->onRsrcEvent(RSRC_RELEASED); + } + inline void locallog() const { + LOC_LOGV("LocEngAtlClosed"); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ATL_OPEN_FAILED: +struct LocEngAtlOpenFailed : public LocMsg { + AgpsStateMachine* mStateMachine; + inline LocEngAtlOpenFailed(AgpsStateMachine* statemachine) : + LocMsg(), mStateMachine(statemachine) { + locallog(); + } + inline virtual void proc() const { + mStateMachine->onRsrcEvent(RSRC_DENIED); + } + inline void locallog() const { + LOC_LOGV("LocEngAtlOpenFailed"); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ENGINE_DOWN: +LocEngDown::LocEngDown(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +inline void LocEngDown::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + loc_eng_handle_engine_down(*locEng); +} +inline void LocEngDown::locallog() const { + LOC_LOGV("LocEngDown"); +} +inline void LocEngDown::log() const { + locallog(); +} + +// case LOC_ENG_MSG_ENGINE_UP: +LocEngUp::LocEngUp(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +inline void LocEngUp::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + loc_eng_handle_engine_up(*locEng); +} +inline void LocEngUp::locallog() const { + LOC_LOGV("LocEngUp"); +} +inline void LocEngUp::log() const { + locallog(); +} + +struct LocEngDataClientInit : public LocMsg { + loc_eng_data_s_type* mLocEng; + inline LocEngDataClientInit(loc_eng_data_s_type* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); + } + virtual void proc() const { + loc_eng_data_s_type *locEng = (loc_eng_data_s_type *)mLocEng; + if(!locEng->adapter->initDataServiceClient()) { + locEng->ds_nif = new DSStateMachine(servicerTypeExt, + (void *)dataCallCb, + locEng->adapter); + } + } + void locallog() const { + LOC_LOGV("LocEngDataClientInit\n"); + } + virtual void log() const { + locallog(); + } +}; + +struct LocEngInstallAGpsCert : public LocMsg { + LocEngAdapter* mpAdapter; + const size_t mNumberOfCerts; + const uint32_t mSlotBitMask; + DerEncodedCertificate* mpData; + inline LocEngInstallAGpsCert(LocEngAdapter* adapter, + const DerEncodedCertificate* pData, + size_t numberOfCerts, + uint32_t slotBitMask) : + LocMsg(), mpAdapter(adapter), + mNumberOfCerts(numberOfCerts), mSlotBitMask(slotBitMask), + mpData(new DerEncodedCertificate[mNumberOfCerts]) + { + for (int i=0; i < mNumberOfCerts; i++) { + mpData[i].data = new u_char[pData[i].length]; + if (mpData[i].data) { + memcpy(mpData[i].data, (void*)pData[i].data, pData[i].length); + mpData[i].length = pData[i].length; + } else { + LOC_LOGE("malloc failed for cert#%d", i); + break; + } + } + locallog(); + } + inline ~LocEngInstallAGpsCert() + { + for (int i=0; i < mNumberOfCerts; i++) { + if (mpData[i].data) { + delete[] mpData[i].data; + } + } + delete[] mpData; + } + inline virtual void proc() const { + mpAdapter->installAGpsCert(mpData, mNumberOfCerts, mSlotBitMask); + } + inline void locallog() const { + LOC_LOGV("LocEngInstallAGpsCert - certs=%u mask=%u", + mNumberOfCerts, mSlotBitMask); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocEngUpdateRegistrationMask : public LocMsg { + loc_eng_data_s_type* mLocEng; + LOC_API_ADAPTER_EVENT_MASK_T mMask; + loc_registration_mask_status mIsEnabled; + inline LocEngUpdateRegistrationMask(loc_eng_data_s_type* locEng, + LOC_API_ADAPTER_EVENT_MASK_T mask, + loc_registration_mask_status isEnabled) : + LocMsg(), mLocEng(locEng), mMask(mask), mIsEnabled(isEnabled) { + locallog(); + } + inline virtual void proc() const { + loc_eng_data_s_type *locEng = (loc_eng_data_s_type *)mLocEng; + locEng->adapter->updateRegistrationMask(mMask, + mIsEnabled); + } + void locallog() const { + LOC_LOGV("LocEngUpdateRegistrationMask\n"); + } + virtual void log() const { + locallog(); + } +}; + +struct LocEngGnssConstellationConfig : public LocMsg { + LocEngAdapter* mAdapter; + inline LocEngGnssConstellationConfig(LocEngAdapter* adapter) : + LocMsg(), mAdapter(adapter) { + locallog(); + } + inline virtual void proc() const { + if (mAdapter->gnssConstellationConfig()) { + LOC_LOGV("Modem supports GNSS measurements\n"); + gps_conf.CAPABILITIES |= GPS_CAPABILITY_MEASUREMENTS; + } else { + LOC_LOGV("Modem does not support GNSS measurements\n"); + } + } + void locallog() const { + LOC_LOGV("LocEngGnssConstellationConfig\n"); + } + virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_REPORT_GNSS_MEASUREMENT: +LocEngReportGpsMeasurement::LocEngReportGpsMeasurement(void* locEng, + GpsData &gpsData) : + LocMsg(), mLocEng(locEng), mGpsData(gpsData) +{ + locallog(); +} +void LocEngReportGpsMeasurement::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng; + if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION) + { + if (locEng->gps_measurement_cb != NULL) { + locEng->gps_measurement_cb((GpsData*)&(mGpsData)); + } + } +} +void LocEngReportGpsMeasurement::locallog() const { + IF_LOC_LOGV { + LOC_LOGV("%s:%d]: Received in GPS HAL." + "GNSS Measurements count: %d \n", + __func__, __LINE__, mGpsData.measurement_count); + for (int i =0; i< mGpsData.measurement_count && i < GPS_MAX_SVS; i++) { + LOC_LOGV(" GNSS measurement data in GPS HAL: \n" + " GPS_HAL => Measurement ID | prn | time_offset_ns | state |" + " received_gps_tow_ns| c_n0_dbhz | pseudorange_rate_mps |" + " pseudorange_rate_uncertainty_mps |" + " accumulated_delta_range_state | flags \n" + " GPS_HAL => %d | %d | %f | %d | %lld | %f | %f | %f | %d | %d \n", + i, + mGpsData.measurements[i].prn, + mGpsData.measurements[i].time_offset_ns, + mGpsData.measurements[i].state, + mGpsData.measurements[i].received_gps_tow_ns, + mGpsData.measurements[i].c_n0_dbhz, + mGpsData.measurements[i].pseudorange_rate_mps, + mGpsData.measurements[i].pseudorange_rate_uncertainty_mps, + mGpsData.measurements[i].accumulated_delta_range_state, + mGpsData.measurements[i].flags); + } + LOC_LOGV(" GPS_HAL => Clocks Info: type | time_ns \n" + " GPS_HAL => Clocks Info: %d | %lld", mGpsData.clock.type, + mGpsData.clock.time_ns); + } +} +inline void LocEngReportGpsMeasurement::log() const { + locallog(); +} + +/********************************************************************* + * Initialization checking macros + *********************************************************************/ +#define STATE_CHECK(ctx, x, ret) \ + if (!(ctx)) \ + { \ + /* Not intialized, abort */\ + LOC_LOGE("%s: log_eng state error: %s", __func__, x); \ + EXIT_LOG(%s, x); \ + ret; \ + } +#define INIT_CHECK(ctx, ret) STATE_CHECK(ctx, "instance not initialized", ret) + +uint32_t getCarrierCapabilities() { + #define carrierMSA (uint32_t)0x2 + #define carrierMSB (uint32_t)0x1 + #define gpsConfMSA (uint32_t)0x4 + #define gpsConfMSB (uint32_t)0x2 + uint32_t capabilities = gps_conf.CAPABILITIES; + if ((gps_conf.SUPL_MODE & carrierMSA) != carrierMSA) { + capabilities &= ~gpsConfMSA; + } + if ((gps_conf.SUPL_MODE & carrierMSB) != carrierMSB) { + capabilities &= ~gpsConfMSB; + } + + LOC_LOGV("getCarrierCapabilities: CAPABILITIES %x, SUPL_MODE %x, carrier capabilities %x", + gps_conf.CAPABILITIES, gps_conf.SUPL_MODE, capabilities); + return capabilities; +} + +/*=========================================================================== +FUNCTION loc_eng_init + +DESCRIPTION + Initialize the location engine, this include setting up global datas + and registers location engien with loc api service. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks, + LOC_API_ADAPTER_EVENT_MASK_T event, ContextBase* context) + +{ + int ret_val = 0; + + ENTRY_LOG_CALLFLOW(); + if (NULL == callbacks || 0 == event) { + LOC_LOGE("loc_eng_init: bad parameters cb %p eMask %d", callbacks, event); + ret_val = -1; + EXIT_LOG(%d, ret_val); + return ret_val; + } + + STATE_CHECK((NULL == loc_eng_data.adapter), + "instance already initialized", return 0); + + memset(&loc_eng_data, 0, sizeof (loc_eng_data)); + + // Save callbacks + loc_eng_data.location_cb = callbacks->location_cb; + loc_eng_data.sv_status_cb = callbacks->sv_status_cb; + loc_eng_data.status_cb = callbacks->status_cb; + loc_eng_data.nmea_cb = callbacks->nmea_cb; + loc_eng_data.set_capabilities_cb = callbacks->set_capabilities_cb; + loc_eng_data.acquire_wakelock_cb = callbacks->acquire_wakelock_cb; + loc_eng_data.release_wakelock_cb = callbacks->release_wakelock_cb; + loc_eng_data.request_utc_time_cb = callbacks->request_utc_time_cb; + loc_eng_data.location_ext_parser = callbacks->location_ext_parser ? + callbacks->location_ext_parser : noProc; + loc_eng_data.sv_ext_parser = callbacks->sv_ext_parser ? + callbacks->sv_ext_parser : noProc; + loc_eng_data.intermediateFix = gps_conf.INTERMEDIATE_POS; + // initial states taken care of by the memset above + // loc_eng_data.engine_status -- GPS_STATUS_NONE; + // loc_eng_data.fix_session_status -- GPS_STATUS_NONE; + // loc_eng_data.mute_session_state -- LOC_MUTE_SESS_NONE; + + if ((event & LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT) && (gps_conf.NMEA_PROVIDER == NMEA_PROVIDER_AP)) + { + event = event ^ LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT; // unregister for modem NMEA report + loc_eng_data.generateNmea = true; + } + else + { + loc_eng_data.generateNmea = false; + } + + loc_eng_data.adapter = + new LocEngAdapter(event, &loc_eng_data, context, + (LocThread::tCreate)callbacks->create_thread_cb); + + LOC_LOGD("loc_eng_init created client, id = %p\n", + loc_eng_data.adapter); + loc_eng_data.adapter->sendMsg(new LocEngInit(&loc_eng_data)); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; + LocEngAdapter* adapter = loc_eng_data.adapter; + + adapter->sendMsg(new LocEngGnssConstellationConfig(adapter)); + adapter->sendMsg(new LocEngSuplVer(adapter, gps_conf.SUPL_VER)); + adapter->sendMsg(new LocEngLppConfig(adapter, gps_conf.LPP_PROFILE)); + adapter->sendMsg(new LocEngSensorControlConfig(adapter, sap_conf.SENSOR_USAGE, + sap_conf.SENSOR_PROVIDER)); + adapter->sendMsg(new LocEngAGlonassProtocol(adapter, gps_conf.A_GLONASS_POS_PROTOCOL_SELECT)); + + /* Make sure at least one of the sensor property is specified by the user in the gps.conf file. */ + if( sap_conf.GYRO_BIAS_RANDOM_WALK_VALID || + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID || + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID || + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID || + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID ) { + adapter->sendMsg(new LocEngSensorProperties(adapter, + sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, + sap_conf.GYRO_BIAS_RANDOM_WALK, + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY)); + } + + adapter->sendMsg(new LocEngSensorPerfControlConfig(adapter, + sap_conf.SENSOR_CONTROL_MODE, + sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, + sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, + sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, + sap_conf.SENSOR_GYRO_BATCHES_PER_SEC, + sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, + sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, + sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, + sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, + sap_conf.SENSOR_ALGORITHM_CONFIG_MASK)); + + adapter->sendMsg(new LocEngEnableData(adapter, NULL, 0, (agpsStatus ? 1:0))); + + loc_eng_xtra_version_check(loc_eng_data, gps_conf.XTRA_VERSION_CHECK); + + LOC_LOGD("loc_eng_reinit reinit() successful"); + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_eng_cleanup + +DESCRIPTION + Cleans location engine. The location client handle will be released. + +DEPENDENCIES + None + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return); + + // XTRA has no state, so we are fine with it. + + // we need to check and clear NI +#if 0 + // we need to check and clear ATL + if (NULL != loc_eng_data.agnss_nif) { + delete loc_eng_data.agnss_nif; + loc_eng_data.agnss_nif = NULL; + } + if (NULL != loc_eng_data.internet_nif) { + delete loc_eng_data.internet_nif; + loc_eng_data.internet_nif = NULL; + } +#endif + if (loc_eng_data.adapter->isInSession()) + { + LOC_LOGD("loc_eng_cleanup: fix not stopped. stop it now."); + loc_eng_stop(loc_eng_data); + } + +#if 0 // can't afford to actually clean up, for many reason. + + LOC_LOGD("loc_eng_init: client opened. close it now."); + delete loc_eng_data.adapter; + loc_eng_data.adapter = NULL; + + loc_eng_dmn_conn_loc_api_server_unblock(); + loc_eng_dmn_conn_loc_api_server_join(); + +#endif + + EXIT_LOG(%s, VOID_RET); +} + + +/*=========================================================================== +FUNCTION loc_eng_start + +DESCRIPTION + Starts the tracking session + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_start(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return -1); + + if(! loc_eng_data.adapter->getUlpProxy()->sendStartFix()) + { + loc_eng_data.adapter->sendMsg(new LocEngStartFix(loc_eng_data.adapter)); + } + + EXIT_LOG(%d, 0); + return 0; +} + +static int loc_eng_start_handler(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; + + if (!loc_eng_data.adapter->isInSession()) { + ret_val = loc_eng_data.adapter->startFix(); + + if (ret_val == LOC_API_ADAPTER_ERR_SUCCESS || + ret_val == LOC_API_ADAPTER_ERR_ENGINE_DOWN || + ret_val == LOC_API_ADAPTER_ERR_PHONE_OFFLINE || + ret_val == LOC_API_ADAPTER_ERR_INTERNAL) + { + loc_eng_data.adapter->setInSession(TRUE); + } + } + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_eng_stop_wrapper + +DESCRIPTION + Stops the tracking session + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_stop(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return -1); + + if(! loc_eng_data.adapter->getUlpProxy()->sendStopFix()) + { + loc_eng_data.adapter->sendMsg(new LocEngStopFix(loc_eng_data.adapter)); + } + + EXIT_LOG(%d, 0); + return 0; +} + +static int loc_eng_stop_handler(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; + + if (loc_eng_data.adapter->isInSession()) { + + ret_val = loc_eng_data.adapter->stopFix(); + loc_eng_data.adapter->setInSession(FALSE); + } + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_eng_mute_one_session + +DESCRIPTION + Mutes one session + +DEPENDENCIES + None + +RETURN VALUE + 0: Success + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_mute_one_session(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + loc_eng_data.mute_session_state = LOC_MUTE_SESS_WAIT; + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_eng_set_position_mode + +DESCRIPTION + Sets the mode and fix frequency for the tracking session. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data, + LocPosMode ¶ms) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return -1); + + // The position mode for AUTO/GSS/QCA1530 can only be standalone + if (!(gps_conf.CAPABILITIES & GPS_CAPABILITY_MSB) && + !(gps_conf.CAPABILITIES & GPS_CAPABILITY_MSA) && + (params.mode != LOC_POSITION_MODE_STANDALONE)) { + params.mode = LOC_POSITION_MODE_STANDALONE; + LOC_LOGD("Position mode changed to standalone for target with AUTO/GSS/qca1530."); + } + + if(! loc_eng_data.adapter->getUlpProxy()->sendFixMode(params)) + { + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngPositionMode(adapter, params)); + } + + EXIT_LOG(%d, 0); + return 0; +} + +/*=========================================================================== +FUNCTION loc_eng_inject_time + +DESCRIPTION + This is used by Java native function to do time injection. + +DEPENDENCIES + None + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data, GpsUtcTime time, + int64_t timeReference, int uncertainty) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return -1); + LocEngAdapter* adapter = loc_eng_data.adapter; + + adapter->sendMsg(new LocEngSetTime(adapter, time, timeReference, + uncertainty)); + + EXIT_LOG(%d, 0); + return 0; +} + + +/*=========================================================================== +FUNCTION loc_eng_inject_location + +DESCRIPTION + This is used by Java native function to do location injection. + +DEPENDENCIES + None + +RETURN VALUE + 0 : Successful + error code : Failure + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data, double latitude, + double longitude, float accuracy) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return -1); + LocEngAdapter* adapter = loc_eng_data.adapter; + if(adapter->mSupportsPositionInjection) + { + adapter->sendMsg(new LocEngInjectLocation(adapter, latitude, longitude, + accuracy)); + } + + EXIT_LOG(%d, 0); + return 0; +} + + +/*=========================================================================== +FUNCTION loc_eng_delete_aiding_data + +DESCRIPTION + This is used by Java native function to delete the aiding data. The function + updates the global variable for the aiding data to be deleted. If the GPS + engine is off, the aiding data will be deleted. Otherwise, the actual action + will happen when gps engine is turned off. + +DEPENDENCIES + Assumes the aiding data type specified in GpsAidingData matches with + LOC API specification. + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data, GpsAidingData f) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return); + + loc_eng_data.adapter->sendMsg(new LocEngDelAidData(&loc_eng_data, f)); + + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== + +FUNCTION loc_inform_gps_state + +DESCRIPTION + Informs the GPS Provider about the GPS status + +DEPENDENCIES + None + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_inform_gps_status(loc_eng_data_s_type &loc_eng_data, GpsStatusValue status) +{ + ENTRY_LOG(); + + if (loc_eng_data.status_cb) + { + GpsStatus gs = { sizeof(gs),status }; + CALLBACK_LOG_CALLFLOW("status_cb", %s, + loc_get_gps_status_name(gs.status)); + loc_eng_data.status_cb(&gs); + } + + EXIT_LOG(%s, VOID_RET); +} + +static int loc_eng_get_zpp_handler(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; + UlpLocation location; + LocPosTechMask tech_mask = LOC_POS_TECH_MASK_DEFAULT; + GpsLocationExtended locationExtended; + memset(&locationExtended, 0, sizeof (GpsLocationExtended)); + locationExtended.size = sizeof(locationExtended); + + ret_val = loc_eng_data.adapter->getZpp(location.gpsLocation, tech_mask); + //Mark the location source as from ZPP + location.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO; + location.position_source = ULP_LOCATION_IS_FROM_ZPP; + + loc_eng_data.adapter->getUlpProxy()->reportPosition(location, + locationExtended, + NULL, + LOC_SESS_SUCCESS, + tech_mask); + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/* + Callback function passed to Data Services State Machine + This becomes part of the state machine's servicer and + is used to send requests to the data services client +*/ +static int dataCallCb(void *cb_data) +{ + LOC_LOGD("Enter dataCallCb\n"); + int ret=0; + if(cb_data != NULL) { + dsCbData *cbData = (dsCbData *)cb_data; + LocEngAdapter *locAdapter = (LocEngAdapter *)cbData->mAdapter; + if(cbData->action == GPS_REQUEST_AGPS_DATA_CONN) { + LOC_LOGD("dataCallCb GPS_REQUEST_AGPS_DATA_CONN\n"); + ret = locAdapter->openAndStartDataCall(); + } + else if(cbData->action == GPS_RELEASE_AGPS_DATA_CONN) { + LOC_LOGD("dataCallCb GPS_RELEASE_AGPS_DATA_CONN\n"); + locAdapter->stopDataCall(); + } + } + else { + LOC_LOGE("NULL argument received. Failing.\n"); + ret = -1; + goto err; + } + +err: + LOC_LOGD("Exit dataCallCb ret = %d\n", ret); + return ret; +} + +/*=========================================================================== +FUNCTION loc_eng_agps_reinit + +DESCRIPTION + 2nd half of loc_eng_agps_init(), singled out for modem restart to use. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_eng_agps_reinit(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + + // Set server addresses which came before init + if (loc_eng_data.supl_host_set) + { + loc_eng_set_server(loc_eng_data, LOC_AGPS_SUPL_SERVER, + loc_eng_data.supl_host_buf, + loc_eng_data.supl_port_buf); + } + + if (loc_eng_data.c2k_host_set) + { + loc_eng_set_server(loc_eng_data, LOC_AGPS_CDMA_PDE_SERVER, + loc_eng_data.c2k_host_buf, + loc_eng_data.c2k_port_buf); + } + EXIT_LOG(%s, VOID_RET); +} +/*=========================================================================== +FUNCTION loc_eng_agps_init + +DESCRIPTION + Initialize the AGps interface. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* callbacks) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter, return); + STATE_CHECK((NULL == loc_eng_data.agps_status_cb), + "agps instance already initialized", + return); + if (callbacks == NULL) { + LOC_LOGE("loc_eng_agps_init: bad parameters cb %p", callbacks); + EXIT_LOG(%s, VOID_RET); + return; + } + LocEngAdapter* adapter = loc_eng_data.adapter; + loc_eng_data.agps_status_cb = callbacks->status_cb; + + loc_eng_data.internet_nif = new AgpsStateMachine(servicerTypeAgps, + (void *)loc_eng_data.agps_status_cb, + AGPS_TYPE_WWAN_ANY, + false); + loc_eng_data.wifi_nif = new AgpsStateMachine(servicerTypeAgps, + (void *)loc_eng_data.agps_status_cb, + AGPS_TYPE_WIFI, + true); + + if ((gps_conf.CAPABILITIES & GPS_CAPABILITY_MSA) || + (gps_conf.CAPABILITIES & GPS_CAPABILITY_MSB)) { + loc_eng_data.agnss_nif = new AgpsStateMachine(servicerTypeAgps, + (void *)loc_eng_data.agps_status_cb, + AGPS_TYPE_SUPL, + false); + + if (adapter->mSupportsAgpsRequests) { + if(gps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) { + loc_eng_data.adapter->sendMsg(new LocEngDataClientInit(&loc_eng_data)); + } + loc_eng_dmn_conn_loc_api_server_launch(callbacks->create_thread_cb, + NULL, NULL, &loc_eng_data); + } + loc_eng_agps_reinit(loc_eng_data); + } + + EXIT_LOG(%s, VOID_RET); +} + +static void deleteAidingData(loc_eng_data_s_type &logEng) { + if (logEng.engine_status != GPS_STATUS_ENGINE_ON && + logEng.aiding_data_for_deletion != 0) { + logEng.adapter->deleteAidingData(logEng.aiding_data_for_deletion); + logEng.aiding_data_for_deletion = 0; + } +} + +static AgpsStateMachine* +getAgpsStateMachine(loc_eng_data_s_type &locEng, AGpsExtType agpsType) { + AgpsStateMachine* stateMachine; + switch (agpsType) { + case AGPS_TYPE_WIFI: { + stateMachine = locEng.wifi_nif; + break; + } + case AGPS_TYPE_INVALID: + case AGPS_TYPE_SUPL: { + stateMachine = locEng.agnss_nif; + break; + } + case AGPS_TYPE_SUPL_ES: { + locEng.ds_nif ? + stateMachine = locEng.ds_nif: + stateMachine = locEng.agnss_nif; + break; + } + default: + stateMachine = locEng.internet_nif; + } + return stateMachine; +} + +/*=========================================================================== +FUNCTION loc_eng_agps_open + +DESCRIPTION + This function is called when on-demand data connection opening is successful. +It should inform engine about the data open result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType, + const char* apn, AGpsBearerType bearerType) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb, + return -1); + + if (apn == NULL) + { + LOC_LOGE("APN Name NULL\n"); + return 0; + } + + LOC_LOGD("loc_eng_agps_open APN name = [%s]", apn); + + int apn_len = smaller_of(strlen (apn), MAX_APN_LEN); + AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType); + + loc_eng_data.adapter->sendMsg( + new LocEngAtlOpenSuccess(sm, apn, apn_len, bearerType)); + + EXIT_LOG(%d, 0); + return 0; +} + +/*=========================================================================== +FUNCTION loc_eng_agps_closed + +DESCRIPTION + This function is called when on-demand data connection closing is done. +It should inform engine about the data close result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb, + return -1); + + AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType); + loc_eng_data.adapter->sendMsg(new LocEngAtlClosed(sm)); + + EXIT_LOG(%d, 0); + return 0; +} + +/*=========================================================================== +FUNCTION loc_eng_agps_open_failed + +DESCRIPTION + This function is called when on-demand data connection opening has failed. +It should inform engine about the data open result. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType) +{ + ENTRY_LOG_CALLFLOW(); + INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb, + return -1); + + AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType); + loc_eng_data.adapter->sendMsg(new LocEngAtlOpenFailed(sm)); + + EXIT_LOG(%d, 0); + return 0; +} + +/*=========================================================================== + +FUNCTION resolve_in_addr + +DESCRIPTION + Translates a hostname to in_addr struct + +DEPENDENCIES + n/a + +RETURN VALUE + TRUE if successful + +SIDE EFFECTS + n/a + +===========================================================================*/ +static boolean resolve_in_addr(const char *host_addr, struct in_addr *in_addr_ptr) +{ + ENTRY_LOG(); + boolean ret_val = TRUE; + + struct hostent *hp; + hp = gethostbyname(host_addr); + if (hp != NULL) /* DNS OK */ + { + memcpy(in_addr_ptr, hp->h_addr_list[0], hp->h_length); + } + else + { + /* Try IP representation */ + if (inet_aton(host_addr, in_addr_ptr) == 0) + { + /* IP not valid */ + LOC_LOGE("DNS query on '%s' failed\n", host_addr); + ret_val = FALSE; + } + } + + EXIT_LOG(%s, loc_logger_boolStr[ret_val!=0]); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_eng_set_server + +DESCRIPTION + This is used to set the default AGPS server. Server address is obtained + from gps.conf. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_eng_set_server(loc_eng_data_s_type &loc_eng_data, + LocServerType type, const char* hostname, int port) +{ + ENTRY_LOG(); + int ret = 0; + LocEngAdapter* adapter = loc_eng_data.adapter; + + if (LOC_AGPS_SUPL_SERVER == type) { + char url[MAX_URL_LEN]; + unsigned int len = 0; + const char nohost[] = "NONE"; + if (hostname == NULL || + strncasecmp(nohost, hostname, sizeof(nohost)) == 0) { + url[0] = NULL; + } else { + len = snprintf(url, sizeof(url), "%s:%u", hostname, (unsigned) port); + } + + if (sizeof(url) > len) { + adapter->sendMsg(new LocEngSetServerUrl(adapter, url, len)); + } + } else if (LOC_AGPS_CDMA_PDE_SERVER == type || + LOC_AGPS_CUSTOM_PDE_SERVER == type || + LOC_AGPS_MPC_SERVER == type) { + struct in_addr addr; + if (!resolve_in_addr(hostname, &addr)) + { + LOC_LOGE("loc_eng_set_server, hostname %s cannot be resolved.\n", hostname); + ret = -2; + } else { + unsigned int ip = htonl(addr.s_addr); + adapter->sendMsg(new LocEngSetServerIpv4(adapter, ip, port, type)); + } + } else { + LOC_LOGE("loc_eng_set_server, type %d cannot be resolved.\n", type); + } + + EXIT_LOG(%d, ret); + return ret; +} + +/*=========================================================================== +FUNCTION loc_eng_set_server_proxy + +DESCRIPTION + If loc_eng_set_server is called before loc_eng_init, it doesn't work. This + proxy buffers server settings and calls loc_eng_set_server when the client is + open. + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data, + LocServerType type, + const char* hostname, int port) +{ + ENTRY_LOG_CALLFLOW(); + int ret_val = 0; + + LOC_LOGV("save the address, type: %d, hostname: %s, port: %d", + (int) type, hostname, port); + switch (type) + { + case LOC_AGPS_SUPL_SERVER: + strlcpy(loc_eng_data.supl_host_buf, hostname, + sizeof(loc_eng_data.supl_host_buf)); + loc_eng_data.supl_port_buf = port; + loc_eng_data.supl_host_set = 1; + break; + case LOC_AGPS_CDMA_PDE_SERVER: + strlcpy(loc_eng_data.c2k_host_buf, hostname, + sizeof(loc_eng_data.c2k_host_buf)); + loc_eng_data.c2k_port_buf = port; + loc_eng_data.c2k_host_set = 1; + break; + default: + LOC_LOGE("loc_eng_set_server_proxy, unknown server type = %d", (int) type); + } + + if (NULL != loc_eng_data.adapter) + { + ret_val = loc_eng_set_server(loc_eng_data, type, hostname, port); + } + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_eng_agps_ril_update_network_availability + +DESCRIPTION + Sets data call allow vs disallow flag to modem + This is the only member of sLocEngAGpsRilInterface implemented. + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data, + int available, const char* apn) +{ + ENTRY_LOG_CALLFLOW(); + + //This is to store the status of data availability over the network. + //If GPS is not enabled, the INIT_CHECK will fail and the modem will + //not be updated with the network's availability. Since the data status + //can change before GPS is enabled the, storing the status will enable + //us to inform the modem after GPS is enabled + agpsStatus = available; + + INIT_CHECK(loc_eng_data.adapter, return); + if (apn != NULL) + { + LOC_LOGD("loc_eng_agps_ril_update_network_availability: APN Name = [%s]\n", apn); + int apn_len = smaller_of(strlen (apn), MAX_APN_LEN); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngEnableData(adapter, apn, apn_len, available)); + } + EXIT_LOG(%s, VOID_RET); +} + +int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data, + const DerEncodedCertificate* certificates, + size_t numberOfCerts) +{ + ENTRY_LOG_CALLFLOW(); + int ret_val = AGPS_CERTIFICATE_OPERATION_SUCCESS; + + uint32_t slotBitMask = gps_conf.AGPS_CERT_WRITABLE_MASK; + uint32_t slotCount = 0; + for (uint32_t slotBitMaskCounter=slotBitMask; slotBitMaskCounter; slotCount++) { + slotBitMaskCounter &= slotBitMaskCounter - 1; + } + LOC_LOGD("SlotBitMask=%u SlotCount=%u NumberOfCerts=%u", + slotBitMask, slotCount, numberOfCerts); + + LocEngAdapter* adapter = loc_eng_data.adapter; + + if (numberOfCerts == 0) { + LOC_LOGE("No certs to install, since numberOfCerts is zero"); + ret_val = AGPS_CERTIFICATE_OPERATION_SUCCESS; + } else if (!adapter) { + LOC_LOGE("adapter is null!"); + ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; + } else if (slotCount < numberOfCerts) { + LOC_LOGE("Not enough cert slots (%u) to install %u certs!", + slotCount, numberOfCerts); + ret_val = AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES; + } else { + for (int i=0; i < numberOfCerts; ++i) + { + if (certificates[i].length > AGPS_CERTIFICATE_MAX_LENGTH) { + LOC_LOGE("cert#(%u) length of %u is too big! greater than %u", + certificates[i].length, AGPS_CERTIFICATE_MAX_LENGTH); + ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; + break; + } + } + + if (ret_val == AGPS_CERTIFICATE_OPERATION_SUCCESS) { + adapter->sendMsg(new LocEngInstallAGpsCert(adapter, + certificates, + numberOfCerts, + slotBitMask)); + } + } + + EXIT_LOG(%d, ret_val); + return ret_val; +} + +void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data, + const char* config_data, int32_t length) +{ + ENTRY_LOG_CALLFLOW(); + + if (config_data && length > 0) { + loc_gps_cfg_s_type gps_conf_tmp = gps_conf; + UTIL_UPDATE_CONF(config_data, length, gps_conf_table); + LocEngAdapter* adapter = loc_eng_data.adapter; + + // it is possible that HAL is not init'ed at this time + if (adapter) { + if (gps_conf_tmp.SUPL_VER != gps_conf.SUPL_VER) { + adapter->sendMsg(new LocEngSuplVer(adapter, gps_conf.SUPL_VER)); + } + if (gps_conf_tmp.LPP_PROFILE != gps_conf.LPP_PROFILE) { + adapter->sendMsg(new LocEngLppConfig(adapter, gps_conf.LPP_PROFILE)); + } + if (gps_conf_tmp.A_GLONASS_POS_PROTOCOL_SELECT != gps_conf.A_GLONASS_POS_PROTOCOL_SELECT) { + adapter->sendMsg(new LocEngAGlonassProtocol(adapter, + gps_conf.A_GLONASS_POS_PROTOCOL_SELECT)); + } + if (gps_conf_tmp.SUPL_MODE != gps_conf.SUPL_MODE) { + adapter->sendMsg(new LocEngSuplMode(adapter->getUlpProxy())); + } + } + + gps_conf_tmp.SUPL_VER = gps_conf.SUPL_VER; + gps_conf_tmp.LPP_PROFILE = gps_conf.LPP_PROFILE; + gps_conf_tmp.A_GLONASS_POS_PROTOCOL_SELECT = gps_conf.A_GLONASS_POS_PROTOCOL_SELECT; + gps_conf_tmp.GPS_LOCK = gps_conf.GPS_LOCK; + gps_conf = gps_conf_tmp; + } + + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_eng_report_status + +DESCRIPTION + Reports GPS engine state to Java layer. + +DEPENDENCIES + N/A + +RETURN VALUE + N/A + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_eng_report_status (loc_eng_data_s_type &loc_eng_data, GpsStatusValue status) +{ + ENTRY_LOG(); + // Switch from WAIT to MUTE, for "engine on" or "session begin" event + if (status == GPS_STATUS_SESSION_BEGIN || status == GPS_STATUS_ENGINE_ON) + { + if (loc_eng_data.mute_session_state == LOC_MUTE_SESS_WAIT) + { + LOC_LOGD("loc_eng_report_status: mute_session_state changed from WAIT to IN SESSION"); + loc_eng_data.mute_session_state = LOC_MUTE_SESS_IN_SESSION; + } + } + + // Switch off MUTE session + if (loc_eng_data.mute_session_state == LOC_MUTE_SESS_IN_SESSION && + (status == GPS_STATUS_SESSION_END || status == GPS_STATUS_ENGINE_OFF)) + { + LOC_LOGD("loc_eng_report_status: mute_session_state changed from IN SESSION to NONE"); + loc_eng_data.mute_session_state = LOC_MUTE_SESS_NONE; + } + + // Session End is not reported during Android navigating state + boolean navigating = loc_eng_data.adapter->isInSession(); + if (status != GPS_STATUS_NONE && + !(status == GPS_STATUS_SESSION_END && navigating) && + !(status == GPS_STATUS_SESSION_BEGIN && !navigating)) + { + if (loc_eng_data.mute_session_state != LOC_MUTE_SESS_IN_SESSION) + { + // Inform GpsLocationProvider about mNavigating status + loc_inform_gps_status(loc_eng_data, status); + } + else { + LOC_LOGD("loc_eng_report_status: muting the status report."); + } + } + + // Only keeps ENGINE ON/OFF in engine_status + if (status == GPS_STATUS_ENGINE_ON || status == GPS_STATUS_ENGINE_OFF) + { + loc_eng_data.engine_status = status; + } + + // Only keeps SESSION BEGIN/END in fix_session_status + if (status == GPS_STATUS_SESSION_BEGIN || status == GPS_STATUS_SESSION_END) + { + loc_eng_data.fix_session_status = status; + } + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_eng_handle_engine_down + loc_eng_handle_engine_up + +DESCRIPTION + Calls this function when it is detected that modem restart is happening. + Either we detected the modem is down or received modem up event. + This must be called from the deferred thread to avoid race condition. + +DEPENDENCIES + None + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_handle_engine_down(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + loc_eng_ni_reset_on_engine_restart(loc_eng_data); + loc_eng_report_status(loc_eng_data, GPS_STATUS_ENGINE_OFF); + EXIT_LOG(%s, VOID_RET); +} + +void loc_eng_handle_engine_up(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + loc_eng_reinit(loc_eng_data); + + loc_eng_data.adapter->requestPowerVote(); + + if (loc_eng_data.agps_status_cb != NULL) { + if (loc_eng_data.agnss_nif) + loc_eng_data.agnss_nif->dropAllSubscribers(); + if (loc_eng_data.internet_nif) + loc_eng_data.internet_nif->dropAllSubscribers(); + + loc_eng_agps_reinit(loc_eng_data); + } + + // modem is back up. If we crashed in the middle of navigating, we restart. + if (loc_eng_data.adapter->isInSession()) { + // This sets the copy in adapter to modem + loc_eng_data.adapter->setInSession(false); + loc_eng_data.adapter->sendMsg(new LocEngStartFix(loc_eng_data.adapter)); + } + EXIT_LOG(%s, VOID_RET); +} + +#ifdef USE_GLIB +/*=========================================================================== +FUNCTION set_sched_policy + +DESCRIPTION + Local copy of this function which bypasses android set_sched_policy + +DEPENDENCIES + None + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int set_sched_policy(int tid, SchedPolicy policy) +{ + return 0; +} +#endif /* USE_GLIB */ + +/*=========================================================================== +FUNCTION loc_eng_read_config + +DESCRIPTION + Initiates the reading of the gps config file stored in /etc dir + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_read_config(void) +{ + ENTRY_LOG_CALLFLOW(); + if(configAlreadyRead == false) + { + // Initialize our defaults before reading of configuration file overwrites them. + loc_default_parameters(); + // We only want to parse the conf file once. This is a good place to ensure that. + // In fact one day the conf file should go into context. + UTIL_READ_CONF(GPS_CONF_FILE, gps_conf_table); + UTIL_READ_CONF(SAP_CONF_FILE, sap_conf_table); + configAlreadyRead = true; + } else { + LOC_LOGV("GPS Config file has already been read\n"); + } + + EXIT_LOG(%d, 0); + return 0; +} + +/*=========================================================================== +FUNCTION loc_eng_gps_measurement_init + +DESCRIPTION + Initialize gps measurement module. + +DEPENDENCIES + N/A + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_gps_measurement_init(loc_eng_data_s_type &loc_eng_data, + GpsMeasurementCallbacks* callbacks) +{ + ENTRY_LOG_CALLFLOW(); + + STATE_CHECK((NULL == loc_eng_data.gps_measurement_cb), + "gps measurement already initialized", + return GPS_MEASUREMENT_ERROR_ALREADY_INIT); + STATE_CHECK((callbacks != NULL), + "callbacks can not be NULL", + return GPS_MEASUREMENT_ERROR_GENERIC); + STATE_CHECK(loc_eng_data.adapter, + "GpsInterface must be initialized first", + return GPS_MEASUREMENT_ERROR_GENERIC); + + // updated the mask + LOC_API_ADAPTER_EVENT_MASK_T event = LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT; + loc_eng_data.adapter->sendMsg(new LocEngUpdateRegistrationMask( + &loc_eng_data, + event, + LOC_REGISTRATION_MASK_ENABLED)); + // set up the callback + loc_eng_data.gps_measurement_cb = callbacks->measurement_callback; + LOC_LOGD ("%s, event masks updated successfully", __func__); + + return GPS_MEASUREMENT_OPERATION_SUCCESS; +} + +/*=========================================================================== +FUNCTION loc_eng_gps_measurement_close + +DESCRIPTION + Close gps measurement module. + +DEPENDENCIES + N/A + +RETURN VALUE + N/A + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_gps_measurement_close(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG_CALLFLOW(); + + INIT_CHECK(loc_eng_data.adapter, return); + + // updated the mask + LOC_API_ADAPTER_EVENT_MASK_T event = LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT; + loc_eng_data.adapter->sendMsg(new LocEngUpdateRegistrationMask( + &loc_eng_data, + event, + LOC_REGISTRATION_MASK_DISABLED)); + // set up the callback + loc_eng_data.gps_measurement_cb = NULL; + EXIT_LOG(%d, 0); +} diff --git a/gps/loc_api/libloc_api_50001/loc_eng.h b/gps/loc_api/libloc_api_50001/loc_eng.h new file mode 100644 index 0000000..a203e6b --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng.h @@ -0,0 +1,270 @@ +/* Copyright (c) 2009-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ENG_H +#define LOC_ENG_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +// Uncomment to keep all LOG messages (LOGD, LOGI, LOGV, etc.) +#define MAX_NUM_ATL_CONNECTIONS 2 + +// Define boolean type to be used by libgps on loc api module +typedef unsigned char boolean; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// The data connection minimal open time +#define DATA_OPEN_MIN_TIME 1 /* sec */ + +// The system sees GPS engine turns off after inactive for this period of time +#define GPS_AUTO_OFF_TIME 2 /* secs */ +#define SUCCESS TRUE +#define FAILURE FALSE +#define INVALID_ATL_CONNECTION_HANDLE -1 + +#define MAX_XTRA_SERVER_URL_LENGTH 256 + +enum loc_nmea_provider_e_type { + NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA + NMEA_PROVIDER_MP // Modem Processor Provider of NMEA +}; + +enum loc_mute_session_e_type { + LOC_MUTE_SESS_NONE = 0, + LOC_MUTE_SESS_WAIT, + LOC_MUTE_SESS_IN_SESSION +}; + +// Module data +typedef struct loc_eng_data_s +{ + LocEngAdapter *adapter; + loc_location_cb_ext location_cb; + gps_status_callback status_cb; + loc_sv_status_cb_ext sv_status_cb; + agps_status_extended agps_status_cb; + gps_nmea_callback nmea_cb; + gps_ni_notify_callback ni_notify_cb; + gps_set_capabilities set_capabilities_cb; + gps_acquire_wakelock acquire_wakelock_cb; + gps_release_wakelock release_wakelock_cb; + gps_request_utc_time request_utc_time_cb; + gps_measurement_callback gps_measurement_cb; + boolean intermediateFix; + AGpsStatusValue agps_status; + loc_eng_xtra_data_s_type xtra_module_data; + loc_eng_ni_data_s_type loc_eng_ni_data; + + // AGPS state machines + AgpsStateMachine* agnss_nif; + AgpsStateMachine* internet_nif; + AgpsStateMachine* wifi_nif; + //State machine for Data Services + AgpsStateMachine* ds_nif; + + // GPS engine status + GpsStatusValue engine_status; + GpsStatusValue fix_session_status; + + // Aiding data information to be deleted, aiding data can only be deleted when GPS engine is off + GpsAidingData aiding_data_for_deletion; + + // For muting session broadcast + loc_mute_session_e_type mute_session_state; + + // For nmea generation + boolean generateNmea; + uint32_t sv_used_mask; + float hdop; + float pdop; + float vdop; + + // Address buffers, for addressing setting before init + int supl_host_set; + char supl_host_buf[101]; + int supl_port_buf; + int c2k_host_set; + char c2k_host_buf[101]; + int c2k_port_buf; + int mpc_host_set; + char mpc_host_buf[101]; + int mpc_port_buf; + + loc_ext_parser location_ext_parser; + loc_ext_parser sv_ext_parser; +} loc_eng_data_s_type; + +/* GPS.conf support */ +/* NOTE: the implementaiton of the parser casts number + fields to 32 bit. To ensure all 'n' fields working, + they must all be 32 bit fields. */ +typedef struct loc_gps_cfg_s +{ + uint32_t INTERMEDIATE_POS; + uint32_t ACCURACY_THRES; + uint32_t SUPL_VER; + uint32_t SUPL_MODE; + uint32_t CAPABILITIES; + uint32_t LPP_PROFILE; + uint32_t XTRA_VERSION_CHECK; + char XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH]; + char XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH]; + char XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH]; + uint32_t USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL; + uint32_t NMEA_PROVIDER; + uint32_t GPS_LOCK; + uint32_t A_GLONASS_POS_PROTOCOL_SELECT; + uint32_t AGPS_CERT_WRITABLE_MASK; +} loc_gps_cfg_s_type; + +/* NOTE: the implementaiton of the parser casts number + fields to 32 bit. To ensure all 'n' fields working, + they must all be 32 bit fields. */ +/* Meanwhile, *_valid fields are 8 bit fields, and 'f' + fields are double. Rigid as they are, it is the + the status quo, until the parsing mechanism is + change, that is. */ +typedef struct +{ + uint8_t GYRO_BIAS_RANDOM_WALK_VALID; + double GYRO_BIAS_RANDOM_WALK; + uint32_t SENSOR_ACCEL_BATCHES_PER_SEC; + uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH; + uint32_t SENSOR_GYRO_BATCHES_PER_SEC; + uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH; + uint32_t SENSOR_ACCEL_BATCHES_PER_SEC_HIGH; + uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH; + uint32_t SENSOR_GYRO_BATCHES_PER_SEC_HIGH; + uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH; + uint32_t SENSOR_CONTROL_MODE; + uint32_t SENSOR_USAGE; + uint32_t SENSOR_ALGORITHM_CONFIG_MASK; + uint8_t ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double ACCEL_RANDOM_WALK_SPECTRAL_DENSITY; + uint8_t ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double ANGLE_RANDOM_WALK_SPECTRAL_DENSITY; + uint8_t RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double RATE_RANDOM_WALK_SPECTRAL_DENSITY; + uint8_t VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY; + uint32_t SENSOR_PROVIDER; +} loc_sap_cfg_s_type; + +extern loc_gps_cfg_s_type gps_conf; +extern loc_sap_cfg_s_type sap_conf; + + +uint32_t getCarrierCapabilities(); + +//loc_eng functions +int loc_eng_init(loc_eng_data_s_type &loc_eng_data, + LocCallbacks* callbacks, + LOC_API_ADAPTER_EVENT_MASK_T event, + ContextBase* context); +int loc_eng_start(loc_eng_data_s_type &loc_eng_data); +int loc_eng_stop(loc_eng_data_s_type &loc_eng_data); +void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data); +int loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data, + GpsUtcTime time, int64_t timeReference, + int uncertainty); +int loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data, + double latitude, double longitude, + float accuracy); +void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data, + GpsAidingData f); +int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data, + LocPosMode ¶ms); +const void* loc_eng_get_extension(loc_eng_data_s_type &loc_eng_data, + const char* name); +int loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data, + LocServerType type, const char *hostname, int port); +void loc_eng_mute_one_session(loc_eng_data_s_type &loc_eng_data); +int loc_eng_read_config(void); + +//loc_eng_agps functions +void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, + AGpsExtCallbacks* callbacks); +int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType, + const char* apn, AGpsBearerType bearerType); +int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType); +int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType); +void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data, + int avaiable, const char* apn); +int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data, + const DerEncodedCertificate* certificates, + size_t length); + +//loc_eng_xtra functions +int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data, + GpsXtraExtCallbacks* callbacks); +int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data, + char* data, int length); +int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data); +void loc_eng_xtra_version_check(loc_eng_data_s_type &loc_eng_data, int check); + +//loc_eng_ni functions +extern void loc_eng_ni_init(loc_eng_data_s_type &loc_eng_data, + GpsNiExtCallbacks *callbacks); +extern void loc_eng_ni_respond(loc_eng_data_s_type &loc_eng_data, + int notif_id, GpsUserResponseType user_response); +extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data, + const GpsNiNotification *notif, + const void* passThrough); +extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data); + +void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data, + const char* config_data, int32_t length); +int loc_eng_gps_measurement_init(loc_eng_data_s_type &loc_eng_data, + GpsMeasurementCallbacks* callbacks); +void loc_eng_gps_measurement_close(loc_eng_data_s_type &loc_eng_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // LOC_ENG_H diff --git a/gps/loc_api/libloc_api_50001/loc_eng_agps.cpp b/gps/loc_api/libloc_api_50001/loc_eng_agps.cpp new file mode 100644 index 0000000..5016b5c --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_agps.cpp @@ -0,0 +1,970 @@ +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_eng" + +#include +#include +#include +#include +#include +#include +#include + +//====================================================================== +// C callbacks +//====================================================================== + +// This is given to linked_list_add as the dealloc callback +// data -- an instance of Subscriber +static void deleteObj(void* data) +{ + delete (Subscriber*)data; +} + +// This is given to linked_list_search() as the comparison callback +// when the state manchine needs to process for particular subscriber +// fromCaller -- caller provides this obj +// fromList -- linked_list_search() function take this one from list +static bool hasSubscriber(void* fromCaller, void* fromList) +{ + Notification* notification = (Notification*)fromCaller; + Subscriber* s1 = (Subscriber*)fromList; + + return s1->forMe(*notification); +} + +// This is gvien to linked_list_search() to notify subscriber objs +// when the state machine needs to inform all subscribers of resource +// status changes, e.g. when resource is GRANTED. +// fromCaller -- caller provides this ptr to a Notification obj. +// fromList -- linked_list_search() function take this one from list +static bool notifySubscriber(void* fromCaller, void* fromList) +{ + Notification* notification = (Notification*)fromCaller; + Subscriber* s1 = (Subscriber*)fromList; + + // we notify every subscriber indiscriminatively + // each subscriber decides if this notification is interesting. + return s1->notifyRsrcStatus(*notification) && + // if we do not want to delete the subscriber from the + // the list, we must set this to false so this function + // returns false + notification->postNotifyDelete; +} + +//====================================================================== +// Notification +//====================================================================== +const int Notification::BROADCAST_ALL = 0x80000000; +const int Notification::BROADCAST_ACTIVE = 0x80000001; +const int Notification::BROADCAST_INACTIVE = 0x80000002; +const unsigned char DSStateMachine::MAX_START_DATA_CALL_RETRIES = 4; +const unsigned int DSStateMachine::DATA_CALL_RETRY_DELAY_MSEC = 500; +//====================================================================== +// Subscriber: BITSubscriber / ATLSubscriber / WIFISubscriber +//====================================================================== +bool Subscriber::forMe(Notification ¬ification) +{ + if (NULL != notification.rcver) { + return equals(notification.rcver); + } else { + return Notification::BROADCAST_ALL == notification.groupID || + (Notification::BROADCAST_ACTIVE == notification.groupID && + !isInactive()) || + (Notification::BROADCAST_INACTIVE == notification.groupID && + isInactive()); + } +} +bool BITSubscriber::equals(const Subscriber *s) const +{ + BITSubscriber* bitS = (BITSubscriber*)s; + + return (ID == bitS->ID && + (INADDR_NONE != (unsigned int)ID || + 0 == strncmp(mIPv6Addr, bitS->mIPv6Addr, sizeof(mIPv6Addr)))); +} + +bool BITSubscriber::notifyRsrcStatus(Notification ¬ification) +{ + bool notify = forMe(notification); + + if (notify) { + switch(notification.rsrcStatus) + { + case RSRC_UNSUBSCRIBE: + case RSRC_RELEASED: + loc_eng_dmn_conn_loc_api_server_data_conn( + LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + GPSONE_LOC_API_IF_RELEASE_SUCCESS); + break; + case RSRC_DENIED: + loc_eng_dmn_conn_loc_api_server_data_conn( + LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + GPSONE_LOC_API_IF_FAILURE); + break; + case RSRC_GRANTED: + loc_eng_dmn_conn_loc_api_server_data_conn( + LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + GPSONE_LOC_API_IF_REQUEST_SUCCESS); + break; + default: + notify = false; + } + } + + return notify; +} + +bool ATLSubscriber::notifyRsrcStatus(Notification ¬ification) +{ + bool notify = forMe(notification); + + if (notify) { + switch(notification.rsrcStatus) + { + case RSRC_UNSUBSCRIBE: + case RSRC_RELEASED: + ((LocEngAdapter*)mLocAdapter)->atlCloseStatus(ID, 1); + break; + case RSRC_DENIED: + { + AGpsExtType type = mBackwardCompatibleMode ? + AGPS_TYPE_INVALID : mStateMachine->getType(); + ((LocEngAdapter*)mLocAdapter)->atlOpenStatus(ID, 0, + (char*)mStateMachine->getAPN(), + mStateMachine->getBearer(), + type); + } + break; + case RSRC_GRANTED: + { + AGpsExtType type = mBackwardCompatibleMode ? + AGPS_TYPE_INVALID : mStateMachine->getType(); + ((LocEngAdapter*)mLocAdapter)->atlOpenStatus(ID, 1, + (char*)mStateMachine->getAPN(), + mStateMachine->getBearer(), + type); + } + break; + default: + notify = false; + } + } + + return notify; +} + +bool WIFISubscriber::notifyRsrcStatus(Notification ¬ification) +{ + bool notify = forMe(notification); + + if (notify) { + switch(notification.rsrcStatus) + { + case RSRC_UNSUBSCRIBE: + break; + case RSRC_RELEASED: + loc_eng_dmn_conn_loc_api_server_data_conn( + senderId, + GPSONE_LOC_API_IF_RELEASE_SUCCESS); + break; + case RSRC_DENIED: + loc_eng_dmn_conn_loc_api_server_data_conn( + senderId, + GPSONE_LOC_API_IF_FAILURE); + break; + case RSRC_GRANTED: + loc_eng_dmn_conn_loc_api_server_data_conn( + senderId, + GPSONE_LOC_API_IF_REQUEST_SUCCESS); + break; + default: + notify = false; + } + } + + return notify; +} +bool DSSubscriber::notifyRsrcStatus(Notification ¬ification) +{ + bool notify = forMe(notification); + LOC_LOGD("DSSubscriber::notifyRsrcStatus. notify:%d \n",(int)(notify)); + if(notify) { + switch(notification.rsrcStatus) { + case RSRC_UNSUBSCRIBE: + case RSRC_RELEASED: + case RSRC_DENIED: + case RSRC_GRANTED: + ((DSStateMachine *)mStateMachine)->informStatus(notification.rsrcStatus, ID); + break; + default: + notify = false; + } + } + return notify; +} +void DSSubscriber :: setInactive() +{ + mIsInactive = true; + ((DSStateMachine *)mStateMachine)->informStatus(RSRC_UNSUBSCRIBE, ID); +} +//====================================================================== +// AgpsState: AgpsReleasedState / AgpsPendingState / AgpsAcquiredState +//====================================================================== + +// AgpsReleasedState +class AgpsReleasedState : public AgpsState +{ + friend class AgpsStateMachine; + + inline AgpsReleasedState(AgpsStateMachine* stateMachine) : + AgpsState(stateMachine) + { mReleasedState = this; } + + inline ~AgpsReleasedState() {} +public: + virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data); + inline virtual char* whoami() {return (char*)"AgpsReleasedState";} +}; + +AgpsState* AgpsReleasedState::onRsrcEvent(AgpsRsrcStatus event, void* data) +{ + LOC_LOGD("AgpsReleasedState::onRsrcEvent; event:%d\n", (int)event); + if (mStateMachine->hasSubscribers()) { + LOC_LOGE("Error: %s subscriber list not empty!!!", whoami()); + // I don't know how to recover from it. I am adding this rather + // for debugging purpose. + } + + AgpsState* nextState = this; + switch (event) + { + case RSRC_SUBSCRIBE: + { + // no notification until we get RSRC_GRANTED + // but we need to add subscriber to the list + mStateMachine->addSubscriber((Subscriber*)data); + // request from connecivity service for NIF + //The if condition is added so that if the data call setup fails + //for DS State Machine, we want to retry in released state. + //for AGps State Machine, sendRsrcRequest() will always return success + if(!mStateMachine->sendRsrcRequest(GPS_REQUEST_AGPS_DATA_CONN)) { + // move the state to PENDING + nextState = mPendingState; + } + } + break; + + case RSRC_UNSUBSCRIBE: + { + // the list should really be empty, nothing to remove. + // but we might as well just tell the client it is + // unsubscribed. False tolerance, right? + Subscriber* subscriber = (Subscriber*) data; + Notification notification(subscriber, event, false); + subscriber->notifyRsrcStatus(notification); + } + // break; + case RSRC_GRANTED: + case RSRC_RELEASED: + case RSRC_DENIED: + default: + LOC_LOGW("%s: unrecognized event %d", whoami(), event); + // no state change. + break; + } + + LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d", + whoami(), nextState->whoami(), event); + return nextState; +} + +// AgpsPendingState +class AgpsPendingState : public AgpsState +{ + friend class AgpsStateMachine; + + inline AgpsPendingState(AgpsStateMachine* stateMachine) : + AgpsState(stateMachine) + { mPendingState = this; } + + inline ~AgpsPendingState() {} +public: + virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data); + inline virtual char* whoami() {return (char*)"AgpsPendingState";} +}; + +AgpsState* AgpsPendingState::onRsrcEvent(AgpsRsrcStatus event, void* data) +{ + AgpsState* nextState = this;; + LOC_LOGD("AgpsPendingState::onRsrcEvent; event:%d\n", (int)event); + switch (event) + { + case RSRC_SUBSCRIBE: + { + // already requested for NIF resource, + // do nothing until we get RSRC_GRANTED indication + // but we need to add subscriber to the list + mStateMachine->addSubscriber((Subscriber*)data); + // no state change. + } + break; + + case RSRC_UNSUBSCRIBE: + { + Subscriber* subscriber = (Subscriber*) data; + if (subscriber->waitForCloseComplete()) { + subscriber->setInactive(); + } else { + // auto notify this subscriber of the unsubscribe + Notification notification(subscriber, event, true); + mStateMachine->notifySubscribers(notification); + } + + // now check if there is any subscribers left + if (!mStateMachine->hasSubscribers()) { + // no more subscribers, move to RELEASED state + nextState = mReleasedState; + + // tell connecivity service we can release NIF + mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN); + } else if (!mStateMachine->hasActiveSubscribers()) { + // only inactive subscribers, move to RELEASING state + nextState = mReleasingState; + + // tell connecivity service we can release NIF + mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN); + } + } + break; + + case RSRC_GRANTED: + { + nextState = mAcquiredState; + Notification notification(Notification::BROADCAST_ACTIVE, event, false); + // notify all subscribers NIF resource GRANTED + // by setting false, we keep subscribers on the linked list + mStateMachine->notifySubscribers(notification); + } + break; + + case RSRC_RELEASED: + // no state change. + // we are expecting either GRANTED or DENIED. Handling RELEASED + // may like break our state machine in race conditions. + break; + + case RSRC_DENIED: + { + nextState = mReleasedState; + Notification notification(Notification::BROADCAST_ALL, event, true); + // notify all subscribers NIF resource RELEASED or DENIED + // by setting true, we remove subscribers from the linked list + mStateMachine->notifySubscribers(notification); + } + break; + + default: + LOC_LOGE("%s: unrecognized event %d", whoami(), event); + // no state change. + } + + LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d", + whoami(), nextState->whoami(), event); + return nextState; +} + + +class AgpsAcquiredState : public AgpsState +{ + friend class AgpsStateMachine; + + inline AgpsAcquiredState(AgpsStateMachine* stateMachine) : + AgpsState(stateMachine) + { mAcquiredState = this; } + + inline ~AgpsAcquiredState() {} +public: + virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data); + inline virtual char* whoami() { return (char*)"AgpsAcquiredState"; } +}; + + +AgpsState* AgpsAcquiredState::onRsrcEvent(AgpsRsrcStatus event, void* data) +{ + AgpsState* nextState = this; + LOC_LOGD("AgpsAcquiredState::onRsrcEvent; event:%d\n", (int)event); + switch (event) + { + case RSRC_SUBSCRIBE: + { + // we already have the NIF resource, simply notify subscriber + Subscriber* subscriber = (Subscriber*) data; + // we have rsrc in hand, so grant it right away + Notification notification(subscriber, RSRC_GRANTED, false); + subscriber->notifyRsrcStatus(notification); + // add subscriber to the list + mStateMachine->addSubscriber(subscriber); + // no state change. + } + break; + + case RSRC_UNSUBSCRIBE: + { + Subscriber* subscriber = (Subscriber*) data; + if (subscriber->waitForCloseComplete()) { + subscriber->setInactive(); + } else { + // auto notify this subscriber of the unsubscribe + Notification notification(subscriber, event, true); + mStateMachine->notifySubscribers(notification); + } + + // now check if there is any subscribers left + if (!mStateMachine->hasSubscribers()) { + // no more subscribers, move to RELEASED state + nextState = mReleasedState; + + // tell connecivity service we can release NIF + mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN); + } else if (!mStateMachine->hasActiveSubscribers()) { + // only inactive subscribers, move to RELEASING state + nextState = mReleasingState; + + // tell connecivity service we can release NIF + mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN); + } + } + break; + + case RSRC_GRANTED: + LOC_LOGW("%s: %d, RSRC_GRANTED already received", whoami(), event); + // no state change. + break; + + case RSRC_RELEASED: + { + LOC_LOGW("%s: %d, a force rsrc release", whoami(), event); + nextState = mReleasedState; + Notification notification(Notification::BROADCAST_ALL, event, true); + // by setting true, we remove subscribers from the linked list + mStateMachine->notifySubscribers(notification); + } + break; + + case RSRC_DENIED: + // no state change. + // we are expecting RELEASED. Handling DENIED + // may like break our state machine in race conditions. + break; + + default: + LOC_LOGE("%s: unrecognized event %d", whoami(), event); + // no state change. + } + + LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d", + whoami(), nextState->whoami(), event); + return nextState; +} + +// AgpsPendingState +class AgpsReleasingState : public AgpsState +{ + friend class AgpsStateMachine; + + inline AgpsReleasingState(AgpsStateMachine* stateMachine) : + AgpsState(stateMachine) + { mReleasingState = this; } + + inline ~AgpsReleasingState() {} +public: + virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data); + inline virtual char* whoami() {return (char*)"AgpsReleasingState";} +}; + +AgpsState* AgpsReleasingState::onRsrcEvent(AgpsRsrcStatus event, void* data) +{ + AgpsState* nextState = this;; + LOC_LOGD("AgpsReleasingState::onRsrcEvent; event:%d\n", (int)event); + + switch (event) + { + case RSRC_SUBSCRIBE: + { + // already requested for NIF resource, + // do nothing until we get RSRC_GRANTED indication + // but we need to add subscriber to the list + mStateMachine->addSubscriber((Subscriber*)data); + // no state change. + } + break; + + case RSRC_UNSUBSCRIBE: + { + Subscriber* subscriber = (Subscriber*) data; + if (subscriber->waitForCloseComplete()) { + subscriber->setInactive(); + } else { + // auto notify this subscriber of the unsubscribe + Notification notification(subscriber, event, true); + mStateMachine->notifySubscribers(notification); + } + + // now check if there is any subscribers left + if (!mStateMachine->hasSubscribers()) { + // no more subscribers, move to RELEASED state + nextState = mReleasedState; + } + } + break; + + case RSRC_DENIED: + // A race condition subscriber unsubscribes before AFW denies resource. + case RSRC_RELEASED: + { + nextState = mAcquiredState; + Notification notification(Notification::BROADCAST_INACTIVE, event, true); + // notify all subscribers that are active NIF resource RELEASE + // by setting false, we keep subscribers on the linked list + mStateMachine->notifySubscribers(notification); + + if (mStateMachine->hasActiveSubscribers()) { + nextState = mPendingState; + // request from connecivity service for NIF + mStateMachine->sendRsrcRequest(GPS_REQUEST_AGPS_DATA_CONN); + } else { + nextState = mReleasedState; + } + } + break; + + case RSRC_GRANTED: + default: + LOC_LOGE("%s: unrecognized event %d", whoami(), event); + // no state change. + } + + LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d", + whoami(), nextState->whoami(), event); + return nextState; +} +//====================================================================== +//Servicer +//====================================================================== +Servicer* Servicer :: getServicer(servicerType type, void *cb_func) +{ + LOC_LOGD(" Enter getServicer type:%d\n", (int)type); + switch(type) { + case servicerTypeNoCbParam: + return (new Servicer(cb_func)); + case servicerTypeExt: + return (new ExtServicer(cb_func)); + case servicerTypeAgps: + return (new AGpsServicer(cb_func)); + default: + return NULL; + } +} + +int Servicer :: requestRsrc(void *cb_data) +{ + callback(); + return 0; +} + +int ExtServicer :: requestRsrc(void *cb_data) +{ + int ret=-1; + LOC_LOGD("Enter ExtServicer :: requestRsrc\n"); + ret = callbackExt(cb_data); + LOC_LOGD("Exit ExtServicer :: requestRsrc\n"); + return(ret); +} + +int AGpsServicer :: requestRsrc(void *cb_data) +{ + callbackAGps((AGpsStatus *)cb_data); + return 0; +} + +//====================================================================== +// AgpsStateMachine +//====================================================================== + +AgpsStateMachine::AgpsStateMachine(servicerType servType, + void *cb_func, + AGpsExtType type, + bool enforceSingleSubscriber) : + mStatePtr(new AgpsReleasedState(this)),mType(type), + mAPN(NULL), + mAPNLen(0), + mBearer(AGPS_APN_BEARER_INVALID), + mEnforceSingleSubscriber(enforceSingleSubscriber), + mServicer(Servicer :: getServicer(servType, (void *)cb_func)) +{ + linked_list_init(&mSubscribers); + + // setting up mReleasedState + mStatePtr->mPendingState = new AgpsPendingState(this); + mStatePtr->mAcquiredState = new AgpsAcquiredState(this); + mStatePtr->mReleasingState = new AgpsReleasingState(this); + + // setting up mAcquiredState + mStatePtr->mAcquiredState->mReleasedState = mStatePtr; + mStatePtr->mAcquiredState->mPendingState = mStatePtr->mPendingState; + mStatePtr->mAcquiredState->mReleasingState = mStatePtr->mReleasingState; + + // setting up mPendingState + mStatePtr->mPendingState->mAcquiredState = mStatePtr->mAcquiredState; + mStatePtr->mPendingState->mReleasedState = mStatePtr; + mStatePtr->mPendingState->mReleasingState = mStatePtr->mReleasingState; + + // setting up mReleasingState + mStatePtr->mReleasingState->mReleasedState = mStatePtr; + mStatePtr->mReleasingState->mPendingState = mStatePtr->mPendingState; + mStatePtr->mReleasingState->mAcquiredState = mStatePtr->mAcquiredState; +} + +AgpsStateMachine::~AgpsStateMachine() +{ + dropAllSubscribers(); + + // free the 3 states. We must read out all 3 pointers first. + // Otherwise we run the risk of getting pointers from already + // freed memory. + AgpsState* acquiredState = mStatePtr->mAcquiredState; + AgpsState* releasedState = mStatePtr->mReleasedState; + AgpsState* pendindState = mStatePtr->mPendingState; + AgpsState* releasingState = mStatePtr->mReleasingState; + + delete acquiredState; + delete releasedState; + delete pendindState; + delete releasingState; + delete mServicer; + linked_list_destroy(&mSubscribers); + + if (NULL != mAPN) { + delete[] mAPN; + mAPN = NULL; + } +} + +void AgpsStateMachine::setAPN(const char* apn, unsigned int len) +{ + if (NULL != mAPN) { + delete mAPN; + } + + if (NULL != apn) { + mAPN = new char[len+1]; + memcpy(mAPN, apn, len); + mAPN[len] = NULL; + + mAPNLen = len; + } else { + mAPN = NULL; + mAPNLen = 0; + } +} + +void AgpsStateMachine::onRsrcEvent(AgpsRsrcStatus event) +{ + switch (event) + { + case RSRC_GRANTED: + case RSRC_RELEASED: + case RSRC_DENIED: + mStatePtr = mStatePtr->onRsrcEvent(event, NULL); + break; + default: + LOC_LOGW("AgpsStateMachine: unrecognized event %d", event); + break; + } +} + +void AgpsStateMachine::notifySubscribers(Notification& notification) const +{ + if (notification.postNotifyDelete) { + // just any non NULL value to get started + Subscriber* s = (Subscriber*)~0; + while (NULL != s) { + s = NULL; + // if the last param sets to true, _search will delete + // the node from the list for us. But the problem is + // once that is done, _search returns, leaving the + // rest of the list unprocessed. So we need a loop. + linked_list_search(mSubscribers, (void**)&s, notifySubscriber, + (void*)¬ification, true); + delete s; + } + } else { + // no loop needed if it the last param sets to false, which + // mean nothing gets deleted from the list. + linked_list_search(mSubscribers, NULL, notifySubscriber, + (void*)¬ification, false); + } +} + +void AgpsStateMachine::addSubscriber(Subscriber* subscriber) const +{ + Subscriber* s = NULL; + Notification notification((const Subscriber*)subscriber); + linked_list_search(mSubscribers, (void**)&s, + hasSubscriber, (void*)¬ification, false); + + if (NULL == s) { + linked_list_add(mSubscribers, subscriber->clone(), deleteObj); + } +} + +int AgpsStateMachine::sendRsrcRequest(AGpsStatusValue action) const +{ + Subscriber* s = NULL; + Notification notification(Notification::BROADCAST_ACTIVE); + linked_list_search(mSubscribers, (void**)&s, hasSubscriber, + (void*)¬ification, false); + + if ((NULL == s) == (GPS_RELEASE_AGPS_DATA_CONN == action)) { + AGpsExtStatus nifRequest; + nifRequest.size = sizeof(nifRequest); + nifRequest.type = mType; + nifRequest.status = action; + + if (s == NULL) { + nifRequest.ipv4_addr = INADDR_NONE; + memset(&nifRequest.addr, 0, sizeof(nifRequest.addr)); + nifRequest.ssid[0] = '\0'; + nifRequest.password[0] = '\0'; + } else { + s->setIPAddresses(nifRequest.addr); + s->setWifiInfo(nifRequest.ssid, nifRequest.password); + } + + CALLBACK_LOG_CALLFLOW("agps_cb", %s, loc_get_agps_status_name(action)); + mServicer->requestRsrc((void *)&nifRequest); + } + return 0; +} + +void AgpsStateMachine::subscribeRsrc(Subscriber *subscriber) +{ + if (mEnforceSingleSubscriber && hasSubscribers()) { + Notification notification(Notification::BROADCAST_ALL, RSRC_DENIED, true); + notifySubscriber(¬ification, subscriber); + } else { + mStatePtr = mStatePtr->onRsrcEvent(RSRC_SUBSCRIBE, (void*)subscriber); + } +} + +bool AgpsStateMachine::unsubscribeRsrc(Subscriber *subscriber) +{ + Subscriber* s = NULL; + Notification notification((const Subscriber*)subscriber); + linked_list_search(mSubscribers, (void**)&s, + hasSubscriber, (void*)¬ification, false); + + if (NULL != s) { + mStatePtr = mStatePtr->onRsrcEvent(RSRC_UNSUBSCRIBE, (void*)s); + return true; + } + return false; +} + +bool AgpsStateMachine::hasActiveSubscribers() const +{ + Subscriber* s = NULL; + Notification notification(Notification::BROADCAST_ACTIVE); + linked_list_search(mSubscribers, (void**)&s, + hasSubscriber, (void*)¬ification, false); + return NULL != s; +} + +//====================================================================== +// DSStateMachine +//====================================================================== +void delay_callback(void *callbackData, int result) +{ + if(callbackData) { + DSStateMachine *DSSMInstance = (DSStateMachine *)callbackData; + DSSMInstance->retryCallback(); + } + else { + LOC_LOGE(" NULL argument received. Failing.\n"); + goto err; + } +err: + return; +} + +DSStateMachine :: DSStateMachine(servicerType type, void *cb_func, + LocEngAdapter* adapterHandle): + AgpsStateMachine(type, cb_func, AGPS_TYPE_INVALID,false), + mLocAdapter(adapterHandle) +{ + LOC_LOGD("%s:%d]: New DSStateMachine\n", __func__, __LINE__); + mRetries = 0; +} + +void DSStateMachine :: retryCallback(void) +{ + DSSubscriber *subscriber = NULL; + Notification notification(Notification::BROADCAST_ACTIVE); + linked_list_search(mSubscribers, (void**)&subscriber, hasSubscriber, + (void*)¬ification, false); + if(subscriber) + mLocAdapter->requestSuplES(subscriber->ID); + else + LOC_LOGE("DSStateMachine :: retryCallback: No subscriber found." \ + "Cannot retry data call\n"); + return; +} + +int DSStateMachine :: sendRsrcRequest(AGpsStatusValue action) const +{ + DSSubscriber* s = NULL; + dsCbData cbData; + int ret=-1; + int connHandle=-1; + LOC_LOGD("Enter DSStateMachine :: sendRsrcRequest\n"); + Notification notification(Notification::BROADCAST_ACTIVE); + linked_list_search(mSubscribers, (void**)&s, hasSubscriber, + (void*)¬ification, false); + if(s) { + connHandle = s->ID; + LOC_LOGD("DSStateMachine :: sendRsrcRequest - subscriber found\n"); + } + else + LOC_LOGD("DSStateMachine :: sendRsrcRequest - No subscriber found\n"); + + cbData.action = action; + cbData.mAdapter = mLocAdapter; + ret = mServicer->requestRsrc((void *)&cbData); + //Only the request to start data call returns a success/failure + //The request to stop data call will always succeed + //Hence, the below block will only be executed when the + //request to start the data call fails + switch(ret) { + case LOC_API_ADAPTER_ERR_ENGINE_BUSY: + LOC_LOGD("DSStateMachine :: sendRsrcRequest - Failure returned: %d\n",ret); + ((DSStateMachine *)this)->incRetries(); + if(mRetries > MAX_START_DATA_CALL_RETRIES) { + LOC_LOGE(" Failed to start Data call. Fallback to normal ATL SUPL\n"); + informStatus(RSRC_DENIED, connHandle); + } + else { + if(loc_timer_start(DATA_CALL_RETRY_DELAY_MSEC, delay_callback, (void *)this)) { + LOC_LOGE("Error: Could not start delay thread\n"); + ret = -1; + goto err; + } + } + break; + case LOC_API_ADAPTER_ERR_UNSUPPORTED: + LOC_LOGE("No profile found for emergency call. Fallback to normal SUPL ATL\n"); + informStatus(RSRC_DENIED, connHandle); + break; + case LOC_API_ADAPTER_ERR_SUCCESS: + LOC_LOGD("%s:%d]: Request to start data call sent\n", __func__, __LINE__); + break; + case -1: + //One of the ways this case can be encountered is if the callback function + //receives a null argument, it just exits with -1 error + LOC_LOGE("Error: Something went wrong somewhere. Falling back to normal SUPL ATL\n"); + informStatus(RSRC_DENIED, connHandle); + break; + default: + LOC_LOGE("%s:%d]: Unrecognized return value\n", __func__, __LINE__); + } +err: + LOC_LOGD("EXIT DSStateMachine :: sendRsrcRequest; ret = %d\n", ret); + return ret; +} + +void DSStateMachine :: onRsrcEvent(AgpsRsrcStatus event) +{ + void* currState = (void *)mStatePtr; + LOC_LOGD("Enter DSStateMachine :: onRsrcEvent. event = %d\n", (int)event); + switch (event) + { + case RSRC_GRANTED: + LOC_LOGD("DSStateMachine :: onRsrcEvent RSRC_GRANTED\n"); + mStatePtr = mStatePtr->onRsrcEvent(event, NULL); + break; + case RSRC_RELEASED: + LOC_LOGD("DSStateMachine :: onRsrcEvent RSRC_RELEASED\n"); + mStatePtr = mStatePtr->onRsrcEvent(event, NULL); + //To handle the case where we get a RSRC_RELEASED in + //pending state, we translate that to a RSRC_DENIED state + //since the callback from DSI is either RSRC_GRANTED or RSRC_RELEASED + //for when the call is connected or disconnected respectively. + if((void *)mStatePtr != currState) + break; + else { + event = RSRC_DENIED; + LOC_LOGE(" Switching event to RSRC_DENIED\n"); + } + case RSRC_DENIED: + mStatePtr = mStatePtr->onRsrcEvent(event, NULL); + break; + default: + LOC_LOGW("AgpsStateMachine: unrecognized event %d", event); + break; + } + LOC_LOGD("Exit DSStateMachine :: onRsrcEvent. event = %d\n", (int)event); +} + +void DSStateMachine :: informStatus(AgpsRsrcStatus status, int ID) const +{ + LOC_LOGD("DSStateMachine :: informStatus. Status=%d\n",(int)status); + switch(status) { + case RSRC_UNSUBSCRIBE: + mLocAdapter->atlCloseStatus(ID, 1); + break; + case RSRC_RELEASED: + mLocAdapter->closeDataCall(); + break; + case RSRC_DENIED: + ((DSStateMachine *)this)->mRetries = 0; + mLocAdapter->requestATL(ID, AGPS_TYPE_SUPL); + break; + case RSRC_GRANTED: + mLocAdapter->atlOpenStatus(ID, 1, + NULL, + AGPS_APN_BEARER_INVALID, + AGPS_TYPE_INVALID); + break; + default: + LOC_LOGW("DSStateMachine :: informStatus - unknown status"); + } + return; +} diff --git a/gps/loc_api/libloc_api_50001/loc_eng_agps.h b/gps/loc_api/libloc_api_50001/loc_eng_agps.h new file mode 100644 index 0000000..2d689ce --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_agps.h @@ -0,0 +1,431 @@ +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_ENG_AGPS_H__ +#define __LOC_ENG_AGPS_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// forward declaration +class AgpsStateMachine; +class Subscriber; + +// NIF resource events +typedef enum { + RSRC_SUBSCRIBE, + RSRC_UNSUBSCRIBE, + RSRC_GRANTED, + RSRC_RELEASED, + RSRC_DENIED, + RSRC_STATUS_MAX +} AgpsRsrcStatus; + +typedef enum { + servicerTypeNoCbParam, + servicerTypeAgps, + servicerTypeExt +}servicerType; + +//DS Callback struct +typedef struct { + LocEngAdapter *mAdapter; + AGpsStatusValue action; +}dsCbData; + +// information bundle for subscribers +struct Notification { + // goes to every subscriber + static const int BROADCAST_ALL; + // goes to every ACTIVE subscriber + static const int BROADCAST_ACTIVE; + // goes to every INACTIVE subscriber + static const int BROADCAST_INACTIVE; + + // go to a specific subscriber + const Subscriber* rcver; + // broadcast + const int groupID; + // the new resource status event + const AgpsRsrcStatus rsrcStatus; + // should the subscriber be deleted after the notification + const bool postNotifyDelete; + + // convenient constructor + inline Notification(const int broadcast, + const AgpsRsrcStatus status, + const bool deleteAfterwards) : + rcver(NULL), groupID(broadcast), rsrcStatus(status), + postNotifyDelete(deleteAfterwards) {} + + // convenient constructor + inline Notification(const Subscriber* subscriber, + const AgpsRsrcStatus status, + const bool deleteAfterwards) : + rcver(subscriber), groupID(-1), rsrcStatus(status), + postNotifyDelete(deleteAfterwards) {} + + // convenient constructor + inline Notification(const int broadcast) : + rcver(NULL), groupID(broadcast), rsrcStatus(RSRC_STATUS_MAX), + postNotifyDelete(false) {} + + // convenient constructor + inline Notification(const Subscriber* subscriber) : + rcver(subscriber), groupID(-1), rsrcStatus(RSRC_STATUS_MAX), + postNotifyDelete(false) {} +}; + +class AgpsState { + // allows AgpsStateMachine to access private data + // no class members are public. We don't want + // anyone but state machine to use state. + friend class AgpsStateMachine; + friend class DSStateMachine; + // state transitions are done here. + // Each state implements its own transitions (of course). + inline virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data) = 0; + +protected: + // handle back to state machine + const AgpsStateMachine* mStateMachine; + // each state has pointers to all 3 states + // one of which is to itself. + AgpsState* mReleasedState; + AgpsState* mAcquiredState; + AgpsState* mPendingState; + AgpsState* mReleasingState; + + inline AgpsState(const AgpsStateMachine *stateMachine) : + mStateMachine(stateMachine), + mReleasedState(NULL), + mAcquiredState(NULL), + mPendingState(NULL), + mReleasingState(NULL) {} + virtual ~AgpsState() {} + +public: + // for logging purpose + inline virtual char* whoami() = 0; +}; + +class Servicer { + void (*callback)(void); +public: + static Servicer* getServicer(servicerType type, void *cb_func); + virtual int requestRsrc(void *cb_data); + Servicer() {} + Servicer(void *cb_func) + { callback = (void(*)(void))(cb_func); } + virtual ~Servicer(){} + inline virtual char *whoami() {return (char*)"Servicer";} +}; + +class ExtServicer : public Servicer { + int (*callbackExt)(void *cb_data); +public: + int requestRsrc(void *cb_data); + ExtServicer() {} + ExtServicer(void *cb_func) + { callbackExt = (int(*)(void *))(cb_func); } + virtual ~ExtServicer(){} + inline virtual char *whoami() {return (char*)"ExtServicer";} +}; + +class AGpsServicer : public Servicer { + void (*callbackAGps)(AGpsStatus* status); +public: + int requestRsrc(void *cb_data); + AGpsServicer() {} + AGpsServicer(void *cb_func) + { callbackAGps = (void(*)(AGpsStatus *))(cb_func); } + virtual ~AGpsServicer(){} + inline virtual char *whoami() {return (char*)"AGpsServicer";} +}; + +class AgpsStateMachine { +protected: + // a linked list of subscribers. + void* mSubscribers; + //handle to whoever provides the service + Servicer *mServicer; + // allows AgpsState to access private data + // each state is really internal data to the + // state machine, so it should be able to + // access anything within the state machine. + friend class AgpsState; + // pointer to the current state. + AgpsState* mStatePtr; +private: + // NIF type: AGNSS or INTERNET. + const AGpsExtType mType; + // apn to the NIF. Each state machine tracks + // resource state of a particular NIF. For each + // NIF, there is also an active APN. + char* mAPN; + // for convenience, we don't do strlen each time. + unsigned int mAPNLen; + // bear + AGpsBearerType mBearer; + // ipv4 address for routing + bool mEnforceSingleSubscriber; + +public: + AgpsStateMachine(servicerType servType, void *cb_func, + AGpsExtType type, bool enforceSingleSubscriber); + virtual ~AgpsStateMachine(); + + // self explanatory methods below + void setAPN(const char* apn, unsigned int len); + inline const char* getAPN() const { return (const char*)mAPN; } + inline void setBearer(AGpsBearerType bearer) { mBearer = bearer; } + inline AGpsBearerType getBearer() const { return mBearer; } + inline AGpsExtType getType() const { return (AGpsExtType)mType; } + + // someone, a ATL client or BIT, is asking for NIF + void subscribeRsrc(Subscriber *subscriber); + + // someone, a ATL client or BIT, is done with NIF + bool unsubscribeRsrc(Subscriber *subscriber); + + // add a subscriber in the linked list, if not already there. + void addSubscriber(Subscriber* subscriber) const; + + virtual void onRsrcEvent(AgpsRsrcStatus event); + + // put the data together and send the FW + virtual int sendRsrcRequest(AGpsStatusValue action) const; + + //if list is empty, linked_list_empty returns 1 + //else if list is not empty, returns 0 + //so hasSubscribers() returns 1 if list is not empty + //and returns 0 if list is empty + inline bool hasSubscribers() const + { return !linked_list_empty(mSubscribers); } + + bool hasActiveSubscribers() const; + + inline void dropAllSubscribers() const + { linked_list_flush(mSubscribers); } + + // private. Only a state gets to call this. + void notifySubscribers(Notification& notification) const; + +}; + +class DSStateMachine : public AgpsStateMachine { + static const unsigned char MAX_START_DATA_CALL_RETRIES; + static const unsigned int DATA_CALL_RETRY_DELAY_MSEC; + LocEngAdapter* mLocAdapter; + unsigned char mRetries; +public: + DSStateMachine(servicerType type, + void *cb_func, + LocEngAdapter* adapterHandle); + int sendRsrcRequest(AGpsStatusValue action) const; + void onRsrcEvent(AgpsRsrcStatus event); + void retryCallback(); + void informStatus(AgpsRsrcStatus status, int ID) const; + inline void incRetries() {mRetries++;} + inline virtual char *whoami() {return (char*)"DSStateMachine";} +}; + +// each subscriber is a AGPS client. In the case of ATL, there could be +// multiple clients from modem. In the case of BIT, there is only one +// cilent from BIT daemon. +struct Subscriber { + const uint32_t ID; + const AgpsStateMachine* mStateMachine; + inline Subscriber(const int id, + const AgpsStateMachine* stateMachine) : + ID(id), mStateMachine(stateMachine) {} + inline virtual ~Subscriber() {} + + virtual void setIPAddresses(uint32_t &v4, char* v6) = 0; + virtual void setIPAddresses(struct sockaddr_storage& addr) = 0; + inline virtual void setWifiInfo(char* ssid, char* password) + { ssid[0] = 0; password[0] = 0; } + + inline virtual bool equals(const Subscriber *s) const + { return ID == s->ID; } + + // notifies a subscriber a new NIF resource status, usually + // either GRANTE, DENIED, or RELEASED + virtual bool notifyRsrcStatus(Notification ¬ification) = 0; + + virtual bool waitForCloseComplete() { return false; } + virtual void setInactive() {} + virtual bool isInactive() { return false; } + + virtual Subscriber* clone() = 0; + // checks if this notification is for me, i.e. + // either has my id, or has a broadcast id. + bool forMe(Notification ¬ification); +}; + +// BITSubscriber, created with requests from BIT daemon +struct BITSubscriber : public Subscriber { + char mIPv6Addr[16]; + + inline BITSubscriber(const AgpsStateMachine* stateMachine, + unsigned int ipv4, char* ipv6) : + Subscriber(ipv4, stateMachine) + { + if (NULL == ipv6) { + mIPv6Addr[0] = 0; + } else { + memcpy(mIPv6Addr, ipv6, sizeof(mIPv6Addr)); + } + } + + virtual bool notifyRsrcStatus(Notification ¬ification); + + inline virtual void setIPAddresses(uint32_t &v4, char* v6) + { v4 = ID; memcpy(v6, mIPv6Addr, sizeof(mIPv6Addr)); } + + inline virtual void setIPAddresses(struct sockaddr_storage& addr) + { addr.ss_family = AF_INET6;/*todo: convert mIPv6Addr into addr */ } + + virtual Subscriber* clone() + { + return new BITSubscriber(mStateMachine, ID, mIPv6Addr); + } + + virtual bool equals(const Subscriber *s) const; + inline virtual ~BITSubscriber(){} +}; + +// ATLSubscriber, created with requests from ATL +struct ATLSubscriber : public Subscriber { + const LocEngAdapter* mLocAdapter; + const bool mBackwardCompatibleMode; + inline ATLSubscriber(const int id, + const AgpsStateMachine* stateMachine, + const LocEngAdapter* adapter, + const bool compatibleMode) : + Subscriber(id, stateMachine), mLocAdapter(adapter), + mBackwardCompatibleMode(compatibleMode){} + virtual bool notifyRsrcStatus(Notification ¬ification); + + inline virtual void setIPAddresses(uint32_t &v4, char* v6) + { v4 = INADDR_NONE; v6[0] = 0; } + + inline virtual void setIPAddresses(struct sockaddr_storage& addr) + { addr.ss_family = AF_INET6; } + + inline virtual Subscriber* clone() + { + return new ATLSubscriber(ID, mStateMachine, mLocAdapter, + mBackwardCompatibleMode); + } + inline virtual ~ATLSubscriber(){} +}; + +// WIFISubscriber, created with requests from MSAPM or QuIPC +struct WIFISubscriber : public Subscriber { + char * mSSID; + char * mPassword; + loc_if_req_sender_id_e_type senderId; + bool mIsInactive; + inline WIFISubscriber(const AgpsStateMachine* stateMachine, + char * ssid, char * password, loc_if_req_sender_id_e_type sender_id) : + Subscriber(sender_id, stateMachine), + mSSID(NULL == ssid ? NULL : new char[SSID_BUF_SIZE]), + mPassword(NULL == password ? NULL : new char[SSID_BUF_SIZE]), + senderId(sender_id) + { + if (NULL != mSSID) + strlcpy(mSSID, ssid, SSID_BUF_SIZE); + if (NULL != mPassword) + strlcpy(mPassword, password, SSID_BUF_SIZE); + mIsInactive = false; + } + + virtual bool notifyRsrcStatus(Notification ¬ification); + + inline virtual void setIPAddresses(uint32_t &v4, char* v6) {} + + inline virtual void setIPAddresses(struct sockaddr_storage& addr) + { addr.ss_family = AF_INET6; } + + inline virtual void setWifiInfo(char* ssid, char* password) + { + if (NULL != mSSID) + strlcpy(ssid, mSSID, SSID_BUF_SIZE); + else + ssid[0] = '\0'; + if (NULL != mPassword) + strlcpy(password, mPassword, SSID_BUF_SIZE); + else + password[0] = '\0'; + } + + inline virtual bool waitForCloseComplete() { return true; } + + inline virtual void setInactive() { mIsInactive = true; } + inline virtual bool isInactive() { return mIsInactive; } + + virtual Subscriber* clone() + { + return new WIFISubscriber(mStateMachine, mSSID, mPassword, senderId); + } + inline virtual ~WIFISubscriber(){} +}; + +struct DSSubscriber : public Subscriber { + bool mIsInactive; + inline DSSubscriber(const AgpsStateMachine *stateMachine, + const int id) : + Subscriber(id, stateMachine) + { + mIsInactive = false; + } + inline virtual void setIPAddresses(uint32_t &v4, char* v6) {} + inline virtual void setIPAddresses(struct sockaddr_storage& addr) + { addr.ss_family = AF_INET6; } + virtual Subscriber* clone() + {return new DSSubscriber(mStateMachine, ID);} + virtual bool notifyRsrcStatus(Notification ¬ification); + inline virtual bool waitForCloseComplete() { return true; } + virtual void setInactive(); + inline virtual bool isInactive() + { return mIsInactive; } + inline virtual ~DSSubscriber(){} + inline virtual char *whoami() {return (char*)"DSSubscriber";} +}; + +#endif //__LOC_ENG_AGPS_H__ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn.cpp b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn.cpp new file mode 100644 index 0000000..c257dff --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn.cpp @@ -0,0 +1,270 @@ +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "log_util.h" +#include "platform_lib_includes.h" +#include "loc_eng_dmn_conn_glue_msg.h" +#include "loc_eng_dmn_conn_handler.h" +#include "loc_eng_dmn_conn.h" +#include "loc_eng_msg.h" + +static int loc_api_server_msgqid; +static int loc_api_resp_msgqid; +static int quipc_msgqid; +static int msapm_msgqid; +static int msapu_msgqid; + +static const char * global_loc_api_q_path = GPSONE_LOC_API_Q_PATH; +static const char * global_loc_api_resp_q_path = GPSONE_LOC_API_RESP_Q_PATH; +static const char * global_quipc_ctrl_q_path = QUIPC_CTRL_Q_PATH; +static const char * global_msapm_ctrl_q_path = MSAPM_CTRL_Q_PATH; +static const char * global_msapu_ctrl_q_path = MSAPU_CTRL_Q_PATH; + +static int loc_api_server_proc_init(void *context) +{ + loc_api_server_msgqid = loc_eng_dmn_conn_glue_msgget(global_loc_api_q_path, O_RDWR); + //change mode/group for the global_loc_api_q_path pipe + int result = chmod (global_loc_api_q_path, 0660); + if (result != 0) + { + LOC_LOGE("failed to change mode for %s, error = %s\n", global_loc_api_q_path, strerror(errno)); + } + + struct group * gps_group = getgrnam("gps"); + if (gps_group != NULL) + { + result = chown (global_loc_api_q_path, -1, gps_group->gr_gid); + if (result != 0) + { + LOC_LOGE("chown for pipe failed, pipe %s, gid = %d, result = %d, error = %s\n", + global_loc_api_q_path, gps_group->gr_gid, result, strerror(errno)); + } + } + else + { + LOC_LOGE("getgrnam for gps failed, error code = %d\n", errno); + } + + loc_api_resp_msgqid = loc_eng_dmn_conn_glue_msgget(global_loc_api_resp_q_path, O_RDWR); + + //change mode/group for the global_loc_api_resp_q_path pipe + result = chmod (global_loc_api_resp_q_path, 0660); + if (result != 0) + { + LOC_LOGE("failed to change mode for %s, error = %s\n", global_loc_api_resp_q_path, strerror(errno)); + } + + if (gps_group != NULL) + { + result = chown (global_loc_api_resp_q_path, -1, gps_group->gr_gid); + if (result != 0) + { + LOC_LOGE("chown for pipe failed, pipe %s, gid = %d, result = %d, error = %s\n", + global_loc_api_resp_q_path, + gps_group->gr_gid, result, strerror(errno)); + } + } + + quipc_msgqid = loc_eng_dmn_conn_glue_msgget(global_quipc_ctrl_q_path, O_RDWR); + msapm_msgqid = loc_eng_dmn_conn_glue_msgget(global_msapm_ctrl_q_path , O_RDWR); + msapu_msgqid = loc_eng_dmn_conn_glue_msgget(global_msapu_ctrl_q_path , O_RDWR); + + LOC_LOGD("%s:%d] loc_api_server_msgqid = %d\n", __func__, __LINE__, loc_api_server_msgqid); + return 0; +} + +static int loc_api_server_proc_pre(void *context) +{ + return 0; +} + +static int loc_api_server_proc(void *context) +{ + int length, sz; + int result = 0; + static int cnt = 0; + struct ctrl_msgbuf * p_cmsgbuf; + struct ctrl_msgbuf cmsg_resp; + + sz = sizeof(struct ctrl_msgbuf) + 256; + p_cmsgbuf = (struct ctrl_msgbuf *) malloc(sz); + + if (!p_cmsgbuf) { + LOC_LOGE("%s:%d] Out of memory\n", __func__, __LINE__); + return -1; + } + + cnt ++; + LOC_LOGD("%s:%d] %d listening on %s...\n", __func__, __LINE__, cnt, (char *) context); + length = loc_eng_dmn_conn_glue_msgrcv(loc_api_server_msgqid, p_cmsgbuf, sz); + if (length <= 0) { + free(p_cmsgbuf); + LOC_LOGE("%s:%d] fail receiving msg from gpsone_daemon, retry later\n", __func__, __LINE__); + usleep(1000); + return -1; + } + + LOC_LOGD("%s:%d] received ctrl_type = %d\n", __func__, __LINE__, p_cmsgbuf->ctrl_type); + switch(p_cmsgbuf->ctrl_type) { + case GPSONE_LOC_API_IF_REQUEST: + result = loc_eng_dmn_conn_loc_api_server_if_request_handler(p_cmsgbuf, length); + break; + + case GPSONE_LOC_API_IF_RELEASE: + result = loc_eng_dmn_conn_loc_api_server_if_release_handler(p_cmsgbuf, length); + break; + + case GPSONE_UNBLOCK: + LOC_LOGD("%s:%d] GPSONE_UNBLOCK\n", __func__, __LINE__); + break; + + default: + LOC_LOGE("%s:%d] unsupported ctrl_type = %d\n", + __func__, __LINE__, p_cmsgbuf->ctrl_type); + break; + } + + free(p_cmsgbuf); + return 0; +} + +static int loc_api_server_proc_post(void *context) +{ + LOC_LOGD("%s:%d]\n", __func__, __LINE__); + loc_eng_dmn_conn_glue_msgremove( global_loc_api_q_path, loc_api_server_msgqid); + loc_eng_dmn_conn_glue_msgremove( global_loc_api_resp_q_path, loc_api_resp_msgqid); + loc_eng_dmn_conn_glue_msgremove( global_quipc_ctrl_q_path, quipc_msgqid); + loc_eng_dmn_conn_glue_msgremove( global_msapm_ctrl_q_path, msapm_msgqid); + loc_eng_dmn_conn_glue_msgremove( global_msapu_ctrl_q_path, msapu_msgqid); + return 0; +} + +static int loc_eng_dmn_conn_unblock_proc(void) +{ + struct ctrl_msgbuf cmsgbuf; + cmsgbuf.ctrl_type = GPSONE_UNBLOCK; + LOC_LOGD("%s:%d]\n", __func__, __LINE__); + loc_eng_dmn_conn_glue_msgsnd(loc_api_server_msgqid, & cmsgbuf, sizeof(cmsgbuf)); + return 0; +} + +static struct loc_eng_dmn_conn_thelper thelper; + +int loc_eng_dmn_conn_loc_api_server_launch(thelper_create_thread create_thread_cb, + const char * loc_api_q_path, const char * resp_q_path, void *agps_handle) +{ + int result; + + loc_api_handle = agps_handle; + + if (loc_api_q_path) global_loc_api_q_path = loc_api_q_path; + if (resp_q_path) global_loc_api_resp_q_path = resp_q_path; + + result = loc_eng_dmn_conn_launch_thelper( &thelper, + loc_api_server_proc_init, + loc_api_server_proc_pre, + loc_api_server_proc, + loc_api_server_proc_post, + create_thread_cb, + (char *) global_loc_api_q_path); + if (result != 0) { + LOC_LOGE("%s:%d]\n", __func__, __LINE__); + return -1; + } + return 0; +} + +int loc_eng_dmn_conn_loc_api_server_unblock(void) +{ + loc_eng_dmn_conn_unblock_thelper(&thelper); + loc_eng_dmn_conn_unblock_proc(); + return 0; +} + +int loc_eng_dmn_conn_loc_api_server_join(void) +{ + loc_eng_dmn_conn_join_thelper(&thelper); + return 0; +} + +int loc_eng_dmn_conn_loc_api_server_data_conn(int sender_id, int status) { + struct ctrl_msgbuf cmsgbuf; + LOC_LOGD("%s:%d] quipc_msgqid = %d\n", __func__, __LINE__, quipc_msgqid); + cmsgbuf.ctrl_type = GPSONE_LOC_API_RESPONSE; + cmsgbuf.cmsg.cmsg_response.result = status; + switch (sender_id) { + case LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC: { + LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC", __func__, __LINE__); + if (loc_eng_dmn_conn_glue_msgsnd(quipc_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { + LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); + return -1; + } + break; + } + case LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM: { + LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM", __func__, __LINE__); + if (loc_eng_dmn_conn_glue_msgsnd(msapm_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { + LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); + return -1; + } + break; + } + case LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU: { + LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU", __func__, __LINE__); + if (loc_eng_dmn_conn_glue_msgsnd(msapu_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { + LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); + return -1; + } + break; + } + case LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON: { + LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON", __func__, __LINE__); + if (loc_eng_dmn_conn_glue_msgsnd(loc_api_resp_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { + LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); + return -1; + } + break; + } + default: { + LOC_LOGD("%s:%d] invalid sender ID!", __func__, __LINE__); + } + } + return 0; +} + diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn.h b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn.h new file mode 100644 index 0000000..1d8c142 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2011-2012,2014 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_ENG_DATA_SERVER_H +#define LOC_ENG_DATA_SERVER_H + +#include "loc_eng_dmn_conn_thread_helper.h" + +#ifdef _ANDROID_ + +#define GPSONE_LOC_API_Q_PATH "/data/misc/location/gpsone_d/gpsone_loc_api_q" +#define GPSONE_LOC_API_RESP_Q_PATH "/data/misc/location/gpsone_d/gpsone_loc_api_resp_q" +#define QUIPC_CTRL_Q_PATH "/data/misc/location/gpsone_d/quipc_ctrl_q" +#define MSAPM_CTRL_Q_PATH "/data/misc/location/gpsone_d/msapm_ctrl_q" +#define MSAPU_CTRL_Q_PATH "/data/misc/location/gpsone_d/msapu_ctrl_q" + +#else + +#define GPSONE_LOC_API_Q_PATH "/tmp/gpsone_loc_api_q" +#define GPSONE_LOC_API_RESP_Q_PATH "/tmp/gpsone_loc_api_resp_q" +#define QUIPC_CTRL_Q_PATH "/tmp/quipc_ctrl_q" +#define MSAPM_CTRL_Q_PATH "/tmp/msapm_ctrl_q" +#define MSAPU_CTRL_Q_PATH "/tmp/msapu_ctrl_q" + +#endif + +int loc_eng_dmn_conn_loc_api_server_launch(thelper_create_thread create_thread_cb, + const char * loc_api_q_path, const char * ctrl_q_path, void *agps_handle); +int loc_eng_dmn_conn_loc_api_server_unblock(void); +int loc_eng_dmn_conn_loc_api_server_join(void); +int loc_eng_dmn_conn_loc_api_server_data_conn(int, int); + +#endif /* LOC_ENG_DATA_SERVER_H */ + diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_msg.c b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_msg.c new file mode 100644 index 0000000..a1076ff --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_msg.c @@ -0,0 +1,223 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include + +#include + +#include "log_util.h" +#include "platform_lib_includes.h" +#include "loc_eng_dmn_conn_glue_msg.h" +#include "loc_eng_dmn_conn_handler.h" + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_msgget + +DESCRIPTION + This function get a message queue + + q_path - name path of the message queue + mode - + +DEPENDENCIES + None + +RETURN VALUE + message queue id + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_msgget(const char * q_path, int mode) +{ + int msgqid; + msgqid = loc_eng_dmn_conn_glue_pipeget(q_path, mode); + return msgqid; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_msgremove + +DESCRIPTION + remove a message queue + + q_path - name path of the message queue + msgqid - message queue id + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_msgremove(const char * q_path, int msgqid) +{ + int result; + result = loc_eng_dmn_conn_glue_piperemove(q_path, msgqid); + return result; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_msgsnd + +DESCRIPTION + Send a message + + msgqid - message queue id + msgp - pointer to the message to be sent + msgsz - size of the message + +DEPENDENCIES + None + +RETURN VALUE + number of bytes sent out or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_msgsnd(int msgqid, const void * msgp, size_t msgsz) +{ + int result; + struct ctrl_msgbuf *pmsg = (struct ctrl_msgbuf *) msgp; + pmsg->msgsz = msgsz; + + result = loc_eng_dmn_conn_glue_pipewrite(msgqid, msgp, msgsz); + if (result != (int) msgsz) { + LOC_LOGE("%s:%d] pipe broken %d, msgsz = %d\n", __func__, __LINE__, result, (int) msgsz); + return -1; + } + + return result; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_msgrcv + +DESCRIPTION + receive a message + + msgqid - message queue id + msgp - pointer to the buffer to hold the message + msgsz - size of the buffer + +DEPENDENCIES + None + +RETURN VALUE + number of bytes received or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_msgrcv(int msgqid, void *msgp, size_t msgbufsz) +{ + int result; + struct ctrl_msgbuf *pmsg = (struct ctrl_msgbuf *) msgp; + + result = loc_eng_dmn_conn_glue_piperead(msgqid, &(pmsg->msgsz), sizeof(pmsg->msgsz)); + if (result != sizeof(pmsg->msgsz)) { + LOC_LOGE("%s:%d] pipe broken %d\n", __func__, __LINE__, result); + return -1; + } + + if (msgbufsz < pmsg->msgsz) { + LOC_LOGE("%s:%d] msgbuf is too small %d < %d\n", __func__, __LINE__, (int) msgbufsz, (int) pmsg->msgsz); + return -1; + } + + result = loc_eng_dmn_conn_glue_piperead(msgqid, (uint8_t *) msgp + sizeof(pmsg->msgsz), pmsg->msgsz - sizeof(pmsg->msgsz)); + if (result != (int) (pmsg->msgsz - sizeof(pmsg->msgsz))) { + LOC_LOGE("%s:%d] pipe broken %d, msgsz = %d\n", __func__, __LINE__, result, (int) pmsg->msgsz); + return -1; + } + + return pmsg->msgsz; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_msgunblock + +DESCRIPTION + unblock a message queue + + msgqid - message queue id + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_msgunblock(int msgqid) +{ + return loc_eng_dmn_conn_glue_pipeunblock(msgqid); +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_msgflush + +DESCRIPTION + flush out the message in a queue + + msgqid - message queue id + +DEPENDENCIES + None + +RETURN VALUE + number of bytes that are flushed out. + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_msgflush(int msgqid) +{ + int length; + char buf[128]; + + do { + length = loc_eng_dmn_conn_glue_piperead(msgqid, buf, 128); + LOC_LOGD("%s:%d] %s\n", __func__, __LINE__, buf); + } while(length); + return length; +} + diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_msg.h b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_msg.h new file mode 100644 index 0000000..d685c87 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_msg.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_ENG_DMN_CONN_GLUE_MSG_H +#define LOC_ENG_DMN_CONN_GLUE_MSG_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#include +#include "loc_eng_dmn_conn_glue_pipe.h" + +int loc_eng_dmn_conn_glue_msgget(const char * q_path, int mode); +int loc_eng_dmn_conn_glue_msgremove(const char * q_path, int msgqid); +int loc_eng_dmn_conn_glue_msgsnd(int msgqid, const void * msgp, size_t msgsz); +int loc_eng_dmn_conn_glue_msgrcv(int msgqid, void *msgp, size_t msgsz); +int loc_eng_dmn_conn_glue_msgflush(int msgqid); +int loc_eng_dmn_conn_glue_msgunblock(int msgqid); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LOC_ENG_DMN_CONN_GLUE_MSG_H */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_pipe.c b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_pipe.c new file mode 100644 index 0000000..dffcad0 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_pipe.c @@ -0,0 +1,214 @@ +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include +#include + +// #include +#include +// #include +#include +#include + +#include "loc_eng_dmn_conn_glue_pipe.h" +#include "log_util.h" +#include "platform_lib_includes.h" +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_pipeget + +DESCRIPTION + create a named pipe. + + pipe_name - pipe name path + mode - mode + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_pipeget(const char * pipe_name, int mode) +{ + int fd; + int result; + + LOC_LOGD("%s, mode = %d\n", pipe_name, mode); + result = mkfifo(pipe_name, 0660); + + if ((result == -1) && (errno != EEXIST)) { + LOC_LOGE("failed: %s\n", strerror(errno)); + return result; + } + + // The mode in mkfifo is not honoured and does not provide the + // group permissions. Doing chmod to add group permissions. + result = chmod (pipe_name, 0660); + if (result != 0){ + LOC_LOGE ("%s failed to change mode for %s, error = %s\n", __func__, + pipe_name, strerror(errno)); + } + + fd = open(pipe_name, mode); + if (fd <= 0) + { + LOC_LOGE("failed: %s\n", strerror(errno)); + } + LOC_LOGD("fd = %d, %s\n", fd, pipe_name); + return fd; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_piperemove + +DESCRIPTION + remove a pipe + + pipe_name - pipe name path + fd - fd for the pipe + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_piperemove(const char * pipe_name, int fd) +{ + close(fd); + if (pipe_name) unlink(pipe_name); + LOC_LOGD("fd = %d, %s\n", fd, pipe_name); + return 0; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_pipewrite + +DESCRIPTION + write to a pipe + + fd - fd of a pipe + buf - buffer for the data to write + sz - size of the data in buffer + +DEPENDENCIES + None + +RETURN VALUE + number of bytes written or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_pipewrite(int fd, const void * buf, size_t sz) +{ + int result; + + result = write(fd, buf, sz); + + /* @todo check for non EINTR & EAGAIN, shall not do select again, select_tut Law 7) */ + + /* LOC_LOGD("fd = %d, buf = 0x%lx, size = %d, result = %d\n", fd, (long) buf, (int) sz, (int) result); */ + return result; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_piperead + +DESCRIPTION + read from a pipe + + fd - fd for the pipe + buf - buffer to hold the data read from pipe + sz - size of the buffer + +DEPENDENCIES + None + +RETURN VALUE + number of bytes read from pipe or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_piperead(int fd, void * buf, size_t sz) +{ + int len; + + len = read(fd, buf, sz); + + /* @todo check for non EINTR & EAGAIN, shall not do select again, select_tut Law 7) */ + + /* LOC_LOGD("fd = %d, buf = 0x%lx, size = %d, len = %d\n", fd, (long) buf, (int) sz, len); */ + return len; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_glue_pipeunblock + +DESCRIPTION + unblock a pipe + + fd - fd for the pipe + +DEPENDENCIES + None + +RETURN VALUE + 0 for success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_glue_pipeunblock(int fd) +{ + int result; + struct flock flock_v; + LOC_LOGD("\n"); +// result = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NDELAY); + flock_v.l_type = F_UNLCK; + flock_v.l_len = 32; + result = fcntl(fd, F_SETLK, &flock_v); + if (result < 0) { + LOC_LOGE("fcntl failure, %s\n", strerror(errno)); + } + + return result; +} diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_pipe.h b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_pipe.h new file mode 100644 index 0000000..b2fa3a0 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_glue_pipe.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_ENG_DMN_CONN_GLUE_PIPE_H +#define LOC_ENG_DMN_CONN_GLUE_PIPE_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +int loc_eng_dmn_conn_glue_pipeget(const char * pipe_name, int mode); +int loc_eng_dmn_conn_glue_piperemove(const char * pipe_name, int fd); +int loc_eng_dmn_conn_glue_pipewrite(int fd, const void * buf, size_t sz); +int loc_eng_dmn_conn_glue_piperead(int fd, void * buf, size_t sz); + +int loc_eng_dmn_conn_glue_pipeflush(int fd); +int loc_eng_dmn_conn_glue_pipeunblock(int fd); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LOC_ENG_DMN_CONN_GLUE_PIPE_H */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp new file mode 100644 index 0000000..edd53f2 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp @@ -0,0 +1,237 @@ +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include +#include +#include + +#include "log_util.h" +#include "platform_lib_includes.h" +#include "loc_eng_msg.h" +#include "loc_eng_dmn_conn.h" +#include "loc_eng_dmn_conn_handler.h" + +void* loc_api_handle = NULL; + +int loc_eng_dmn_conn_loc_api_server_if_request_handler(struct ctrl_msgbuf *pmsg, int len) +{ + LOC_LOGD("%s:%d]\n", __func__, __LINE__); +#ifndef DEBUG_DMN_LOC_API + if (NULL == loc_api_handle) { + LOC_LOGE("%s:%d] NO agps data handle\n", __func__, __LINE__); + return 1; + } + + if (NULL != loc_api_handle) { + AGpsExtType type; + switch (pmsg->cmsg.cmsg_if_request.type) { + case IF_REQUEST_TYPE_SUPL: + { + LOC_LOGD("IF_REQUEST_TYPE_SUPL"); + type = AGPS_TYPE_SUPL; + break; + } + case IF_REQUEST_TYPE_WIFI: + { + LOC_LOGD("IF_REQUEST_TYPE_WIFI"); + type = AGPS_TYPE_WIFI; + break; + } + case IF_REQUEST_TYPE_ANY: + { + LOC_LOGD("IF_REQUEST_TYPE_ANY"); + type = AGPS_TYPE_ANY; + break; + } + default: + { + LOC_LOGD("invalid IF_REQUEST_TYPE!"); + return -1; + } + } + switch (pmsg->cmsg.cmsg_if_request.sender_id) { + case IF_REQUEST_SENDER_ID_QUIPC: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_QUIPC"); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + true); + msg->send(); + break; + } + case IF_REQUEST_SENDER_ID_MSAPM: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPM"); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + true); + msg->send(); + break; + } + case IF_REQUEST_SENDER_ID_MSAPU: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPU"); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + true); + msg->send(); + break; + } + case IF_REQUEST_SENDER_ID_GPSONE_DAEMON: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_GPSONE_DAEMON"); + LocEngReqRelBIT* msg = + new LocEngReqRelBIT(loc_api_handle, + type, + pmsg->cmsg.cmsg_if_request.ipv4_addr, + (char*)pmsg->cmsg.cmsg_if_request.ipv6_addr, + true); + msg->send(); + break; + } + default: + { + LOC_LOGD("invalid IF_REQUEST_SENDER_ID!"); + return -1; + } + } + } + +#else + loc_eng_dmn_conn_loc_api_server_data_conn(LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, GPSONE_LOC_API_IF_REQUEST_SUCCESS); +#endif + return 0; +} + +int loc_eng_dmn_conn_loc_api_server_if_release_handler(struct ctrl_msgbuf *pmsg, int len) +{ + LOC_LOGD("%s:%d]\n", __func__, __LINE__); +#ifndef DEBUG_DMN_LOC_API + AGpsExtType type; + switch (pmsg->cmsg.cmsg_if_request.type) { + case IF_REQUEST_TYPE_SUPL: + { + LOC_LOGD("IF_REQUEST_TYPE_SUPL"); + type = AGPS_TYPE_SUPL; + break; + } + case IF_REQUEST_TYPE_WIFI: + { + LOC_LOGD("IF_REQUEST_TYPE_WIFI"); + type = AGPS_TYPE_WIFI; + break; + } + case IF_REQUEST_TYPE_ANY: + { + LOC_LOGD("IF_REQUEST_TYPE_ANY"); + type = AGPS_TYPE_ANY; + break; + } + default: + { + LOC_LOGD("invalid IF_REQUEST_TYPE!"); + return -1; + } + } + switch (pmsg->cmsg.cmsg_if_request.sender_id) { + case IF_REQUEST_SENDER_ID_QUIPC: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_QUIPC"); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + false); + msg->send(); + break; + } + case IF_REQUEST_SENDER_ID_MSAPM: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPM"); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + false); + msg->send(); + break; + } + case IF_REQUEST_SENDER_ID_MSAPU: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPU"); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + false); + msg->send(); + break; + } + case IF_REQUEST_SENDER_ID_GPSONE_DAEMON: + { + LOC_LOGD("IF_REQUEST_SENDER_ID_GPSONE_DAEMON"); + LocEngReqRelBIT* msg = + new LocEngReqRelBIT(loc_api_handle, + type, + pmsg->cmsg.cmsg_if_request.ipv4_addr, + (char*)pmsg->cmsg.cmsg_if_request.ipv6_addr, + false); + msg->send(); + break; + } + default: + { + LOC_LOGD("invalid IF_REQUEST_SENDER_ID!"); + return -1; + } + } +#else + loc_eng_dmn_conn_loc_api_server_data_conn(LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, GPSONE_LOC_API_IF_RELEASE_SUCCESS); +#endif + return 0; +} + diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.h b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.h new file mode 100644 index 0000000..1c0edd5 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.h @@ -0,0 +1,106 @@ +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_ENG_DATA_SERVER_HANDLER +#define LOC_ENG_DATA_SERVER_HANDLER + +#include +#include + +//for SSID_BUF_SIZE +#include + +#ifndef SSID_BUF_SIZE + #define SSID_BUF_SIZE (32+1) +#endif + +enum { + /* 0x0 - 0xEF is reserved for daemon internal */ + GPSONE_LOC_API_IF_REQUEST = 0xF0, + GPSONE_LOC_API_IF_RELEASE, + GPSONE_LOC_API_RESPONSE, + GPSONE_UNBLOCK, +}; + +enum { + GPSONE_LOC_API_IF_REQUEST_SUCCESS = 0xF0, + GPSONE_LOC_API_IF_RELEASE_SUCCESS, + GPSONE_LOC_API_IF_FAILURE, +}; + + +struct ctrl_msg_response { + int result; +}; + +struct ctrl_msg_unblock { + int reserved; +}; + +typedef enum { + IF_REQUEST_TYPE_SUPL = 0, + IF_REQUEST_TYPE_WIFI, + IF_REQUEST_TYPE_ANY +} ctrl_if_req_type_e_type; + +typedef enum { + IF_REQUEST_SENDER_ID_QUIPC = 0, + IF_REQUEST_SENDER_ID_MSAPM, + IF_REQUEST_SENDER_ID_MSAPU, + IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + IF_REQUEST_SENDER_ID_MODEM +} ctrl_if_req_sender_id_e_type; + +struct ctrl_msg_if_request { + ctrl_if_req_type_e_type type; + ctrl_if_req_sender_id_e_type sender_id; + unsigned long ipv4_addr; + unsigned char ipv6_addr[16]; + char ssid[SSID_BUF_SIZE]; + char password[SSID_BUF_SIZE]; +}; + +/* do not change this structure */ +struct ctrl_msgbuf { + size_t msgsz; + uint16_t reserved1; + uint32_t reserved2; + uint8_t ctrl_type; + union { + struct ctrl_msg_response cmsg_response; + struct ctrl_msg_unblock cmsg_unblock; + struct ctrl_msg_if_request cmsg_if_request; + } cmsg; +}; + +extern void* loc_api_handle; + +int loc_eng_dmn_conn_loc_api_server_if_request_handler(struct ctrl_msgbuf *pmsg, int len); +int loc_eng_dmn_conn_loc_api_server_if_release_handler(struct ctrl_msgbuf *pmsg, int len); + +#endif /* LOC_ENG_DATA_SERVER_HANDLER */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_thread_helper.c b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_thread_helper.c new file mode 100644 index 0000000..9fed9d4 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_thread_helper.c @@ -0,0 +1,399 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include + +#include "log_util.h" +#include "platform_lib_includes.h" +#include "loc_eng_dmn_conn_thread_helper.h" + +/*=========================================================================== +FUNCTION thelper_signal_init + +DESCRIPTION + This function will initialize the conditional variable resources. + + thelper - thelper instance + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int thelper_signal_init(struct loc_eng_dmn_conn_thelper * thelper) +{ + int result; + thelper->thread_exit = 0; + thelper->thread_ready = 0; + result = pthread_cond_init( &thelper->thread_cond, NULL); + if (result) { + return result; + } + + result = pthread_mutex_init(&thelper->thread_mutex, NULL); + if (result) { + pthread_cond_destroy(&thelper->thread_cond); + } + return result; +} + +/*=========================================================================== +FUNCTION + +DESCRIPTION + This function will destroy the conditional variable resources + + thelper - pointer to thelper instance + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int thelper_signal_destroy(struct loc_eng_dmn_conn_thelper * thelper) +{ + int result, ret_result = 0; + result = pthread_cond_destroy( &thelper->thread_cond); + if (result) { + ret_result = result; + } + + result = pthread_mutex_destroy(&thelper->thread_mutex); + if (result) { + ret_result = result; + } + + return ret_result; +} + +/*=========================================================================== +FUNCTION thelper_signal_wait + +DESCRIPTION + This function will be blocked on the conditional variable until thelper_signal_ready + is called + + thelper - pointer to thelper instance + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int thelper_signal_wait(struct loc_eng_dmn_conn_thelper * thelper) +{ + int result = 0; + + pthread_mutex_lock(&thelper->thread_mutex); + if (!thelper->thread_ready && !thelper->thread_exit) { + result = pthread_cond_wait(&thelper->thread_cond, &thelper->thread_mutex); + } + + if (thelper->thread_exit) { + result = -1; + } + pthread_mutex_unlock(&thelper->thread_mutex); + + return result; +} + +/*=========================================================================== +FUNCTION thelper_signal_ready + +DESCRIPTION + This function will wake up the conditional variable + + thelper - pointer to thelper instance + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int thelper_signal_ready(struct loc_eng_dmn_conn_thelper * thelper) +{ + int result; + + LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + + pthread_mutex_lock(&thelper->thread_mutex); + thelper->thread_ready = 1; + result = pthread_cond_signal(&thelper->thread_cond); + pthread_mutex_unlock(&thelper->thread_mutex); + + return result; +} + +/*=========================================================================== +FUNCTION thelper_signal_block + +DESCRIPTION + This function will set the thread ready to 0 to block the thelper_signal_wait + + thelper - pointer to thelper instance + +DEPENDENCIES + None + +RETURN VALUE + if thread_ready is set + +SIDE EFFECTS + N/A + +===========================================================================*/ +int thelper_signal_block(struct loc_eng_dmn_conn_thelper * thelper) +{ + int result = thelper->thread_ready; + + LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + + pthread_mutex_lock(&thelper->thread_mutex); + thelper->thread_ready = 0; + pthread_mutex_unlock(&thelper->thread_mutex); + + return result; +} + +/*=========================================================================== +FUNCTION thelper_main + +DESCRIPTION + This function is the main thread. It will be launched as a child thread + + data - pointer to the instance + +DEPENDENCIES + None + +RETURN VALUE + NULL + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void * thelper_main(void *data) +{ + int result = 0; + struct loc_eng_dmn_conn_thelper * thelper = (struct loc_eng_dmn_conn_thelper *) data; + + if (thelper->thread_proc_init) { + result = thelper->thread_proc_init(thelper->thread_context); + if (result < 0) { + thelper->thread_exit = 1; + thelper_signal_ready(thelper); + LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper); + return NULL; + } + } + + thelper_signal_ready(thelper); + + if (thelper->thread_proc_pre) { + result = thelper->thread_proc_pre(thelper->thread_context); + if (result < 0) { + thelper->thread_exit = 1; + LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper); + return NULL; + } + } + + do { + if (thelper->thread_proc) { + result = thelper->thread_proc(thelper->thread_context); + if (result < 0) { + thelper->thread_exit = 1; + LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper); + } + } + } while (thelper->thread_exit == 0); + + if (thelper->thread_proc_post) { + result = thelper->thread_proc_post(thelper->thread_context); + } + + if (result != 0) { + LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper); + } + return NULL; +} + +static void thelper_main_2(void *data) +{ + thelper_main(data); + return; +} + + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_launch_thelper + +DESCRIPTION + This function will initialize the thread context and launch the thelper_main + + thelper - pointer to thelper instance + thread_proc_init - The initialization function pointer + thread_proc_pre - The function to call before task loop and after initialization + thread_proc - The task loop + thread_proc_post - The function to call after the task loop + context - the context for the above four functions + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_launch_thelper(struct loc_eng_dmn_conn_thelper * thelper, + int (*thread_proc_init) (void * context), + int (*thread_proc_pre) (void * context), + int (*thread_proc) (void * context), + int (*thread_proc_post) (void * context), + thelper_create_thread create_thread_cb, + void * context) +{ + int result; + + thelper_signal_init(thelper); + + if (context) { + thelper->thread_context = context; + } + + thelper->thread_proc_init = thread_proc_init; + thelper->thread_proc_pre = thread_proc_pre; + thelper->thread_proc = thread_proc; + thelper->thread_proc_post = thread_proc_post; + + LOC_LOGD("%s:%d] 0x%lx call pthread_create\n", __func__, __LINE__, (long) thelper); + if (create_thread_cb) { + result = 0; + thelper->thread_id = create_thread_cb("loc_eng_dmn_conn", + thelper_main_2, (void *)thelper); + } else { + result = pthread_create(&thelper->thread_id, NULL, + thelper_main, (void *)thelper); + } + + if (result != 0) { + LOC_LOGE("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + return -1; + } + + LOC_LOGD("%s:%d] 0x%lx pthread_create done\n", __func__, __LINE__, (long) thelper); + + thelper_signal_wait(thelper); + + LOC_LOGD("%s:%d] 0x%lx pthread ready\n", __func__, __LINE__, (long) thelper); + return thelper->thread_exit; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_unblock_thelper + +DESCRIPTION + This function unblocks thelper_main to release the thread + + thelper - pointer to thelper instance + +DEPENDENCIES + None + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_unblock_thelper(struct loc_eng_dmn_conn_thelper * thelper) +{ + LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + thelper->thread_exit = 1; + return 0; +} + +/*=========================================================================== +FUNCTION loc_eng_dmn_conn_join_thelper + + thelper - pointer to thelper instance + +DESCRIPTION + This function will wait for the thread of thelper_main to finish + +DEPENDENCIES + None + +RETURN VALUE + 0: success or negative value for failure + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_dmn_conn_join_thelper(struct loc_eng_dmn_conn_thelper * thelper) +{ + int result; + + LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + result = pthread_join(thelper->thread_id, NULL); + if (result != 0) { + LOC_LOGE("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + } + LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper); + + thelper_signal_destroy(thelper); + + return result; +} + diff --git a/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_thread_helper.h b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_thread_helper.h new file mode 100644 index 0000000..89e598b --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_dmn_conn_thread_helper.h @@ -0,0 +1,74 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_ENG_DMN_CONN_THREAD_HELPER_H__ +#define __LOC_ENG_DMN_CONN_THREAD_HELPER_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +struct loc_eng_dmn_conn_thelper { + unsigned char thread_exit; + unsigned char thread_ready; + pthread_cond_t thread_cond; + pthread_mutex_t thread_mutex; + pthread_t thread_id; + void * thread_context; + int (*thread_proc_init) (void * context); + int (*thread_proc_pre) (void * context); + int (*thread_proc) (void * context); + int (*thread_proc_post) (void * context); +}; + +typedef pthread_t (* thelper_create_thread)(const char* name, void (*start)(void *), void* arg); +int loc_eng_dmn_conn_launch_thelper(struct loc_eng_dmn_conn_thelper * thelper, + int (*thread_proc_init) (void * context), + int (*thread_proc_pre) (void * context), + int (*thread_proc) (void * context), + int (*thread_proc_post) (void * context), + thelper_create_thread create_thread_cb, + void * context); + +int loc_eng_dmn_conn_unblock_thelper(struct loc_eng_dmn_conn_thelper * thelper); +int loc_eng_dmn_conn_join_thelper(struct loc_eng_dmn_conn_thelper * thelper); + +/* if only need to use signal */ +int thelper_signal_init(struct loc_eng_dmn_conn_thelper * thelper); +int thelper_signal_destroy(struct loc_eng_dmn_conn_thelper * thelper); +int thelper_signal_wait(struct loc_eng_dmn_conn_thelper * thelper); +int thelper_signal_ready(struct loc_eng_dmn_conn_thelper * thelper); +int thelper_signal_block(struct loc_eng_dmn_conn_thelper * thelper); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LOC_ENG_DMN_CONN_THREAD_HELPER_H__ */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_log.cpp b/gps/loc_api/libloc_api_50001/loc_eng_log.cpp new file mode 100644 index 0000000..3a34167 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_log.cpp @@ -0,0 +1,35 @@ +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_eng" + +#include "loc_log.h" +#include "loc_eng_log.h" + diff --git a/gps/loc_api/libloc_api_50001/loc_eng_log.h b/gps/loc_api/libloc_api_50001/loc_eng_log.h new file mode 100644 index 0000000..a68bd84 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_log.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ENG_LOG_H +#define LOC_ENG_LOG_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +#ifdef __cplusplus +} +#endif + +#endif /* LOC_ENG_LOG_H */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_msg.h b/gps/loc_api/libloc_api_50001/loc_eng_msg.h new file mode 100644 index 0000000..3bff162 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_msg.h @@ -0,0 +1,306 @@ +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_ENG_MSG_H +#define LOC_ENG_MSG_H + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef SSID_BUF_SIZE + #define SSID_BUF_SIZE (32+1) +#endif +#ifdef USE_GLIB + +#include + +#endif /* USE_GLIB */ +#include "platform_lib_includes.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +using namespace loc_core; + +struct LocEngPositionMode : public LocMsg { + LocEngAdapter* mAdapter; + const LocPosMode mPosMode; + LocEngPositionMode(LocEngAdapter* adapter, LocPosMode &mode); + virtual void proc() const; + virtual void log() const; + void send() const; +}; + + +struct LocEngStartFix : public LocMsg { + LocEngAdapter* mAdapter; + LocEngStartFix(LocEngAdapter* adapter); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngStopFix : public LocMsg { + LocEngAdapter* mAdapter; + LocEngStopFix(LocEngAdapter* adapter); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngReportPosition : public LocMsg { + LocAdapterBase* mAdapter; + const UlpLocation mLocation; + const GpsLocationExtended mLocationExtended; + const void* mLocationExt; + const enum loc_sess_status mStatus; + const LocPosTechMask mTechMask; + LocEngReportPosition(LocAdapterBase* adapter, + UlpLocation &loc, + GpsLocationExtended &locExtended, + void* locExt, + enum loc_sess_status st, + LocPosTechMask technology); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngReportSv : public LocMsg { + LocAdapterBase* mAdapter; + const HaxxSvStatus mSvStatus; + const GpsLocationExtended mLocationExtended; + const void* mSvExt; + LocEngReportSv(LocAdapterBase* adapter, + HaxxSvStatus &sv, + GpsLocationExtended &locExtended, + void* svExtended); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngReportStatus : public LocMsg { + LocAdapterBase* mAdapter; + const GpsStatusValue mStatus; + LocEngReportStatus(LocAdapterBase* adapter, + GpsStatusValue engineStatus); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngReportNmea : public LocMsg { + void* mLocEng; + char* const mNmea; + const int mLen; + LocEngReportNmea(void* locEng, + const char* data, int len); + inline virtual ~LocEngReportNmea() + { + delete[] mNmea; + } + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngReportXtraServer : public LocMsg { + void* mLocEng; + int mMaxLen; + char *mServers; + LocEngReportXtraServer(void* locEng, + const char *url1, const char *url2, + const char *url3, const int maxlength); + inline virtual ~LocEngReportXtraServer() + { + delete[] mServers; + } + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngSuplEsOpened : public LocMsg { + void* mLocEng; + LocEngSuplEsOpened(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngSuplEsClosed : public LocMsg { + void* mLocEng; + LocEngSuplEsClosed(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestSuplEs : public LocMsg { + void* mLocEng; + const int mID; + LocEngRequestSuplEs(void* locEng, int id); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestATL : public LocMsg { + void* mLocEng; + const int mID; + const AGpsExtType mType; + LocEngRequestATL(void* locEng, int id, + AGpsExtType agps_type); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngReleaseATL : public LocMsg { + void* mLocEng; + const int mID; + LocEngReleaseATL(void* locEng, int id); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngReqRelBIT : public LocMsg { + void* mLocEng; + const AGpsExtType mType; + const int mIPv4Addr; + char* const mIPv6Addr; + const bool mIsReq; + LocEngReqRelBIT(void* instance, AGpsExtType type, + int ipv4, char* ipv6, bool isReq); + virtual ~LocEngReqRelBIT(); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngReqRelWifi : public LocMsg { + void* mLocEng; + const AGpsExtType mType; + const loc_if_req_sender_id_e_type mSenderId; + char* const mSSID; + char* const mPassword; + const bool mIsReq; + LocEngReqRelWifi(void* locEng, AGpsExtType type, + loc_if_req_sender_id_e_type sender_id, + char* s, char* p, bool isReq); + virtual ~LocEngReqRelWifi(); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngRequestXtra : public LocMsg { + void* mLocEng; + LocEngRequestXtra(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestTime : public LocMsg { + void* mLocEng; + LocEngRequestTime(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestNi : public LocMsg { + void* mLocEng; + const GpsNiNotification mNotify; + const void *mPayload; + LocEngRequestNi(void* locEng, + GpsNiNotification ¬if, + const void* data); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngDown : public LocMsg { + void* mLocEng; + LocEngDown(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngUp : public LocMsg { + void* mLocEng; + LocEngUp(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngGetZpp : public LocMsg { + LocEngAdapter* mAdapter; + LocEngGetZpp(LocEngAdapter* adapter); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngReportGpsMeasurement : public LocMsg { + void* mLocEng; + const GpsData mGpsData; + LocEngReportGpsMeasurement(void* locEng, + GpsData &gpsData); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LOC_ENG_MSG_H */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_ni.cpp b/gps/loc_api/libloc_api_50001/loc_eng_ni.cpp new file mode 100644 index 0000000..4597b98 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_ni.cpp @@ -0,0 +1,414 @@ +/* Copyright (c) 2009-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_eng" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "log_util.h" +#include "platform_lib_includes.h" + +using namespace loc_core; + +/*============================================================================= + * + * DATA DECLARATION + * + *============================================================================*/ + +/*============================================================================= + * + * FUNCTION DECLARATIONS + * + *============================================================================*/ +static void* ni_thread_proc(void *args); + +struct LocEngInformNiResponse : public LocMsg { + LocEngAdapter* mAdapter; + const GpsUserResponseType mResponse; + const void *mPayload; + inline LocEngInformNiResponse(LocEngAdapter* adapter, + GpsUserResponseType resp, + const void* data) : + LocMsg(), mAdapter(adapter), + mResponse(resp), mPayload(data) + { + locallog(); + } + inline ~LocEngInformNiResponse() + { + // this is a bit weird since mPayload is not + // allocated by this class. But there is no better way. + // mPayload actually won't be NULL here. + free((void*)mPayload); + } + inline virtual void proc() const + { + mAdapter->informNiResponse(mResponse, mPayload); + } + inline void locallog() const + { + LOC_LOGV("LocEngInformNiResponse - " + "response: %s\n mPayload: %p", + loc_get_ni_response_name(mResponse), + mPayload); + } + inline virtual void log() const + { + locallog(); + } +}; + +/*=========================================================================== + +FUNCTION loc_eng_ni_request_handler + +DESCRIPTION + Displays the NI request and awaits user input. If a previous request is + in session, it is ignored. + +RETURN VALUE + none + +===========================================================================*/ +void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data, + const GpsNiNotification *notif, + const void* passThrough) +{ + ENTRY_LOG(); + char lcs_addr[32]; // Decoded LCS address for UMTS CP NI + loc_eng_ni_data_s_type* loc_eng_ni_data_p = &loc_eng_data.loc_eng_ni_data; + loc_eng_ni_session_s_type* pSession = NULL; + + if (NULL == loc_eng_data.ni_notify_cb) { + EXIT_LOG(%s, "loc_eng_ni_init hasn't happened yet."); + return; + } + + if (notif->ni_type == GPS_NI_TYPE_EMERGENCY_SUPL) { + if (NULL != loc_eng_ni_data_p->sessionEs.rawRequest) { + LOC_LOGW("loc_eng_ni_request_handler, supl es NI in progress, new supl es NI ignored, type: %d", + notif->ni_type); + if (NULL != passThrough) { + free((void*)passThrough); + } + } else { + pSession = &loc_eng_ni_data_p->sessionEs; + } + } else { + if (NULL != loc_eng_ni_data_p->session.rawRequest || + NULL != loc_eng_ni_data_p->sessionEs.rawRequest) { + LOC_LOGW("loc_eng_ni_request_handler, supl NI in progress, new supl NI ignored, type: %d", + notif->ni_type); + if (NULL != passThrough) { + free((void*)passThrough); + } + } else { + pSession = &loc_eng_ni_data_p->session; + } + } + + + if (pSession) { + /* Save request */ + pSession->rawRequest = (void*)passThrough; + pSession->reqID = ++loc_eng_ni_data_p->reqIDCounter; + pSession->adapter = loc_eng_data.adapter; + + /* Fill in notification */ + ((GpsNiNotification*)notif)->notification_id = pSession->reqID; + + if (notif->notify_flags == GPS_NI_PRIVACY_OVERRIDE) + { + loc_eng_mute_one_session(loc_eng_data); + } + + /* Log requestor ID and text for debugging */ + LOC_LOGI("Notification: notif_type: %d, timeout: %d, default_resp: %d", notif->ni_type, notif->timeout, notif->default_response); + LOC_LOGI(" requestor_id: %s (encoding: %d)", notif->requestor_id, notif->requestor_id_encoding); + LOC_LOGI(" text: %s text (encoding: %d)", notif->text, notif->text_encoding); + if (notif->extras[0]) + { + LOC_LOGI(" extras: %s", notif->extras); + } + + /* For robustness, spawn a thread at this point to timeout to clear up the notification status, even though + * the OEM layer in java does not do so. + **/ + pSession->respTimeLeft = 5 + (notif->timeout != 0 ? notif->timeout : LOC_NI_NO_RESPONSE_TIME); + LOC_LOGI("Automatically sends 'no response' in %d seconds (to clear status)\n", pSession->respTimeLeft); + + int rc = 0; + rc = pthread_create(&pSession->thread, NULL, ni_thread_proc, pSession); + if (rc) + { + LOC_LOGE("Loc NI thread is not created.\n"); + } + rc = pthread_detach(pSession->thread); + if (rc) + { + LOC_LOGE("Loc NI thread is not detached.\n"); + } + + CALLBACK_LOG_CALLFLOW("ni_notify_cb - id", %d, notif->notification_id); + loc_eng_data.ni_notify_cb((GpsNiNotification*)notif); + } + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== + +FUNCTION ni_thread_proc + +===========================================================================*/ +static void* ni_thread_proc(void *args) +{ + ENTRY_LOG(); + + loc_eng_ni_session_s_type* pSession = (loc_eng_ni_session_s_type*)args; + int rc = 0; /* return code from pthread calls */ + + struct timeval present_time; + struct timespec expire_time; + + LOC_LOGD("Starting Loc NI thread...\n"); + pthread_mutex_lock(&pSession->tLock); + /* Calculate absolute expire time */ + gettimeofday(&present_time, NULL); + expire_time.tv_sec = present_time.tv_sec + pSession->respTimeLeft; + expire_time.tv_nsec = present_time.tv_usec * 1000; + LOC_LOGD("ni_thread_proc-Time out set for abs time %ld with delay %d sec\n", + (long) expire_time.tv_sec, pSession->respTimeLeft ); + + while (!pSession->respRecvd) + { + rc = pthread_cond_timedwait(&pSession->tCond, + &pSession->tLock, + &expire_time); + if (rc == ETIMEDOUT) + { + pSession->resp = GPS_NI_RESPONSE_NORESP; + LOC_LOGD("ni_thread_proc-Thread time out after valting for specified time. Ret Val %d\n",rc ); + break; + } + } + LOC_LOGD("ni_thread_proc-Java layer has sent us a user response and return value from " + "pthread_cond_timedwait = %d\n",rc ); + pSession->respRecvd = FALSE; /* Reset the user response flag for the next session*/ + + LOC_LOGD("pSession->resp is %d\n",pSession->resp); + + // adding this check to support modem restart, in which case, we need the thread + // to exit without calling sending data. We made sure that rawRequest is NULL in + // loc_eng_ni_reset_on_engine_restart() + LocEngAdapter* adapter = pSession->adapter; + LocEngInformNiResponse *msg = NULL; + + if (NULL != pSession->rawRequest) { + if (pSession->resp != GPS_NI_RESPONSE_IGNORE) { + LOC_LOGD("pSession->resp != GPS_NI_RESPONSE_IGNORE \n"); + msg = new LocEngInformNiResponse(adapter, + pSession->resp, + pSession->rawRequest); + } else { + LOC_LOGD("this is the ignore reply for SUPL ES\n"); + free(pSession->rawRequest); + } + pSession->rawRequest = NULL; + } + pthread_mutex_unlock(&pSession->tLock); + + pSession->respTimeLeft = 0; + pSession->reqID = 0; + + if (NULL != msg) { + LOC_LOGD("ni_thread_proc: adapter->sendMsg(msg)\n"); + adapter->sendMsg(msg); + } + + EXIT_LOG(%s, VOID_RET); + return NULL; +} + +void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + loc_eng_ni_data_s_type* loc_eng_ni_data_p = &loc_eng_data.loc_eng_ni_data; + + if (NULL == loc_eng_data.ni_notify_cb) { + EXIT_LOG(%s, "loc_eng_ni_init hasn't happened yet."); + return; + } + + // only if modem has requested but then died. + if (NULL != loc_eng_ni_data_p->sessionEs.rawRequest) { + free(loc_eng_ni_data_p->sessionEs.rawRequest); + loc_eng_ni_data_p->sessionEs.rawRequest = NULL; + + pthread_mutex_lock(&loc_eng_ni_data_p->sessionEs.tLock); + // the goal is to wake up ni_thread_proc + // and let it exit. + loc_eng_ni_data_p->sessionEs.respRecvd = TRUE; + pthread_cond_signal(&loc_eng_ni_data_p->sessionEs.tCond); + pthread_mutex_unlock(&loc_eng_ni_data_p->sessionEs.tLock); + } + + if (NULL != loc_eng_ni_data_p->session.rawRequest) { + free(loc_eng_ni_data_p->session.rawRequest); + loc_eng_ni_data_p->session.rawRequest = NULL; + + pthread_mutex_lock(&loc_eng_ni_data_p->session.tLock); + // the goal is to wake up ni_thread_proc + // and let it exit. + loc_eng_ni_data_p->session.respRecvd = TRUE; + pthread_cond_signal(&loc_eng_ni_data_p->session.tCond); + pthread_mutex_unlock(&loc_eng_ni_data_p->session.tLock); + } + + EXIT_LOG(%s, VOID_RET); +} + +/*=========================================================================== +FUNCTION loc_eng_ni_init + +DESCRIPTION + This function initializes the NI interface + +DEPENDENCIES + NONE + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_ni_init(loc_eng_data_s_type &loc_eng_data, GpsNiExtCallbacks *callbacks) +{ + ENTRY_LOG_CALLFLOW(); + + if(callbacks == NULL) + EXIT_LOG(%s, "loc_eng_ni_init: failed, cb is NULL"); + else if (NULL == callbacks->notify_cb) { + EXIT_LOG(%s, "loc_eng_ni_init: failed, no cb."); + } else if (NULL != loc_eng_data.ni_notify_cb) { + EXIT_LOG(%s, "loc_eng_ni_init: already inited."); + } else { + loc_eng_ni_data_s_type* loc_eng_ni_data_p = &loc_eng_data.loc_eng_ni_data; + loc_eng_ni_data_p->sessionEs.respTimeLeft = 0; + loc_eng_ni_data_p->sessionEs.respRecvd = FALSE; + loc_eng_ni_data_p->sessionEs.rawRequest = NULL; + loc_eng_ni_data_p->sessionEs.reqID = 0; + pthread_cond_init(&loc_eng_ni_data_p->sessionEs.tCond, NULL); + pthread_mutex_init(&loc_eng_ni_data_p->sessionEs.tLock, NULL); + + loc_eng_ni_data_p->session.respTimeLeft = 0; + loc_eng_ni_data_p->session.respRecvd = FALSE; + loc_eng_ni_data_p->session.rawRequest = NULL; + loc_eng_ni_data_p->session.reqID = 0; + pthread_cond_init(&loc_eng_ni_data_p->session.tCond, NULL); + pthread_mutex_init(&loc_eng_ni_data_p->session.tLock, NULL); + + loc_eng_data.ni_notify_cb = callbacks->notify_cb; + EXIT_LOG(%s, VOID_RET); + } +} + +/*=========================================================================== +FUNCTION loc_eng_ni_respond + +DESCRIPTION + This function receives user response from upper layer framework + +DEPENDENCIES + NONE + +RETURN VALUE + None + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_ni_respond(loc_eng_data_s_type &loc_eng_data, + int notif_id, GpsUserResponseType user_response) +{ + ENTRY_LOG_CALLFLOW(); + loc_eng_ni_data_s_type* loc_eng_ni_data_p = &loc_eng_data.loc_eng_ni_data; + loc_eng_ni_session_s_type* pSession = NULL; + + if (NULL == loc_eng_data.ni_notify_cb) { + EXIT_LOG(%s, "loc_eng_ni_init hasn't happened yet."); + return; + } + + if (notif_id == loc_eng_ni_data_p->sessionEs.reqID && + NULL != loc_eng_ni_data_p->sessionEs.rawRequest) { + pSession = &loc_eng_ni_data_p->sessionEs; + // ignore any SUPL NI non-Es session if a SUPL NI ES is accepted + if (user_response == GPS_NI_RESPONSE_ACCEPT && + NULL != loc_eng_ni_data_p->session.rawRequest) { + pthread_mutex_lock(&loc_eng_ni_data_p->session.tLock); + loc_eng_ni_data_p->session.resp = GPS_NI_RESPONSE_IGNORE; + loc_eng_ni_data_p->session.respRecvd = TRUE; + pthread_cond_signal(&loc_eng_ni_data_p->session.tCond); + pthread_mutex_unlock(&loc_eng_ni_data_p->session.tLock); + } + } else if (notif_id == loc_eng_ni_data_p->session.reqID && + NULL != loc_eng_ni_data_p->session.rawRequest) { + pSession = &loc_eng_ni_data_p->session; + } + + if (pSession) { + LOC_LOGI("loc_eng_ni_respond: send user response %d for notif %d", user_response, notif_id); + pthread_mutex_lock(&pSession->tLock); + pSession->resp = user_response; + pSession->respRecvd = TRUE; + pthread_cond_signal(&pSession->tCond); + pthread_mutex_unlock(&pSession->tLock); + } + else { + LOC_LOGE("loc_eng_ni_respond: notif_id %d not an active session", notif_id); + } + + EXIT_LOG(%s, VOID_RET); +} diff --git a/gps/loc_api/libloc_api_50001/loc_eng_ni.h b/gps/loc_api/libloc_api_50001/loc_eng_ni.h new file mode 100644 index 0000000..068f5cd --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_ni.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2009,2011,2014 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ENG_NI_H +#define LOC_ENG_NI_H + +#include +#include + +#define LOC_NI_NO_RESPONSE_TIME 20 /* secs */ +#define LOC_NI_NOTIF_KEY_ADDRESS "Address" +#define GPS_NI_RESPONSE_IGNORE 4 + +typedef struct { + pthread_t thread; /* NI thread */ + int respTimeLeft; /* examine time for NI response */ + bool respRecvd; /* NI User reponse received or not from Java layer*/ + void* rawRequest; + int reqID; /* ID to check against response */ + GpsUserResponseType resp; + pthread_cond_t tCond; + pthread_mutex_t tLock; + LocEngAdapter* adapter; +} loc_eng_ni_session_s_type; + +typedef struct { + loc_eng_ni_session_s_type session; /* SUPL NI Session */ + loc_eng_ni_session_s_type sessionEs; /* Emergency SUPL NI Session */ + int reqIDCounter; +} loc_eng_ni_data_s_type; + + +#endif /* LOC_ENG_NI_H */ diff --git a/gps/loc_api/libloc_api_50001/loc_eng_nmea.cpp b/gps/loc_api/libloc_api_50001/loc_eng_nmea.cpp new file mode 100644 index 0000000..b4cfcd2 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_nmea.cpp @@ -0,0 +1,817 @@ +/* Copyright (c) 2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_eng_nmea" +#define GPS_PRN_START 1 +#define GPS_PRN_END 32 +#define GLONASS_PRN_START 65 +#define GLONASS_PRN_END 96 +#include +#include +#include +#include "log_util.h" + +/*=========================================================================== +FUNCTION loc_eng_nmea_send + +DESCRIPTION + send out NMEA sentence + +DEPENDENCIES + NONE + +RETURN VALUE + Total length of the nmea sentence + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_nmea_send(char *pNmea, int length, loc_eng_data_s_type *loc_eng_data_p) +{ + struct timeval tv; + gettimeofday(&tv, (struct timezone *) NULL); + int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000; + if (loc_eng_data_p->nmea_cb != NULL) + loc_eng_data_p->nmea_cb(now, pNmea, length); + LOC_LOGD("NMEA <%s", pNmea); +} + +/*=========================================================================== +FUNCTION loc_eng_nmea_put_checksum + +DESCRIPTION + Generate NMEA sentences generated based on position report + +DEPENDENCIES + NONE + +RETURN VALUE + Total length of the nmea sentence + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_nmea_put_checksum(char *pNmea, int maxSize) +{ + uint8_t checksum = 0; + int length = 0; + + pNmea++; //skip the $ + while (*pNmea != '\0') + { + checksum ^= *pNmea++; + length++; + } + + // length now contains nmea sentence string length not including $ sign. + int checksumLength = snprintf(pNmea,(maxSize-length-1),"*%02X\r\n", checksum); + + // total length of nmea sentence is length of nmea sentence inc $ sign plus + // length of checksum (+1 is to cover the $ character in the length). + return (length + checksumLength + 1); +} + +/*=========================================================================== +FUNCTION loc_eng_nmea_generate_pos + +DESCRIPTION + Generate NMEA sentences generated based on position report + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_nmea_generate_pos(loc_eng_data_s_type *loc_eng_data_p, + const UlpLocation &location, + const GpsLocationExtended &locationExtended, + unsigned char generate_nmea) +{ + ENTRY_LOG(); + time_t utcTime(location.gpsLocation.timestamp/1000); + tm * pTm = gmtime(&utcTime); + if (NULL == pTm) { + LOC_LOGE("gmtime failed"); + return; + } + + char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char* pMarker = sentence; + int lengthRemaining = sizeof(sentence); + int length = 0; + int utcYear = pTm->tm_year % 100; // 2 digit year + int utcMonth = pTm->tm_mon + 1; // tm_mon starts at zero + int utcDay = pTm->tm_mday; + int utcHours = pTm->tm_hour; + int utcMinutes = pTm->tm_min; + int utcSeconds = pTm->tm_sec; + + if (generate_nmea) { + // ------------------ + // ------$GPGSA------ + // ------------------ + + uint32_t svUsedCount = 0; + uint32_t svUsedList[32] = {0}; + uint32_t mask = loc_eng_data_p->sv_used_mask; + for (uint8_t i = 1; mask > 0 && svUsedCount < 32; i++) + { + if (mask & 1) + svUsedList[svUsedCount++] = i; + mask = mask >> 1; + } + // clear the cache so they can't be used again + loc_eng_data_p->sv_used_mask = 0; + + char fixType; + if (svUsedCount == 0) + fixType = '1'; // no fix + else if (svUsedCount <= 3) + fixType = '2'; // 2D fix + else + fixType = '3'; // 3D fix + + length = snprintf(pMarker, lengthRemaining, "$GPGSA,A,%c,", fixType); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + for (uint8_t i = 0; i < 12; i++) // only the first 12 sv go in sentence + { + if (i < svUsedCount) + length = snprintf(pMarker, lengthRemaining, "%02d,", svUsedList[i]); + else + length = snprintf(pMarker, lengthRemaining, ","); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + } + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) + { // dop is in locationExtended, (QMI) + length = snprintf(pMarker, lengthRemaining, "%.1f,%.1f,%.1f", + locationExtended.pdop, + locationExtended.hdop, + locationExtended.vdop); + } + else if (loc_eng_data_p->pdop > 0 && loc_eng_data_p->hdop > 0 && loc_eng_data_p->vdop > 0) + { // dop was cached from sv report (RPC) + length = snprintf(pMarker, lengthRemaining, "%.1f,%.1f,%.1f", + loc_eng_data_p->pdop, + loc_eng_data_p->hdop, + loc_eng_data_p->vdop); + } + else + { // no dop + length = snprintf(pMarker, lengthRemaining, ",,"); + } + + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + // ------------------ + // ------$GPVTG------ + // ------------------ + + pMarker = sentence; + lengthRemaining = sizeof(sentence); + + if (location.gpsLocation.flags & GPS_LOCATION_HAS_BEARING) + { + float magTrack = location.gpsLocation.bearing; + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MAG_DEV) + { + float magTrack = location.gpsLocation.bearing - locationExtended.magneticDeviation; + if (magTrack < 0.0) + magTrack += 360.0; + else if (magTrack > 360.0) + magTrack -= 360.0; + } + + length = snprintf(pMarker, lengthRemaining, "$GPVTG,%.1lf,T,%.1lf,M,", location.gpsLocation.bearing, magTrack); + } + else + { + length = snprintf(pMarker, lengthRemaining, "$GPVTG,,T,,M,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & GPS_LOCATION_HAS_SPEED) + { + float speedKnots = location.gpsLocation.speed * (3600.0/1852.0); + float speedKmPerHour = location.gpsLocation.speed * 3.6; + + length = snprintf(pMarker, lengthRemaining, "%.1lf,N,%.1lf,K,", speedKnots, speedKmPerHour); + } + else + { + length = snprintf(pMarker, lengthRemaining, ",N,,K,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (!(location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG)) + length = snprintf(pMarker, lengthRemaining, "%c", 'N'); // N means no fix + else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->adapter->getPositionMode().mode) + length = snprintf(pMarker, lengthRemaining, "%c", 'A'); // A means autonomous + else + length = snprintf(pMarker, lengthRemaining, "%c", 'D'); // D means differential + + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + // ------------------ + // ------$GPRMC------ + // ------------------ + + pMarker = sentence; + lengthRemaining = sizeof(sentence); + + length = snprintf(pMarker, lengthRemaining, "$GPRMC,%02d%02d%02d,A," , + utcHours, utcMinutes, utcSeconds); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG) + { + double latitude = location.gpsLocation.latitude; + double longitude = location.gpsLocation.longitude; + char latHemisphere; + char lonHemisphere; + double latMinutes; + double lonMinutes; + + if (latitude > 0) + { + latHemisphere = 'N'; + } + else + { + latHemisphere = 'S'; + latitude *= -1.0; + } + + if (longitude < 0) + { + lonHemisphere = 'W'; + longitude *= -1.0; + } + else + { + lonHemisphere = 'E'; + } + + latMinutes = fmod(latitude * 60.0 , 60.0); + lonMinutes = fmod(longitude * 60.0 , 60.0); + + length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,", + (uint8_t)floor(latitude), latMinutes, latHemisphere, + (uint8_t)floor(longitude),lonMinutes, lonHemisphere); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,,,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & GPS_LOCATION_HAS_SPEED) + { + float speedKnots = location.gpsLocation.speed * (3600.0/1852.0); + length = snprintf(pMarker, lengthRemaining, "%.1lf,", speedKnots); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & GPS_LOCATION_HAS_BEARING) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,", location.gpsLocation.bearing); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + length = snprintf(pMarker, lengthRemaining, "%2.2d%2.2d%2.2d,", + utcDay, utcMonth, utcYear); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MAG_DEV) + { + float magneticVariation = locationExtended.magneticDeviation; + char direction; + if (magneticVariation < 0.0) + { + direction = 'W'; + magneticVariation *= -1.0; + } + else + { + direction = 'E'; + } + + length = snprintf(pMarker, lengthRemaining, "%.1lf,%c,", + magneticVariation, direction); + } + else + { + length = snprintf(pMarker, lengthRemaining, ",,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (!(location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG)) + length = snprintf(pMarker, lengthRemaining, "%c", 'N'); // N means no fix + else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->adapter->getPositionMode().mode) + length = snprintf(pMarker, lengthRemaining, "%c", 'A'); // A means autonomous + else + length = snprintf(pMarker, lengthRemaining, "%c", 'D'); // D means differential + + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + // ------------------ + // ------$GPGGA------ + // ------------------ + + pMarker = sentence; + lengthRemaining = sizeof(sentence); + + length = snprintf(pMarker, lengthRemaining, "$GPGGA,%02d%02d%02d," , + utcHours, utcMinutes, utcSeconds); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG) + { + double latitude = location.gpsLocation.latitude; + double longitude = location.gpsLocation.longitude; + char latHemisphere; + char lonHemisphere; + double latMinutes; + double lonMinutes; + + if (latitude > 0) + { + latHemisphere = 'N'; + } + else + { + latHemisphere = 'S'; + latitude *= -1.0; + } + + if (longitude < 0) + { + lonHemisphere = 'W'; + longitude *= -1.0; + } + else + { + lonHemisphere = 'E'; + } + + latMinutes = fmod(latitude * 60.0 , 60.0); + lonMinutes = fmod(longitude * 60.0 , 60.0); + + length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,", + (uint8_t)floor(latitude), latMinutes, latHemisphere, + (uint8_t)floor(longitude),lonMinutes, lonHemisphere); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,,,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + char gpsQuality; + if (!(location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG)) + gpsQuality = '0'; // 0 means no fix + else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->adapter->getPositionMode().mode) + gpsQuality = '1'; // 1 means GPS fix + else + gpsQuality = '2'; // 2 means DGPS fix + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) + { // dop is in locationExtended, (QMI) + length = snprintf(pMarker, lengthRemaining, "%c,%02d,%.1f,", + gpsQuality, svUsedCount, locationExtended.hdop); + } + else if (loc_eng_data_p->pdop > 0 && loc_eng_data_p->hdop > 0 && loc_eng_data_p->vdop > 0) + { // dop was cached from sv report (RPC) + length = snprintf(pMarker, lengthRemaining, "%c,%02d,%.1f,", + gpsQuality, svUsedCount, loc_eng_data_p->hdop); + } + else + { // no hdop + length = snprintf(pMarker, lengthRemaining, "%c,%02d,,", + gpsQuality, svUsedCount); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,M,", + locationExtended.altitudeMeanSeaLevel); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if ((location.gpsLocation.flags & GPS_LOCATION_HAS_ALTITUDE) && + (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL)) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,M,,", + location.gpsLocation.altitude - locationExtended.altitudeMeanSeaLevel); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,,"); + } + + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + } + //Send blank NMEA reports for non-final fixes + else { + strlcpy(sentence, "$GPGSA,A,1,,,,,,,,,,,,,,,", sizeof(sentence)); + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + strlcpy(sentence, "$GPVTG,,T,,M,,N,,K,N", sizeof(sentence)); + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + strlcpy(sentence, "$GPRMC,,V,,,,,,,,,,N", sizeof(sentence)); + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + + strlcpy(sentence, "$GPGGA,,,,,,0,,,,,,,,", sizeof(sentence)); + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + } + // clear the dop cache so they can't be used again + loc_eng_data_p->pdop = 0; + loc_eng_data_p->hdop = 0; + loc_eng_data_p->vdop = 0; + + EXIT_LOG(%d, 0); +} + + + +/*=========================================================================== +FUNCTION loc_eng_nmea_generate_sv + +DESCRIPTION + Generate NMEA sentences generated based on sv report + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_nmea_generate_sv(loc_eng_data_s_type *loc_eng_data_p, + const HaxxSvStatus &svStatus, const GpsLocationExtended &locationExtended) +{ + ENTRY_LOG(); + + char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char* pMarker = sentence; + int lengthRemaining = sizeof(sentence); + int length = 0; + int svCount = svStatus.num_svs; + int sentenceCount = 0; + int sentenceNumber = 1; + int svNumber = 1; + int gpsCount = 0; + int glnCount = 0; + + //Count GPS SVs for saparating GPS from GLONASS and throw others + + for(svNumber=1; svNumber <= svCount; svNumber++) { + if( (svStatus.sv_list[svNumber-1].prn >= GPS_PRN_START)&& + (svStatus.sv_list[svNumber-1].prn <= GPS_PRN_END) ) + { + gpsCount++; + } + else if( (svStatus.sv_list[svNumber-1].prn >= GLONASS_PRN_START) && + (svStatus.sv_list[svNumber-1].prn <= GLONASS_PRN_END) ) + { + glnCount++; + } + } + + // ------------------ + // ------$GPGSV------ + // ------------------ + + if (gpsCount <= 0) + { + // no svs in view, so just send a blank $GPGSV sentence + strlcpy(sentence, "$GPGSV,1,1,0,", sizeof(sentence)); + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + } + else + { + svNumber = 1; + sentenceNumber = 1; + sentenceCount = gpsCount/4 + (gpsCount % 4 != 0); + + while (sentenceNumber <= sentenceCount) + { + pMarker = sentence; + lengthRemaining = sizeof(sentence); + + length = snprintf(pMarker, lengthRemaining, "$GPGSV,%d,%d,%02d", + sentenceCount, sentenceNumber, gpsCount); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + for (int i=0; (svNumber <= svCount) && (i < 4); svNumber++) + { + if( (svStatus.sv_list[svNumber-1].prn >= GPS_PRN_START) && + (svStatus.sv_list[svNumber-1].prn <= GPS_PRN_END) ) + { + length = snprintf(pMarker, lengthRemaining,",%02d,%02d,%03d,", + svStatus.sv_list[svNumber-1].prn, + (int)(0.5 + svStatus.sv_list[svNumber-1].elevation), //float to int + (int)(0.5 + svStatus.sv_list[svNumber-1].azimuth)); //float to int + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (svStatus.sv_list[svNumber-1].snr > 0) + { + length = snprintf(pMarker, lengthRemaining,"%02d", + (int)(0.5 + svStatus.sv_list[svNumber-1].snr)); //float to int + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + } + + i++; + } + + } + + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + sentenceNumber++; + + } //while + + } //if + + // ------------------ + // ------$GLGSV------ + // ------------------ + + if (glnCount <= 0) + { + // no svs in view, so just send a blank $GLGSV sentence + strlcpy(sentence, "$GLGSV,1,1,0,", sizeof(sentence)); + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + } + else + { + svNumber = 1; + sentenceNumber = 1; + sentenceCount = glnCount/4 + (glnCount % 4 != 0); + + while (sentenceNumber <= sentenceCount) + { + pMarker = sentence; + lengthRemaining = sizeof(sentence); + + length = snprintf(pMarker, lengthRemaining, "$GLGSV,%d,%d,%02d", + sentenceCount, sentenceNumber, glnCount); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + for (int i=0; (svNumber <= svCount) && (i < 4); svNumber++) + { + if( (svStatus.sv_list[svNumber-1].prn >= GLONASS_PRN_START) && + (svStatus.sv_list[svNumber-1].prn <= GLONASS_PRN_END) ) { + + length = snprintf(pMarker, lengthRemaining,",%02d,%02d,%03d,", + svStatus.sv_list[svNumber-1].prn, + (int)(0.5 + svStatus.sv_list[svNumber-1].elevation), //float to int + (int)(0.5 + svStatus.sv_list[svNumber-1].azimuth)); //float to int + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (svStatus.sv_list[svNumber-1].snr > 0) + { + length = snprintf(pMarker, lengthRemaining,"%02d", + (int)(0.5 + svStatus.sv_list[svNumber-1].snr)); //float to int + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + } + + i++; + } + + } + + length = loc_eng_nmea_put_checksum(sentence, sizeof(sentence)); + loc_eng_nmea_send(sentence, length, loc_eng_data_p); + sentenceNumber++; + + } //while + + }//if + + // cache the used in fix mask, as it will be needed to send $GPGSA + // during the position report + loc_eng_data_p->sv_used_mask = svStatus.gps_used_in_fix_mask; + + // For RPC, the DOP are sent during sv report, so cache them + // now to be sent during position report. + // For QMI, the DOP will be in position report. + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) + { + loc_eng_data_p->pdop = locationExtended.pdop; + loc_eng_data_p->hdop = locationExtended.hdop; + loc_eng_data_p->vdop = locationExtended.vdop; + } + else + { + loc_eng_data_p->pdop = 0; + loc_eng_data_p->hdop = 0; + loc_eng_data_p->vdop = 0; + } + + EXIT_LOG(%d, 0); +} diff --git a/gps/loc_api/libloc_api_50001/loc_eng_nmea.h b/gps/loc_api/libloc_api_50001/loc_eng_nmea.h new file mode 100644 index 0000000..7b0c524 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_nmea.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ENG_NMEA_H +#define LOC_ENG_NMEA_H + +#include +#include + +#define NMEA_SENTENCE_MAX_LENGTH 200 + +void loc_eng_nmea_send(char *pNmea, int length, loc_eng_data_s_type *loc_eng_data_p); +int loc_eng_nmea_put_checksum(char *pNmea, int maxSize); +void loc_eng_nmea_generate_sv(loc_eng_data_s_type *loc_eng_data_p, const HaxxSvStatus &svStatus, const GpsLocationExtended &locationExtended); +void loc_eng_nmea_generate_pos(loc_eng_data_s_type *loc_eng_data_p, const UlpLocation &location, const GpsLocationExtended &locationExtended, unsigned char generate_nmea); + +#endif // LOC_ENG_NMEA_H diff --git a/gps/loc_api/libloc_api_50001/loc_eng_xtra.cpp b/gps/loc_api/libloc_api_50001/loc_eng_xtra.cpp new file mode 100644 index 0000000..7bb8083 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_xtra.cpp @@ -0,0 +1,213 @@ +/* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_eng" + +#include +#include +#include "log_util.h" +#include "platform_lib_includes.h" + +using namespace loc_core; + +struct LocEngRequestXtraServer : public LocMsg { + LocEngAdapter* mAdapter; + inline LocEngRequestXtraServer(LocEngAdapter* adapter) : + LocMsg(), mAdapter(adapter) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->requestXtraServer(); + } + inline void locallog() const { + LOC_LOGV("LocEngRequestXtraServer"); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocEngInjectXtraData : public LocMsg { + LocEngAdapter* mAdapter; + char* mData; + const int mLen; + inline LocEngInjectXtraData(LocEngAdapter* adapter, + char* data, int len): + LocMsg(), mAdapter(adapter), + mData(new char[len]), mLen(len) + { + memcpy((void*)mData, (void*)data, len); + locallog(); + } + inline ~LocEngInjectXtraData() + { + delete[] mData; + } + inline virtual void proc() const { + mAdapter->setXtraData(mData, mLen); + } + inline void locallog() const { + LOC_LOGV("length: %d\n data: %p", mLen, mData); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocEngSetXtraVersionCheck : public LocMsg { + LocEngAdapter *mAdapter; + int mCheck; + inline LocEngSetXtraVersionCheck(LocEngAdapter* adapter, + int check): + mAdapter(adapter), mCheck(check) {} + inline virtual void proc() const { + locallog(); + mAdapter->setXtraVersionCheck(mCheck); + } + inline void locallog() const { + LOC_LOGD("%s:%d]: mCheck: %d", + __func__, __LINE__, mCheck); + } + inline virtual void log() const { + locallog(); + } +}; + +/*=========================================================================== +FUNCTION loc_eng_xtra_init + +DESCRIPTION + Initialize XTRA module. + +DEPENDENCIES + N/A + +RETURN VALUE + 0: success + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data, + GpsXtraExtCallbacks* callbacks) +{ + int ret_val = -1; + loc_eng_xtra_data_s_type *xtra_module_data_ptr; + ENTRY_LOG(); + + if(callbacks == NULL) { + LOC_LOGE("loc_eng_xtra_init: failed, cb is NULL"); + } else { + xtra_module_data_ptr = &loc_eng_data.xtra_module_data; + xtra_module_data_ptr->download_request_cb = callbacks->download_request_cb; + xtra_module_data_ptr->report_xtra_server_cb = callbacks->report_xtra_server_cb; + + ret_val = 0; + } + EXIT_LOG(%d, ret_val); + return ret_val; +} + +/*=========================================================================== +FUNCTION loc_eng_xtra_inject_data + +DESCRIPTION + Injects XTRA file into the engine but buffers the data if engine is busy. + +DEPENDENCIES + N/A + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data, + char* data, int length) +{ + ENTRY_LOG(); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngInjectXtraData(adapter, data, length)); + EXIT_LOG(%d, 0); + return 0; +} +/*=========================================================================== +FUNCTION loc_eng_xtra_request_server + +DESCRIPTION + Request the Xtra server url from the modem + +DEPENDENCIES + N/A + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data) +{ + ENTRY_LOG(); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngRequestXtraServer(adapter)); + EXIT_LOG(%d, 0); + return 0; +} +/*=========================================================================== +FUNCTION loc_eng_xtra_version_check + +DESCRIPTION + Injects the enable/disable value for checking XTRA version + that is specified in gps.conf + +DEPENDENCIES + N/A + +RETURN VALUE + none + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_eng_xtra_version_check(loc_eng_data_s_type &loc_eng_data, + int check) +{ + ENTRY_LOG(); + LocEngAdapter *adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngSetXtraVersionCheck(adapter, check)); + EXIT_LOG(%d, 0); +} diff --git a/gps/loc_api/libloc_api_50001/loc_eng_xtra.h b/gps/loc_api/libloc_api_50001/loc_eng_xtra.h new file mode 100644 index 0000000..175f497 --- /dev/null +++ b/gps/loc_api/libloc_api_50001/loc_eng_xtra.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ENG_XTRA_H +#define LOC_ENG_XTRA_H + +#include + +// Module data +typedef struct +{ + // loc_eng_ioctl_cb_data_s_type ioctl_cb_data; + gps_xtra_download_request download_request_cb; + report_xtra_server report_xtra_server_cb; + + // XTRA data buffer + char *xtra_data_for_injection; // NULL if no pending data + int xtra_data_len; +} loc_eng_xtra_data_s_type; + +#endif // LOC_ENG_XTRA_H diff --git a/gps/utils/Android.mk b/gps/utils/Android.mk new file mode 100644 index 0000000..22d4f06 --- /dev/null +++ b/gps/utils/Android.mk @@ -0,0 +1,52 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +## Libs +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libcutils \ + liblog \ + libhardware + +LOCAL_SRC_FILES += \ + loc_log.cpp \ + loc_cfg.cpp \ + msg_q.c \ + linked_list.c \ + loc_target.cpp \ + platform_lib_abstractions/elapsed_millis_since_boot.cpp \ + LocHeap.cpp \ + LocTimer.cpp \ + LocThread.cpp \ + MsgTask.cpp \ + loc_misc_utils.cpp + +# Flag -std=c++11 is not accepted by compiler when LOCAL_CLANG is set to true +LOCAL_CFLAGS += \ + -fno-short-enums \ + -D_ANDROID_ \ + -Wno-unused-parameter + +ifeq ($(TARGET_BUILD_VARIANT),user) + LOCAL_CFLAGS += -DTARGET_BUILD_VARIANT_USER +endif + +LOCAL_LDFLAGS += -Wl,--export-dynamic + +## Includes +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/platform_lib_abstractions + +LOCAL_MODULE := libgps.utils +LOCAL_MODULE_OWNER := qcom +LOCAL_PROPRIETARY_MODULE := true + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libgps.utils_headers +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) $(LOCAL_PATH)/platform_lib_abstractions +include $(BUILD_HEADER_LIBRARY) diff --git a/gps/utils/LocHeap.cpp b/gps/utils/LocHeap.cpp new file mode 100644 index 0000000..d667f14 --- /dev/null +++ b/gps/utils/LocHeap.cpp @@ -0,0 +1,354 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include + +class LocHeapNode { + friend class LocHeap; + + // size of of the subtree, excluding self, 1 if no subtree + int mSize; + LocHeapNode* mLeft; + LocHeapNode* mRight; + LocRankable* mData; +public: + inline LocHeapNode(LocRankable& data) : + mSize(1), mLeft(NULL), mRight(NULL), mData(&data) {} + ~LocHeapNode(); + + // this only swaps the data of the two nodes, so no + // detach / re-attached is necessary + void swap(LocHeapNode& node); + + LocRankable* detachData(); + + // push a node into the tree stucture, keeping sorted by rank + void push(LocHeapNode& node); + + // pop the head node out of the tree stucture. keeping sorted by rank + static LocHeapNode* pop(LocHeapNode*& top); + + // remove a specific node from the tree + // returns the pointer to the node removed, which would be either the + // same as input (if successfully removed); or NULL (if failed). + static LocHeapNode* remove(LocHeapNode*& top, LocRankable& data); + + // convenience method to compare data ranking + inline bool outRanks(LocHeapNode& node) { return mData->outRanks(*node.mData); } + inline bool outRanks(LocRankable& data) { return mData->outRanks(data); } + + // checks if mSize is correct, AND this node is the highest ranking + // of the entire subtree + bool checkNodes(); + + inline int getSize() { return mSize; } +}; + +inline +LocHeapNode::~LocHeapNode() { + if (mLeft) { + delete mLeft; + mLeft = NULL; + } + if (mRight) { + delete mRight; + mRight = NULL; + } + if (mData) { + mData = NULL; + } +} + +inline +void LocHeapNode::swap(LocHeapNode& node) { + LocRankable* tmpData = node.mData; + node.mData = mData; + mData = tmpData; +} + +inline +LocRankable* LocHeapNode::detachData() { + LocRankable* data = mData; + mData = NULL; + return data; +} + +// push keeps the tree sorted by rank, it also tries to balance the +// tree by adding the new node to the smaller of the subtrees. +// The pointer to the tree and internal links never change. If the +// mData of tree top ranks lower than that of the incoming node, +// mData will be swapped with that of the incoming node to ensure +// ranking, no restructuring the container nodes. +void LocHeapNode::push(LocHeapNode& node) { + // ensure the current node ranks higher than in the incoming one + if (node.outRanks(*this)) { + swap(node); + } + + // now drop the new node (ensured lower than *this) into a subtree + if (NULL == mLeft) { + mLeft = &node; + } else if (NULL == mRight) { + mRight = &node; + } else if (mLeft->mSize <= mRight->mSize) { + mLeft->push(node); + } else { + mRight->push(node); + } + mSize++; +} + +// pop keeps the tree sorted by rank, but it does not try to balance +// the tree. It recursively swaps with the higher ranked top of the +// subtrees. +// The return is a popped out node from leaf level, that has the data +// swapped all the way down from the top. The pinter to the tree and +// internal links will not be changed or restructured, except for the +// node that is popped out. +// If the return pointer == this, this the last node in the tree. +LocHeapNode* LocHeapNode::pop(LocHeapNode*& top) { + // we know the top has the highest ranking at this point, else + // the tree is broken. This top will be popped out. But we need + // a node from the left or right child, whichever ranks higher, + // to replace the current top. This then will need to be done + // recursively to the leaf level. So we swap the mData of the + // current top node all the way down to the leaf level. + LocHeapNode* poppedNode = top; + // top is losing a node in its subtree + top->mSize--; + if (top->mLeft || top->mRight) { + // if mLeft is NULL, mRight for sure is NOT NULL, take that; + // else if mRight is NULL, mLeft for sure is NOT, take that; + // else we take the address of whatever has higher ranking mData + LocHeapNode*& subTop = (NULL == top->mLeft) ? top->mRight : + ((NULL == top->mRight) ? top->mLeft : + (top->mLeft->outRanks(*(top->mRight)) ? top->mLeft : top->mRight)); + // swap mData, the tree top gets updated with the new data. + top->swap(*subTop); + // pop out from the subtree + poppedNode = pop(subTop); + } else { + // if the top has only single node + // detach the poppedNode from the tree + // subTop is the reference of ether mLeft or mRight + // NOT a local stack pointer. so it MUST be NULL'ed here. + top = NULL; + } + + return poppedNode; +} + +// navigating through the tree and find the node that hass the input +// data. Since this is a heap, we do recursive linear search. +// returns the pointer to the node removed, which would be either the +// same as input (if successfully removed); or NULL (if failed). +LocHeapNode* LocHeapNode::remove(LocHeapNode*& top, LocRankable& data) { + LocHeapNode* removedNode = NULL; + // this is the node, by address + if (&data == (LocRankable*)(top->mData)) { + // pop this node out + removedNode = pop(top); + } else if (!data.outRanks(*top->mData)) { + // subtrees might have this node + if (top->mLeft) { + removedNode = remove(top->mLeft, data); + } + // if we did not find in mLeft, and mRight is not empty + if (!removedNode && top->mRight) { + removedNode = remove(top->mRight, data); + } + + // top lost a node in its subtree + if (removedNode) { + top->mSize--; + } + } + + return removedNode; +} + +// checks if mSize is correct, AND this node is the highest ranking +// of the entire subtree +bool LocHeapNode::checkNodes() { + // size of the current subtree + int totalSize = mSize; + if (mLeft) { + // check the consistency of left subtree + if (mLeft->outRanks(*this) || !mLeft->checkNodes()) { + return false; + } + // subtract the size of left subtree (with subtree head) + totalSize -= mLeft->mSize; + } + + if (mRight) { + // check the consistency of right subtree + if (mRight->outRanks(*this) || !mRight->checkNodes()) { + return false; + } + // subtract the size of right subtree (with subtree head) + totalSize -= mRight->mSize; + } + + // for the tree nodes to consistent, totalSize must be 1 now + return totalSize == 1; +} + +LocHeap::~LocHeap() { + if (mTree) { + delete mTree; + } +} + +void LocHeap::push(LocRankable& node) { + LocHeapNode* heapNode = new LocHeapNode(node); + if (!mTree) { + mTree = heapNode; + } else { + mTree->push(*heapNode); + } +} + +LocRankable* LocHeap::peek() { + LocRankable* top = NULL; + if (mTree) { + top = mTree->mData; + } + return top; +} + +LocRankable* LocHeap::pop() { + LocRankable* locNode = NULL; + if (mTree) { + // mTree may become NULL after this call + LocHeapNode* heapNode = LocHeapNode::pop(mTree); + locNode = heapNode->detachData(); + delete heapNode; + } + return locNode; +} + +LocRankable* LocHeap::remove(LocRankable& rankable) { + LocRankable* locNode = NULL; + if (mTree) { + // mTree may become NULL after this call + LocHeapNode* heapNode = LocHeapNode::remove(mTree, rankable); + if (heapNode) { + locNode = heapNode->detachData(); + delete heapNode; + } + } + return locNode; +} + +#ifdef __LOC_UNIT_TEST__ +bool LocHeap::checkTree() { + return ((NULL == mTree) || mTree->checkNodes()); +} +uint32_t LocHeap::getTreeSize() { + return (NULL == mTree) ? 0 : mTree->getSize(); +} +#endif + +#ifdef __LOC_DEBUG__ + +#include +#include +#include + +class LocHeapDebug : public LocHeap { +public: + bool checkTree() { + return ((NULL == mTree) || mTree->checkNodes()); + } + + uint32_t getTreeSize() { + return (NULL == mTree) ? 0 : (mTree->getSize()); + } +}; + +class LocHeapDebugData : public LocRankable { + const int mID; +public: + LocHeapDebugData(int id) : mID(id) {} + inline virtual int ranks(LocRankable& rankable) { + LocHeapDebugData* testData = dynamic_cast(&rankable); + return testData->mID - mID; + } +}; + +// For Linux command line testing: +// compilation: g++ -D__LOC_HOST_DEBUG__ -D__LOC_DEBUG__ -g -I. -I../../../../vendor/qcom/proprietary/gps-internal/unit-tests/fakes_for_host -I../../../../system/core/include LocHeap.cpp +// test: valgrind --leak-check=full ./a.out 100 +int main(int argc, char** argv) { + srand(time(NULL)); + int tries = atoi(argv[1]); + int checks = tries >> 3; + LocHeapDebug heap; + int treeSize = 0; + + for (int i = 0; i < tries; i++) { + if (i % checks == 0 && !heap.checkTree()) { + printf("tree check failed before %dth op\n", i); + } + int r = rand(); + + if (r & 1) { + LocHeapDebugData* data = new LocHeapDebugData(r >> 1); + heap.push(dynamic_cast(*data)); + treeSize++; + } else { + LocRankable* rankable = heap.pop(); + if (rankable) { + delete rankable; + } + treeSize ? treeSize-- : 0; + } + + printf("%s: %d == %d\n", (r&1)?"push":"pop", treeSize, heap.getTreeSize()); + if (treeSize != heap.getTreeSize()) { + printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + tries = i+1; + break; + } + } + + if (!heap.checkTree()) { + printf("!!!!!!!!!!tree check failed at the end after %d ops!!!!!!!\n", tries); + } else { + printf("success!\n"); + } + + for (LocRankable* data = heap.pop(); NULL != data; data = heap.pop()) { + delete data; + } + + return 0; +} + +#endif diff --git a/gps/utils/LocHeap.h b/gps/utils/LocHeap.h new file mode 100644 index 0000000..b491948 --- /dev/null +++ b/gps/utils/LocHeap.h @@ -0,0 +1,96 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_HEAP__ +#define __LOC_HEAP__ + +#include +#include + +// abstract class to be implemented by client to provide a rankable class +class LocRankable { +public: + virtual inline ~LocRankable() {} + + // method to rank objects of such type for sorting purposes. + // The pointer of the input node would be stored in the heap. + // >0 if ranks higher than the input; + // ==0 if equally ranks with the input; + // <0 if ranks lower than the input + virtual int ranks(LocRankable& rankable) = 0; + + // convenient method to rank objects of such type for sorting purposes. + inline bool outRanks(LocRankable& rankable) { return ranks(rankable) > 0; } +}; + +// opaque class to provide service implementation. +class LocHeapNode; + +// a heap whose left and right children are not sorted. It is sorted only vertically, +// i.e. parent always ranks higher than children, if they exist. Ranking algorithm is +// implemented in Rankable. The reason that there is no sort between children is to +// help beter balance the tree with lower cost. When a node is pushed to the tree, +// it is guaranteed that the subtree that is smaller gets to have the new node. +class LocHeap { +protected: + LocHeapNode* mTree; +public: + inline LocHeap() : mTree(NULL) {} + ~LocHeap(); + + // push keeps the tree sorted by rank, it also tries to balance the + // tree by adding the new node to the smaller of the subtrees. + // node is reference to an obj that is managed by client, that client + // creates and destroyes. The destroy should happen after the + // node is popped out from the heap. + void push(LocRankable& node); + + // Peeks the node data on tree top, which has currently the highest ranking + // There is no change the tree structure with this operation + // Returns NULL if the tree is empty, otherwise pointer to the node data of + // the tree top. + LocRankable* peek(); + + // pop keeps the tree sorted by rank, but it does not try to balance + // the tree. + // Return - pointer to the node popped out, or NULL if heap is already empty + LocRankable* pop(); + + // navigating through the tree and find the node that ranks the same + // as the input data, then remove it from the tree. Rank is implemented + // by rankable obj. + // returns the pointer to the node removed; or NULL (if failed). + LocRankable* remove(LocRankable& rankable); + +#ifdef __LOC_UNIT_TEST__ + bool checkTree(); + uint32_t getTreeSize(); +#endif +}; + +#endif //__LOC_HEAP__ diff --git a/gps/utils/LocSharedLock.h b/gps/utils/LocSharedLock.h new file mode 100644 index 0000000..7fe6237 --- /dev/null +++ b/gps/utils/LocSharedLock.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_SHARED_LOCK__ +#define __LOC_SHARED_LOCK__ + +#include +#include +#include + +// This is a utility created for use cases such that there are more than +// one client who need to share the same lock, but it is not predictable +// which of these clients is to last to go away. This shared lock deletes +// itself when the last client calls its drop() method. To add a cient, +// this share lock's share() method has to be called, so that the obj +// can maintain an accurate client count. +class LocSharedLock { + volatile int32_t mRef; + pthread_mutex_t mMutex; + inline ~LocSharedLock() { pthread_mutex_destroy(&mMutex); } +public: + // first client to create this LockSharedLock + inline LocSharedLock() : mRef(1) { pthread_mutex_init(&mMutex, NULL); } + // following client(s) are to *share()* this lock created by the first client + inline LocSharedLock* share() { android_atomic_inc(&mRef); return this; } + // whe a client no longer needs this shared lock, drop() shall be called. + inline void drop() { if (1 == android_atomic_dec(&mRef)) delete this; } + // locking the lock to enter critical section + inline void lock() { pthread_mutex_lock(&mMutex); } + // unlocking the lock to leave the critical section + inline void unlock() { pthread_mutex_unlock(&mMutex); } +}; + +#endif //__LOC_SHARED_LOCK__ diff --git a/gps/utils/LocThread.cpp b/gps/utils/LocThread.cpp new file mode 100644 index 0000000..19bf101 --- /dev/null +++ b/gps/utils/LocThread.cpp @@ -0,0 +1,264 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include +#include + +class LocThreadDelegate { + LocRunnable* mRunnable; + bool mJoinable; + pthread_t mThandle; + pthread_mutex_t mMutex; + int mRefCount; + ~LocThreadDelegate(); + LocThreadDelegate(LocThread::tCreate creator, const char* threadName, + LocRunnable* runnable, bool joinable); + void destroy(); +public: + static LocThreadDelegate* create(LocThread::tCreate creator, + const char* threadName, LocRunnable* runnable, bool joinable); + void stop(); + // bye() is for the parent thread to go away. if joinable, + // parent must stop the spawned thread, join, and then + // destroy(); if detached, the parent can go straight + // ahead to destroy() + inline void bye() { mJoinable ? stop() : destroy(); } + inline bool isRunning() { return (NULL != mRunnable); } + static void* threadMain(void* arg); +}; + +// it is important to note that internal members must be +// initialized to values as if pthread_create succeeds. +// This is to avoid the race condition between the threads, +// once the thread is created, some of these values will +// be check in the spawned thread, and must set correctly +// then and there. +// However, upon pthread_create failure, the data members +// must be set to indicate failure, e.g. mRunnable, and +// threashold approprietly for destroy(), e.g. mRefCount. +LocThreadDelegate::LocThreadDelegate(LocThread::tCreate creator, + const char* threadName, LocRunnable* runnable, bool joinable) : + mRunnable(runnable), mJoinable(joinable), mThandle(NULL), + mMutex(PTHREAD_MUTEX_INITIALIZER), mRefCount(2) { + + // set up thread name, if nothing is passed in + if (!threadName) { + threadName = "LocThread"; + } + + // create the thread here, then if successful + // and a name is given, we set the thread name + if (creator) { + mThandle = creator(threadName, threadMain, this); + } else if (pthread_create(&mThandle, NULL, threadMain, this)) { + // pthread_create() failed + mThandle = NULL; + } + + if (mThandle) { + // set thread name + char lname[16]; + int len = sizeof(lname) - 1; + memcpy(lname, threadName, len); + lname[len] = 0; + // set the thread name here + pthread_setname_np(mThandle, lname); + + // detach, if not joinable + if (!joinable) { + pthread_detach(mThandle); + } + } else { + // must set these values upon failure + mRunnable = NULL; + mJoinable = false; + mRefCount = 1; + } +} + +inline +LocThreadDelegate::~LocThreadDelegate() { + // at this point nothing should need done any more +} + +// factory method so that we could return NULL upon failure +LocThreadDelegate* LocThreadDelegate::create(LocThread::tCreate creator, + const char* threadName, LocRunnable* runnable, bool joinable) { + LocThreadDelegate* thread = NULL; + if (runnable) { + thread = new LocThreadDelegate(creator, threadName, runnable, joinable); + if (thread && !thread->isRunning()) { + thread->destroy(); + thread = NULL; + } + } + + return thread; +} + +// The order is importang +// NULLing mRunnalbe stops the while loop in threadMain() +// join() if mJoinble must come before destroy() call, as +// the obj must remain alive at this time so that mThandle +// remains valud. +void LocThreadDelegate::stop() { + // mRunnable and mJoinable are reset on different triggers. + // mRunnable may get nulled on the spawned thread's way out; + // or here. + // mJouinable (if ever been true) gets falsed when client + // thread triggers stop, with either a stop() + // call or the client releases thread obj handle. + if (mRunnable) { + mRunnable = NULL; + } + if (mJoinable) { + mJoinable = false; + pthread_join(mThandle, NULL); + } + // call destroy() to possibly delete the obj + destroy(); +} + +// method for clients to call to release the obj +// when it is a detached thread, the client thread +// and the spawned thread can both try to destroy() +// asynchronously. And we delete this obj when +// mRefCount becomes 0. +void LocThreadDelegate::destroy() { + // else case shouldn't happen, unless there is a + // leaking obj. But only our code here has such + // obj, so if we test our code well, else case + // will never happen + if (mRefCount > 0) { + // we need a flag on the stack + bool callDelete = false; + + // critical section between threads + pthread_mutex_lock(&mMutex); + // last destroy() call + callDelete = (1 == mRefCount--); + pthread_mutex_unlock(&mMutex); + + // upon last destroy() call we delete this obj + if (callDelete) { + delete this; + } + } +} + +void* LocThreadDelegate::threadMain(void* arg) { + LocThreadDelegate* locThread = (LocThreadDelegate*)(arg); + + if (locThread) { + LocRunnable* runnable = locThread->mRunnable; + + if (runnable) { + if (locThread->isRunning()) { + runnable->prerun(); + } + + while (locThread->isRunning() && runnable->run()); + + if (locThread->isRunning()) { + runnable->postrun(); + } + + // at this time, locThread->mRunnable may or may not be NULL + // NULL it just to be safe and clean, as we want the field + // in the released memory slot to be NULL. + locThread->mRunnable = NULL; + delete runnable; + } + locThread->destroy(); + } + + return NULL; +} + +LocThread::~LocThread() { + if (mThread) { + mThread->bye(); + mThread = NULL; + } +} + +bool LocThread::start(tCreate creator, const char* threadName, LocRunnable* runnable, bool joinable) { + bool success = false; + if (!mThread) { + mThread = LocThreadDelegate::create(creator, threadName, runnable, joinable); + // true only if thread is created successfully + success = (NULL != mThread); + } + return success; +} + +void LocThread::stop() { + if (mThread) { + mThread->stop(); + mThread = NULL; + } +} + +#ifdef __LOC_DEBUG__ + +#include +#include +#include + +class LocRunnableTest1 : public LocRunnable { + int mID; +public: + LocRunnableTest1(int id) : LocRunnable(), mID(id) {} + virtual bool run() { + printf("LocRunnableTest1: %d\n", mID++); + sleep(1); + return true; + } +}; + +// on linux command line: +// compile: g++ -D__LOC_HOST_DEBUG__ -D__LOC_DEBUG__ -g -std=c++0x -I. -I../../../../vendor/qcom/proprietary/gps-internal/unit-tests/fakes_for_host -I../../../../system/core/include -lpthread LocThread.cpp +// test detached thread: valgrind ./a.out 0 +// test joinable thread: valgrind ./a.out 1 +int main(int argc, char** argv) { + LocRunnableTest1 test(10); + + LocThread thread; + thread.start("LocThreadTest", test, atoi(argv[1])); + + sleep(10); + + thread.stop(); + + sleep(5); + + return 0; +} + +#endif diff --git a/gps/utils/LocThread.h b/gps/utils/LocThread.h new file mode 100644 index 0000000..2a65d8f --- /dev/null +++ b/gps/utils/LocThread.h @@ -0,0 +1,92 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_THREAD__ +#define __LOC_THREAD__ + +#include +#include + +// abstract class to be implemented by client to provide a runnable class +// which gets scheduled by LocThread +class LocRunnable { +public: + inline LocRunnable() {} + inline virtual ~LocRunnable() {} + + // The method to be implemented by thread clients + // and be scheduled by LocThread + // This method will be repeated called until it returns false; or + // until thread is stopped. + virtual bool run() = 0; + + // The method to be run before thread loop (conditionally repeatedly) + // calls run() + inline virtual void prerun() {} + + // The method to be run after thread loop (conditionally repeatedly) + // calls run() + inline virtual void postrun() {} +}; + +// opaque class to provide service implementation. +class LocThreadDelegate; + +// A utility class to create a thread and run LocRunnable +// caller passes in. +class LocThread { + LocThreadDelegate* mThread; +public: + inline LocThread() : mThread(NULL) {} + virtual ~LocThread(); + + typedef pthread_t (*tCreate)(const char* name, void* (*start)(void*), void* arg); + // client starts thread with a runnable, which implements + // the logics to fun in the created thread context. + // The thread could be either joinable or detached. + // runnable is an obj managed by client. Client creates and + // frees it (but must be after stop() is called, or + // this LocThread obj is deleted). + // The obj will be deleted by LocThread if start() + // returns true. Else it is client's responsibility + // to delete the object + // Returns 0 if success; false if failure. + bool start(tCreate creator, const char* threadName, LocRunnable* runnable, bool joinable = true); + inline bool start(const char* threadName, LocRunnable* runnable, bool joinable = true) { + return start(NULL, threadName, runnable, joinable); + } + + // NOTE: if this is a joinable thread, this stop may block + // for a while until the thread is joined. + void stop(); + + // thread status check + inline bool isRunning() { return NULL != mThread; } +}; + +#endif //__LOC_THREAD__ diff --git a/gps/utils/LocTimer.cpp b/gps/utils/LocTimer.cpp new file mode 100644 index 0000000..c083e51 --- /dev/null +++ b/gps/utils/LocTimer.cpp @@ -0,0 +1,738 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __HOST_UNIT_TEST__ +#define EPOLLWAKEUP 0 +#define CLOCK_BOOTTIME CLOCK_MONOTONIC +#define CLOCK_BOOTTIME_ALARM CLOCK_MONOTONIC +#endif + +/* +There are implementations of 5 classes in this file: +LocTimer, LocTimerDelegate, LocTimerContainer, LocTimerPollTask, LocTimerWrapper + +LocTimer - client front end, interface for client to start / stop timers, also + to provide a callback. +LocTimerDelegate - an internal timer entity, which also is a LocRankable obj. + Its life cycle is different than that of LocTimer. It gets + created when LocTimer::start() is called, and gets deleted + when it expires or clients calls the hosting LocTimer obj's + stop() method. When a LocTimerDelegate obj is ticking, it + stays in the corresponding LocTimerContainer. When expired + or stopped, the obj is removed from the container. Since it + is also a LocRankable obj, and LocTimerContainer also is a + heap, its ranks() implementation decides where it is placed + in the heap. +LocTimerContainer - core of the timer service. It is a container (derived from + LocHeap) for LocTimerDelegate (implements LocRankable) objs. + There are 2 of such containers, one for sw timers (or Linux + timers) one for hw timers (or Linux alarms). It adds one of + each (those that expire the soonest) to kernel via services + provided by LocTimerPollTask. All the heap management on the + LocTimerDelegate objs are done in the MsgTask context, such + that synchronization is ensured. +LocTimerPollTask - is a class that wraps timerfd and epoll POXIS APIs. It also + both implements LocRunnalbe with epoll_wait() in the run() + method. It is also a LocThread client, so as to loop the run + method. +LocTimerWrapper - a LocTimer client itself, to implement the existing C API with + APIs, loc_timer_start() and loc_timer_stop(). + +*/ + +class LocTimerPollTask; + +// This is a multi-functaional class that: +// * extends the LocHeap class for the detection of head update upon add / remove +// events. When that happens, soonest time out changes, so timerfd needs update. +// * contains the timers, and add / remove them into the heap +// * provides and maps 2 of such containers, one for timers (or mSwTimers), one +// for alarms (or mHwTimers); +// * provides a polling thread; +// * provides a MsgTask thread for synchronized add / remove / timer client callback. +class LocTimerContainer : public LocHeap { + // mutex to synchronize getters of static members + static pthread_mutex_t mMutex; + // Container of timers + static LocTimerContainer* mSwTimers; + // Container of alarms + static LocTimerContainer* mHwTimers; + // Msg task to provider msg Q, sender and reader. + static MsgTask* mMsgTask; + // Poll task to provide epoll call and threading to poll. + static LocTimerPollTask* mPollTask; + // timer / alarm fd + int mDevFd; + // ctor + LocTimerContainer(bool wakeOnExpire); + // dtor + ~LocTimerContainer(); + static MsgTask* getMsgTaskLocked(); + static LocTimerPollTask* getPollTaskLocked(); + // extend LocHeap and pop if the top outRanks input + LocTimerDelegate* popIfOutRanks(LocTimerDelegate& timer); + // update the timer POSIX calls with updated soonest timer spec + void updateSoonestTime(LocTimerDelegate* priorTop); + +public: + // factory method to control the creation of mSwTimers / mHwTimers + static LocTimerContainer* get(bool wakeOnExpire); + + LocTimerDelegate* getSoonestTimer(); + int getTimerFd(); + // add a timer / alarm obj into the container + void add(LocTimerDelegate& timer); + // remove a timer / alarm obj from the container + void remove(LocTimerDelegate& timer); + // handling of timer / alarm expiration + void expire(); +}; + +// This class implements the polling thread that epolls imer / alarm fds. +// The LocRunnable::run() contains the actual polling. The other methods +// will be run in the caller's thread context to add / remove timer / alarm +// fds the kernel, while the polling is blocked on epoll_wait() call. +// Since the design is that we have maximally 2 polls, one for all the +// timers; one for all the alarms, we will poll at most on 2 fds. But it +// is possile that all we have are only timers or alarms at one time, so we +// allow dynamically add / remove fds we poll on. The design decision of +// having 1 fd per container of timer / alarm is such that, we may not need +// to make a system call each time a timer / alarm is added / removed, unless +// that changes the "soonest" time out of that of all the timers / alarms. +class LocTimerPollTask : public LocRunnable { + // the epoll fd + const int mFd; + // the thread that calls run() method + LocThread* mThread; + friend class LocThreadDelegate; + // dtor + ~LocTimerPollTask(); +public: + // ctor + LocTimerPollTask(); + // this obj will be deleted once thread is deleted + void destroy(); + // add a container of timers. Each contain has a unique device fd, i.e. + // either timer or alarm fd, and a heap of timers / alarms. It is expected + // that container would have written to the device fd with the soonest + // time out value in the heap at the time of calling this method. So all + // this method does is to add the fd of the input container to the poll + // and also add the pointer of the container to the event data ptr, such + // when poll_wait wakes up on events, we know who is the owner of the fd. + void addPoll(LocTimerContainer& timerContainer); + // remove a fd that is assciated with a container. The expectation is that + // the atual timer would have been removed from the container. + void removePoll(LocTimerContainer& timerContainer); + // The polling thread context will call this method. This is where + // epoll_wait() is blocking and waiting for events.. + virtual bool run(); +}; + +// Internal class of timer obj. It gets born when client calls LocTimer::start(); +// and gets deleted when client calls LocTimer::stop() or when the it expire()'s. +// This class implements LocRankable::ranks() so that when an obj is added into +// the container (of LocHeap), it gets placed in sorted order. +class LocTimerDelegate : public LocRankable { + friend class LocTimerContainer; + friend class LocTimer; + LocTimer* mClient; + LocSharedLock* mLock; + struct timespec mFutureTime; + LocTimerContainer* mContainer; + // not a complete obj, just ctor for LocRankable comparisons + inline LocTimerDelegate(struct timespec& delay) + : mClient(NULL), mLock(NULL), mFutureTime(delay), mContainer(NULL) {} + inline ~LocTimerDelegate() { if (mLock) { mLock->drop(); mLock = NULL; } } +public: + LocTimerDelegate(LocTimer& client, struct timespec& futureTime, bool wakeOnExpire); + void destroyLocked(); + // LocRankable virtual method + virtual int ranks(LocRankable& rankable); + void expire(); + inline struct timespec getFutureTime() { return mFutureTime; } +}; + +/***************************LocTimerContainer methods***************************/ + +// Most of these static recources are created on demand. They however are never +// destoyed. The theory is that there are processes that link to this util lib +// but never use timer, then these resources would never need to be created. +// For those processes that do use timer, it will likely also need to every +// once in a while. It might be cheaper keeping them around. +pthread_mutex_t LocTimerContainer::mMutex = PTHREAD_MUTEX_INITIALIZER; +LocTimerContainer* LocTimerContainer::mSwTimers = NULL; +LocTimerContainer* LocTimerContainer::mHwTimers = NULL; +MsgTask* LocTimerContainer::mMsgTask = NULL; +LocTimerPollTask* LocTimerContainer::mPollTask = NULL; + +// ctor - initialize timer heaps +// A container for swTimer (timer) is created, when wakeOnExpire is true; or +// HwTimer (alarm), when wakeOnExpire is false. +LocTimerContainer::LocTimerContainer(bool wakeOnExpire) : + mDevFd(timerfd_create(wakeOnExpire ? CLOCK_BOOTTIME_ALARM : CLOCK_BOOTTIME, 0)) { + + if ((-1 == mDevFd) && (errno == EINVAL)) { + LOC_LOGW("%s: timerfd_create failure, fallback to CLOCK_MONOTONIC - %s", + __FUNCTION__, strerror(errno)); + mDevFd = timerfd_create(CLOCK_MONOTONIC, 0); + } + + if (-1 != mDevFd) { + // ensure we have the necessary resources created + LocTimerContainer::getPollTaskLocked(); + LocTimerContainer::getMsgTaskLocked(); + } else { + LOC_LOGE("%s: timerfd_create failure - %s", __FUNCTION__, strerror(errno)); + } +} + +// dtor +// we do not ever destroy the static resources. +inline +LocTimerContainer::~LocTimerContainer() { + close(mDevFd); +} + +LocTimerContainer* LocTimerContainer::get(bool wakeOnExpire) { + // get the reference of either mHwTimer or mSwTimers per wakeOnExpire + LocTimerContainer*& container = wakeOnExpire ? mHwTimers : mSwTimers; + // it is cheap to check pointer first than locking mutext unconditionally + if (!container) { + pthread_mutex_lock(&mMutex); + // let's check one more time to be safe + if (!container) { + container = new LocTimerContainer(wakeOnExpire); + // timerfd_create failure + if (-1 == container->getTimerFd()) { + delete container; + container = NULL; + } + } + pthread_mutex_unlock(&mMutex); + } + return container; +} + +MsgTask* LocTimerContainer::getMsgTaskLocked() { + // it is cheap to check pointer first than locking mutext unconditionally + if (!mMsgTask) { + mMsgTask = new MsgTask("LocTimerMsgTask", false); + } + return mMsgTask; +} + +LocTimerPollTask* LocTimerContainer::getPollTaskLocked() { + // it is cheap to check pointer first than locking mutext unconditionally + if (!mPollTask) { + mPollTask = new LocTimerPollTask(); + } + return mPollTask; +} + +inline +LocTimerDelegate* LocTimerContainer::getSoonestTimer() { + return (LocTimerDelegate*)(peek()); +} + +inline +int LocTimerContainer::getTimerFd() { + return mDevFd; +} + +void LocTimerContainer::updateSoonestTime(LocTimerDelegate* priorTop) { + LocTimerDelegate* curTop = getSoonestTimer(); + + // check if top has changed + if (curTop != priorTop) { + struct itimerspec delay = {0}; + bool toSetTime = false; + // if tree is empty now, we remove poll and disarm timer + if (!curTop) { + mPollTask->removePoll(*this); + // setting the values to disarm timer + delay.it_value.tv_sec = 0; + delay.it_value.tv_nsec = 0; + toSetTime = true; + } else if (!priorTop || curTop->outRanks(*priorTop)) { + // do this first to avoid race condition, in case settime is called + // with too small an interval + mPollTask->addPoll(*this); + delay.it_value = curTop->getFutureTime(); + toSetTime = true; + } + if (toSetTime) { + timerfd_settime(getTimerFd(), TFD_TIMER_ABSTIME, &delay, NULL); + } + } +} + +// all the heap management is done in the MsgTask context. +inline +void LocTimerContainer::add(LocTimerDelegate& timer) { + struct MsgTimerPush : public LocMsg { + LocTimerContainer* mTimerContainer; + LocHeapNode* mTree; + LocTimerDelegate* mTimer; + inline MsgTimerPush(LocTimerContainer& container, LocTimerDelegate& timer) : + LocMsg(), mTimerContainer(&container), mTimer(&timer) {} + inline virtual void proc() const { + LocTimerDelegate* priorTop = mTimerContainer->getSoonestTimer(); + mTimerContainer->push((LocRankable&)(*mTimer)); + mTimerContainer->updateSoonestTime(priorTop); + } + }; + + mMsgTask->sendMsg(new MsgTimerPush(*this, timer)); +} + +// all the heap management is done in the MsgTask context. +void LocTimerContainer::remove(LocTimerDelegate& timer) { + struct MsgTimerRemove : public LocMsg { + LocTimerContainer* mTimerContainer; + LocTimerDelegate* mTimer; + inline MsgTimerRemove(LocTimerContainer& container, LocTimerDelegate& timer) : + LocMsg(), mTimerContainer(&container), mTimer(&timer) {} + inline virtual void proc() const { + LocTimerDelegate* priorTop = mTimerContainer->getSoonestTimer(); + + // update soonest timer only if mTimer is actually removed from + // mTimerContainer AND mTimer is not priorTop. + if (priorTop == ((LocHeap*)mTimerContainer)->remove((LocRankable&)*mTimer)) { + // if passing in NULL, we tell updateSoonestTime to update + // kernel with the current top timer interval. + mTimerContainer->updateSoonestTime(NULL); + } + // all timers are deleted here, and only here. + delete mTimer; + } + }; + + mMsgTask->sendMsg(new MsgTimerRemove(*this, timer)); +} + +// all the heap management is done in the MsgTask context. +// Upon expire, we check and continuously pop the heap until +// the top node's timeout is in the future. +void LocTimerContainer::expire() { + struct MsgTimerExpire : public LocMsg { + LocTimerContainer* mTimerContainer; + inline MsgTimerExpire(LocTimerContainer& container) : + LocMsg(), mTimerContainer(&container) {} + inline virtual void proc() const { + struct timespec now; + // get time spec of now + clock_gettime(CLOCK_BOOTTIME, &now); + LocTimerDelegate timerOfNow(now); + // pop everything in the heap that outRanks now, i.e. has time older than now + // and then call expire() on that timer. + for (LocTimerDelegate* timer = (LocTimerDelegate*)mTimerContainer->pop(); + NULL != timer; + timer = mTimerContainer->popIfOutRanks(timerOfNow)) { + // the timer delegate obj will be deleted before the return of this call + timer->expire(); + } + mTimerContainer->updateSoonestTime(NULL); + } + }; + + struct itimerspec delay = {0}; + timerfd_settime(getTimerFd(), TFD_TIMER_ABSTIME, &delay, NULL); + mPollTask->removePoll(*this); + mMsgTask->sendMsg(new MsgTimerExpire(*this)); +} + +LocTimerDelegate* LocTimerContainer::popIfOutRanks(LocTimerDelegate& timer) { + LocTimerDelegate* poppedNode = NULL; + if (mTree && !timer.outRanks(*peek())) { + poppedNode = (LocTimerDelegate*)(pop()); + } + + return poppedNode; +} + + +/***************************LocTimerPollTask methods***************************/ + +inline +LocTimerPollTask::LocTimerPollTask() + : mFd(epoll_create(2)), mThread(new LocThread()) { + // before a next call returens, a thread will be created. The run() method + // could already be running in parallel. Also, since each of the objs + // creates a thread, the container will make sure that there will be only + // one of such obj for our timer implementation. + if (!mThread->start("LocTimerPollTask", this)) { + delete mThread; + mThread = NULL; + } +} + +inline +LocTimerPollTask::~LocTimerPollTask() { + // when fs is closed, epoll_wait() should fail run() should return false + // and the spawned thread should exit. + close(mFd); +} + +void LocTimerPollTask::destroy() { + if (mThread) { + LocThread* thread = mThread; + mThread = NULL; + delete thread; + } else { + delete this; + } +} + +void LocTimerPollTask::addPoll(LocTimerContainer& timerContainer) { + struct epoll_event ev; + memset(&ev, 0, sizeof(ev)); + + ev.events = EPOLLIN | EPOLLWAKEUP; + ev.data.fd = timerContainer.getTimerFd(); + // it is important that we set this context pointer with the input + // timer container this is how we know which container should handle + // which expiration. + ev.data.ptr = &timerContainer; + + epoll_ctl(mFd, EPOLL_CTL_ADD, timerContainer.getTimerFd(), &ev); +} + +inline +void LocTimerPollTask::removePoll(LocTimerContainer& timerContainer) { + epoll_ctl(mFd, EPOLL_CTL_DEL, timerContainer.getTimerFd(), NULL); +} + +// The polling thread context will call this method. If run() method needs to +// be repetitvely called, it must return true from the previous call. +bool LocTimerPollTask::run() { + struct epoll_event ev[2]; + + // we have max 2 descriptors to poll from + int fds = epoll_wait(mFd, ev, 2, -1); + + // we pretty much want to continually poll until the fd is closed + bool rerun = (fds > 0) || (errno == EINTR); + + if (fds > 0) { + // we may have 2 events + for (int i = 0; i < fds; i++) { + // each fd has a context pointer associated with the right timer container + LocTimerContainer* container = (LocTimerContainer*)(ev[i].data.ptr); + if (container) { + container->expire(); + } else { + epoll_ctl(mFd, EPOLL_CTL_DEL, ev[i].data.fd, NULL); + } + } + } + + // if rerun is true, we are requesting to be scheduled again + return rerun; +} + +/***************************LocTimerDelegate methods***************************/ + +inline +LocTimerDelegate::LocTimerDelegate(LocTimer& client, struct timespec& futureTime, bool wakeOnExpire) + : mClient(&client), + mLock(mClient->mLock->share()), + mFutureTime(futureTime), + mContainer(LocTimerContainer::get(wakeOnExpire)) { + // adding the timer into the container + mContainer->add(*this); +} + +inline +void LocTimerDelegate::destroyLocked() { + // client handle will likely be deleted soon after this + // method returns. Nulling this handle so that expire() + // won't call the callback on the dead handle any more. + mClient = NULL; + + if (mContainer) { + LocTimerContainer* container = mContainer; + mContainer = NULL; + if (container) { + container->remove(*this); + } + } // else we do not do anything. No such *this* can be + // created and reached here with mContainer ever been + // a non NULL. So *this* must have reached the if clause + // once, and we want it reach there only once. +} + +int LocTimerDelegate::ranks(LocRankable& rankable) { + int rank = -1; + LocTimerDelegate* timer = (LocTimerDelegate*)(&rankable); + if (timer) { + // larger time ranks lower!!! + // IOW, if input obj has bigger tv_sec, this obj outRanks higher + rank = timer->mFutureTime.tv_sec - mFutureTime.tv_sec; + } + return rank; +} + +inline +void LocTimerDelegate::expire() { + // keeping a copy of client pointer to be safe + // when timeOutCallback() is called at the end of this + // method, *this* obj may be already deleted. + LocTimer* client = mClient; + // force a stop, which will lead to delete of this obj + if (client && client->stop()) { + // calling client callback with a pointer save on the stack + // only if stop() returns true, i.e. it hasn't been stopped + // already. + client->timeOutCallback(); + } +} + + +/***************************LocTimer methods***************************/ +LocTimer::LocTimer() : mTimer(NULL), mLock(new LocSharedLock()) { +} + +LocTimer::~LocTimer() { + stop(); + if (mLock) { + mLock->drop(); + mLock = NULL; + } +} + +bool LocTimer::start(unsigned int timeOutInMs, bool wakeOnExpire) { + bool success = false; + mLock->lock(); + if (!mTimer) { + struct timespec futureTime; + clock_gettime(CLOCK_BOOTTIME, &futureTime); + futureTime.tv_sec += timeOutInMs / 1000; + futureTime.tv_nsec += (timeOutInMs % 1000) * 1000000; + if (futureTime.tv_nsec >= 1000000000) { + futureTime.tv_sec += futureTime.tv_nsec / 1000000000; + futureTime.tv_nsec %= 1000000000; + } + mTimer = new LocTimerDelegate(*this, futureTime, wakeOnExpire); + // if mTimer is non 0, success should be 0; or vice versa + success = (NULL != mTimer); + } + mLock->unlock(); + return success; +} + +bool LocTimer::stop() { + bool success = false; + mLock->lock(); + if (mTimer) { + LocTimerDelegate* timer = mTimer; + mTimer = NULL; + if (timer) { + timer->destroyLocked(); + success = true; + } + } + mLock->unlock(); + return success; +} + +/***************************LocTimerWrapper methods***************************/ +////////////////////////////////////////////////////////////////////////// +// This section below wraps for the C style APIs +////////////////////////////////////////////////////////////////////////// +class LocTimerWrapper : public LocTimer { + loc_timer_callback mCb; + void* mCallerData; + LocTimerWrapper* mMe; + static pthread_mutex_t mMutex; + inline ~LocTimerWrapper() { mCb = NULL; mMe = NULL; } +public: + inline LocTimerWrapper(loc_timer_callback cb, void* callerData) : + mCb(cb), mCallerData(callerData), mMe(this) { + } + void destroy() { + pthread_mutex_lock(&mMutex); + if (NULL != mCb && this == mMe) { + delete this; + } + pthread_mutex_unlock(&mMutex); + } + virtual void timeOutCallback() { + loc_timer_callback cb = mCb; + void* callerData = mCallerData; + if (cb) { + cb(callerData, 0); + } + destroy(); + } +}; + +pthread_mutex_t LocTimerWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER; + +void* loc_timer_start(uint64_t msec, loc_timer_callback cb_func, + void *caller_data, bool wake_on_expire) +{ + LocTimerWrapper* locTimerWrapper = NULL; + + if (cb_func) { + locTimerWrapper = new LocTimerWrapper(cb_func, caller_data); + + if (locTimerWrapper) { + locTimerWrapper->start(msec, wake_on_expire); + } + } + + return locTimerWrapper; +} + +void loc_timer_stop(void*& handle) +{ + if (handle) { + LocTimerWrapper* locTimerWrapper = (LocTimerWrapper*)(handle); + locTimerWrapper->destroy(); + handle = NULL; + } +} + +////////////////////////////////////////////////////////////////////////// +// This section above wraps for the C style APIs +////////////////////////////////////////////////////////////////////////// + +#ifdef __LOC_DEBUG__ + +double getDeltaSeconds(struct timespec from, struct timespec to) { + return (double)to.tv_sec + (double)to.tv_nsec / 1000000000 + - from.tv_sec - (double)from.tv_nsec / 1000000000; +} + +struct timespec getNow() { + struct timespec now; + clock_gettime(CLOCK_BOOTTIME, &now); + return now; +} + +class LocTimerTest : public LocTimer, public LocRankable { + int mTimeOut; + const struct timespec mTimeOfBirth; + inline struct timespec getTimerWrapper(int timeout) { + struct timespec now; + clock_gettime(CLOCK_BOOTTIME, &now); + now.tv_sec += timeout; + return now; + } +public: + inline LocTimerTest(int timeout) : LocTimer(), LocRankable(), + mTimeOut(timeout), mTimeOfBirth(getTimerWrapper(0)) {} + inline virtual int ranks(LocRankable& rankable) { + LocTimerTest* timer = dynamic_cast(&rankable); + return timer->mTimeOut - mTimeOut; + } + inline virtual void timeOutCallback() { + printf("timeOutCallback() - "); + deviation(); + } + double deviation() { + struct timespec now = getTimerWrapper(0); + double delta = getDeltaSeconds(mTimeOfBirth, now); + printf("%lf: %lf\n", delta, delta * 100 / mTimeOut); + return delta / mTimeOut; + } +}; + +// For Linux command line testing: +// compilation: +// g++ -D__LOC_HOST_DEBUG__ -D__LOC_DEBUG__ -g -I. -I../../../../system/core/include -o LocHeap.o LocHeap.cpp +// g++ -D__LOC_HOST_DEBUG__ -D__LOC_DEBUG__ -g -std=c++0x -I. -I../../../../system/core/include -lpthread -o LocThread.o LocThread.cpp +// g++ -D__LOC_HOST_DEBUG__ -D__LOC_DEBUG__ -g -I. -I../../../../system/core/include -o LocTimer.o LocTimer.cpp +int main(int argc, char** argv) { + struct timespec timeOfStart=getNow(); + srand(time(NULL)); + int tries = atoi(argv[1]); + int checks = tries >> 3; + LocTimerTest** timerArray = new LocTimerTest*[tries]; + memset(timerArray, NULL, tries); + + for (int i = 0; i < tries; i++) { + int r = rand() % tries; + LocTimerTest* timer = new LocTimerTest(r); + if (timerArray[r]) { + if (!timer->stop()) { + printf("%lf:\n", getDeltaSeconds(timeOfStart, getNow())); + printf("ERRER: %dth timer, id %d, not running when it should be\n", i, r); + exit(0); + } else { + printf("stop() - %d\n", r); + delete timer; + timerArray[r] = NULL; + } + } else { + if (!timer->start(r, false)) { + printf("%lf:\n", getDeltaSeconds(timeOfStart, getNow())); + printf("ERRER: %dth timer, id %d, running when it should not be\n", i, r); + exit(0); + } else { + printf("stop() - %d\n", r); + timerArray[r] = timer; + } + } + } + + for (int i = 0; i < tries; i++) { + if (timerArray[i]) { + if (!timerArray[i]->stop()) { + printf("%lf:\n", getDeltaSeconds(timeOfStart, getNow())); + printf("ERRER: %dth timer, not running when it should be\n", i); + exit(0); + } else { + printf("stop() - %d\n", i); + delete timerArray[i]; + timerArray[i] = NULL; + } + } + } + + delete[] timerArray; + + return 0; +} + +#endif diff --git a/gps/utils/LocTimer.h b/gps/utils/LocTimer.h new file mode 100644 index 0000000..c146852 --- /dev/null +++ b/gps/utils/LocTimer.h @@ -0,0 +1,74 @@ +/* Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_TIMER_CPP_H__ +#define __LOC_TIMER_CPP_H__ + +#include +#include + +// opaque class to provide service implementation. +class LocTimerDelegate; +class LocSharedLock; + +// LocTimer client must extend this class and implementthe callback. +// start() / stop() methods are to arm / disarm timer. +class LocTimer +{ + LocTimerDelegate* mTimer; + LocSharedLock* mLock; + // don't really want mLock to be manipulated by clients, yet LocTimer + // has to have a reference to the lock so that the delete of LocTimer + // and LocTimerDelegate can work together on their share resources. + friend class LocTimerDelegate; + +public: + LocTimer(); + virtual ~LocTimer(); + + // timeOutInMs: timeout delay in ms + // wakeOnExpire: true if to wake up CPU (if sleeping) upon timer + // expiration and notify the client. + // false if to wait until next time CPU wakes up (if + // sleeping) and then notify the client. + // return: true on success; + // false on failure, e.g. timer is already running. + bool start(uint32_t timeOutInMs, bool wakeOnExpire); + + // return: true on success; + // false on failure, e.g. timer is not running. + bool stop(); + + // LocTimer client Should implement this method. + // This method is used for timeout calling back to client. This method + // should be short enough (eg: send a message to your own thread). + virtual void timeOutCallback() = 0; +}; + +#endif //__LOC_DELAY_H__ diff --git a/gps/utils/MsgTask.cpp b/gps/utils/MsgTask.cpp new file mode 100644 index 0000000..6f9d0e9 --- /dev/null +++ b/gps/utils/MsgTask.cpp @@ -0,0 +1,102 @@ +/* Copyright (c) 2011-2013,2015 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_MsgTask" + +#include +#include +#include +#include +#include +#include + +static void LocMsgDestroy(void* msg) { + delete (LocMsg*)msg; +} + +MsgTask::MsgTask(LocThread::tCreate tCreator, + const char* threadName, bool joinable) : + mQ(msg_q_init2()), mThread(new LocThread()) { + if (!mThread->start(tCreator, threadName, this, joinable)) { + delete mThread; + mThread = NULL; + } +} + +MsgTask::MsgTask(const char* threadName, bool joinable) : + mQ(msg_q_init2()), mThread(new LocThread()) { + if (!mThread->start(threadName, this, joinable)) { + delete mThread; + mThread = NULL; + } +} + +MsgTask::~MsgTask() { + msg_q_flush((void*)mQ); + msg_q_destroy((void**)&mQ); +} + +void MsgTask::destroy() { + msg_q_unblock((void*)mQ); + if (mThread) { + LocThread* thread = mThread; + mThread = NULL; + delete thread; + } else { + delete this; + } +} + +void MsgTask::sendMsg(const LocMsg* msg) const { + msg_q_snd((void*)mQ, (void*)msg, LocMsgDestroy); +} + +void MsgTask::prerun() { + // make sure we do not run in background scheduling group + set_sched_policy(gettid(), SP_FOREGROUND); +} + +bool MsgTask::run() { + LOC_LOGV("MsgTask::loop() listening ...\n"); + LocMsg* msg; + msq_q_err_type result = msg_q_rcv((void*)mQ, (void **)&msg); + if (eMSG_Q_SUCCESS != result) { + LOC_LOGE("%s:%d] fail receiving msg: %s\n", __func__, __LINE__, + loc_get_msg_q_status(result)); + return false; + } + + msg->log(); + // there is where each individual msg handling is invoked + msg->proc(); + + delete msg; + + return true; +} diff --git a/gps/utils/MsgTask.h b/gps/utils/MsgTask.h new file mode 100644 index 0000000..9eb1f56 --- /dev/null +++ b/gps/utils/MsgTask.h @@ -0,0 +1,67 @@ +/* Copyright (c) 2011-2013,2015 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __MSG_TASK__ +#define __MSG_TASK__ + +#include + +struct LocMsg { + inline LocMsg() {} + inline virtual ~LocMsg() {} + virtual void proc() const = 0; + inline virtual void log() const {} +}; + +class MsgTask : public LocRunnable { + const void* mQ; + LocThread* mThread; + friend class LocThreadDelegate; +protected: + virtual ~MsgTask(); +public: + MsgTask(LocThread::tCreate tCreator, const char* threadName = NULL, bool joinable = true); + MsgTask(const char* threadName = NULL, bool joinable = true); + // this obj will be deleted once thread is deleted + void destroy(); + void sendMsg(const LocMsg* msg) const; + // Overrides of LocRunnable methods + // This method will be repeated called until it returns false; or + // until thread is stopped. + virtual bool run(); + + // The method to be run before thread loop (conditionally repeatedly) + // calls run() + virtual void prerun(); + + // The method to be run after thread loop (conditionally repeatedly) + // calls run() + inline virtual void postrun() {} +}; + +#endif //__MSG_TASK__ diff --git a/gps/utils/linked_list.c b/gps/utils/linked_list.c new file mode 100644 index 0000000..2c91714 --- /dev/null +++ b/gps/utils/linked_list.c @@ -0,0 +1,328 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "linked_list.h" +#include +#include + +#define LOG_TAG "LocSvc_utils_ll" +#include "log_util.h" +#include "platform_lib_includes.h" +#include +#include + +typedef struct list_element { + struct list_element* next; + struct list_element* prev; + void* data_ptr; + void (*dealloc_func)(void*); +}list_element; + +typedef struct list_state { + list_element* p_head; + list_element* p_tail; +} list_state; + +/* ----------------------- END INTERNAL FUNCTIONS ---------------------------------------- */ + +/*=========================================================================== + + FUNCTION: linked_list_init + + ===========================================================================*/ +linked_list_err_type linked_list_init(void** list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_PARAMETER; + } + + list_state* tmp_list; + tmp_list = (list_state*)calloc(1, sizeof(list_state)); + if( tmp_list == NULL ) + { + LOC_LOGE("%s: Unable to allocate space for list!\n", __FUNCTION__); + return eLINKED_LIST_FAILURE_GENERAL; + } + + tmp_list->p_head = NULL; + tmp_list->p_tail = NULL; + + *list_data = tmp_list; + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_destroy + + ===========================================================================*/ +linked_list_err_type linked_list_destroy(void** list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + list_state* p_list = (list_state*)*list_data; + + linked_list_flush(p_list); + + free(*list_data); + *list_data = NULL; + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_add + + ===========================================================================*/ +linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*)) +{ + LOC_LOGV("%s: Adding to list data_obj = 0x%08X\n", __FUNCTION__, data_obj); + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + if( data_obj == NULL ) + { + LOC_LOGE("%s: Invalid input parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_PARAMETER; + } + + list_state* p_list = (list_state*)list_data; + list_element* elem = (list_element*)malloc(sizeof(list_element)); + if( elem == NULL ) + { + LOC_LOGE("%s: Memory allocation failed\n", __FUNCTION__); + return eLINKED_LIST_FAILURE_GENERAL; + } + + /* Copy data to newly created element */ + elem->data_ptr = data_obj; + elem->next = NULL; + elem->prev = NULL; + elem->dealloc_func = dealloc; + + /* Replace head element */ + list_element* tmp = p_list->p_head; + p_list->p_head = elem; + /* Point next to the previous head element */ + p_list->p_head->next = tmp; + + if( tmp != NULL ) + { + tmp->prev = p_list->p_head; + } + else + { + p_list->p_tail = p_list->p_head; + } + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_remove + + ===========================================================================*/ +linked_list_err_type linked_list_remove(void* list_data, void **data_obj) +{ + LOC_LOGV("%s: Removing from list\n", __FUNCTION__); + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + if( data_obj == NULL ) + { + LOC_LOGE("%s: Invalid input parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_PARAMETER; + } + + list_state* p_list = (list_state*)list_data; + if( p_list->p_tail == NULL ) + { + return eLINKED_LIST_UNAVAILABLE_RESOURCE; + } + + list_element* tmp = p_list->p_tail; + + /* Replace tail element */ + p_list->p_tail = tmp->prev; + + if( p_list->p_tail != NULL ) + { + p_list->p_tail->next = NULL; + } + else + { + p_list->p_head = p_list->p_tail; + } + + /* Copy data to output param */ + *data_obj = tmp->data_ptr; + + /* Free allocated list element */ + free(tmp); + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_empty + + ===========================================================================*/ +int linked_list_empty(void* list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return (int)eLINKED_LIST_INVALID_HANDLE; + } + else + { + list_state* p_list = (list_state*)list_data; + return p_list->p_head == NULL ? 1 : 0; + } +} + +/*=========================================================================== + + FUNCTION: linked_list_flush + + ===========================================================================*/ +linked_list_err_type linked_list_flush(void* list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + list_state* p_list = (list_state*)list_data; + + /* Remove all dynamically allocated elements */ + while( p_list->p_head != NULL ) + { + list_element* tmp = p_list->p_head->next; + + /* Free data pointer if told to do so. */ + if( p_list->p_head->dealloc_func != NULL ) + { + p_list->p_head->dealloc_func(p_list->p_head->data_ptr); + } + + /* Free list element */ + free(p_list->p_head); + + p_list->p_head = tmp; + } + + p_list->p_tail = NULL; + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_search + + ===========================================================================*/ +linked_list_err_type linked_list_search(void* list_data, void **data_p, + bool (*equal)(void* data_0, void* data), + void* data_0, bool rm_if_found) +{ + LOC_LOGV("%s: Search the list\n", __FUNCTION__); + if( list_data == NULL || NULL == equal ) + { + LOC_LOGE("%s: Invalid list parameter! list_data %p equal %p\n", + __FUNCTION__, list_data, equal); + return eLINKED_LIST_INVALID_HANDLE; + } + + list_state* p_list = (list_state*)list_data; + if( p_list->p_tail == NULL ) + { + return eLINKED_LIST_UNAVAILABLE_RESOURCE; + } + + list_element* tmp = p_list->p_head; + + if (NULL != data_p) { + *data_p = NULL; + } + + while (NULL != tmp) { + if ((*equal)(data_0, tmp->data_ptr)) { + if (NULL != data_p) { + *data_p = tmp->data_ptr; + } + + if (rm_if_found) { + if (NULL == tmp->prev) { + p_list->p_head = tmp->next; + } else { + tmp->prev->next = tmp->next; + } + + if (NULL == tmp->next) { + p_list->p_tail = tmp->prev; + } else { + tmp->next->prev = tmp->prev; + } + + tmp->prev = tmp->next = NULL; + + // dealloc data if it is not copied out && caller + // has given us a dealloc function pointer. + if (NULL == data_p && NULL != tmp->dealloc_func) { + tmp->dealloc_func(tmp->data_ptr); + } + free(tmp); + } + + tmp = NULL; + } else { + tmp = tmp->next; + } + } + + return eLINKED_LIST_SUCCESS; +} + diff --git a/gps/utils/linked_list.h b/gps/utils/linked_list.h new file mode 100644 index 0000000..a85f09a --- /dev/null +++ b/gps/utils/linked_list.h @@ -0,0 +1,217 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __LINKED_LIST_H__ +#define __LINKED_LIST_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include + +/** Linked List Return Codes */ +typedef enum +{ + eLINKED_LIST_SUCCESS = 0, + /**< Request was successful. */ + eLINKED_LIST_FAILURE_GENERAL = -1, + /**< Failed because of a general failure. */ + eLINKED_LIST_INVALID_PARAMETER = -2, + /**< Failed because the request contained invalid parameters. */ + eLINKED_LIST_INVALID_HANDLE = -3, + /**< Failed because an invalid handle was specified. */ + eLINKED_LIST_UNAVAILABLE_RESOURCE = -4, + /**< Failed because an there were not enough resources. */ + eLINKED_LIST_INSUFFICIENT_BUFFER = -5, + /**< Failed because an the supplied buffer was too small. */ +}linked_list_err_type; + +/*=========================================================================== +FUNCTION linked_list_init + +DESCRIPTION + Initializes internal structures for linked list. + + list_data: State of list to be initialized. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_init(void** list_data); + +/*=========================================================================== +FUNCTION linked_list_destroy + +DESCRIPTION + Destroys internal structures for linked list. + + p_list_data: State of list to be destroyed. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_destroy(void** list_data); + +/*=========================================================================== +FUNCTION linked_list_add + +DESCRIPTION + Adds an element to the head of the linked list. The passed in data pointer + is not modified or freed. Passed in data_obj is expected to live throughout + the use of the linked_list (i.e. data is not allocated internally) + + p_list_data: List to add data to the head of. + data_obj: Pointer to data to add into list + dealloc: Function used to deallocate memory for this element. Pass NULL + if you do not want data deallocated during a flush operation + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*)); + +/*=========================================================================== +FUNCTION linked_list_remove + +DESCRIPTION + Retrieves data from the list tail. data_obj is the tail element from the list + passed in by linked_list_add. + + p_list_data: List to remove the tail from. + data_obj: Pointer to data removed from list + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_remove(void* list_data, void **data_obj); + +/*=========================================================================== +FUNCTION linked_list_empty + +DESCRIPTION + Tells whether the list currently contains any elements + + p_list_data: List to check if empty. + +DEPENDENCIES + N/A + +RETURN VALUE + 0/FALSE : List contains elements + 1/TRUE : List is Empty + Otherwise look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +int linked_list_empty(void* list_data); + +/*=========================================================================== +FUNCTION linked_list_flush + +DESCRIPTION + Removes all elements from the list and deallocates them using the provided + dealloc function while adding elements. + + p_list_data: List to remove all elements from. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_flush(void* list_data); + +/*=========================================================================== +FUNCTION linked_list_search + +DESCRIPTION + Searches for an element in the linked list. + + p_list_data: List handle. + data_p: to be stored with the data found; NUll if no match. + if data_p passed in as NULL, then no write to it. + equal: Function ptr takes in a list element, and returns + indication if this the one looking for. + data_0: The data being compared against. + rm_if_found: Should data be removed if found? + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_search(void* list_data, void **data_p, + bool (*equal)(void* data_0, void* data), + void* data_0, bool rm_if_found); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LINKED_LIST_H__ */ diff --git a/gps/utils/loc_cfg.cpp b/gps/utils/loc_cfg.cpp new file mode 100644 index 0000000..967d2f3 --- /dev/null +++ b/gps/utils/loc_cfg.cpp @@ -0,0 +1,400 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_utils_cfg" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_GLIB +#include +#endif +#include "platform_lib_includes.h" + +/*============================================================================= + * + * GLOBAL DATA DECLARATION + * + *============================================================================*/ + +/* Parameter data */ +static uint32_t DEBUG_LEVEL = 0xff; +static uint32_t TIMESTAMP = 0; + +/* Parameter spec table */ +static const loc_param_s_type loc_param_table[] = +{ + {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, + {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, +}; +static const int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type); + +typedef struct loc_param_v_type +{ + char* param_name; + char* param_str_value; + int param_int_value; + double param_double_value; +}loc_param_v_type; + +/*=========================================================================== +FUNCTION loc_set_config_entry + +DESCRIPTION + Potentially sets a given configuration table entry based on the passed in + configuration value. This is done by using a string comparison of the + parameter names and those found in the configuration file. + +PARAMETERS: + config_entry: configuration entry in the table to possibly set + config_value: value to store in the entry if the parameter names match + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_set_config_entry(const loc_param_s_type* config_entry, loc_param_v_type* config_value) +{ + int ret=-1; + if(NULL == config_entry || NULL == config_value) + { + LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__); + return ret; + } + + if (strcmp(config_entry->param_name, config_value->param_name) == 0 && + config_entry->param_ptr) + { + switch (config_entry->param_type) + { + case 's': + if (strcmp(config_value->param_str_value, "NULL") == 0) + { + *((char*)config_entry->param_ptr) = '\0'; + } + else { + strlcpy((char*) config_entry->param_ptr, + config_value->param_str_value, + LOC_MAX_PARAM_STRING + 1); + } + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, + config_entry->param_name, (char*)config_entry->param_ptr); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + case 'n': + *((int *)config_entry->param_ptr) = config_value->param_int_value; + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, + config_entry->param_name, config_value->param_int_value); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + case 'f': + *((double *)config_entry->param_ptr) = config_value->param_double_value; + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, + config_entry->param_name, config_value->param_double_value); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + default: + LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", + __FUNCTION__, config_entry->param_name); + } + } + return ret; +} + +/*=========================================================================== +FUNCTION loc_fill_conf_item + +DESCRIPTION + Takes a line of configuration item and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + +PARAMETERS: + input_buf : buffer contanis config item + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + 0: Number of records in the config_table filled with input_buf + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_fill_conf_item(char* input_buf, + const loc_param_s_type* config_table, uint32_t table_length) +{ + int ret = 0; + + if (input_buf && config_table) { + char *lasts; + loc_param_v_type config_value; + memset(&config_value, 0, sizeof(config_value)); + + /* Separate variable and value */ + config_value.param_name = strtok_r(input_buf, "=", &lasts); + /* skip lines that do not contain "=" */ + if (config_value.param_name) { + config_value.param_str_value = strtok_r(NULL, "=", &lasts); + + /* skip lines that do not contain two operands */ + if (config_value.param_str_value) { + /* Trim leading and trailing spaces */ + loc_util_trim_space(config_value.param_name); + loc_util_trim_space(config_value.param_str_value); + + /* Parse numerical value */ + if ((strlen(config_value.param_str_value) >=3) && + (config_value.param_str_value[0] == '0') && + (tolower(config_value.param_str_value[1]) == 'x')) + { + /* hex */ + config_value.param_int_value = (int) strtol(&config_value.param_str_value[2], + (char**) NULL, 16); + } + else { + config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */ + config_value.param_int_value = atoi(config_value.param_str_value); /* dec */ + } + + for(uint32_t i = 0; NULL != config_table && i < table_length; i++) + { + if(!loc_set_config_entry(&config_table[i], &config_value)) { + ret += 1; + } + } + } + } + } + + return ret; +} + +/*=========================================================================== +FUNCTION loc_read_conf_r (repetitive) + +DESCRIPTION + Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + The difference between this and loc_read_conf is that this function returns + the file pointer position at the end of filling a config table. Also, it + reads a fixed number of parameters at a time which is equal to the length + of the configuration table. This functionality enables the caller to + repeatedly call the function to read data from the same file. + +PARAMETERS: + conf_fp : file pointer + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + 0: Table filled successfully + 1: No more parameters to read + -1: Error filling table + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_read_conf_r(FILE *conf_fp, const loc_param_s_type* config_table, uint32_t table_length) +{ + int ret=0; + + unsigned int num_params=table_length; + if(conf_fp == NULL) { + LOC_LOGE("%s:%d]: ERROR: File pointer is NULL\n", __func__, __LINE__); + ret = -1; + goto err; + } + + /* Clear all validity bits */ + for(uint32_t i = 0; NULL != config_table && i < table_length; i++) + { + if(NULL != config_table[i].param_set) + { + *(config_table[i].param_set) = 0; + } + } + + char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */ + + LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params); + while(num_params) + { + if(!fgets(input_buf, LOC_MAX_PARAM_LINE, conf_fp)) { + LOC_LOGD("%s:%d]: fgets returned NULL\n", __func__, __LINE__); + break; + } + + num_params -= loc_fill_conf_item(input_buf, config_table, table_length); + } + +err: + return ret; +} + +/*=========================================================================== +FUNCTION loc_udpate_conf + +DESCRIPTION + Parses the passed in buffer for configuration items, and update the table + that is also passed in. + +Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + +PARAMETERS: + conf_data: configuration items in bufferas a string + length: strlen(conf_data) + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + number of the records in the table that is updated at time of return. + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_update_conf(const char* conf_data, int32_t length, + const loc_param_s_type* config_table, uint32_t table_length) +{ + int ret = -1; + + if (conf_data && length && config_table && table_length) { + // make a copy, so we do not tokenize the original data + char* conf_copy = (char*)malloc(length+1); + + if (conf_copy != NULL) + { + memcpy(conf_copy, conf_data, length); + // we hard NULL the end of string to be safe + conf_copy[length] = 0; + + // start with one record off + uint32_t num_params = table_length - 1; + char* saveptr = NULL; + char* input_buf = strtok_r(conf_copy, "\n", &saveptr); + ret = 0; + + LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params); + while(num_params && input_buf) { + ret++; + num_params -= loc_fill_conf_item(input_buf, config_table, table_length); + input_buf = strtok_r(NULL, "\n", &saveptr); + } + free(conf_copy); + } + } + + return ret; +} + +/*=========================================================================== +FUNCTION loc_read_conf + +DESCRIPTION + Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + +PARAMETERS: + conf_file_name: configuration file to read + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_read_conf(const char* conf_file_name, const loc_param_s_type* config_table, + uint32_t table_length) +{ + FILE *conf_fp = NULL; + char *lasts; + loc_param_v_type config_value; + uint32_t i; + + if((conf_fp = fopen(conf_file_name, "r")) != NULL) + { + LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name); + if(table_length && config_table) { + loc_read_conf_r(conf_fp, config_table, table_length); + rewind(conf_fp); + } + loc_read_conf_r(conf_fp, loc_param_table, loc_param_num); + fclose(conf_fp); + } + /* Initialize logging mechanism with parsed data */ + loc_logger_init(DEBUG_LEVEL, TIMESTAMP); +} diff --git a/gps/utils/loc_cfg.h b/gps/utils/loc_cfg.h new file mode 100644 index 0000000..9045e1d --- /dev/null +++ b/gps/utils/loc_cfg.h @@ -0,0 +1,91 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_CFG_H +#define LOC_CFG_H + +#include +#include + +#define LOC_MAX_PARAM_NAME 80 +#define LOC_MAX_PARAM_STRING 80 +#define LOC_MAX_PARAM_LINE (LOC_MAX_PARAM_NAME + LOC_MAX_PARAM_STRING) + +#define UTIL_UPDATE_CONF(conf_data, len, config_table) \ + loc_update_conf((conf_data), (len), (config_table), \ + sizeof(config_table) / sizeof(config_table[0])) + +#define UTIL_READ_CONF_DEFAULT(filename) \ + loc_read_conf((filename), NULL, 0); + +#define UTIL_READ_CONF(filename, config_table) \ + loc_read_conf((filename), (config_table), sizeof(config_table) / sizeof(config_table[0])) + +/*============================================================================= + * + * MODULE TYPE DECLARATION + * + *============================================================================*/ +typedef struct +{ + const char *param_name; + void *param_ptr; + uint8_t *param_set; /* was this value set by config file? */ + char param_type; /* 'n' for number, + 's' for string, + 'f' for float */ +} loc_param_s_type; + +/*============================================================================= + * + * MODULE EXTERNAL DATA + * + *============================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*============================================================================= + * + * MODULE EXPORTED FUNCTIONS + * + *============================================================================*/ +void loc_read_conf(const char* conf_file_name, + const loc_param_s_type* config_table, + uint32_t table_length); +int loc_read_conf_r(FILE *conf_fp, const loc_param_s_type* config_table, + uint32_t table_length); +int loc_update_conf(const char* conf_data, int32_t length, + const loc_param_s_type* config_table, uint32_t table_length); +#ifdef __cplusplus +} +#endif + +#endif /* LOC_CFG_H */ diff --git a/gps/utils/loc_log.cpp b/gps/utils/loc_log.cpp new file mode 100644 index 0000000..2ff0277 --- /dev/null +++ b/gps/utils/loc_log.cpp @@ -0,0 +1,244 @@ +/* Copyright (c) 2011-2012, 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDDEBUG 0 + +#include +#include +#include +#include +#include +#include "loc_log.h" +#include "msg_q.h" +#ifdef USE_GLIB +#include +#endif /* USE_GLIB */ +#include "log_util.h" +#include "platform_lib_includes.h" + +#define BUFFER_SIZE 120 + +// Logging Improvements +const char *loc_logger_boolStr[]={"False","True"}; +const char VOID_RET[] = "None"; +const char FROM_AFW[] = "===>"; +const char TO_MODEM[] = "--->"; +const char FROM_MODEM[] = "<---"; +const char TO_AFW[] = "<==="; +const char EXIT_TAG[] = "Exiting"; +const char ENTRY_TAG[] = "Entering"; +const char EXIT_ERROR_TAG[] = "Exiting with error"; + +/* Logging Mechanism */ +loc_logger_s_type loc_logger; + +/* Get names from value */ +const char* loc_get_name_from_mask(const loc_name_val_s_type table[], size_t table_size, long mask) +{ + size_t i; + for (i = 0; i < table_size; i++) + { + if (table[i].val & (long) mask) + { + return table[i].name; + } + } + return UNKNOWN_STR; +} + +/* Get names from value */ +const char* loc_get_name_from_val(const loc_name_val_s_type table[], size_t table_size, long value) +{ + size_t i; + for (i = 0; i < table_size; i++) + { + if (table[i].val == (long) value) + { + return table[i].name; + } + } + return UNKNOWN_STR; +} + +static const loc_name_val_s_type loc_msg_q_status[] = +{ + NAME_VAL( eMSG_Q_SUCCESS ), + NAME_VAL( eMSG_Q_FAILURE_GENERAL ), + NAME_VAL( eMSG_Q_INVALID_PARAMETER ), + NAME_VAL( eMSG_Q_INVALID_HANDLE ), + NAME_VAL( eMSG_Q_UNAVAILABLE_RESOURCE ), + NAME_VAL( eMSG_Q_INSUFFICIENT_BUFFER ) +}; +static const size_t loc_msg_q_status_num = LOC_TABLE_SIZE(loc_msg_q_status); + +/* Find msg_q status name */ +const char* loc_get_msg_q_status(int status) +{ + return loc_get_name_from_val(loc_msg_q_status, loc_msg_q_status_num, (long) status); +} + +const char* log_succ_fail_string(int is_succ) +{ + return is_succ? "successful" : "failed"; +} + +//Target names +static const loc_name_val_s_type target_name[] = +{ + NAME_VAL(GNSS_NONE), + NAME_VAL(GNSS_MSM), + NAME_VAL(GNSS_GSS), + NAME_VAL(GNSS_MDM), + NAME_VAL(GNSS_QCA1530), + NAME_VAL(GNSS_AUTO), + NAME_VAL(GNSS_UNKNOWN) +}; + +static const size_t target_name_num = LOC_TABLE_SIZE(target_name); + +/*=========================================================================== + +FUNCTION loc_get_target_name + +DESCRIPTION + Returns pointer to a string that contains name of the target + + XX:XX:XX.000\0 + +RETURN VALUE + The target name string + +===========================================================================*/ +const char *loc_get_target_name(unsigned int target) +{ + int index = 0; + static char ret[BUFFER_SIZE]; + + index = getTargetGnssType(target); + if( index < 0 || (unsigned)index >= target_name_num ) + index = target_name_num - 1; + + if( (target & HAS_SSC) == HAS_SSC ) { + snprintf(ret, sizeof(ret), " %s with SSC", + loc_get_name_from_val(target_name, target_name_num, (long)index) ); + } + else { + snprintf(ret, sizeof(ret), " %s without SSC", + loc_get_name_from_val(target_name, target_name_num, (long)index) ); + } + return ret; +} + + +/*=========================================================================== + +FUNCTION loc_get_time + +DESCRIPTION + Logs a callback event header. + The pointer time_string should point to a buffer of at least 13 bytes: + + XX:XX:XX.000\0 + +RETURN VALUE + The time string + +===========================================================================*/ +char *loc_get_time(char *time_string, size_t buf_size) +{ + struct timeval now; /* sec and usec */ + struct tm now_tm; /* broken-down time */ + char hms_string[80]; /* HH:MM:SS */ + + gettimeofday(&now, NULL); + localtime_r(&now.tv_sec, &now_tm); + + strftime(hms_string, sizeof hms_string, "%H:%M:%S", &now_tm); + snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_usec / 1000)); + + return time_string; +} + + +/*=========================================================================== +FUNCTION loc_logger_init + +DESCRIPTION + Initializes the state of DEBUG_LEVEL and TIMESTAMP + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_logger_init(unsigned long debug, unsigned long timestamp) +{ + loc_logger.DEBUG_LEVEL = debug; +#ifdef TARGET_BUILD_VARIANT_USER + // force user builds to 2 or less + if (loc_logger.DEBUG_LEVEL > 2) { + loc_logger.DEBUG_LEVEL = 2; + } +#endif + loc_logger.TIMESTAMP = timestamp; +} + + +/*=========================================================================== +FUNCTION get_timestamp + +DESCRIPTION + Generates a timestamp using the current system time + +DEPENDENCIES + N/A + +RETURN VALUE + Char pointer to the parameter str + +SIDE EFFECTS + N/A +===========================================================================*/ +char * get_timestamp(char *str, unsigned long buf_size) +{ + struct timeval tv; + struct timezone tz; + int hh, mm, ss; + gettimeofday(&tv, &tz); + hh = tv.tv_sec/3600%24; + mm = (tv.tv_sec%3600)/60; + ss = tv.tv_sec%60; + snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_usec); + return str; +} + diff --git a/gps/utils/loc_log.h b/gps/utils/loc_log.h new file mode 100644 index 0000000..be492b1 --- /dev/null +++ b/gps/utils/loc_log.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2011-2012, 2015 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_LOG_H +#define LOC_LOG_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include +#include "loc_target.h" + +typedef struct +{ + const char *name; + long val; +} loc_name_val_s_type; + +#define NAME_VAL(x) {"" #x "", x } + +#define UNKNOWN_STR "UNKNOWN" + +#define CHECK_MASK(type, value, mask_var, mask) \ + (((mask_var) & (mask)) ? (type) (value) : (type) (-1)) + +#define LOC_TABLE_SIZE(table) (sizeof(table)/sizeof((table)[0])) + +/* Get names from value */ +const char* loc_get_name_from_mask(const loc_name_val_s_type table[], size_t table_size, long mask); +const char* loc_get_name_from_val(const loc_name_val_s_type table[], size_t table_size, long value); +const char* loc_get_msg_q_status(int status); +const char* loc_get_target_name(unsigned int target); + +extern const char* log_succ_fail_string(int is_succ); + +extern char *loc_get_time(char *time_string, size_t buf_size); + +#ifdef __cplusplus +} +#endif + +#endif /* LOC_LOG_H */ diff --git a/gps/utils/loc_misc_utils.cpp b/gps/utils/loc_misc_utils.cpp new file mode 100644 index 0000000..7e96313 --- /dev/null +++ b/gps/utils/loc_misc_utils.cpp @@ -0,0 +1,114 @@ +/* Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include +#include +#include +#include + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_misc_utils" + +int loc_util_split_string(char *raw_string, char **split_strings_ptr, + int max_num_substrings, char delimiter) +{ + int raw_string_index=0; + int num_split_strings=0; + unsigned char end_string=0; + int raw_string_length=0; + + if(!raw_string || !split_strings_ptr) { + LOC_LOGE("%s:%d]: NULL parameters", __func__, __LINE__); + num_split_strings = -1; + goto err; + } + LOC_LOGD("%s:%d]: raw string: %s\n", __func__, __LINE__, raw_string); + raw_string_length = strlen(raw_string) + 1; + split_strings_ptr[num_split_strings] = &raw_string[raw_string_index]; + for(raw_string_index=0; raw_string_index < raw_string_length; raw_string_index++) { + if(raw_string[raw_string_index] == '\0') + end_string=1; + if((raw_string[raw_string_index] == delimiter) || end_string) { + raw_string[raw_string_index] = '\0'; + LOC_LOGD("%s:%d]: split string: %s\n", + __func__, __LINE__, split_strings_ptr[num_split_strings]); + num_split_strings++; + if(((raw_string_index + 1) < raw_string_length) && + (num_split_strings < max_num_substrings)) { + split_strings_ptr[num_split_strings] = &raw_string[raw_string_index+1]; + } + else { + break; + } + } + if(end_string) + break; + } +err: + LOC_LOGD("%s:%d]: num_split_strings: %d\n", __func__, __LINE__, num_split_strings); + return num_split_strings; +} + +void loc_util_trim_space(char *org_string) +{ + char *scan_ptr, *write_ptr; + char *first_nonspace = NULL, *last_nonspace = NULL; + + if(org_string == NULL) { + LOC_LOGE("%s:%d]: NULL parameter", __func__, __LINE__); + goto err; + } + + scan_ptr = write_ptr = org_string; + + while (*scan_ptr) { + //Find the first non-space character + if ( !isspace(*scan_ptr) && first_nonspace == NULL) { + first_nonspace = scan_ptr; + } + //Once the first non-space character is found in the + //above check, keep shifting the characters to the left + //to replace the spaces + if (first_nonspace != NULL) { + *(write_ptr++) = *scan_ptr; + //Keep track of which was the last non-space character + //encountered + //last_nonspace will not be updated in the case where + //the string ends with spaces + if ( !isspace(*scan_ptr)) { + last_nonspace = write_ptr; + } + } + scan_ptr++; + } + //Add NULL terminator after the last non-space character + if (last_nonspace) { *last_nonspace = '\0'; } +err: + return; +} diff --git a/gps/utils/loc_misc_utils.h b/gps/utils/loc_misc_utils.h new file mode 100644 index 0000000..7d66d84 --- /dev/null +++ b/gps/utils/loc_misc_utils.h @@ -0,0 +1,99 @@ +/* Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _LOC_MISC_UTILS_H_ +#define _LOC_MISC_UTILS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*=========================================================================== +FUNCTION loc_split_string + +DESCRIPTION: + This function is used to split a delimiter separated string into + sub-strings. This function does not allocate new memory to store the split + strings. Instead, it places '\0' in places of delimiters and assings the + starting address of the substring within the raw string as the string address + The input raw_string no longer remains to be a collection of sub-strings + after this function is executed. + Please make a copy of the input string before calling this function if + necessary + +PARAMETERS: + char *raw_string: is the original string with delimiter separated substrings + char **split_strings_ptr: is the arraw of pointers which will hold the addresses + of individual substrings + int max_num_substrings: is the maximum number of substrings that are expected + by the caller. The array of pointers in the above parameter + is usually this long + char delimiter: is the delimiter that separates the substrings. Examples: ' ', ';' + +DEPENDENCIES + N/A + +RETURN VALUE + int Number of split strings + +SIDE EFFECTS + The input raw_string no longer remains a delimiter separated single string. + +EXAMPLE + delimiter = ' ' //space + raw_string = "hello new user" //delimiter is space ' ' + addresses = 0123456789abcd + split_strings_ptr[0] = &raw_string[0]; //split_strings_ptr[0] contains "hello" + split_strings_ptr[1] = &raw_string[6]; //split_strings_ptr[1] contains "new" + split_strings_ptr[2] = &raw_string[a]; //split_strings_ptr[2] contains "user" + +===========================================================================*/ +int loc_util_split_string(char *raw_string, char **split_strings_ptr, int max_num_substrings, + char delimiter); + +/*=========================================================================== +FUNCTION trim_space + +DESCRIPTION + Removes leading and trailing spaces of the string + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_util_trim_space(char *org_string); +#ifdef __cplusplus +} +#endif + +#endif //_LOC_MISC_UTILS_H_ diff --git a/gps/utils/loc_target.cpp b/gps/utils/loc_target.cpp new file mode 100644 index 0000000..cd7c8b9 --- /dev/null +++ b/gps/utils/loc_target.cpp @@ -0,0 +1,262 @@ +/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "loc_target.h" +#include "loc_log.h" +#include "log_util.h" + +#define APQ8064_ID_1 "109" +#define APQ8064_ID_2 "153" +#define MPQ8064_ID_1 "130" +#define MSM8930_ID_1 "142" +#define MSM8930_ID_2 "116" +#define APQ8030_ID_1 "157" +#define APQ8074_ID_1 "184" + +#define LINE_LEN 100 +#define STR_LIQUID "Liquid" +#define STR_SURF "Surf" +#define STR_MTP "MTP" +#define STR_APQ "apq" +#define STR_AUTO "auto" +#define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r') +#define LENGTH(s) (sizeof(s) - 1) +#define GPS_CHECK_NO_ERROR 0 +#define GPS_CHECK_NO_GPS_HW 1 +/* When system server is started, it uses 20 seconds as ActivityManager + * timeout. After that it sends SIGSTOP signal to process. + */ +#define QCA1530_DETECT_TIMEOUT 15 +#define QCA1530_DETECT_PRESENT "yes" +#define QCA1530_DETECT_PROGRESS "detect" + +static unsigned int gTarget = (unsigned int)-1; + +static int read_a_line(const char * file_path, char * line, int line_size) +{ + FILE *fp; + int result = 0; + + * line = '\0'; + fp = fopen(file_path, "r" ); + if( fp == NULL ) { + LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno)); + result = -1; + } else { + int len; + fgets(line, line_size, fp); + len = strlen(line); + len = len < line_size - 1? len : line_size - 1; + line[len] = '\0'; + LOC_LOGD("cat %s: %s", file_path, line); + fclose(fp); + } + return result; +} + +/*! + * \brief Checks if QCA1530 is avalable. + * + * Function verifies if qca1530 SoC is configured on the device. The test is + * based on property value. For 1530 scenario, the value shall be one of the + * following: "yes", "no", "detect". All other values are treated equally to + * "no". When the value is "detect" the system waits for SoC detection to + * finish before returning result. + * + * \retval true - QCA1530 is available. + * \retval false - QCA1530 is not available. + */ +static bool is_qca1530(void) +{ + static const char qca1530_property_name[] = "sys.qca1530"; + bool res = false; + int ret, i; + char buf[PROPERTY_VALUE_MAX]; + + memset(buf, 0, sizeof(buf)); + + for (i = 0; i < QCA1530_DETECT_TIMEOUT; ++i) + { + ret = property_get(qca1530_property_name, buf, NULL); + if (ret < 0) + { + LOC_LOGV( "qca1530: property %s is not accessible, ret=%d", + qca1530_property_name, + ret); + + break; + } + + LOC_LOGV( "qca1530: property %s is set to %s", + qca1530_property_name, + buf); + + if (!memcmp(buf, QCA1530_DETECT_PRESENT, + sizeof(QCA1530_DETECT_PRESENT))) + { + res = true; + break; + } + if (!memcmp(buf, QCA1530_DETECT_PROGRESS, + sizeof(QCA1530_DETECT_PROGRESS))) + { + LOC_LOGV("qca1530: SoC detection is in progress."); + sleep(1); + continue; + } + break; + } + + LOC_LOGD("qca1530: detected=%s", res ? "true" : "false"); + return res; +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_target_baseband(char *baseband, int array_length) +{ + if(baseband && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.baseband", baseband, ""); + LOC_LOGD("%s:%d]: Baseband: %s\n", __func__, __LINE__, baseband); + } + else { + LOC_LOGE("%s:%d]: NULL parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_platform_name(char *platform_name, int array_length) +{ + if(platform_name && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.board.platform", platform_name, ""); + LOC_LOGD("%s:%d]: Target name: %s\n", __func__, __LINE__, platform_name); + } + else { + LOC_LOGE("%s:%d]: Null parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + +unsigned int loc_get_target(void) +{ + if (gTarget != (unsigned int)-1) + return gTarget; + + static const char hw_platform[] = "/sys/devices/soc0/hw_platform"; + static const char id[] = "/sys/devices/soc0/soc_id"; + static const char hw_platform_dep[] = + "/sys/devices/system/soc/soc0/hw_platform"; + static const char id_dep[] = "/sys/devices/system/soc/soc0/id"; + static const char mdm[] = "/dev/mdm"; // No such file or directory + + char rd_hw_platform[LINE_LEN]; + char rd_id[LINE_LEN]; + char rd_mdm[LINE_LEN]; + char baseband[LINE_LEN]; + + if (is_qca1530()) { + gTarget = TARGET_QCA1530; + goto detected; + } + + loc_get_target_baseband(baseband, sizeof(baseband)); + + if (!access(hw_platform, F_OK)) { + read_a_line(hw_platform, rd_hw_platform, LINE_LEN); + } else { + read_a_line(hw_platform_dep, rd_hw_platform, LINE_LEN); + } + if (!access(id, F_OK)) { + read_a_line(id, rd_id, LINE_LEN); + } else { + read_a_line(id_dep, rd_id, LINE_LEN); + } + if( !memcmp(baseband, STR_AUTO, LENGTH(STR_AUTO)) ) + { + gTarget = TARGET_AUTO; + goto detected; + } + if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){ + + if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1)) + && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) ) + gTarget = TARGET_MPQ; + else + gTarget = TARGET_APQ_SA; + } + else { + if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) || + (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) || + (!memcmp(rd_hw_platform, STR_MTP, LENGTH(STR_MTP)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) { + + if (!read_a_line( mdm, rd_mdm, LINE_LEN)) + gTarget = TARGET_MDM; + } + else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1)) + && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) || + (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) + && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) ) + gTarget = TARGET_MSM_NO_SSC; + else + gTarget = TARGET_UNKNOWN; + } + +detected: + LOC_LOGD("HAL: %s returned %d", __FUNCTION__, gTarget); + return gTarget; +} + +/*Reads the property ro.lean to identify if this is a lean target + Returns: + 0 if not a lean and mean target + 1 if this is a lean and mean target +*/ +int loc_identify_lean_target() +{ + int ret = 0; + char lean_target[PROPERTY_VALUE_MAX]; + property_get("ro.lean", lean_target, ""); + LOC_LOGD("%s:%d]: lean target: %s\n", __func__, __LINE__, lean_target); + return !(strncmp(lean_target, "true", PROPERTY_VALUE_MAX)); +} diff --git a/gps/utils/loc_target.h b/gps/utils/loc_target.h new file mode 100644 index 0000000..3bb3b5e --- /dev/null +++ b/gps/utils/loc_target.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_TARGET_H +#define LOC_TARGET_H +#define TARGET_SET(gnss,ssc) ( (gnss<<1)|ssc ) +#define TARGET_DEFAULT TARGET_SET(GNSS_MSM, HAS_SSC) +#define TARGET_MDM TARGET_SET(GNSS_MDM, HAS_SSC) +#define TARGET_APQ_SA TARGET_SET(GNSS_GSS, NO_SSC) +#define TARGET_MPQ TARGET_SET(GNSS_NONE,NO_SSC) +#define TARGET_MSM_NO_SSC TARGET_SET(GNSS_MSM, NO_SSC) +#define TARGET_QCA1530 TARGET_SET(GNSS_QCA1530, NO_SSC) +#define TARGET_AUTO TARGET_SET(GNSS_AUTO, NO_SSC) +#define TARGET_UNKNOWN TARGET_SET(GNSS_UNKNOWN, NO_SSC) +#define getTargetGnssType(target) (target>>1) + +#ifdef __cplusplus +extern "C" +{ +#endif + +unsigned int loc_get_target(void); + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_target_baseband(char *baseband, int array_length); +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_platform_name(char *platform_name, int array_length); +/*Reads the property ro.lean to identify if this is a lean target + Returns: + 0 if not a lean and mean target + 1 if this is a lean and mean target*/ +int loc_identify_lean_target(); + +/* Please remember to update 'target_name' in loc_log.cpp, + if do any changes to this enum. */ +typedef enum { + GNSS_NONE = 0, + GNSS_MSM, + GNSS_GSS, + GNSS_MDM, + GNSS_QCA1530, + GNSS_AUTO, + GNSS_UNKNOWN +}GNSS_TARGET; + +typedef enum { + NO_SSC = 0, + HAS_SSC +}SSC_TYPE; + +#ifdef __cplusplus +} +#endif + +#endif /*LOC_TARGET_H*/ diff --git a/gps/utils/loc_timer.h b/gps/utils/loc_timer.h new file mode 100644 index 0000000..2967858 --- /dev/null +++ b/gps/utils/loc_timer.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2013,2015 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_DELAY_H__ +#define __LOC_DELAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include + +/* + user_data: client context pointer, passthrough. Originally received + from calling client when loc_timer_start() is called. + result: 0 if timer successfully timed out; else timer failed. +*/ +typedef void (*loc_timer_callback)(void *user_data, int32_t result); + + +/* + delay_msec: timeout value for the timer. + cb_func: callback function pointer, implemented by client. + Can not be NULL. + user_data: client context pointer, passthrough. Will be + returned when loc_timer_callback() is called. + wakeOnExpire: true if to wake up CPU (if sleeping) upon timer + expiration and notify the client. + false if to wait until next time CPU wakes up (if + sleeping) and then notify the client. + Returns the handle, which can be used to stop the timer + NULL, if timer start fails (e.g. if cb_func is NULL). +*/ +void* loc_timer_start(uint64_t delay_msec, + loc_timer_callback cb_func, + void *user_data, + bool wake_on_expire=false); + +/* + handle becomes invalid upon the return of the callback +*/ +void loc_timer_stop(void*& handle); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif //__LOC_DELAY_H__ diff --git a/gps/utils/log_util.h b/gps/utils/log_util.h new file mode 100644 index 0000000..0d59f01 --- /dev/null +++ b/gps/utils/log_util.h @@ -0,0 +1,167 @@ +/* Copyright (c) 2011-2014 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOG_UTIL_H__ +#define __LOG_UTIL_H__ + +#ifndef USE_GLIB +#include +#endif /* USE_GLIB */ + +#ifdef USE_GLIB + +#include +#include +#include + +#ifndef LOG_TAG +#define LOG_TAG "GPS_UTILS" + +#endif // LOG_TAG + +#endif /* USE_GLIB */ + +#ifdef __cplusplus +extern "C" +{ +#endif +/*============================================================================= + * + * LOC LOGGER TYPE DECLARATION + * + *============================================================================*/ +/* LOC LOGGER */ +typedef struct loc_logger_s +{ + unsigned long DEBUG_LEVEL; + unsigned long TIMESTAMP; +} loc_logger_s_type; + +/*============================================================================= + * + * EXTERNAL DATA + * + *============================================================================*/ +extern loc_logger_s_type loc_logger; + +// Logging Improvements +extern const char *loc_logger_boolStr[]; + +extern const char *boolStr[]; +extern const char VOID_RET[]; +extern const char FROM_AFW[]; +extern const char TO_MODEM[]; +extern const char FROM_MODEM[]; +extern const char TO_AFW[]; +extern const char EXIT_TAG[]; +extern const char ENTRY_TAG[]; +extern const char EXIT_ERROR_TAG[]; + +/*============================================================================= + * + * MODULE EXPORTED FUNCTIONS + * + *============================================================================*/ +extern void loc_logger_init(unsigned long debug, unsigned long timestamp); +extern char* get_timestamp(char* str, unsigned long buf_size); + +#ifndef DEBUG_DMN_LOC_API + +/* LOGGING MACROS */ +/*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp + if that value remains unchanged, it means gps.conf did not + provide a value and we default to the initial value to use + Android's logging levels*/ +#define IF_LOC_LOGE if((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5)) +#define IF_LOC_LOGW if((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5)) +#define IF_LOC_LOGI if((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5)) +#define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5)) +#define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5)) + +#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); } +#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); } +#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); } +#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); } +#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); } + +#else /* DEBUG_DMN_LOC_API */ + +#define LOC_LOGE(...) ALOGE(__VA_ARGS__) +#define LOC_LOGW(...) ALOGW(__VA_ARGS__) +#define LOC_LOGI(...) ALOGI(__VA_ARGS__) +#define LOC_LOGD(...) ALOGD(__VA_ARGS__) +#define LOC_LOGV(...) ALOGV(__VA_ARGS__) + +#endif /* DEBUG_DMN_LOC_API */ + +/*============================================================================= + * + * LOGGING IMPROVEMENT MACROS + * + *============================================================================*/ +#define LOG_(LOC_LOG, ID, WHAT, SPEC, VAL) \ + do { \ + if (loc_logger.TIMESTAMP) { \ + char ts[32]; \ + LOC_LOG("[%s] %s %s line %d " #SPEC, \ + get_timestamp(ts, sizeof(ts)), ID, WHAT, __LINE__, VAL); \ + } else { \ + LOC_LOG("%s %s line %d " #SPEC, \ + ID, WHAT, __LINE__, VAL); \ + } \ + } while(0) + +#define LOG_I(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGI, ID, WHAT, SPEC, VAL) +#define LOG_V(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGV, ID, WHAT, SPEC, VAL) +#define LOG_E(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGE, ID, WHAT, SPEC, VAL) + +#define ENTRY_LOG() LOG_V(ENTRY_TAG, __FUNCTION__, %s, "") +#define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __FUNCTION__, SPEC, VAL) +#define EXIT_LOG_WITH_ERROR(SPEC, VAL) \ + if (VAL != 0) { \ + LOG_E(EXIT_ERROR_TAG, __FUNCTION__, SPEC, VAL); \ + } else { \ + LOG_V(EXIT_TAG, __FUNCTION__, SPEC, VAL); \ + } + + +// Used for logging callflow from Android Framework +#define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __FUNCTION__, %s, "") +// Used for logging callflow to Modem +#define EXIT_LOG_CALLFLOW(SPEC, VAL) LOG_I(TO_MODEM, __FUNCTION__, SPEC, VAL) +// Used for logging callflow from Modem(TO_MODEM, __FUNCTION__, %s, "") +#define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __FUNCTION__, SPEC, VAL) +// Used for logging callflow to Android Framework +#define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL) + +#ifdef __cplusplus +} +#endif + +#endif // __LOG_UTIL_H__ diff --git a/gps/utils/msg_q.c b/gps/utils/msg_q.c new file mode 100644 index 0000000..5be8547 --- /dev/null +++ b/gps/utils/msg_q.c @@ -0,0 +1,336 @@ +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "msg_q.h" + +#define LOG_TAG "LocSvc_utils_q" +#include "log_util.h" +#include "platform_lib_includes.h" +#include "linked_list.h" +#include +#include +#include + +typedef struct msg_q { + void* msg_list; /* Linked list to store information */ + pthread_cond_t list_cond; /* Condition variable for waiting on msg queue */ + pthread_mutex_t list_mutex; /* Mutex for exclusive access to message queue */ + int unblocked; /* Has this message queue been unblocked? */ +} msg_q; + +/*=========================================================================== +FUNCTION convert_linked_list_err_type + +DESCRIPTION + Converts from one set of enum values to another. + + linked_list_val: Value to convert to msg_q_enum_type + +DEPENDENCIES + N/A + +RETURN VALUE + Corresponding linked_list_enum_type in msg_q_enum_type + +SIDE EFFECTS + N/A + +===========================================================================*/ +static msq_q_err_type convert_linked_list_err_type(linked_list_err_type linked_list_val) +{ + switch( linked_list_val ) + { + case eLINKED_LIST_SUCCESS: + return eMSG_Q_SUCCESS; + case eLINKED_LIST_INVALID_PARAMETER: + return eMSG_Q_INVALID_PARAMETER; + case eLINKED_LIST_INVALID_HANDLE: + return eMSG_Q_INVALID_HANDLE; + case eLINKED_LIST_UNAVAILABLE_RESOURCE: + return eMSG_Q_UNAVAILABLE_RESOURCE; + case eLINKED_LIST_INSUFFICIENT_BUFFER: + return eMSG_Q_INSUFFICIENT_BUFFER; + + case eLINKED_LIST_FAILURE_GENERAL: + default: + return eMSG_Q_FAILURE_GENERAL; + } +} + +/* ----------------------- END INTERNAL FUNCTIONS ---------------------------------------- */ + +/*=========================================================================== + + FUNCTION: msg_q_init + + ===========================================================================*/ +msq_q_err_type msg_q_init(void** msg_q_data) +{ + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* tmp_msg_q; + tmp_msg_q = (msg_q*)calloc(1, sizeof(msg_q)); + if( tmp_msg_q == NULL ) + { + LOC_LOGE("%s: Unable to allocate space for message queue!\n", __FUNCTION__); + return eMSG_Q_FAILURE_GENERAL; + } + + if( linked_list_init(&tmp_msg_q->msg_list) != 0 ) + { + LOC_LOGE("%s: Unable to initialize storage list!\n", __FUNCTION__); + free(tmp_msg_q); + return eMSG_Q_FAILURE_GENERAL; + } + + if( pthread_mutex_init(&tmp_msg_q->list_mutex, NULL) != 0 ) + { + LOC_LOGE("%s: Unable to initialize list mutex!\n", __FUNCTION__); + linked_list_destroy(&tmp_msg_q->msg_list); + free(tmp_msg_q); + return eMSG_Q_FAILURE_GENERAL; + } + + if( pthread_cond_init(&tmp_msg_q->list_cond, NULL) != 0 ) + { + LOC_LOGE("%s: Unable to initialize msg q cond var!\n", __FUNCTION__); + linked_list_destroy(&tmp_msg_q->msg_list); + pthread_mutex_destroy(&tmp_msg_q->list_mutex); + free(tmp_msg_q); + return eMSG_Q_FAILURE_GENERAL; + } + + tmp_msg_q->unblocked = 0; + + *msg_q_data = tmp_msg_q; + + return eMSG_Q_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: msg_q_init2 + + ===========================================================================*/ +const void* msg_q_init2() +{ + void* q = NULL; + if (eMSG_Q_SUCCESS != msg_q_init(&q)) { + q = NULL; + } + return q; +} + +/*=========================================================================== + + FUNCTION: msg_q_destroy + + ===========================================================================*/ +msq_q_err_type msg_q_destroy(void** msg_q_data) +{ + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + msg_q* p_msg_q = (msg_q*)*msg_q_data; + + linked_list_destroy(&p_msg_q->msg_list); + pthread_mutex_destroy(&p_msg_q->list_mutex); + pthread_cond_destroy(&p_msg_q->list_cond); + + p_msg_q->unblocked = 0; + + free(*msg_q_data); + *msg_q_data = NULL; + + return eMSG_Q_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: msg_q_snd + + ===========================================================================*/ +msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*)) +{ + msq_q_err_type rv; + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + if( msg_obj == NULL ) + { + LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + pthread_mutex_lock(&p_msg_q->list_mutex); + LOC_LOGV("%s: Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj); + + if( p_msg_q->unblocked ) + { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + rv = convert_linked_list_err_type(linked_list_add(p_msg_q->msg_list, msg_obj, dealloc)); + + /* Show data is in the message queue. */ + pthread_cond_signal(&p_msg_q->list_cond); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGV("%s: Finished Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj); + + return rv; +} + +/*=========================================================================== + + FUNCTION: msg_q_rcv + + ===========================================================================*/ +msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj) +{ + msq_q_err_type rv; + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + if( msg_obj == NULL ) + { + LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + LOC_LOGV("%s: Waiting on message\n", __FUNCTION__); + + pthread_mutex_lock(&p_msg_q->list_mutex); + + if( p_msg_q->unblocked ) + { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + /* Wait for data in the message queue */ + while( linked_list_empty(p_msg_q->msg_list) && !p_msg_q->unblocked ) + { + pthread_cond_wait(&p_msg_q->list_cond, &p_msg_q->list_mutex); + } + + rv = convert_linked_list_err_type(linked_list_remove(p_msg_q->msg_list, msg_obj)); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGV("%s: Received message 0x%08X rv = %d\n", __FUNCTION__, *msg_obj, rv); + + return rv; +} + +/*=========================================================================== + + FUNCTION: msg_q_flush + + ===========================================================================*/ +msq_q_err_type msg_q_flush(void* msg_q_data) +{ + msq_q_err_type rv; + if ( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + LOC_LOGD("%s: Flushing Message Queue\n", __FUNCTION__); + + pthread_mutex_lock(&p_msg_q->list_mutex); + + /* Remove all elements from the list */ + rv = convert_linked_list_err_type(linked_list_flush(p_msg_q->msg_list)); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGD("%s: Message Queue flushed\n", __FUNCTION__); + + return rv; +} + +/*=========================================================================== + + FUNCTION: msg_q_unblock + + ===========================================================================*/ +msq_q_err_type msg_q_unblock(void* msg_q_data) +{ + if ( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + pthread_mutex_lock(&p_msg_q->list_mutex); + + if( p_msg_q->unblocked ) + { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + LOC_LOGD("%s: Unblocking Message Queue\n", __FUNCTION__); + /* Unblocking message queue */ + p_msg_q->unblocked = 1; + + /* Allow all the waiters to wake up */ + pthread_cond_broadcast(&p_msg_q->list_cond); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGD("%s: Message Queue unblocked\n", __FUNCTION__); + + return eMSG_Q_SUCCESS; +} diff --git a/gps/utils/msg_q.h b/gps/utils/msg_q.h new file mode 100644 index 0000000..453b8ce --- /dev/null +++ b/gps/utils/msg_q.h @@ -0,0 +1,207 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MSG_Q_H__ +#define __MSG_Q_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +/** Linked List Return Codes */ +typedef enum +{ + eMSG_Q_SUCCESS = 0, + /**< Request was successful. */ + eMSG_Q_FAILURE_GENERAL = -1, + /**< Failed because of a general failure. */ + eMSG_Q_INVALID_PARAMETER = -2, + /**< Failed because the request contained invalid parameters. */ + eMSG_Q_INVALID_HANDLE = -3, + /**< Failed because an invalid handle was specified. */ + eMSG_Q_UNAVAILABLE_RESOURCE = -4, + /**< Failed because an there were not enough resources. */ + eMSG_Q_INSUFFICIENT_BUFFER = -5, + /**< Failed because an the supplied buffer was too small. */ +}msq_q_err_type; + +/*=========================================================================== +FUNCTION msg_q_init + +DESCRIPTION + Initializes internal structures for message queue. + + msg_q_data: pointer to an opaque Q handle to be returned; NULL if fails + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_init(void** msg_q_data); + +/*=========================================================================== +FUNCTION msg_q_init2 + +DESCRIPTION + Initializes internal structures for message queue. + +DEPENDENCIES + N/A + +RETURN VALUE + opaque handle to the Q created; NULL if create fails + +SIDE EFFECTS + N/A + +===========================================================================*/ +const void* msg_q_init2(); + +/*=========================================================================== +FUNCTION msg_q_destroy + +DESCRIPTION + Releases internal structures for message queue. + + msg_q_data: State of message queue to be released. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_destroy(void** msg_q_data); + +/*=========================================================================== +FUNCTION msg_q_snd + +DESCRIPTION + Sends data to the message queue. The passed in data pointer + is not modified or freed. Passed in msg_obj is expected to live throughout + the use of the msg_q (i.e. data is not allocated internally) + + msg_q_data: Message Queue to add the element to. + msgp: Pointer to data to add into message queue. + dealloc: Function used to deallocate memory for this element. Pass NULL + if you do not want data deallocated during a flush operation + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*)); + +/*=========================================================================== +FUNCTION msg_q_rcv + +DESCRIPTION + Retrieves data from the message queue. msg_obj is the oldest message received + and pointer is simply removed from message queue. + + msg_q_data: Message Queue to copy data from into msgp. + msg_obj: Pointer to space to copy msg_q contents to. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj); + +/*=========================================================================== +FUNCTION msg_q_flush + +DESCRIPTION + Function removes all elements from the message queue. + + msg_q_data: Message Queue to remove elements from. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_flush(void* msg_q_data); + +/*=========================================================================== +FUNCTION msg_q_unblock + +DESCRIPTION + This function will stop use of the message queue. All waiters will wake up + and likely receive nothing from the queue resulting in a negative return + value. The message queue can no longer be used until it is destroyed + and initialized again after calling this function. + + msg_q_data: Message queue to unblock. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_unblock(void* msg_q_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __MSG_Q_H__ */ diff --git a/gps/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp b/gps/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp new file mode 100644 index 0000000..e8cb93a --- /dev/null +++ b/gps/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "platform_lib_time.h" + +int64_t systemTime(int clock) +{ + struct timeval t; + t.tv_sec = t.tv_usec = 0; + gettimeofday(&t, NULL); + return t.tv_sec*1000000LL + t.tv_usec; +} + + +int64_t elapsedMillisSinceBoot() +{ + int64_t t_us = systemTime(0); + return (int64_t) t_us / 1000LL; +} diff --git a/gps/utils/platform_lib_abstractions/platform_lib_includes.h b/gps/utils/platform_lib_abstractions/platform_lib_includes.h new file mode 100644 index 0000000..5858674 --- /dev/null +++ b/gps/utils/platform_lib_abstractions/platform_lib_includes.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _PLATFORM_LIB_INCLUDES_H_ +#define _PLATFORM_LIB_INCLUDES_H_ + +#include "platform_lib_time.h" +#include "platform_lib_macros.h" + +#endif diff --git a/gps/utils/platform_lib_abstractions/platform_lib_macros.h b/gps/utils/platform_lib_abstractions/platform_lib_macros.h new file mode 100644 index 0000000..bc48dd9 --- /dev/null +++ b/gps/utils/platform_lib_abstractions/platform_lib_macros.h @@ -0,0 +1,81 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PLATFORM_LIB_MACROS_H__ +#define __PLATFORM_LIB_MACROS_H__ + +#include + +#define TS_PRINTF(format, x...) \ +{ \ + struct timeval tv; \ + struct timezone tz; \ + int hh, mm, ss; \ + gettimeofday(&tv, &tz); \ + hh = tv.tv_sec/3600%24; \ + mm = (tv.tv_sec%3600)/60; \ + ss = tv.tv_sec%60; \ + fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_usec,##x); \ +} + + +#ifdef USE_GLIB + +#define strlcat g_strlcat +#define strlcpy g_strlcpy + +#define ALOGE(format, x...) TS_PRINTF("E/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGW(format, x...) TS_PRINTF("W/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGI(format, x...) TS_PRINTF("I/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGD(format, x...) TS_PRINTF("D/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGV(format, x...) TS_PRINTF("V/%s (%d): " format , LOG_TAG, getpid(), ##x) + +#define GETTID_PLATFORM_LIB_ABSTRACTION (syscall(SYS_gettid)) + +#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION createPthread +#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION (elapsedMillisSinceBoot()) + + +#else + +#ifdef __cplusplus +extern "C" { +#endif +pid_t gettid(void); + +#ifdef __cplusplus +} +#endif + +#define GETTID_PLATFORM_LIB_ABSTRACTION (gettid()) +#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION android::AndroidRuntime::createJavaThread +#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION (android::elapsedRealtime()) + +#endif + +#endif diff --git a/gps/utils/platform_lib_abstractions/platform_lib_time.h b/gps/utils/platform_lib_abstractions/platform_lib_time.h new file mode 100644 index 0000000..ce013af --- /dev/null +++ b/gps/utils/platform_lib_abstractions/platform_lib_time.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _PLATFORM_LIB_TIME_H_ +#define _PLATFORM_LIB_TIME_H_ + +int64_t systemTime(int clock); +int64_t elapsedMillisSinceBoot(); + +#endif diff --git a/hidl/Android.mk b/hidl/Android.mk new file mode 100644 index 0000000..7a6c116 --- /dev/null +++ b/hidl/Android.mk @@ -0,0 +1,13 @@ +include $(CLEAR_VARS) +LOCAL_SHARED_LIBRARIES := libhidltransport +LOCAL_MODULE := android.hidl.base@1.0 +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_SHARED_LIBRARIES := libhidltransport +LOCAL_MODULE := android.hidl.manager@1.0 +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +include $(BUILD_SHARED_LIBRARY) diff --git a/imx175/Android.mk b/imx175/Android.mk new file mode 100644 index 0000000..78fd54f --- /dev/null +++ b/imx175/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := imx175_shim.cpp +LOCAL_MODULE := libimx175_shim +LOCAL_SHARED_LIBRARIES := liblog +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) + diff --git a/imx175/imx175_shim.cpp b/imx175/imx175_shim.cpp new file mode 100644 index 0000000..aa4aa45 --- /dev/null +++ b/imx175/imx175_shim.cpp @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +extern "C" { + int property_get(const char * key, char * value, const char * default_value) { + ALOGE("%s: E", __FUNCTION__); + if (strcmp("ro.revision", key) == 0) { + ALOGE("%s: ro.revision was called!", __FUNCTION__); + strcpy(value, "4"); + return 3; + } + ALOGE("%s: called other property: %s", __FUNCTION__, key); + return ((int( * )(const char * , char *, const char * ))(dlsym((void * ) - 1, "property_get")))(key, value, default_value); + } +} diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h new file mode 100644 index 0000000..586e85c --- /dev/null +++ b/include/camera/CameraParameters.h @@ -0,0 +1,818 @@ +/* + * Copyright (C) 2008 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. + */ + +#ifndef ANDROID_HARDWARE_CAMERA_PARAMETERS_H +#define ANDROID_HARDWARE_CAMERA_PARAMETERS_H + +#include +#include + +namespace android { + +struct Size { + int width; + int height; + + Size() { + width = 0; + height = 0; + } + + Size(int w, int h) { + width = w; + height = h; + } +}; + +class CameraParameters +{ +public: + CameraParameters(); + CameraParameters(const String8 ¶ms) { unflatten(params); } + ~CameraParameters(); + + String8 flatten() const; + void unflatten(const String8 ¶ms); + + void set(const char *key, const char *value); + void set(const char *key, int value); + void setFloat(const char *key, float value); + const char *get(const char *key) const; + int getInt(const char *key) const; + float getFloat(const char *key) const; + + void remove(const char *key); + + void setPreviewSize(int width, int height); + void getPreviewSize(int *width, int *height) const; + void getSupportedPreviewSizes(Vector &sizes) const; + + // Set the dimensions in pixels to the given width and height + // for video frames. The given width and height must be one + // of the supported dimensions returned from + // getSupportedVideoSizes(). Must not be called if + // getSupportedVideoSizes() returns an empty Vector of Size. + void setVideoSize(int width, int height); + // Retrieve the current dimensions (width and height) + // in pixels for video frames, which must be one of the + // supported dimensions returned from getSupportedVideoSizes(). + // Must not be called if getSupportedVideoSizes() returns an + // empty Vector of Size. + void getVideoSize(int *width, int *height) const; + // Retrieve a Vector of supported dimensions (width and height) + // in pixels for video frames. If sizes returned from the method + // is empty, the camera does not support calls to setVideoSize() + // or getVideoSize(). In adddition, it also indicates that + // the camera only has a single output, and does not have + // separate output for video frames and preview frame. + void getSupportedVideoSizes(Vector &sizes) const; + // Retrieve the preferred preview size (width and height) in pixels + // for video recording. The given width and height must be one of + // supported preview sizes returned from getSupportedPreviewSizes(). + // Must not be called if getSupportedVideoSizes() returns an empty + // Vector of Size. If getSupportedVideoSizes() returns an empty + // Vector of Size, the width and height returned from this method + // is invalid, and is "-1x-1". + void getPreferredPreviewSizeForVideo(int *width, int *height) const; + + void setPreviewFrameRate(int fps); + int getPreviewFrameRate() const; + void getPreviewFpsRange(int *min_fps, int *max_fps) const; + void setPreviewFormat(const char *format); + const char *getPreviewFormat() const; + void setPictureSize(int width, int height); + void getPictureSize(int *width, int *height) const; + void getSupportedPictureSizes(Vector &sizes) const; + void setPictureFormat(const char *format); + const char *getPictureFormat() const; + + void dump() const; + status_t dump(int fd, const Vector& args) const; + + /** + * Returns a Vector containing the supported preview formats + * as enums given in graphics.h. + */ + void getSupportedPreviewFormats(Vector& formats) const; + + // Returns true if no keys are present + bool isEmpty() const; + + // Parameter keys to communicate between camera application and driver. + // The access (read/write, read only, or write only) is viewed from the + // perspective of applications, not driver. + + // Preview frame size in pixels (width x height). + // Example value: "480x320". Read/Write. + static const char KEY_PREVIEW_SIZE[]; + // Supported preview frame sizes in pixels. + // Example value: "800x600,480x320". Read only. + static const char KEY_SUPPORTED_PREVIEW_SIZES[]; + // The current minimum and maximum preview fps. This controls the rate of + // preview frames received (CAMERA_MSG_PREVIEW_FRAME). The minimum and + // maximum fps must be one of the elements from + // KEY_SUPPORTED_PREVIEW_FPS_RANGE parameter. + // Example value: "10500,26623" + static const char KEY_PREVIEW_FPS_RANGE[]; + // The supported preview fps (frame-per-second) ranges. Each range contains + // a minimum fps and maximum fps. If minimum fps equals to maximum fps, the + // camera outputs frames in fixed frame rate. If not, the camera outputs + // frames in auto frame rate. The actual frame rate fluctuates between the + // minimum and the maximum. The list has at least one element. The list is + // sorted from small to large (first by maximum fps and then minimum fps). + // Example value: "(10500,26623),(15000,26623),(30000,30000)" + static const char KEY_SUPPORTED_PREVIEW_FPS_RANGE[]; + // The image format for preview frames. See CAMERA_MSG_PREVIEW_FRAME in + // frameworks/av/include/camera/Camera.h. The default is + // PIXEL_FORMAT_YUV420SP. Example value: "yuv420sp" or PIXEL_FORMAT_XXX + // constants. Read/write. + static const char KEY_PREVIEW_FORMAT[]; + // Supported image formats for preview frames. + // Example value: "yuv420sp,yuv422i-yuyv". Read only. + static const char KEY_SUPPORTED_PREVIEW_FORMATS[]; + // Number of preview frames per second. This is the target frame rate. The + // actual frame rate depends on the driver. + // Example value: "15". Read/write. + static const char KEY_PREVIEW_FRAME_RATE[]; + // Supported number of preview frames per second. + // Example value: "24,15,10". Read. + static const char KEY_SUPPORTED_PREVIEW_FRAME_RATES[]; + // The dimensions for captured pictures in pixels (width x height). + // Example value: "1024x768". Read/write. + static const char KEY_PICTURE_SIZE[]; + // Supported dimensions for captured pictures in pixels. + // Example value: "2048x1536,1024x768". Read only. + static const char KEY_SUPPORTED_PICTURE_SIZES[]; + // The image format for captured pictures. See CAMERA_MSG_COMPRESSED_IMAGE + // in frameworks/base/include/camera/Camera.h. + // Example value: "jpeg" or PIXEL_FORMAT_XXX constants. Read/write. + static const char KEY_PICTURE_FORMAT[]; + // Supported image formats for captured pictures. + // Example value: "jpeg,rgb565". Read only. + static const char KEY_SUPPORTED_PICTURE_FORMATS[]; + // The width (in pixels) of EXIF thumbnail in Jpeg picture. + // Example value: "512". Read/write. + static const char KEY_JPEG_THUMBNAIL_WIDTH[]; + // The height (in pixels) of EXIF thumbnail in Jpeg picture. + // Example value: "384". Read/write. + static const char KEY_JPEG_THUMBNAIL_HEIGHT[]; + // Supported EXIF thumbnail sizes (width x height). 0x0 means not thumbnail + // in EXIF. + // Example value: "512x384,320x240,0x0". Read only. + static const char KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[]; + // The quality of the EXIF thumbnail in Jpeg picture. The range is 1 to 100, + // with 100 being the best. + // Example value: "90". Read/write. + static const char KEY_JPEG_THUMBNAIL_QUALITY[]; + // Jpeg quality of captured picture. The range is 1 to 100, with 100 being + // the best. + // Example value: "90". Read/write. + static const char KEY_JPEG_QUALITY[]; + // The rotation angle in degrees relative to the orientation of the camera. + // This affects the pictures returned from CAMERA_MSG_COMPRESSED_IMAGE. The + // camera driver may set orientation in the EXIF header without rotating the + // picture. Or the driver may rotate the picture and the EXIF thumbnail. If + // the Jpeg picture is rotated, the orientation in the EXIF header will be + // missing or 1 (row #0 is top and column #0 is left side). + // + // Note that the JPEG pictures of front-facing cameras are not mirrored + // as in preview display. + // + // For example, suppose the natural orientation of the device is portrait. + // The device is rotated 270 degrees clockwise, so the device orientation is + // 270. Suppose a back-facing camera sensor is mounted in landscape and the + // top side of the camera sensor is aligned with the right edge of the + // display in natural orientation. So the camera orientation is 90. The + // rotation should be set to 0 (270 + 90). + // + // Example value: "0" or "90" or "180" or "270". Write only. + static const char KEY_ROTATION[]; + // GPS latitude coordinate. GPSLatitude and GPSLatitudeRef will be stored in + // JPEG EXIF header. + // Example value: "25.032146" or "-33.462809". Write only. + static const char KEY_GPS_LATITUDE[]; + // GPS longitude coordinate. GPSLongitude and GPSLongitudeRef will be stored + // in JPEG EXIF header. + // Example value: "121.564448" or "-70.660286". Write only. + static const char KEY_GPS_LONGITUDE[]; + // GPS altitude. GPSAltitude and GPSAltitudeRef will be stored in JPEG EXIF + // header. + // Example value: "21.0" or "-5". Write only. + static const char KEY_GPS_ALTITUDE[]; + // GPS timestamp (UTC in seconds since January 1, 1970). This should be + // stored in JPEG EXIF header. + // Example value: "1251192757". Write only. + static const char KEY_GPS_TIMESTAMP[]; + // GPS Processing Method + // Example value: "GPS" or "NETWORK". Write only. + static const char KEY_GPS_PROCESSING_METHOD[]; + // Current white balance setting. + // Example value: "auto" or WHITE_BALANCE_XXX constants. Read/write. + static const char KEY_WHITE_BALANCE[]; + // Supported white balance settings. + // Example value: "auto,incandescent,daylight". Read only. + static const char KEY_SUPPORTED_WHITE_BALANCE[]; + // Current color effect setting. + // Example value: "none" or EFFECT_XXX constants. Read/write. + static const char KEY_EFFECT[]; + // Supported color effect settings. + // Example value: "none,mono,sepia". Read only. + static const char KEY_SUPPORTED_EFFECTS[]; + // Current antibanding setting. + // Example value: "auto" or ANTIBANDING_XXX constants. Read/write. + static const char KEY_ANTIBANDING[]; + // Supported antibanding settings. + // Example value: "auto,50hz,60hz,off". Read only. + static const char KEY_SUPPORTED_ANTIBANDING[]; + // Current scene mode. + // Example value: "auto" or SCENE_MODE_XXX constants. Read/write. + static const char KEY_SCENE_MODE[]; + // Supported scene mode settings. + // Example value: "auto,night,fireworks". Read only. + static const char KEY_SUPPORTED_SCENE_MODES[]; + // Current flash mode. + // Example value: "auto" or FLASH_MODE_XXX constants. Read/write. + static const char KEY_FLASH_MODE[]; + // Supported flash modes. + // Example value: "auto,on,off". Read only. + static const char KEY_SUPPORTED_FLASH_MODES[]; + // Current focus mode. This will not be empty. Applications should call + // CameraHardwareInterface.autoFocus to start the focus if focus mode is + // FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. + // Example value: "auto" or FOCUS_MODE_XXX constants. Read/write. + static const char KEY_FOCUS_MODE[]; + // Supported focus modes. + // Example value: "auto,macro,fixed". Read only. + static const char KEY_SUPPORTED_FOCUS_MODES[]; + // The maximum number of focus areas supported. This is the maximum length + // of KEY_FOCUS_AREAS. + // Example value: "0" or "2". Read only. + static const char KEY_MAX_NUM_FOCUS_AREAS[]; + // Current focus areas. + // + // Before accessing this parameter, apps should check + // KEY_MAX_NUM_FOCUS_AREAS first to know the maximum number of focus areas + // first. If the value is 0, focus area is not supported. + // + // Each focus area is a five-element int array. The first four elements are + // the rectangle of the area (left, top, right, bottom). The direction is + // relative to the sensor orientation, that is, what the sensor sees. The + // direction is not affected by the rotation or mirroring of + // CAMERA_CMD_SET_DISPLAY_ORIENTATION. Coordinates range from -1000 to 1000. + // (-1000,-1000) is the upper left point. (1000, 1000) is the lower right + // point. The width and height of focus areas cannot be 0 or negative. + // + // The fifth element is the weight. Values for weight must range from 1 to + // 1000. The weight should be interpreted as a per-pixel weight - all + // pixels in the area have the specified weight. This means a small area + // with the same weight as a larger area will have less influence on the + // focusing than the larger area. Focus areas can partially overlap and the + // driver will add the weights in the overlap region. + // + // A special case of single focus area (0,0,0,0,0) means driver to decide + // the focus area. For example, the driver may use more signals to decide + // focus areas and change them dynamically. Apps can set (0,0,0,0,0) if they + // want the driver to decide focus areas. + // + // Focus areas are relative to the current field of view (KEY_ZOOM). No + // matter what the zoom level is, (-1000,-1000) represents the top of the + // currently visible camera frame. The focus area cannot be set to be + // outside the current field of view, even when using zoom. + // + // Focus area only has effect if the current focus mode is FOCUS_MODE_AUTO, + // FOCUS_MODE_MACRO, FOCUS_MODE_CONTINUOUS_VIDEO, or + // FOCUS_MODE_CONTINUOUS_PICTURE. + // Example value: "(-10,-10,0,0,300),(0,0,10,10,700)". Read/write. + static const char KEY_FOCUS_AREAS[]; + // Focal length in millimeter. + // Example value: "4.31". Read only. + static const char KEY_FOCAL_LENGTH[]; + // Horizontal angle of view in degrees. + // Example value: "54.8". Read only. + static const char KEY_HORIZONTAL_VIEW_ANGLE[]; + // Vertical angle of view in degrees. + // Example value: "42.5". Read only. + static const char KEY_VERTICAL_VIEW_ANGLE[]; + // Exposure compensation index. 0 means exposure is not adjusted. + // Example value: "-5" or "5". Read/write. + static const char KEY_EXPOSURE_COMPENSATION[]; + // The maximum exposure compensation index (>=0). + // Example value: "6". Read only. + static const char KEY_MAX_EXPOSURE_COMPENSATION[]; + // The minimum exposure compensation index (<=0). + // Example value: "-6". Read only. + static const char KEY_MIN_EXPOSURE_COMPENSATION[]; + // The exposure compensation step. Exposure compensation index multiply by + // step eqals to EV. Ex: if exposure compensation index is -6 and step is + // 0.3333, EV is -2. + // Example value: "0.333333333" or "0.5". Read only. + static const char KEY_EXPOSURE_COMPENSATION_STEP[]; + // The state of the auto-exposure lock. "true" means that + // auto-exposure is locked to its current value and will not + // change. "false" means the auto-exposure routine is free to + // change exposure values. If auto-exposure is already locked, + // setting this to true again has no effect (the driver will not + // recalculate exposure values). Changing exposure compensation + // settings will still affect the exposure settings while + // auto-exposure is locked. Stopping preview or taking a still + // image will not change the lock. In conjunction with + // exposure compensation, this allows for capturing multi-exposure + // brackets with known relative exposure values. Locking + // auto-exposure after open but before the first call to + // startPreview may result in severely over- or under-exposed + // images. The driver will not change the AE lock after + // auto-focus completes. + static const char KEY_AUTO_EXPOSURE_LOCK[]; + // Whether locking the auto-exposure is supported. "true" means it is, and + // "false" or this key not existing means it is not supported. + static const char KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[]; + // The state of the auto-white balance lock. "true" means that + // auto-white balance is locked to its current value and will not + // change. "false" means the auto-white balance routine is free to + // change white balance values. If auto-white balance is already + // locked, setting this to true again has no effect (the driver + // will not recalculate white balance values). Stopping preview or + // taking a still image will not change the lock. In conjunction + // with exposure compensation, this allows for capturing + // multi-exposure brackets with fixed white balance. Locking + // auto-white balance after open but before the first call to + // startPreview may result in severely incorrect color. The + // driver will not change the AWB lock after auto-focus + // completes. + static const char KEY_AUTO_WHITEBALANCE_LOCK[]; + // Whether locking the auto-white balance is supported. "true" + // means it is, and "false" or this key not existing means it is + // not supported. + static const char KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[]; + + // The maximum number of metering areas supported. This is the maximum + // length of KEY_METERING_AREAS. + // Example value: "0" or "2". Read only. + static const char KEY_MAX_NUM_METERING_AREAS[]; + // Current metering areas. Camera driver uses these areas to decide + // exposure. + // + // Before accessing this parameter, apps should check + // KEY_MAX_NUM_METERING_AREAS first to know the maximum number of metering + // areas first. If the value is 0, metering area is not supported. + // + // Each metering area is a rectangle with specified weight. The direction is + // relative to the sensor orientation, that is, what the sensor sees. The + // direction is not affected by the rotation or mirroring of + // CAMERA_CMD_SET_DISPLAY_ORIENTATION. Coordinates of the rectangle range + // from -1000 to 1000. (-1000, -1000) is the upper left point. (1000, 1000) + // is the lower right point. The width and height of metering areas cannot + // be 0 or negative. + // + // The fifth element is the weight. Values for weight must range from 1 to + // 1000. The weight should be interpreted as a per-pixel weight - all + // pixels in the area have the specified weight. This means a small area + // with the same weight as a larger area will have less influence on the + // metering than the larger area. Metering areas can partially overlap and + // the driver will add the weights in the overlap region. + // + // A special case of all-zero single metering area means driver to decide + // the metering area. For example, the driver may use more signals to decide + // metering areas and change them dynamically. Apps can set all-zero if they + // want the driver to decide metering areas. + // + // Metering areas are relative to the current field of view (KEY_ZOOM). + // No matter what the zoom level is, (-1000,-1000) represents the top of the + // currently visible camera frame. The metering area cannot be set to be + // outside the current field of view, even when using zoom. + // + // No matter what metering areas are, the final exposure are compensated + // by KEY_EXPOSURE_COMPENSATION. + // Example value: "(-10,-10,0,0,300),(0,0,10,10,700)". Read/write. + static const char KEY_METERING_AREAS[]; + // Current zoom value. + // Example value: "0" or "6". Read/write. + static const char KEY_ZOOM[]; + // Maximum zoom value. + // Example value: "6". Read only. + static const char KEY_MAX_ZOOM[]; + // The zoom ratios of all zoom values. The zoom ratio is in 1/100 + // increments. Ex: a zoom of 3.2x is returned as 320. The number of list + // elements is KEY_MAX_ZOOM + 1. The first element is always 100. The last + // element is the zoom ratio of zoom value KEY_MAX_ZOOM. + // Example value: "100,150,200,250,300,350,400". Read only. + static const char KEY_ZOOM_RATIOS[]; + // Whether zoom is supported. Zoom is supported if the value is "true". Zoom + // is not supported if the value is not "true" or the key does not exist. + // Example value: "true". Read only. + static const char KEY_ZOOM_SUPPORTED[]; + // Whether if smooth zoom is supported. Smooth zoom is supported if the + // value is "true". It is not supported if the value is not "true" or the + // key does not exist. + // See CAMERA_CMD_START_SMOOTH_ZOOM, CAMERA_CMD_STOP_SMOOTH_ZOOM, and + // CAMERA_MSG_ZOOM in frameworks/base/include/camera/Camera.h. + // Example value: "true". Read only. + static const char KEY_SMOOTH_ZOOM_SUPPORTED[]; + + // The distances (in meters) from the camera to where an object appears to + // be in focus. The object is sharpest at the optimal focus distance. The + // depth of field is the far focus distance minus near focus distance. + // + // Focus distances may change after starting auto focus, canceling auto + // focus, or starting the preview. Applications can read this anytime to get + // the latest focus distances. If the focus mode is FOCUS_MODE_CONTINUOUS, + // focus distances may change from time to time. + // + // This is intended to estimate the distance between the camera and the + // subject. After autofocus, the subject distance may be within near and far + // focus distance. However, the precision depends on the camera hardware, + // autofocus algorithm, the focus area, and the scene. The error can be + // large and it should be only used as a reference. + // + // Far focus distance > optimal focus distance > near focus distance. If + // the far focus distance is infinity, the value should be "Infinity" (case + // sensitive). The format is three float values separated by commas. The + // first is near focus distance. The second is optimal focus distance. The + // third is far focus distance. + // Example value: "0.95,1.9,Infinity" or "0.049,0.05,0.051". Read only. + static const char KEY_FOCUS_DISTANCES[]; + + // The current dimensions in pixels (width x height) for video frames. + // The width and height must be one of the supported sizes retrieved + // via KEY_SUPPORTED_VIDEO_SIZES. + // Example value: "1280x720". Read/write. + static const char KEY_VIDEO_SIZE[]; + // A list of the supported dimensions in pixels (width x height) + // for video frames. See CAMERA_MSG_VIDEO_FRAME for details in + // frameworks/base/include/camera/Camera.h. + // Example: "176x144,1280x720". Read only. + static const char KEY_SUPPORTED_VIDEO_SIZES[]; + + // The maximum number of detected faces supported by hardware face + // detection. If the value is 0, hardware face detection is not supported. + // Example: "5". Read only + static const char KEY_MAX_NUM_DETECTED_FACES_HW[]; + + // The maximum number of detected faces supported by software face + // detection. If the value is 0, software face detection is not supported. + // Example: "5". Read only + static const char KEY_MAX_NUM_DETECTED_FACES_SW[]; + + // Preferred preview frame size in pixels for video recording. + // The width and height must be one of the supported sizes retrieved + // via KEY_SUPPORTED_PREVIEW_SIZES. This key can be used only when + // getSupportedVideoSizes() does not return an empty Vector of Size. + // Camcorder applications are recommended to set the preview size + // to a value that is not larger than the preferred preview size. + // In other words, the product of the width and height of the + // preview size should not be larger than that of the preferred + // preview size. In addition, we recommend to choos a preview size + // that has the same aspect ratio as the resolution of video to be + // recorded. + // Example value: "800x600". Read only. + static const char KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[]; + + // The image format for video frames. See CAMERA_MSG_VIDEO_FRAME in + // frameworks/base/include/camera/Camera.h. + // Example value: "yuv420sp" or PIXEL_FORMAT_XXX constants. Read only. + static const char KEY_VIDEO_FRAME_FORMAT[]; + + // Sets the hint of the recording mode. If this is true, MediaRecorder.start + // may be faster or has less glitches. This should be called before starting + // the preview for the best result. But it is allowed to change the hint + // while the preview is active. The default value is false. + // + // The apps can still call Camera.takePicture when the hint is true. The + // apps can call MediaRecorder.start when the hint is false. But the + // performance may be worse. + // Example value: "true" or "false". Read/write. + static const char KEY_RECORDING_HINT[]; + + // Returns true if video snapshot is supported. That is, applications + // can call Camera.takePicture during recording. Applications do not need to + // call Camera.startPreview after taking a picture. The preview will be + // still active. Other than that, taking a picture during recording is + // identical to taking a picture normally. All settings and methods related + // to takePicture work identically. Ex: KEY_PICTURE_SIZE, + // KEY_SUPPORTED_PICTURE_SIZES, KEY_JPEG_QUALITY, KEY_ROTATION, and etc. + // The picture will have an EXIF header. FLASH_MODE_AUTO and FLASH_MODE_ON + // also still work, but the video will record the flash. + // + // Applications can set shutter callback as null to avoid the shutter + // sound. It is also recommended to set raw picture and post view callbacks + // to null to avoid the interrupt of preview display. + // + // Field-of-view of the recorded video may be different from that of the + // captured pictures. + // Example value: "true" or "false". Read only. + static const char KEY_VIDEO_SNAPSHOT_SUPPORTED[]; + + // The state of the video stabilization. If set to true, both the + // preview stream and the recorded video stream are stabilized by + // the camera. Only valid to set if KEY_VIDEO_STABILIZATION_SUPPORTED is + // set to true. + // + // The value of this key can be changed any time the camera is + // open. If preview or recording is active, it is acceptable for + // there to be a slight video glitch when video stabilization is + // toggled on and off. + // + // This only stabilizes video streams (between-frames stabilization), and + // has no effect on still image capture. + static const char KEY_VIDEO_STABILIZATION[]; + + // Returns true if video stabilization is supported. That is, applications + // can set KEY_VIDEO_STABILIZATION to true and have a stabilized preview + // stream and record stabilized videos. + static const char KEY_VIDEO_STABILIZATION_SUPPORTED[]; + + // Supported modes for special effects with light. + // Example values: "lowlight,hdr". + static const char KEY_LIGHTFX[]; + + // Value for KEY_ZOOM_SUPPORTED or KEY_SMOOTH_ZOOM_SUPPORTED. + static const char TRUE[]; + static const char FALSE[]; + + // Value for KEY_FOCUS_DISTANCES. + static const char FOCUS_DISTANCE_INFINITY[]; + + // Values for white balance settings. + static const char WHITE_BALANCE_AUTO[]; + static const char WHITE_BALANCE_INCANDESCENT[]; + static const char WHITE_BALANCE_FLUORESCENT[]; + static const char WHITE_BALANCE_WARM_FLUORESCENT[]; + static const char WHITE_BALANCE_DAYLIGHT[]; + static const char WHITE_BALANCE_CLOUDY_DAYLIGHT[]; + static const char WHITE_BALANCE_TWILIGHT[]; + static const char WHITE_BALANCE_SHADE[]; + + // Values for effect settings. + static const char EFFECT_NONE[]; + static const char EFFECT_MONO[]; + static const char EFFECT_NEGATIVE[]; + static const char EFFECT_SOLARIZE[]; + static const char EFFECT_SEPIA[]; + static const char EFFECT_POSTERIZE[]; + static const char EFFECT_WHITEBOARD[]; + static const char EFFECT_BLACKBOARD[]; + static const char EFFECT_AQUA[]; + + // Values for antibanding settings. + static const char ANTIBANDING_AUTO[]; + static const char ANTIBANDING_50HZ[]; + static const char ANTIBANDING_60HZ[]; + static const char ANTIBANDING_OFF[]; + + // Values for flash mode settings. + // Flash will not be fired. + static const char FLASH_MODE_OFF[]; + // Flash will be fired automatically when required. The flash may be fired + // during preview, auto-focus, or snapshot depending on the driver. + static const char FLASH_MODE_AUTO[]; + // Flash will always be fired during snapshot. The flash may also be + // fired during preview or auto-focus depending on the driver. + static const char FLASH_MODE_ON[]; + // Flash will be fired in red-eye reduction mode. + static const char FLASH_MODE_RED_EYE[]; + // Constant emission of light during preview, auto-focus and snapshot. + // This can also be used for video recording. + static const char FLASH_MODE_TORCH[]; + + // Values for scene mode settings. + static const char SCENE_MODE_AUTO[]; + static const char SCENE_MODE_ACTION[]; + static const char SCENE_MODE_PORTRAIT[]; + static const char SCENE_MODE_LANDSCAPE[]; + static const char SCENE_MODE_NIGHT[]; + static const char SCENE_MODE_NIGHT_PORTRAIT[]; + static const char SCENE_MODE_THEATRE[]; + static const char SCENE_MODE_BEACH[]; + static const char SCENE_MODE_SNOW[]; + static const char SCENE_MODE_SUNSET[]; + static const char SCENE_MODE_STEADYPHOTO[]; + static const char SCENE_MODE_FIREWORKS[]; + static const char SCENE_MODE_SPORTS[]; + static const char SCENE_MODE_PARTY[]; + static const char SCENE_MODE_CANDLELIGHT[]; + // Applications are looking for a barcode. Camera driver will be optimized + // for barcode reading. + static const char SCENE_MODE_BARCODE[]; + // A high-dynamic range mode. In this mode, the HAL module will use a + // capture strategy that extends the dynamic range of the captured + // image in some fashion. Only the final image is returned. + static const char SCENE_MODE_HDR[]; + + // Pixel color formats for KEY_PREVIEW_FORMAT, KEY_PICTURE_FORMAT, + // and KEY_VIDEO_FRAME_FORMAT + static const char PIXEL_FORMAT_YUV422SP[]; + static const char PIXEL_FORMAT_YUV420SP[]; // NV21 + static const char PIXEL_FORMAT_YUV422I[]; // YUY2 + static const char PIXEL_FORMAT_YUV420P[]; // YV12 + static const char PIXEL_FORMAT_RGB565[]; + static const char PIXEL_FORMAT_RGBA8888[]; + static const char PIXEL_FORMAT_JPEG[]; + // Raw bayer format used for images, which is 10 bit precision samples + // stored in 16 bit words. The filter pattern is RGGB. + static const char PIXEL_FORMAT_BAYER_RGGB[]; + // Pixel format is not known to the framework + static const char PIXEL_FORMAT_ANDROID_OPAQUE[]; + + // Values for focus mode settings. + // Auto-focus mode. Applications should call + // CameraHardwareInterface.autoFocus to start the focus in this mode. + static const char FOCUS_MODE_AUTO[]; + // Focus is set at infinity. Applications should not call + // CameraHardwareInterface.autoFocus in this mode. + static const char FOCUS_MODE_INFINITY[]; + // Macro (close-up) focus mode. Applications should call + // CameraHardwareInterface.autoFocus to start the focus in this mode. + static const char FOCUS_MODE_MACRO[]; + // Focus is fixed. The camera is always in this mode if the focus is not + // adjustable. If the camera has auto-focus, this mode can fix the + // focus, which is usually at hyperfocal distance. Applications should + // not call CameraHardwareInterface.autoFocus in this mode. + static const char FOCUS_MODE_FIXED[]; + // Extended depth of field (EDOF). Focusing is done digitally and + // continuously. Applications should not call + // CameraHardwareInterface.autoFocus in this mode. + static const char FOCUS_MODE_EDOF[]; + // Continuous auto focus mode intended for video recording. The camera + // continuously tries to focus. This is the best choice for video + // recording because the focus changes smoothly . Applications still can + // call CameraHardwareInterface.takePicture in this mode but the subject may + // not be in focus. Auto focus starts when the parameter is set. + // + // Applications can call CameraHardwareInterface.autoFocus in this mode. The + // focus callback will immediately return with a boolean that indicates + // whether the focus is sharp or not. The focus position is locked after + // autoFocus call. If applications want to resume the continuous focus, + // cancelAutoFocus must be called. Restarting the preview will not resume + // the continuous autofocus. To stop continuous focus, applications should + // change the focus mode to other modes. + static const char FOCUS_MODE_CONTINUOUS_VIDEO[]; + // Continuous auto focus mode intended for taking pictures. The camera + // continuously tries to focus. The speed of focus change is more aggressive + // than FOCUS_MODE_CONTINUOUS_VIDEO. Auto focus starts when the parameter is + // set. + // + // Applications can call CameraHardwareInterface.autoFocus in this mode. If + // the autofocus is in the middle of scanning, the focus callback will + // return when it completes. If the autofocus is not scanning, focus + // callback will immediately return with a boolean that indicates whether + // the focus is sharp or not. The apps can then decide if they want to take + // a picture immediately or to change the focus mode to auto, and run a full + // autofocus cycle. The focus position is locked after autoFocus call. If + // applications want to resume the continuous focus, cancelAutoFocus must be + // called. Restarting the preview will not resume the continuous autofocus. + // To stop continuous focus, applications should change the focus mode to + // other modes. + static const char FOCUS_MODE_CONTINUOUS_PICTURE[]; + + // Values for light special effects + // Low-light enhancement mode + static const char LIGHTFX_LOWLIGHT[]; + // High-dynamic range mode + static const char LIGHTFX_HDR[]; + + // Custom parameters for Samsung + static const char KEY_SUPPORTED_ISO_MODES[]; + static const char KEY_QC_FACE_RECOGNITION[]; + static const char KEY_QC_SUPPORTED_FACE_RECOGNITION[]; + static const char KEY_QC_SUPPORTED_FACE_RECOGNITION_MODES[]; + static const char KEY_QC_FACE_DETECTION[]; + static const char KEY_QC_SUPPORTED_FACE_DETECTION[]; + static const char KEY_FACE_DETECTION[]; + static const char KEY_SUPPORTED_FACE_DETECTION[]; + static const char FACE_DETECTION_OFF[]; + static const char FACE_DETECTION_ON[]; + static const char KEY_ZSL[]; + static const char KEY_SUPPORTED_ZSL_MODES[]; + static const char ZSL_OFF[]; + static const char ZSL_ON[]; + static const char KEY_ISO_MODE[]; + static const char KEY_CAMERA_MODE[]; + static const char KEY_SAMSUNG_CAMERA_MODE[]; + static const char KEY_SELECTABLE_ZONE_AF[]; + static const char KEY_SUPPORTED_SELECTABLE_ZONE_AF[]; + static const char SELECTABLE_ZONE_AF_AUTO[]; + static const char SELECTABLE_ZONE_AF_SPOT_METERING[]; + static const char SELECTABLE_ZONE_AF_CENTER_WEIGHTED[]; + static const char SELECTABLE_ZONE_AF_FRAME_AVERAGE[]; + static const char KEY_PREVIEW_FRAME_RATE_MODE[]; + static const char KEY_SUPPORTED_PREVIEW_FRAME_RATE_MODES[]; + static const char KEY_PREVIEW_FRAME_RATE_AUTO_MODE[]; + static const char KEY_PREVIEW_FRAME_RATE_FIXED_MODE[]; + static const char KEY_SHARPNESS[]; + static const char KEY_SATURATION[]; + static const char KEY_CONTRAST[]; + static const char KEY_SCENE_DETECT[]; + static const char KEY_SUPPORTED_SCENE_DETECT[]; + static const char SCENE_DETECT_OFF[]; + static const char SCENE_DETECT_ON[]; + static const char KEY_WEATHER[]; + static const char KEY_CITYID[]; + static const char KEY_TOUCH_AF_AEC[]; + static const char KEY_SUPPORTED_TOUCH_AF_AEC[]; + static const char TOUCH_AF_AEC_OFF[]; + static const char TOUCH_AF_AEC_ON[]; + static const char KEY_MEMORY_COLOR_ENHANCEMENT[]; + static const char KEY_LENSSHADE[]; + static const char KEY_REDEYE_REDUCTION[]; + static const char KEY_SUPPORTED_REDEYE_REDUCTION[]; + static const char REDEYE_REDUCTION_ENABLE[]; + static const char REDEYE_REDUCTION_DISABLE[]; + static const char KEY_GPS_LATITUDE_REF[]; + static const char KEY_GPS_LONGITUDE_REF[]; + static const char KEY_GPS_ALTITUDE_REF[]; + static const char KEY_GPS_STATUS[]; + static const char KEY_EXIF_DATETIME[]; + static const char KEY_AUTO_EXPOSURE[]; + static const char KEY_SUPPORTED_AUTO_EXPOSURE[]; + static const char KEY_SUPPORTED_LENSSHADE_MODES[]; + static const char LENSSHADE_ENABLE[]; + static const char LENSSHADE_DISABLE[]; + static const char MCE_ENABLE[]; + static const char MCE_DISABLE[]; + static const char ISO_AUTO[]; + static const char ISO_HJR[]; + static const char ISO_100[]; + static const char ISO_200[]; + static const char ISO_400[]; + static const char ISO_800[]; + static const char ISO_1600[]; + static const char ISO_3200[]; + static const char ISO_6400[]; + static const char KEY_SUPPORTED_HFR_SIZES[]; + static const char KEY_SUPPORTED_MEM_COLOR_ENHANCE_MODES[]; + static const char VIDEO_HFR_OFF[]; + static const char VIDEO_HFR_2X[]; + static const char VIDEO_HFR_3X[]; + static const char VIDEO_HFR_4X[]; + static const char KEY_VIDEO_HIGH_FRAME_RATE[]; + static const char KEY_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[]; + static const char KEY_HISTOGRAM[]; + static const char KEY_SUPPORTED_HISTOGRAM_MODES[]; + static const char HISTOGRAM_ENABLE[]; + static const char HISTOGRAM_DISABLE[]; + static const char SKIN_TONE_ENHANCEMENT_ENABLE[]; + static const char SKIN_TONE_ENHANCEMENT_DISABLE[]; + static const char KEY_SKIN_TONE_ENHANCEMENT[]; + static const char KEY_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[]; + static const char DENOISE_OFF[]; + static const char DENOISE_ON[]; + static const char KEY_DENOISE[]; + static const char KEY_SUPPORTED_DENOISE[]; + static const char EFFECT_EMBOSS[]; + static const char EFFECT_SKETCH[]; + static const char EFFECT_NEON[]; + static const char SCENE_MODE_FLOWERS[]; + static const char SCENE_MODE_AR[]; + static const char PIXEL_FORMAT_YUV420SP_ADRENO[]; + static const char PIXEL_FORMAT_RAW[]; + static const char PIXEL_FORMAT_YV12[]; + static const char PIXEL_FORMAT_NV12[]; + static const char EFFECT_CARTOONIZE[]; + static const char EFFECT_POINT_RED_YELLOW[]; + static const char EFFECT_POINT_GREEN[]; + static const char EFFECT_POINT_BLUE[]; + static const char EFFECT_VINTAGE_COLD[]; + static const char EFFECT_VINTAGE_WARM[]; + static const char EFFECT_WASHED[]; + static const char SCENE_MODE_BACKLIGHT[]; + static const char SCENE_MODE_ASD[]; + + /** + * Returns the the supported preview formats as an enum given in graphics.h + * corrsponding to the format given in the input string or -1 if no such + * conversion exists. + */ + static int previewFormatToEnum(const char* format); + + /** + * Custom parameters for Samsung + */ + int getInt64(const char *key) const; + const char *getPreviewFrameRateMode() const; + void setPreviewFrameRateMode(const char *mode); + void getMeteringAreaCenter(int *x, int *y) const; + void setTouchIndexAec(int x, int y); + void setTouchIndexAf(int x, int y); + void setPreviewFpsRange(int minFPS, int maxFPS); + +private: + DefaultKeyedVector mMap; + CameraParameters *mParams; +}; + +}; // namespace android + +#endif diff --git a/include/device_perms.h b/include/device_perms.h new file mode 100644 index 0000000..e2f1b1a --- /dev/null +++ b/include/device_perms.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2014 The CyanogenMod 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. + */ + +#ifndef DEVICE_PERMS_H +#define DEVICE_PERMS_H + +#define PROPERTY_PERMS_APPEND \ + { "persist.audio.", AID_SYSTEM, 0 }, \ + { "persist.sys.camera.", AID_MEDIA, 0 }, +#endif /* DEVICE_PERMS_H */ diff --git a/include/samsung_lights.h b/include/samsung_lights.h new file mode 100644 index 0000000..029be32 --- /dev/null +++ b/include/samsung_lights.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * Copyright (C) 2017 The LineageOS 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. + */ + +#ifndef SAMSUNG_LIGHTS_H +#define SAMSUNG_LIGHTS_H + +/* + * Board specific nodes + * + * If your kernel exposes these controls in another place, you can either + * symlink to the locations given here, or override this header in your + * device tree. + */ +#define PANEL_BRIGHTNESS_NODE "/sys/class/leds/lcd-backlight/brightness" +#define PANEL_MAX_BRIGHTNESS_NODE "/sys/class/leds/lcd-backlight/max_brightness" +#define BUTTON_BRIGHTNESS_NODE "/sys/class/sec/sec_touchkey/brightness" +#define LED_BLINK_NODE "/sys/class/sec/led/led_blink" + +/* + * Brightness adjustment factors + * + * If one of your device's LEDs is more powerful than the others, use these + * values to equalise them. This value is in the range 0.0-1.0. + */ +#define LED_ADJUSTMENT_R 1.0 +#define LED_ADJUSTMENT_G 1.0 +#define LED_ADJUSTMENT_B 1.0 + +/* + * Light brightness factors + * + * It might make sense for all colours to be scaled down (for example, if your + * LED is too bright). Use these values to adjust the brightness of each + * light. This value is within the range 0-255. + */ +#define LED_BRIGHTNESS_BATTERY 255 +#define LED_BRIGHTNESS_NOTIFICATION 255 +#define LED_BRIGHTNESS_ATTENTION 255 + +#endif // SAMSUNG_LIGHTS_H diff --git a/include/telephony/ril.h b/include/telephony/ril.h new file mode 100644 index 0000000..9c935aa --- /dev/null +++ b/include/telephony/ril.h @@ -0,0 +1,7359 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * Copyright (C) 2018 The LineageOS 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. + */ + +#ifndef ANDROID_RIL_H +#define ANDROID_RIL_H 1 + +#include +#include +#include +#include +#include + +#ifndef FEATURE_UNIT_TEST +#include +#endif /* !FEATURE_UNIT_TEST */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef SIM_COUNT +#if defined(ANDROID_SIM_COUNT_2) +#define SIM_COUNT 2 +#elif defined(ANDROID_SIM_COUNT_3) +#define SIM_COUNT 3 +#elif defined(ANDROID_SIM_COUNT_4) +#define SIM_COUNT 4 +#else +#define SIM_COUNT 1 +#endif + +#ifndef ANDROID_MULTI_SIM +#define SIM_COUNT 1 +#endif +#endif + +/* + * RIL version. + * Value of RIL_VERSION should not be changed in future. Here onwards, + * when a new change is supposed to be introduced which could involve new + * schemes added like Wakelocks, data structures added/updated, etc, we would + * just document RIL version associated with that change below. When OEM updates its + * RIL with those changes, they would return that new RIL version during RIL_REGISTER. + * We should make use of the returned version by vendor to identify appropriate scheme + * or data structure version to use. + * + * Documentation of RIL version and associated changes + * RIL_VERSION = 12 : This version corresponds to updated data structures namely + * RIL_Data_Call_Response_v11, RIL_SIM_IO_v6, RIL_CardStatus_v6, + * RIL_SimRefreshResponse_v7, RIL_CDMA_CallWaiting_v6, + * RIL_LTE_SignalStrength_v8, RIL_SignalStrength_v10, RIL_CellIdentityGsm_v12 + * RIL_CellIdentityWcdma_v12, RIL_CellIdentityLte_v12,RIL_CellInfoGsm_v12, + * RIL_CellInfoWcdma_v12, RIL_CellInfoLte_v12, RIL_CellInfo_v12. + * + * RIL_VERSION = 13 : This version includes new wakelock semantics and as the first + * strongly versioned version it enforces structure use. + * + * RIL_VERSION = 14 : New data structures are added, namely RIL_CarrierMatchType, + * RIL_Carrier, RIL_CarrierRestrictions and RIL_PCO_Data. + * New commands added: RIL_REQUEST_SET_CARRIER_RESTRICTIONS, + * RIL_REQUEST_SET_CARRIER_RESTRICTIONS and RIL_UNSOL_PCO_DATA. + * + * RIL_VERSION = 15 : New commands added: + * RIL_UNSOL_MODEM_RESTART, + * RIL_REQUEST_SEND_DEVICE_STATE, + * RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, + * RIL_REQUEST_SET_SIM_CARD_POWER, + * RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, + * RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION + * The new parameters for RIL_REQUEST_SETUP_DATA_CALL, + * Updated data structures: RIL_DataProfileInfo_v15, RIL_InitialAttachApn_v15 + * New data structure RIL_DataRegistrationStateResponse, + * RIL_VoiceRegistrationStateResponse same is + * used in RIL_REQUEST_DATA_REGISTRATION_STATE and + * RIL_REQUEST_VOICE_REGISTRATION_STATE respectively. + * New data structure RIL_OpenChannelParams. + * RIL_REQUEST_START_NETWORK_SCAN + * RIL_REQUEST_STOP_NETWORK_SCAN + * RIL_UNSOL_NETWORK_SCAN_RESULT + */ +#define RIL_VERSION 12 +#define LAST_IMPRECISE_RIL_VERSION 12 // Better self-documented name +#define RIL_VERSION_MIN 6 /* Minimum RIL_VERSION supported */ + +#define CDMA_ALPHA_INFO_BUFFER_LENGTH 64 +#define CDMA_NUMBER_INFO_BUFFER_LENGTH 81 + +#define MAX_RILDS 3 +#define MAX_SERVICE_NAME_LENGTH 6 +#define MAX_CLIENT_ID_LENGTH 2 +#define MAX_DEBUG_SOCKET_NAME_LENGTH 12 +#define MAX_QEMU_PIPE_NAME_LENGTH 11 +#define MAX_UUID_LENGTH 64 +#define MAX_BANDS 8 +#define MAX_CHANNELS 32 +#define MAX_RADIO_ACCESS_NETWORKS 8 + + +typedef void * RIL_Token; + +typedef enum { + RIL_SOCKET_1, +#if (SIM_COUNT >= 2) + RIL_SOCKET_2, +#if (SIM_COUNT >= 3) + RIL_SOCKET_3, +#endif +#if (SIM_COUNT >= 4) + RIL_SOCKET_4, +#endif +#endif + RIL_SOCKET_NUM +} RIL_SOCKET_ID; + + +typedef enum { + RIL_E_SUCCESS = 0, + RIL_E_RADIO_NOT_AVAILABLE = 1, /* If radio did not start or is resetting */ + RIL_E_GENERIC_FAILURE = 2, + RIL_E_PASSWORD_INCORRECT = 3, /* for PIN/PIN2 methods only! */ + RIL_E_SIM_PIN2 = 4, /* Operation requires SIM PIN2 to be entered */ + RIL_E_SIM_PUK2 = 5, /* Operation requires SIM PIN2 to be entered */ + RIL_E_REQUEST_NOT_SUPPORTED = 6, + RIL_E_CANCELLED = 7, + RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL = 8, /* data ops are not allowed during voice + call on a Class C GPRS device */ + RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW = 9, /* data ops are not allowed before device + registers in network */ + RIL_E_SMS_SEND_FAIL_RETRY = 10, /* fail to send sms and need retry */ + RIL_E_SIM_ABSENT = 11, /* fail to set the location where CDMA subscription + shall be retrieved because of SIM or RUIM + card absent */ + RIL_E_SUBSCRIPTION_NOT_AVAILABLE = 12, /* fail to find CDMA subscription from specified + location */ + RIL_E_MODE_NOT_SUPPORTED = 13, /* HW does not support preferred network type */ + RIL_E_FDN_CHECK_FAILURE = 14, /* command failed because recipient is not on FDN list */ + RIL_E_ILLEGAL_SIM_OR_ME = 15, /* network selection failed due to + illegal SIM or ME */ + RIL_E_MISSING_RESOURCE = 16, /* no logical channel available */ + RIL_E_NO_SUCH_ELEMENT = 17, /* application not found on SIM */ + RIL_E_DIAL_MODIFIED_TO_USSD = 18, /* DIAL request modified to USSD */ + RIL_E_DIAL_MODIFIED_TO_SS = 19, /* DIAL request modified to SS */ + RIL_E_DIAL_MODIFIED_TO_DIAL = 20, /* DIAL request modified to DIAL with different + data */ + RIL_E_USSD_MODIFIED_TO_DIAL = 21, /* USSD request modified to DIAL */ + RIL_E_USSD_MODIFIED_TO_SS = 22, /* USSD request modified to SS */ + RIL_E_USSD_MODIFIED_TO_USSD = 23, /* USSD request modified to different USSD + request */ + RIL_E_SS_MODIFIED_TO_DIAL = 24, /* SS request modified to DIAL */ + RIL_E_SS_MODIFIED_TO_USSD = 25, /* SS request modified to USSD */ + RIL_E_SUBSCRIPTION_NOT_SUPPORTED = 26, /* Subscription not supported by RIL */ + RIL_E_SS_MODIFIED_TO_SS = 27, /* SS request modified to different SS request */ + RIL_E_LCE_NOT_SUPPORTED = 36, /* LCE service not supported(36 in RILConstants.java) */ + RIL_E_NO_MEMORY = 37, /* Not sufficient memory to process the request */ + RIL_E_INTERNAL_ERR = 38, /* Modem hit unexpected error scenario while handling + this request */ + RIL_E_SYSTEM_ERR = 39, /* Hit platform or system error */ + RIL_E_MODEM_ERR = 40, /* Vendor RIL got unexpected or incorrect response + from modem for this request */ + RIL_E_INVALID_STATE = 41, /* Unexpected request for the current state */ + RIL_E_NO_RESOURCES = 42, /* Not sufficient resource to process the request */ + RIL_E_SIM_ERR = 43, /* Received error from SIM card */ + RIL_E_INVALID_ARGUMENTS = 44, /* Received invalid arguments in request */ + RIL_E_INVALID_SIM_STATE = 45, /* Can not process the request in current SIM state */ + RIL_E_INVALID_MODEM_STATE = 46, /* Can not process the request in current Modem state */ + RIL_E_INVALID_CALL_ID = 47, /* Received invalid call id in request */ + RIL_E_NO_SMS_TO_ACK = 48, /* ACK received when there is no SMS to ack */ + RIL_E_NETWORK_ERR = 49, /* Received error from network */ + RIL_E_REQUEST_RATE_LIMITED = 50, /* Operation denied due to overly-frequent requests */ + RIL_E_SIM_BUSY = 51, /* SIM is busy */ + RIL_E_SIM_FULL = 52, /* The target EF is full */ + RIL_E_NETWORK_REJECT = 53, /* Request is rejected by network */ + RIL_E_OPERATION_NOT_ALLOWED = 54, /* Not allowed the request now */ + RIL_E_EMPTY_RECORD = 55, /* The request record is empty */ + RIL_E_INVALID_SMS_FORMAT = 56, /* Invalid sms format */ + RIL_E_ENCODING_ERR = 57, /* Message not encoded properly */ + RIL_E_INVALID_SMSC_ADDRESS = 58, /* SMSC address specified is invalid */ + RIL_E_NO_SUCH_ENTRY = 59, /* No such entry present to perform the request */ + RIL_E_NETWORK_NOT_READY = 60, /* Network is not ready to perform the request */ + RIL_E_NOT_PROVISIONED = 61, /* Device doesnot have this value provisioned */ + RIL_E_NO_SUBSCRIPTION = 62, /* Device doesnot have subscription */ + RIL_E_NO_NETWORK_FOUND = 63, /* Network cannot be found */ + RIL_E_DEVICE_IN_USE = 64, /* Operation cannot be performed because the device + is currently in use */ + RIL_E_ABORTED = 65, /* Operation aborted */ + RIL_E_INVALID_RESPONSE = 66, /* Invalid response sent by vendor code */ + // OEM specific error codes. To be used by OEM when they don't want to reveal + // specific error codes which would be replaced by Generic failure. + RIL_E_OEM_ERROR_1 = 501, + RIL_E_OEM_ERROR_2 = 502, + RIL_E_OEM_ERROR_3 = 503, + RIL_E_OEM_ERROR_4 = 504, + RIL_E_OEM_ERROR_5 = 505, + RIL_E_OEM_ERROR_6 = 506, + RIL_E_OEM_ERROR_7 = 507, + RIL_E_OEM_ERROR_8 = 508, + RIL_E_OEM_ERROR_9 = 509, + RIL_E_OEM_ERROR_10 = 510, + RIL_E_OEM_ERROR_11 = 511, + RIL_E_OEM_ERROR_12 = 512, + RIL_E_OEM_ERROR_13 = 513, + RIL_E_OEM_ERROR_14 = 514, + RIL_E_OEM_ERROR_15 = 515, + RIL_E_OEM_ERROR_16 = 516, + RIL_E_OEM_ERROR_17 = 517, + RIL_E_OEM_ERROR_18 = 518, + RIL_E_OEM_ERROR_19 = 519, + RIL_E_OEM_ERROR_20 = 520, + RIL_E_OEM_ERROR_21 = 521, + RIL_E_OEM_ERROR_22 = 522, + RIL_E_OEM_ERROR_23 = 523, + RIL_E_OEM_ERROR_24 = 524, + RIL_E_OEM_ERROR_25 = 525 +} RIL_Errno; + +typedef enum { + RIL_CALL_ACTIVE = 0, + RIL_CALL_HOLDING = 1, + RIL_CALL_DIALING = 2, /* MO call only */ + RIL_CALL_ALERTING = 3, /* MO call only */ + RIL_CALL_INCOMING = 4, /* MT call only */ + RIL_CALL_WAITING = 5 /* MT call only */ +} RIL_CallState; + +typedef enum { + RADIO_STATE_OFF = 0, /* Radio explictly powered off (eg CFUN=0) */ + RADIO_STATE_UNAVAILABLE = 1, /* Radio unavailable (eg, resetting or not booted) */ + RADIO_STATE_ON = 10 /* Radio is on */ +} RIL_RadioState; + +typedef enum { + RADIO_TECH_UNKNOWN = 0, + RADIO_TECH_GPRS = 1, + RADIO_TECH_EDGE = 2, + RADIO_TECH_UMTS = 3, + RADIO_TECH_IS95A = 4, + RADIO_TECH_IS95B = 5, + RADIO_TECH_1xRTT = 6, + RADIO_TECH_EVDO_0 = 7, + RADIO_TECH_EVDO_A = 8, + RADIO_TECH_HSDPA = 9, + RADIO_TECH_HSUPA = 10, + RADIO_TECH_HSPA = 11, + RADIO_TECH_EVDO_B = 12, + RADIO_TECH_EHRPD = 13, + RADIO_TECH_LTE = 14, + RADIO_TECH_HSPAP = 15, // HSPA+ + RADIO_TECH_GSM = 16, // Only supports voice + RADIO_TECH_TD_SCDMA = 17, + RADIO_TECH_IWLAN = 18, + RADIO_TECH_LTE_CA = 19 +} RIL_RadioTechnology; + +typedef enum { + RAF_UNKNOWN = (1 << RADIO_TECH_UNKNOWN), + RAF_GPRS = (1 << RADIO_TECH_GPRS), + RAF_EDGE = (1 << RADIO_TECH_EDGE), + RAF_UMTS = (1 << RADIO_TECH_UMTS), + RAF_IS95A = (1 << RADIO_TECH_IS95A), + RAF_IS95B = (1 << RADIO_TECH_IS95B), + RAF_1xRTT = (1 << RADIO_TECH_1xRTT), + RAF_EVDO_0 = (1 << RADIO_TECH_EVDO_0), + RAF_EVDO_A = (1 << RADIO_TECH_EVDO_A), + RAF_HSDPA = (1 << RADIO_TECH_HSDPA), + RAF_HSUPA = (1 << RADIO_TECH_HSUPA), + RAF_HSPA = (1 << RADIO_TECH_HSPA), + RAF_EVDO_B = (1 << RADIO_TECH_EVDO_B), + RAF_EHRPD = (1 << RADIO_TECH_EHRPD), + RAF_LTE = (1 << RADIO_TECH_LTE), + RAF_HSPAP = (1 << RADIO_TECH_HSPAP), + RAF_GSM = (1 << RADIO_TECH_GSM), + RAF_TD_SCDMA = (1 << RADIO_TECH_TD_SCDMA), + RAF_LTE_CA = (1 << RADIO_TECH_LTE_CA) +} RIL_RadioAccessFamily; + +typedef enum { + BAND_MODE_UNSPECIFIED = 0, //"unspecified" (selected by baseband automatically) + BAND_MODE_EURO = 1, //"EURO band" (GSM-900 / DCS-1800 / WCDMA-IMT-2000) + BAND_MODE_USA = 2, //"US band" (GSM-850 / PCS-1900 / WCDMA-850 / WCDMA-PCS-1900) + BAND_MODE_JPN = 3, //"JPN band" (WCDMA-800 / WCDMA-IMT-2000) + BAND_MODE_AUS = 4, //"AUS band" (GSM-900 / DCS-1800 / WCDMA-850 / WCDMA-IMT-2000) + BAND_MODE_AUS_2 = 5, //"AUS band 2" (GSM-900 / DCS-1800 / WCDMA-850) + BAND_MODE_CELL_800 = 6, //"Cellular" (800-MHz Band) + BAND_MODE_PCS = 7, //"PCS" (1900-MHz Band) + BAND_MODE_JTACS = 8, //"Band Class 3" (JTACS Band) + BAND_MODE_KOREA_PCS = 9, //"Band Class 4" (Korean PCS Band) + BAND_MODE_5_450M = 10, //"Band Class 5" (450-MHz Band) + BAND_MODE_IMT2000 = 11, //"Band Class 6" (2-GMHz IMT2000 Band) + BAND_MODE_7_700M_2 = 12, //"Band Class 7" (Upper 700-MHz Band) + BAND_MODE_8_1800M = 13, //"Band Class 8" (1800-MHz Band) + BAND_MODE_9_900M = 14, //"Band Class 9" (900-MHz Band) + BAND_MODE_10_800M_2 = 15, //"Band Class 10" (Secondary 800-MHz Band) + BAND_MODE_EURO_PAMR_400M = 16, //"Band Class 11" (400-MHz European PAMR Band) + BAND_MODE_AWS = 17, //"Band Class 15" (AWS Band) + BAND_MODE_USA_2500M = 18 //"Band Class 16" (US 2.5-GHz Band) +} RIL_RadioBandMode; + +typedef enum { + RC_PHASE_CONFIGURED = 0, // LM is configured is initial value and value after FINISH completes + RC_PHASE_START = 1, // START is sent before Apply and indicates that an APPLY will be + // forthcoming with these same parameters + RC_PHASE_APPLY = 2, // APPLY is sent after all LM's receive START and returned + // RIL_RadioCapability.status = 0, if any START's fail no + // APPLY will be sent + RC_PHASE_UNSOL_RSP = 3, // UNSOL_RSP is sent with RIL_UNSOL_RADIO_CAPABILITY + RC_PHASE_FINISH = 4 // FINISH is sent after all commands have completed. If an error + // occurs in any previous command the RIL_RadioAccessesFamily and + // logicalModemUuid fields will be the prior configuration thus + // restoring the configuration to the previous value. An error + // returned by this command will generally be ignored or may + // cause that logical modem to be removed from service. +} RadioCapabilityPhase; + +typedef enum { + RC_STATUS_NONE = 0, // This parameter has no meaning with RC_PHASE_START, + // RC_PHASE_APPLY + RC_STATUS_SUCCESS = 1, // Tell modem the action transaction of set radio + // capability was success with RC_PHASE_FINISH + RC_STATUS_FAIL = 2, // Tell modem the action transaction of set radio + // capability is fail with RC_PHASE_FINISH. +} RadioCapabilityStatus; + +#define RIL_RADIO_CAPABILITY_VERSION 1 +typedef struct { + int version; // Version of structure, RIL_RADIO_CAPABILITY_VERSION + int session; // Unique session value defined by framework returned in all "responses/unsol" + int phase; // CONFIGURED, START, APPLY, FINISH + int rat; // RIL_RadioAccessFamily for the radio + char logicalModemUuid[MAX_UUID_LENGTH]; // A UUID typically "com.xxxx.lmX where X is the logical modem. + int status; // Return status and an input parameter for RC_PHASE_FINISH +} RIL_RadioCapability; + +// Do we want to split Data from Voice and the use +// RIL_RadioTechnology for get/setPreferredVoice/Data ? +typedef enum { + PREF_NET_TYPE_GSM_WCDMA = 0, /* GSM/WCDMA (WCDMA preferred) */ + PREF_NET_TYPE_GSM_ONLY = 1, /* GSM only */ + PREF_NET_TYPE_WCDMA = 2, /* WCDMA */ + PREF_NET_TYPE_GSM_WCDMA_AUTO = 3, /* GSM/WCDMA (auto mode, according to PRL) */ + PREF_NET_TYPE_CDMA_EVDO_AUTO = 4, /* CDMA and EvDo (auto mode, according to PRL) */ + PREF_NET_TYPE_CDMA_ONLY = 5, /* CDMA only */ + PREF_NET_TYPE_EVDO_ONLY = 6, /* EvDo only */ + PREF_NET_TYPE_GSM_WCDMA_CDMA_EVDO_AUTO = 7, /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL) */ + PREF_NET_TYPE_LTE_CDMA_EVDO = 8, /* LTE, CDMA and EvDo */ + PREF_NET_TYPE_LTE_GSM_WCDMA = 9, /* LTE, GSM/WCDMA */ + PREF_NET_TYPE_LTE_CMDA_EVDO_GSM_WCDMA = 10, /* LTE, CDMA, EvDo, GSM/WCDMA */ + PREF_NET_TYPE_LTE_ONLY = 11, /* LTE only */ + PREF_NET_TYPE_LTE_WCDMA = 12, /* LTE/WCDMA */ + PREF_NET_TYPE_TD_SCDMA_ONLY = 13, /* TD-SCDMA only */ + PREF_NET_TYPE_TD_SCDMA_WCDMA = 14, /* TD-SCDMA and WCDMA */ + PREF_NET_TYPE_TD_SCDMA_LTE = 15, /* TD-SCDMA and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM = 16, /* TD-SCDMA and GSM */ + PREF_NET_TYPE_TD_SCDMA_GSM_LTE = 17, /* TD-SCDMA,GSM and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM_WCDMA = 18, /* TD-SCDMA, GSM/WCDMA */ + PREF_NET_TYPE_TD_SCDMA_WCDMA_LTE = 19, /* TD-SCDMA, WCDMA and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM_WCDMA_LTE = 20, /* TD-SCDMA, GSM/WCDMA and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM_WCDMA_CDMA_EVDO_AUTO = 21, /* TD-SCDMA, GSM/WCDMA, CDMA and EvDo */ + PREF_NET_TYPE_TD_SCDMA_LTE_CDMA_EVDO_GSM_WCDMA = 22 /* TD-SCDMA, LTE, CDMA, EvDo GSM/WCDMA */ +} RIL_PreferredNetworkType; + +/* Source for cdma subscription */ +typedef enum { + CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM = 0, + CDMA_SUBSCRIPTION_SOURCE_NV = 1 +} RIL_CdmaSubscriptionSource; + +/* User-to-User signaling Info activation types derived from 3GPP 23.087 v8.0 */ +typedef enum { + RIL_UUS_TYPE1_IMPLICIT = 0, + RIL_UUS_TYPE1_REQUIRED = 1, + RIL_UUS_TYPE1_NOT_REQUIRED = 2, + RIL_UUS_TYPE2_REQUIRED = 3, + RIL_UUS_TYPE2_NOT_REQUIRED = 4, + RIL_UUS_TYPE3_REQUIRED = 5, + RIL_UUS_TYPE3_NOT_REQUIRED = 6 +} RIL_UUS_Type; + +/* User-to-User Signaling Information data coding schemes. Possible values for + * Octet 3 (Protocol Discriminator field) in the UUIE. The values have been + * specified in section 10.5.4.25 of 3GPP TS 24.008 */ +typedef enum { + RIL_UUS_DCS_USP = 0, /* User specified protocol */ + RIL_UUS_DCS_OSIHLP = 1, /* OSI higher layer protocol */ + RIL_UUS_DCS_X244 = 2, /* X.244 */ + RIL_UUS_DCS_RMCF = 3, /* Reserved for system mangement + convergence function */ + RIL_UUS_DCS_IA5c = 4 /* IA5 characters */ +} RIL_UUS_DCS; + +/* User-to-User Signaling Information defined in 3GPP 23.087 v8.0 + * This data is passed in RIL_ExtensionRecord and rec contains this + * structure when type is RIL_UUS_INFO_EXT_REC */ +typedef struct { + RIL_UUS_Type uusType; /* UUS Type */ + RIL_UUS_DCS uusDcs; /* UUS Data Coding Scheme */ + int uusLength; /* Length of UUS Data */ + char * uusData; /* UUS Data */ +} RIL_UUS_Info; + +/* CDMA Signal Information Record as defined in C.S0005 section 3.7.5.5 */ +typedef struct { + char isPresent; /* non-zero if signal information record is present */ + char signalType; /* as defined 3.7.5.5-1 */ + char alertPitch; /* as defined 3.7.5.5-2 */ + char signal; /* as defined 3.7.5.5-3, 3.7.5.5-4 or 3.7.5.5-5 */ +} RIL_CDMA_SignalInfoRecord; + +typedef struct { + RIL_CallState state; + unsigned char index; /* Connection Index for use with, eg, AT+CHLD */ + unsigned char call_id; /* Samsung field */ + unsigned char pad; /* Unsigned gap padding */ + char pad1; /* Signed gap padding */ + int toa; /* type of address, eg 145 = intl */ + char isMpty; /* nonzero if is mpty call */ + char isMT; /* nonzero if call is mobile terminated */ + char als; /* ALS line indicator if available + (0 = line 1) */ + char isVoice; /* nonzero if this is is a voice call */ + char isVoicePrivacy; /* nonzero if CDMA voice privacy mode is active */ + char * number; /* Remote party number */ + int numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown 3=Payphone */ + char * name; /* Remote party name */ + int namePresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown 3=Payphone */ + long call_details; /* Samsung call detail additions. Just padding, do not use */ + RIL_UUS_Info * uusInfo; /* NULL or Pointer to User-User Signaling Information */ +} RIL_Call; + +/* Deprecated, use RIL_Data_Call_Response_v6 */ +typedef struct { + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". */ + char * apn; /* ignored */ + char * address; /* An address, e.g., "192.0.1.3" or "2001:db8::1". */ +} RIL_Data_Call_Response_v4; + +/* + * Returned by RIL_REQUEST_SETUP_DATA_CALL, RIL_REQUEST_DATA_CALL_LIST + * and RIL_UNSOL_DATA_CALL_LIST_CHANGED, on error status != 0. + */ +typedef struct { + int status; /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */ + int suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry + back-off timer value RIL wants to override the one + pre-configured in FW. + The unit is miliseconds. + The value < 0 means no value is suggested. + The value 0 means retry should be done ASAP. + The value of INT_MAX(0x7fffffff) means no retry. */ + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". If status is + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported + such as "IP" or "IPV6" */ + char * ifname; /* The network interface name */ + char * addresses; /* A space-delimited list of addresses with optional "/" prefix length, + e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". + May not be empty, typically 1 IPv4 or 1 IPv6 or + one of each. If the prefix length is absent the addresses + are assumed to be point to point with IPv4 having a prefix + length of 32 and IPv6 128. */ + char * dnses; /* A space-delimited list of DNS server addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty. */ + char * gateways; /* A space-delimited list of default gateway addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty in which case the addresses represent point + to point connections. */ +} RIL_Data_Call_Response_v6; + +typedef struct { + int status; /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */ + int suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry + back-off timer value RIL wants to override the one + pre-configured in FW. + The unit is miliseconds. + The value < 0 means no value is suggested. + The value 0 means retry should be done ASAP. + The value of INT_MAX(0x7fffffff) means no retry. */ + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". If status is + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported + such as "IP" or "IPV6" */ + char * ifname; /* The network interface name */ + char * addresses; /* A space-delimited list of addresses with optional "/" prefix length, + e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". + May not be empty, typically 1 IPv4 or 1 IPv6 or + one of each. If the prefix length is absent the addresses + are assumed to be point to point with IPv4 having a prefix + length of 32 and IPv6 128. */ + char * dnses; /* A space-delimited list of DNS server addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty. */ + char * gateways; /* A space-delimited list of default gateway addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty in which case the addresses represent point + to point connections. */ + char * pcscf; /* the Proxy Call State Control Function address + via PCO(Protocol Configuration Option) for IMS client. */ +} RIL_Data_Call_Response_v9; + +typedef struct { + int status; /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */ + int suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry + back-off timer value RIL wants to override the one + pre-configured in FW. + The unit is miliseconds. + The value < 0 means no value is suggested. + The value 0 means retry should be done ASAP. + The value of INT_MAX(0x7fffffff) means no retry. */ + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". If status is + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported + such as "IP" or "IPV6" */ + char * ifname; /* The network interface name */ + char * addresses; /* A space-delimited list of addresses with optional "/" prefix length, + e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". + May not be empty, typically 1 IPv4 or 1 IPv6 or + one of each. If the prefix length is absent the addresses + are assumed to be point to point with IPv4 having a prefix + length of 32 and IPv6 128. */ + char * dnses; /* A space-delimited list of DNS server addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty. */ + char * gateways; /* A space-delimited list of default gateway addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty in which case the addresses represent point + to point connections. */ + char * pcscf; /* the Proxy Call State Control Function address + via PCO(Protocol Configuration Option) for IMS client. */ + int mtu; /* MTU received from network + Value <= 0 means network has either not sent a value or + sent an invalid value */ +} RIL_Data_Call_Response_v11; + +typedef enum { + RADIO_TECH_3GPP = 1, /* 3GPP Technologies - GSM, WCDMA */ + RADIO_TECH_3GPP2 = 2 /* 3GPP2 Technologies - CDMA */ +} RIL_RadioTechnologyFamily; + +typedef struct { + RIL_RadioTechnologyFamily tech; + unsigned char retry; /* 0 == not retry, nonzero == retry */ + int messageRef; /* Valid field if retry is set to nonzero. + Contains messageRef from RIL_SMS_Response + corresponding to failed MO SMS. + */ + + union { + /* Valid field if tech is RADIO_TECH_3GPP2. See RIL_REQUEST_CDMA_SEND_SMS */ + RIL_CDMA_SMS_Message* cdmaMessage; + + /* Valid field if tech is RADIO_TECH_3GPP. See RIL_REQUEST_SEND_SMS */ + char** gsmMessage; /* This is an array of pointers where pointers + are contiguous but elements pointed by those pointers + are not contiguous + */ + } message; +} RIL_IMS_SMS_Message; + +typedef struct { + int messageRef; /* TP-Message-Reference for GSM, + and BearerData MessageId for CDMA + (See 3GPP2 C.S0015-B, v2.0, table 4.5-1). */ + char *ackPDU; /* or NULL if n/a */ + int errorCode; /* See 3GPP 27.005, 3.2.5 for GSM/UMTS, + 3GPP2 N.S0005 (IS-41C) Table 171 for CDMA, + -1 if unknown or not applicable*/ +} RIL_SMS_Response; + +typedef struct { + RIL_SMS_Response response; + int retryCount; /* Samsung */ +} RIL_SMS_Response_Ext; + +/** Used by RIL_REQUEST_WRITE_SMS_TO_SIM */ +typedef struct { + int status; /* Status of message. See TS 27.005 3.1, "": */ + /* 0 = "REC UNREAD" */ + /* 1 = "REC READ" */ + /* 2 = "STO UNSENT" */ + /* 3 = "STO SENT" */ + char * pdu; /* PDU of message to write, as an ASCII hex string less the SMSC address, + the TP-layer length is "strlen(pdu)/2". */ + char * smsc; /* SMSC address in GSM BCD format prefixed by a length byte + (as expected by TS 27.005) or NULL for default SMSC */ +} RIL_SMS_WriteArgs; + +/** Used by RIL_REQUEST_DIAL */ +typedef struct { + char * address; + int clir; + /* (same as 'n' paremeter in TS 27.007 7.7 "+CLIR" + * clir == 0 on "use subscription default value" + * clir == 1 on "CLIR invocation" (restrict CLI presentation) + * clir == 2 on "CLIR suppression" (allow CLI presentation) + */ + RIL_UUS_Info * uusInfo; /* NULL or Pointer to User-User Signaling Information */ +} RIL_Dial; + +typedef struct { + int command; /* one of the commands listed for TS 27.007 +CRSM*/ + int fileid; /* EF id */ + char *path; /* "pathid" from TS 27.007 +CRSM command. + Path is in hex asciii format eg "7f205f70" + Path must always be provided. + */ + int p1; + int p2; + int p3; + char *data; /* May be NULL*/ + char *pin2; /* May be NULL*/ +} RIL_SIM_IO_v5; + +typedef struct { + int command; /* one of the commands listed for TS 27.007 +CRSM*/ + int fileid; /* EF id */ + char *path; /* "pathid" from TS 27.007 +CRSM command. + Path is in hex asciii format eg "7f205f70" + Path must always be provided. + */ + int p1; + int p2; + int p3; + char *data; /* May be NULL*/ + char *pin2; /* May be NULL*/ + char *aidPtr; /* AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. */ +} RIL_SIM_IO_v6; + +/* Used by RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL and + * RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC. */ +typedef struct { + int sessionid; /* "sessionid" from TS 27.007 +CGLA command. Should be + ignored for +CSIM command. */ + + /* Following fields are used to derive the APDU ("command" and "length" + values in TS 27.007 +CSIM and +CGLA commands). */ + int cla; + int instruction; + int p1; + int p2; + int p3; /* A negative P3 implies a 4 byte APDU. */ + char *data; /* May be NULL. In hex string format. */ +} RIL_SIM_APDU; + +typedef struct { + int sw1; + int sw2; + char *simResponse; /* In hex string format ([a-fA-F0-9]*), except for SIM_AUTHENTICATION + response for which it is in Base64 format, see 3GPP TS 31.102 7.1.2 */ +} RIL_SIM_IO_Response; + +/* See also com.android.internal.telephony.gsm.CallForwardInfo */ + +typedef struct { + int status; /* + * For RIL_REQUEST_QUERY_CALL_FORWARD_STATUS + * status 1 = active, 0 = not active + * + * For RIL_REQUEST_SET_CALL_FORWARD: + * status is: + * 0 = disable + * 1 = enable + * 2 = interrogate + * 3 = registeration + * 4 = erasure + */ + + int reason; /* from TS 27.007 7.11 "reason" */ + int serviceClass;/* From 27.007 +CCFC/+CLCK "class" + See table for Android mapping from + MMI service code + 0 means user doesn't input class */ + int toa; /* "type" from TS 27.007 7.11 */ + char * number; /* "number" from TS 27.007 7.11. May be NULL */ + int timeSeconds; /* for CF no reply only */ +}RIL_CallForwardInfo; + +typedef struct { + char * cid; /* Combination of LAC and Cell Id in 32 bits in GSM. + * Upper 16 bits is LAC and lower 16 bits + * is CID (as described in TS 27.005) + * Primary Scrambling Code (as described in TS 25.331) + * in 9 bits in UMTS + * Valid values are hexadecimal 0x0000 - 0xffffffff. + */ + int rssi; /* Received RSSI in GSM, + * Level index of CPICH Received Signal Code Power in UMTS + */ +} RIL_NeighboringCell; + +typedef struct { + char lce_status; /* LCE service status: + * -1 = not supported; + * 0 = stopped; + * 1 = active. + */ + unsigned int actual_interval_ms; /* actual LCE reporting interval, + * meaningful only if LCEStatus = 1. + */ +} RIL_LceStatusInfo; + +typedef struct { + unsigned int last_hop_capacity_kbps; /* last-hop cellular capacity: kilobits/second. */ + unsigned char confidence_level; /* capacity estimate confidence: 0-100 */ + unsigned char lce_suspended; /* LCE report going to be suspended? (e.g., radio + * moves to inactive state or network type change) + * 1 = suspended; + * 0 = not suspended. + */ +} RIL_LceDataInfo; + +typedef enum { + RIL_MATCH_ALL = 0, /* Apply to all carriers with the same mcc/mnc */ + RIL_MATCH_SPN = 1, /* Use SPN and mcc/mnc to identify the carrier */ + RIL_MATCH_IMSI_PREFIX = 2, /* Use IMSI prefix and mcc/mnc to identify the carrier */ + RIL_MATCH_GID1 = 3, /* Use GID1 and mcc/mnc to identify the carrier */ + RIL_MATCH_GID2 = 4, /* Use GID2 and mcc/mnc to identify the carrier */ +} RIL_CarrierMatchType; + +typedef struct { + const char * mcc; + const char * mnc; + RIL_CarrierMatchType match_type; /* Specify match type for the carrier. + * If it's RIL_MATCH_ALL, match_data is null; + * otherwise, match_data is the value for the match type. + */ + const char * match_data; +} RIL_Carrier; + +typedef struct { + int32_t len_allowed_carriers; /* length of array allowed_carriers */ + int32_t len_excluded_carriers; /* length of array excluded_carriers */ + RIL_Carrier * allowed_carriers; /* whitelist for allowed carriers */ + RIL_Carrier * excluded_carriers; /* blacklist for explicitly excluded carriers + * which match allowed_carriers. Eg. allowed_carriers match + * mcc/mnc, excluded_carriers has same mcc/mnc and gid1 + * is ABCD. It means except the carrier whose gid1 is ABCD, + * all carriers with the same mcc/mnc are allowed. + */ +} RIL_CarrierRestrictions; + +typedef struct { + char * mcc; /* MCC of the Carrier. */ + char * mnc ; /* MNC of the Carrier. */ + uint8_t * carrierKey; /* Public Key from the Carrier used to encrypt the + * IMSI/IMPI. + */ + char * keyIdentifier; /* The keyIdentifier Attribute value pair that helps + * a server locate the private key to decrypt the + * permanent identity. + */ + int64_t expirationTime; /* Date-Time (in UTC) when the key will expire. */ + +} RIL_CarrierInfoForImsiEncryption; + +/* See RIL_REQUEST_LAST_CALL_FAIL_CAUSE */ +typedef enum { + CALL_FAIL_UNOBTAINABLE_NUMBER = 1, + CALL_FAIL_NO_ROUTE_TO_DESTINATION = 3, + CALL_FAIL_CHANNEL_UNACCEPTABLE = 6, + CALL_FAIL_OPERATOR_DETERMINED_BARRING = 8, + CALL_FAIL_NORMAL = 16, + CALL_FAIL_BUSY = 17, + CALL_FAIL_NO_USER_RESPONDING = 18, + CALL_FAIL_NO_ANSWER_FROM_USER = 19, + CALL_FAIL_CALL_REJECTED = 21, + CALL_FAIL_NUMBER_CHANGED = 22, + CALL_FAIL_PREEMPTION = 25, + CALL_FAIL_DESTINATION_OUT_OF_ORDER = 27, + CALL_FAIL_INVALID_NUMBER_FORMAT = 28, + CALL_FAIL_FACILITY_REJECTED = 29, + CALL_FAIL_RESP_TO_STATUS_ENQUIRY = 30, + CALL_FAIL_NORMAL_UNSPECIFIED = 31, + CALL_FAIL_CONGESTION = 34, + CALL_FAIL_NETWORK_OUT_OF_ORDER = 38, + CALL_FAIL_TEMPORARY_FAILURE = 41, + CALL_FAIL_SWITCHING_EQUIPMENT_CONGESTION = 42, + CALL_FAIL_ACCESS_INFORMATION_DISCARDED = 43, + CALL_FAIL_REQUESTED_CIRCUIT_OR_CHANNEL_NOT_AVAILABLE = 44, + CALL_FAIL_RESOURCES_UNAVAILABLE_OR_UNSPECIFIED = 47, + CALL_FAIL_QOS_UNAVAILABLE = 49, + CALL_FAIL_REQUESTED_FACILITY_NOT_SUBSCRIBED = 50, + CALL_FAIL_INCOMING_CALLS_BARRED_WITHIN_CUG = 55, + CALL_FAIL_BEARER_CAPABILITY_NOT_AUTHORIZED = 57, + CALL_FAIL_BEARER_CAPABILITY_UNAVAILABLE = 58, + CALL_FAIL_SERVICE_OPTION_NOT_AVAILABLE = 63, + CALL_FAIL_BEARER_SERVICE_NOT_IMPLEMENTED = 65, + CALL_FAIL_ACM_LIMIT_EXCEEDED = 68, + CALL_FAIL_REQUESTED_FACILITY_NOT_IMPLEMENTED = 69, + CALL_FAIL_ONLY_DIGITAL_INFORMATION_BEARER_AVAILABLE = 70, + CALL_FAIL_SERVICE_OR_OPTION_NOT_IMPLEMENTED = 79, + CALL_FAIL_INVALID_TRANSACTION_IDENTIFIER = 81, + CALL_FAIL_USER_NOT_MEMBER_OF_CUG = 87, + CALL_FAIL_INCOMPATIBLE_DESTINATION = 88, + CALL_FAIL_INVALID_TRANSIT_NW_SELECTION = 91, + CALL_FAIL_SEMANTICALLY_INCORRECT_MESSAGE = 95, + CALL_FAIL_INVALID_MANDATORY_INFORMATION = 96, + CALL_FAIL_MESSAGE_TYPE_NON_IMPLEMENTED = 97, + CALL_FAIL_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE = 98, + CALL_FAIL_INFORMATION_ELEMENT_NON_EXISTENT = 99, + CALL_FAIL_CONDITIONAL_IE_ERROR = 100, + CALL_FAIL_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE = 101, + CALL_FAIL_RECOVERY_ON_TIMER_EXPIRED = 102, + CALL_FAIL_PROTOCOL_ERROR_UNSPECIFIED = 111, + CALL_FAIL_INTERWORKING_UNSPECIFIED = 127, + CALL_FAIL_CALL_BARRED = 240, + CALL_FAIL_FDN_BLOCKED = 241, + CALL_FAIL_IMSI_UNKNOWN_IN_VLR = 242, + CALL_FAIL_IMEI_NOT_ACCEPTED = 243, + CALL_FAIL_DIAL_MODIFIED_TO_USSD = 244, /* STK Call Control */ + CALL_FAIL_DIAL_MODIFIED_TO_SS = 245, + CALL_FAIL_DIAL_MODIFIED_TO_DIAL = 246, + CALL_FAIL_RADIO_OFF = 247, /* Radio is OFF */ + CALL_FAIL_OUT_OF_SERVICE = 248, /* No cellular coverage */ + CALL_FAIL_NO_VALID_SIM = 249, /* No valid SIM is present */ + CALL_FAIL_RADIO_INTERNAL_ERROR = 250, /* Internal error at Modem */ + CALL_FAIL_NETWORK_RESP_TIMEOUT = 251, /* No response from network */ + CALL_FAIL_NETWORK_REJECT = 252, /* Explicit network reject */ + CALL_FAIL_RADIO_ACCESS_FAILURE = 253, /* RRC connection failure. Eg.RACH */ + CALL_FAIL_RADIO_LINK_FAILURE = 254, /* Radio Link Failure */ + CALL_FAIL_RADIO_LINK_LOST = 255, /* Radio link lost due to poor coverage */ + CALL_FAIL_RADIO_UPLINK_FAILURE = 256, /* Radio uplink failure */ + CALL_FAIL_RADIO_SETUP_FAILURE = 257, /* RRC connection setup failure */ + CALL_FAIL_RADIO_RELEASE_NORMAL = 258, /* RRC connection release, normal */ + CALL_FAIL_RADIO_RELEASE_ABNORMAL = 259, /* RRC connection release, abnormal */ + CALL_FAIL_ACCESS_CLASS_BLOCKED = 260, /* Access class barring */ + CALL_FAIL_NETWORK_DETACH = 261, /* Explicit network detach */ + CALL_FAIL_CDMA_LOCKED_UNTIL_POWER_CYCLE = 1000, + CALL_FAIL_CDMA_DROP = 1001, + CALL_FAIL_CDMA_INTERCEPT = 1002, + CALL_FAIL_CDMA_REORDER = 1003, + CALL_FAIL_CDMA_SO_REJECT = 1004, + CALL_FAIL_CDMA_RETRY_ORDER = 1005, + CALL_FAIL_CDMA_ACCESS_FAILURE = 1006, + CALL_FAIL_CDMA_PREEMPTED = 1007, + CALL_FAIL_CDMA_NOT_EMERGENCY = 1008, /* For non-emergency number dialed + during emergency callback mode */ + CALL_FAIL_CDMA_ACCESS_BLOCKED = 1009, /* CDMA network access probes blocked */ + + /* OEM specific error codes. Used to distinguish error from + * CALL_FAIL_ERROR_UNSPECIFIED and help assist debugging */ + CALL_FAIL_OEM_CAUSE_1 = 0xf001, + CALL_FAIL_OEM_CAUSE_2 = 0xf002, + CALL_FAIL_OEM_CAUSE_3 = 0xf003, + CALL_FAIL_OEM_CAUSE_4 = 0xf004, + CALL_FAIL_OEM_CAUSE_5 = 0xf005, + CALL_FAIL_OEM_CAUSE_6 = 0xf006, + CALL_FAIL_OEM_CAUSE_7 = 0xf007, + CALL_FAIL_OEM_CAUSE_8 = 0xf008, + CALL_FAIL_OEM_CAUSE_9 = 0xf009, + CALL_FAIL_OEM_CAUSE_10 = 0xf00a, + CALL_FAIL_OEM_CAUSE_11 = 0xf00b, + CALL_FAIL_OEM_CAUSE_12 = 0xf00c, + CALL_FAIL_OEM_CAUSE_13 = 0xf00d, + CALL_FAIL_OEM_CAUSE_14 = 0xf00e, + CALL_FAIL_OEM_CAUSE_15 = 0xf00f, + + CALL_FAIL_ERROR_UNSPECIFIED = 0xffff /* This error will be deprecated soon, + vendor code should make sure to map error + code to specific error */ +} RIL_LastCallFailCause; + +typedef struct { + RIL_LastCallFailCause cause_code; + char * vendor_cause; +} RIL_LastCallFailCauseInfo; + +/* See RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE */ +typedef enum { + PDP_FAIL_NONE = 0, /* No error, connection ok */ + + /* an integer cause code defined in TS 24.008 + section 6.1.3.1.3 or TS 24.301 Release 8+ Annex B. + If the implementation does not have access to the exact cause codes, + then it should return one of the following values, + as the UI layer needs to distinguish these + cases for error notification and potential retries. */ + PDP_FAIL_OPERATOR_BARRED = 0x08, /* no retry */ + PDP_FAIL_NAS_SIGNALLING = 0x0E, + PDP_FAIL_LLC_SNDCP = 0x19, + PDP_FAIL_INSUFFICIENT_RESOURCES = 0x1A, + PDP_FAIL_MISSING_UKNOWN_APN = 0x1B, /* no retry */ + PDP_FAIL_UNKNOWN_PDP_ADDRESS_TYPE = 0x1C, /* no retry */ + PDP_FAIL_USER_AUTHENTICATION = 0x1D, /* no retry */ + PDP_FAIL_ACTIVATION_REJECT_GGSN = 0x1E, /* no retry */ + PDP_FAIL_ACTIVATION_REJECT_UNSPECIFIED = 0x1F, + PDP_FAIL_SERVICE_OPTION_NOT_SUPPORTED = 0x20, /* no retry */ + PDP_FAIL_SERVICE_OPTION_NOT_SUBSCRIBED = 0x21, /* no retry */ + PDP_FAIL_SERVICE_OPTION_OUT_OF_ORDER = 0x22, + PDP_FAIL_NSAPI_IN_USE = 0x23, /* no retry */ + PDP_FAIL_REGULAR_DEACTIVATION = 0x24, /* possibly restart radio, + based on framework config */ + PDP_FAIL_QOS_NOT_ACCEPTED = 0x25, + PDP_FAIL_NETWORK_FAILURE = 0x26, + PDP_FAIL_UMTS_REACTIVATION_REQ = 0x27, + PDP_FAIL_FEATURE_NOT_SUPP = 0x28, + PDP_FAIL_TFT_SEMANTIC_ERROR = 0x29, + PDP_FAIL_TFT_SYTAX_ERROR = 0x2A, + PDP_FAIL_UNKNOWN_PDP_CONTEXT = 0x2B, + PDP_FAIL_FILTER_SEMANTIC_ERROR = 0x2C, + PDP_FAIL_FILTER_SYTAX_ERROR = 0x2D, + PDP_FAIL_PDP_WITHOUT_ACTIVE_TFT = 0x2E, + PDP_FAIL_ONLY_IPV4_ALLOWED = 0x32, /* no retry */ + PDP_FAIL_ONLY_IPV6_ALLOWED = 0x33, /* no retry */ + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED = 0x34, + PDP_FAIL_ESM_INFO_NOT_RECEIVED = 0x35, + PDP_FAIL_PDN_CONN_DOES_NOT_EXIST = 0x36, + PDP_FAIL_MULTI_CONN_TO_SAME_PDN_NOT_ALLOWED = 0x37, + PDP_FAIL_MAX_ACTIVE_PDP_CONTEXT_REACHED = 0x41, + PDP_FAIL_UNSUPPORTED_APN_IN_CURRENT_PLMN = 0x42, + PDP_FAIL_INVALID_TRANSACTION_ID = 0x51, + PDP_FAIL_MESSAGE_INCORRECT_SEMANTIC = 0x5F, + PDP_FAIL_INVALID_MANDATORY_INFO = 0x60, + PDP_FAIL_MESSAGE_TYPE_UNSUPPORTED = 0x61, + PDP_FAIL_MSG_TYPE_NONCOMPATIBLE_STATE = 0x62, + PDP_FAIL_UNKNOWN_INFO_ELEMENT = 0x63, + PDP_FAIL_CONDITIONAL_IE_ERROR = 0x64, + PDP_FAIL_MSG_AND_PROTOCOL_STATE_UNCOMPATIBLE = 0x65, + PDP_FAIL_PROTOCOL_ERRORS = 0x6F, /* no retry */ + PDP_FAIL_APN_TYPE_CONFLICT = 0x70, + PDP_FAIL_INVALID_PCSCF_ADDR = 0x71, + PDP_FAIL_INTERNAL_CALL_PREEMPT_BY_HIGH_PRIO_APN = 0x72, + PDP_FAIL_EMM_ACCESS_BARRED = 0x73, + PDP_FAIL_EMERGENCY_IFACE_ONLY = 0x74, + PDP_FAIL_IFACE_MISMATCH = 0x75, + PDP_FAIL_COMPANION_IFACE_IN_USE = 0x76, + PDP_FAIL_IP_ADDRESS_MISMATCH = 0x77, + PDP_FAIL_IFACE_AND_POL_FAMILY_MISMATCH = 0x78, + PDP_FAIL_EMM_ACCESS_BARRED_INFINITE_RETRY = 0x79, + PDP_FAIL_AUTH_FAILURE_ON_EMERGENCY_CALL = 0x7A, + + // OEM specific error codes. To be used by OEMs when they don't want to + // reveal error code which would be replaced by PDP_FAIL_ERROR_UNSPECIFIED + PDP_FAIL_OEM_DCFAILCAUSE_1 = 0x1001, + PDP_FAIL_OEM_DCFAILCAUSE_2 = 0x1002, + PDP_FAIL_OEM_DCFAILCAUSE_3 = 0x1003, + PDP_FAIL_OEM_DCFAILCAUSE_4 = 0x1004, + PDP_FAIL_OEM_DCFAILCAUSE_5 = 0x1005, + PDP_FAIL_OEM_DCFAILCAUSE_6 = 0x1006, + PDP_FAIL_OEM_DCFAILCAUSE_7 = 0x1007, + PDP_FAIL_OEM_DCFAILCAUSE_8 = 0x1008, + PDP_FAIL_OEM_DCFAILCAUSE_9 = 0x1009, + PDP_FAIL_OEM_DCFAILCAUSE_10 = 0x100A, + PDP_FAIL_OEM_DCFAILCAUSE_11 = 0x100B, + PDP_FAIL_OEM_DCFAILCAUSE_12 = 0x100C, + PDP_FAIL_OEM_DCFAILCAUSE_13 = 0x100D, + PDP_FAIL_OEM_DCFAILCAUSE_14 = 0x100E, + PDP_FAIL_OEM_DCFAILCAUSE_15 = 0x100F, + + /* Not mentioned in the specification */ + PDP_FAIL_VOICE_REGISTRATION_FAIL = -1, + PDP_FAIL_DATA_REGISTRATION_FAIL = -2, + + /* reasons for data call drop - network/modem disconnect */ + PDP_FAIL_SIGNAL_LOST = -3, + PDP_FAIL_PREF_RADIO_TECH_CHANGED = -4,/* preferred technology has changed, should retry + with parameters appropriate for new technology */ + PDP_FAIL_RADIO_POWER_OFF = -5, /* data call was disconnected because radio was resetting, + powered off - no retry */ + PDP_FAIL_TETHERED_CALL_ACTIVE = -6, /* data call was disconnected by modem because tethered + mode was up on same APN/data profile - no retry until + tethered call is off */ + + PDP_FAIL_ERROR_UNSPECIFIED = 0xffff, /* retry silently. Will be deprecated soon as + new error codes are added making this unnecessary */ +} RIL_DataCallFailCause; + +/* See RIL_REQUEST_SETUP_DATA_CALL */ +typedef enum { + RIL_DATA_PROFILE_DEFAULT = 0, + RIL_DATA_PROFILE_TETHERED = 1, + RIL_DATA_PROFILE_IMS = 2, + RIL_DATA_PROFILE_FOTA = 3, + RIL_DATA_PROFILE_CBS = 4, + RIL_DATA_PROFILE_OEM_BASE = 1000, /* Start of OEM-specific profiles */ + RIL_DATA_PROFILE_INVALID = 0xFFFFFFFF +} RIL_DataProfile; + +/* Used by RIL_UNSOL_SUPP_SVC_NOTIFICATION */ +typedef struct { + int notificationType; /* + * 0 = MO intermediate result code + * 1 = MT unsolicited result code + */ + int code; /* See 27.007 7.17 + "code1" for MO + "code2" for MT. */ + int index; /* CUG index. See 27.007 7.17. */ + int type; /* "type" from 27.007 7.17 (MT only). */ + char * number; /* "number" from 27.007 7.17 + (MT only, may be NULL). */ +} RIL_SuppSvcNotification; + +#define RIL_CARD_MAX_APPS 8 + +typedef enum { + RIL_CARDSTATE_ABSENT = 0, + RIL_CARDSTATE_PRESENT = 1, + RIL_CARDSTATE_ERROR = 2, + RIL_CARDSTATE_RESTRICTED = 3 /* card is present but not usable due to carrier restrictions.*/ +} RIL_CardState; + +typedef enum { + RIL_PERSOSUBSTATE_UNKNOWN = 0, /* initial state */ + RIL_PERSOSUBSTATE_IN_PROGRESS = 1, /* in between each lock transition */ + RIL_PERSOSUBSTATE_READY = 2, /* when either SIM or RUIM Perso is finished + since each app can only have 1 active perso + involved */ + RIL_PERSOSUBSTATE_SIM_NETWORK = 3, + RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET = 4, + RIL_PERSOSUBSTATE_SIM_CORPORATE = 5, + RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER = 6, + RIL_PERSOSUBSTATE_SIM_SIM = 7, + RIL_PERSOSUBSTATE_SIM_NETWORK_PUK = 8, /* The corresponding perso lock is blocked */ + RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK = 9, + RIL_PERSOSUBSTATE_SIM_CORPORATE_PUK = 10, + RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK = 11, + RIL_PERSOSUBSTATE_SIM_SIM_PUK = 12, + RIL_PERSOSUBSTATE_RUIM_NETWORK1 = 13, + RIL_PERSOSUBSTATE_RUIM_NETWORK2 = 14, + RIL_PERSOSUBSTATE_RUIM_HRPD = 15, + RIL_PERSOSUBSTATE_RUIM_CORPORATE = 16, + RIL_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER = 17, + RIL_PERSOSUBSTATE_RUIM_RUIM = 18, + RIL_PERSOSUBSTATE_RUIM_NETWORK1_PUK = 19, /* The corresponding perso lock is blocked */ + RIL_PERSOSUBSTATE_RUIM_NETWORK2_PUK = 20, + RIL_PERSOSUBSTATE_RUIM_HRPD_PUK = 21, + RIL_PERSOSUBSTATE_RUIM_CORPORATE_PUK = 22, + RIL_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK = 23, + RIL_PERSOSUBSTATE_RUIM_RUIM_PUK = 24 +} RIL_PersoSubstate; + +typedef enum { + RIL_APPSTATE_UNKNOWN = 0, + RIL_APPSTATE_DETECTED = 1, + RIL_APPSTATE_PIN = 2, /* If PIN1 or UPin is required */ + RIL_APPSTATE_PUK = 3, /* If PUK1 or Puk for UPin is required */ + RIL_APPSTATE_SUBSCRIPTION_PERSO = 4, /* perso_substate should be look at + when app_state is assigned to this value */ + RIL_APPSTATE_READY = 5 +} RIL_AppState; + +typedef enum { + RIL_PINSTATE_UNKNOWN = 0, + RIL_PINSTATE_ENABLED_NOT_VERIFIED = 1, + RIL_PINSTATE_ENABLED_VERIFIED = 2, + RIL_PINSTATE_DISABLED = 3, + RIL_PINSTATE_ENABLED_BLOCKED = 4, + RIL_PINSTATE_ENABLED_PERM_BLOCKED = 5 +} RIL_PinState; + +typedef enum { + RIL_APPTYPE_UNKNOWN = 0, + RIL_APPTYPE_SIM = 1, + RIL_APPTYPE_USIM = 2, + RIL_APPTYPE_RUIM = 3, + RIL_APPTYPE_CSIM = 4, + RIL_APPTYPE_ISIM = 5 +} RIL_AppType; + +/* + * Please note that registration state UNKNOWN is + * treated as "out of service" in the Android telephony. + * Registration state REG_DENIED must be returned if Location Update + * Reject (with cause 17 - Network Failure) is received + * repeatedly from the network, to facilitate + * "managed roaming" + */ +typedef enum { + RIL_NOT_REG_AND_NOT_SEARCHING = 0, // Not registered, MT is not currently searching + // a new operator to register + RIL_REG_HOME = 1, // Registered, home network + RIL_NOT_REG_AND_SEARCHING = 2, // Not registered, but MT is currently searching + // a new operator to register + RIL_REG_DENIED = 3, // Registration denied + RIL_UNKNOWN = 4, // Unknown + RIL_REG_ROAMING = 5, // Registered, roaming + RIL_NOT_REG_AND_EMERGENCY_AVAILABLE_AND_NOT_SEARCHING = 10, // Same as + // RIL_NOT_REG_AND_NOT_SEARCHING but indicates that + // emergency calls are enabled. + RIL_NOT_REG_AND_EMERGENCY_AVAILABLE_AND_SEARCHING = 12, // Same as RIL_NOT_REG_AND_SEARCHING + // but indicates that + // emergency calls are enabled. + RIL_REG_DENIED_AND_EMERGENCY_AVAILABLE = 13, // Same as REG_DENIED but indicates that + // emergency calls are enabled. + RIL_UNKNOWN_AND_EMERGENCY_AVAILABLE = 14, // Same as UNKNOWN but indicates that + // emergency calls are enabled. +} RIL_RegState; + +typedef struct +{ + RIL_AppType app_type; + RIL_AppState app_state; + RIL_PersoSubstate perso_substate; /* applicable only if app_state == + RIL_APPSTATE_SUBSCRIPTION_PERSO */ + char *aid_ptr; /* null terminated string, e.g., from 0xA0, 0x00 -> 0x41, + 0x30, 0x30, 0x30 */ + char *app_label_ptr; /* null terminated string */ + int pin1_replaced; /* applicable to USIM, CSIM & ISIM */ + RIL_PinState pin1; + RIL_PinState pin2; + /* Samsung SIM PIN/Unlock fields */ + int pin1_num_retries; + int puk1_num_retries; + int pin2_num_retries; + int puk2_num_retries; + int perso_unblock_retries; +} RIL_AppStatus; + +/* Deprecated, use RIL_CardStatus_v6 */ +typedef struct +{ + RIL_CardState card_state; + RIL_PinState universal_pin_state; /* applicable to USIM and CSIM: RIL_PINSTATE_xxx */ + int gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int cdma_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int num_applications; /* value <= RIL_CARD_MAX_APPS */ + RIL_AppStatus applications[RIL_CARD_MAX_APPS]; +} RIL_CardStatus_v5; + +typedef struct +{ + RIL_CardState card_state; + RIL_PinState universal_pin_state; /* applicable to USIM and CSIM: RIL_PINSTATE_xxx */ + int gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int cdma_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int ims_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int num_applications; /* value <= RIL_CARD_MAX_APPS */ + RIL_AppStatus applications[RIL_CARD_MAX_APPS]; +} RIL_CardStatus_v6; + +/** The result of a SIM refresh, returned in data[0] of RIL_UNSOL_SIM_REFRESH + * or as part of RIL_SimRefreshResponse_v7 + */ +typedef enum { + /* A file on SIM has been updated. data[1] contains the EFID. */ + SIM_FILE_UPDATE = 0, + /* SIM initialized. All files should be re-read. */ + SIM_INIT = 1, + /* SIM reset. SIM power required, SIM may be locked and all files should be re-read. */ + SIM_RESET = 2 +} RIL_SimRefreshResult; + +typedef struct { + RIL_SimRefreshResult result; + int ef_id; /* is the EFID of the updated file if the result is */ + /* SIM_FILE_UPDATE or 0 for any other result. */ + char * aid; /* is AID(application ID) of the card application */ + /* See ETSI 102.221 8.1 and 101.220 4 */ + /* For SIM_FILE_UPDATE result it can be set to AID of */ + /* application in which updated EF resides or it can be */ + /* NULL if EF is outside of an application. */ + /* For SIM_INIT result this field is set to AID of */ + /* application that caused REFRESH */ + /* For SIM_RESET result it is NULL. */ +} RIL_SimRefreshResponse_v7; + +/* Deprecated, use RIL_CDMA_CallWaiting_v6 */ +typedef struct { + char * number; /* Remote party number */ + int numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown */ + char * name; /* Remote party name */ + RIL_CDMA_SignalInfoRecord signalInfoRecord; +} RIL_CDMA_CallWaiting_v5; + +typedef struct { + char * number; /* Remote party number */ + int numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown */ + char * name; /* Remote party name */ + RIL_CDMA_SignalInfoRecord signalInfoRecord; + /* Number type/Number plan required to support International Call Waiting */ + int number_type; /* 0=Unknown, 1=International, 2=National, + 3=Network specific, 4=subscriber */ + int number_plan; /* 0=Unknown, 1=ISDN, 3=Data, 4=Telex, 8=Nat'l, 9=Private */ +} RIL_CDMA_CallWaiting_v6; + +/** + * Which types of Cell Broadcast Message (CBM) are to be received by the ME + * + * uFromServiceID - uToServiceID defines a range of CBM message identifiers + * whose value is 0x0000 - 0xFFFF as defined in TS 23.041 9.4.1.2.2 for GMS + * and 9.4.4.2.2 for UMTS. All other values can be treated as empty + * CBM message ID. + * + * uFromCodeScheme - uToCodeScheme defines a range of CBM data coding schemes + * whose value is 0x00 - 0xFF as defined in TS 23.041 9.4.1.2.3 for GMS + * and 9.4.4.2.3 for UMTS. + * All other values can be treated as empty CBM data coding scheme. + * + * selected 0 means message types specified in + * and are not accepted, while 1 means accepted. + * + * Used by RIL_REQUEST_GSM_GET_BROADCAST_CONFIG and + * RIL_REQUEST_GSM_SET_BROADCAST_CONFIG. + */ +typedef struct { + int fromServiceId; + int toServiceId; + int fromCodeScheme; + int toCodeScheme; + unsigned char selected; +} RIL_GSM_BroadcastSmsConfigInfo; + +/* No restriction at all including voice/SMS/USSD/SS/AV64 and packet data. */ +#define RIL_RESTRICTED_STATE_NONE 0x00 +/* Block emergency call due to restriction. But allow all normal voice/SMS/USSD/SS/AV64. */ +#define RIL_RESTRICTED_STATE_CS_EMERGENCY 0x01 +/* Block all normal voice/SMS/USSD/SS/AV64 due to restriction. Only Emergency call allowed. */ +#define RIL_RESTRICTED_STATE_CS_NORMAL 0x02 +/* Block all voice/SMS/USSD/SS/AV64 including emergency call due to restriction.*/ +#define RIL_RESTRICTED_STATE_CS_ALL 0x04 +/* Block packet data access due to restriction. */ +#define RIL_RESTRICTED_STATE_PS_ALL 0x10 + +/* The status for an OTASP/OTAPA session */ +typedef enum { + CDMA_OTA_PROVISION_STATUS_SPL_UNLOCKED, + CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED, + CDMA_OTA_PROVISION_STATUS_A_KEY_EXCHANGED, + CDMA_OTA_PROVISION_STATUS_SSD_UPDATED, + CDMA_OTA_PROVISION_STATUS_NAM_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_MDN_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_IMSI_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_PRL_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_COMMITTED, + CDMA_OTA_PROVISION_STATUS_OTAPA_STARTED, + CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED, + CDMA_OTA_PROVISION_STATUS_OTAPA_ABORTED +} RIL_CDMA_OTA_ProvisionStatus; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int bitErrorRate; /* bit error rate (0-7, 99) as defined in TS 27.007 8.5 */ +} RIL_GW_SignalStrength; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int bitErrorRate; /* bit error rate (0-7, 99) as defined in TS 27.007 8.5 */ + int timingAdvance; /* Timing Advance in bit periods. 1 bit period = 48/13 us. + * INT_MAX denotes invalid value */ +} RIL_GSM_SignalStrength_v12; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int bitErrorRate; /* bit error rate (0-7, 99) as defined in TS 27.007 8.5 */ +} RIL_SignalStrengthWcdma; + +typedef struct { + int dbm; /* Valid values are positive integers. This value is the actual RSSI value + * multiplied by -1. Example: If the actual RSSI is -75, then this response + * value will be 75. + */ + int ecio; /* Valid values are positive integers. This value is the actual Ec/Io multiplied + * by -10. Example: If the actual Ec/Io is -12.5 dB, then this response value + * will be 125. + */ +} RIL_CDMA_SignalStrength; + + +typedef struct { + int dbm; /* Valid values are positive integers. This value is the actual RSSI value + * multiplied by -1. Example: If the actual RSSI is -75, then this response + * value will be 75. + */ + int ecio; /* Valid values are positive integers. This value is the actual Ec/Io multiplied + * by -10. Example: If the actual Ec/Io is -12.5 dB, then this response value + * will be 125. + */ + int signalNoiseRatio; /* Valid values are 0-8. 8 is the highest signal to noise ratio. */ +} RIL_EVDO_SignalStrength; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int rsrp; /* The current Reference Signal Receive Power in dBm multipled by -1. + * Range: 44 to 140 dBm + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.4 */ + int rsrq; /* The current Reference Signal Receive Quality in dB multiplied by -1. + * Range: 20 to 3 dB. + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.7 */ + int rssnr; /* The current reference signal signal-to-noise ratio in 0.1 dB units. + * Range: -200 to +300 (-200 = -20.0 dB, +300 = 30dB). + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 8.1.1 */ + int cqi; /* The current Channel Quality Indicator. + * Range: 0 to 15. + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 9.2, 9.3, A.4 */ +} RIL_LTE_SignalStrength; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int rsrp; /* The current Reference Signal Receive Power in dBm multipled by -1. + * Range: 44 to 140 dBm + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.4 */ + int rsrq; /* The current Reference Signal Receive Quality in dB multiplied by -1. + * Range: 20 to 3 dB. + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.7 */ + int rssnr; /* The current reference signal signal-to-noise ratio in 0.1 dB units. + * Range: -200 to +300 (-200 = -20.0 dB, +300 = 30dB). + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 8.1.1 */ + int cqi; /* The current Channel Quality Indicator. + * Range: 0 to 15. + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 9.2, 9.3, A.4 */ + int timingAdvance; /* timing advance in micro seconds for a one way trip from cell to device. + * Approximate distance can be calculated using 300m/us * timingAdvance. + * Range: 0 to 0x7FFFFFFE + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP 36.321 section 6.1.3.5 + * also: http://www.cellular-planningoptimization.com/2010/02/timing-advance-with-calculation.html */ +} RIL_LTE_SignalStrength_v8; + +typedef struct { + int rscp; /* The Received Signal Code Power in dBm multipled by -1. + * Range : 25 to 120 + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 25.123, section 9.1.1.1 */ +} RIL_TD_SCDMA_SignalStrength; + +/* Deprecated, use RIL_SignalStrength_v6 */ +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; +} RIL_SignalStrength_v5; + +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; + RIL_LTE_SignalStrength LTE_SignalStrength; +} RIL_SignalStrength_v6; + +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; + RIL_LTE_SignalStrength_v8 LTE_SignalStrength; +} RIL_SignalStrength_v8; + +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; + RIL_LTE_SignalStrength_v8 LTE_SignalStrength; + RIL_TD_SCDMA_SignalStrength TD_SCDMA_SignalStrength; +} RIL_SignalStrength_v10; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 16-bit GSM Cell Identity described in TS 27.007, 0..65535, INT_MAX if unknown */ +} RIL_CellIdentityGsm; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 16-bit GSM Cell Identity described in TS 27.007, 0..65535, INT_MAX if unknown */ + int arfcn; /* 16-bit GSM Absolute RF channel number; this value must be reported */ + uint8_t bsic; /* 6-bit Base Station Identity Code; 0xFF if unknown */ +} RIL_CellIdentityGsm_v12; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ + int psc; /* 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, INT_MAX if unknown */ +} RIL_CellIdentityWcdma; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ + int psc; /* 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511; this value must be reported */ + int uarfcn; /* 16-bit UMTS Absolute RF Channel Number; this value must be reported */ +} RIL_CellIdentityWcdma_v12; + +typedef struct { + int networkId; /* Network Id 0..65535, INT_MAX if unknown */ + int systemId; /* CDMA System Id 0..32767, INT_MAX if unknown */ + int basestationId; /* Base Station Id 0..65535, INT_MAX if unknown */ + int longitude; /* Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. + * It is represented in units of 0.25 seconds and ranges from -2592000 + * to 2592000, both values inclusive (corresponding to a range of -180 + * to +180 degrees). INT_MAX if unknown */ + + int latitude; /* Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. + * It is represented in units of 0.25 seconds and ranges from -1296000 + * to 1296000, both values inclusive (corresponding to a range of -90 + * to +90 degrees). INT_MAX if unknown */ +} RIL_CellIdentityCdma; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int ci; /* 28-bit Cell Identity described in TS ???, INT_MAX if unknown */ + int pci; /* physical cell id 0..503, INT_MAX if unknown */ + int tac; /* 16-bit tracking area code, INT_MAX if unknown */ +} RIL_CellIdentityLte; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int ci; /* 28-bit Cell Identity described in TS ???, INT_MAX if unknown */ + int pci; /* physical cell id 0..503; this value must be reported */ + int tac; /* 16-bit tracking area code, INT_MAX if unknown */ + int earfcn; /* 18-bit LTE Absolute RF Channel Number; this value must be reported */ +} RIL_CellIdentityLte_v12; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ + int cpid; /* 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown */ +} RIL_CellIdentityTdscdma; + +typedef struct { + RIL_CellIdentityGsm cellIdentityGsm; + RIL_GW_SignalStrength signalStrengthGsm; +} RIL_CellInfoGsm; + +typedef struct { + RIL_CellIdentityGsm_v12 cellIdentityGsm; + RIL_GSM_SignalStrength_v12 signalStrengthGsm; +} RIL_CellInfoGsm_v12; + +typedef struct { + RIL_CellIdentityWcdma cellIdentityWcdma; + RIL_SignalStrengthWcdma signalStrengthWcdma; +} RIL_CellInfoWcdma; + +typedef struct { + RIL_CellIdentityWcdma_v12 cellIdentityWcdma; + RIL_SignalStrengthWcdma signalStrengthWcdma; +} RIL_CellInfoWcdma_v12; + +typedef struct { + RIL_CellIdentityCdma cellIdentityCdma; + RIL_CDMA_SignalStrength signalStrengthCdma; + RIL_EVDO_SignalStrength signalStrengthEvdo; +} RIL_CellInfoCdma; + +typedef struct { + RIL_CellIdentityLte cellIdentityLte; + RIL_LTE_SignalStrength_v8 signalStrengthLte; +} RIL_CellInfoLte; + +typedef struct { + RIL_CellIdentityLte_v12 cellIdentityLte; + RIL_LTE_SignalStrength_v8 signalStrengthLte; +} RIL_CellInfoLte_v12; + +typedef struct { + RIL_CellIdentityTdscdma cellIdentityTdscdma; + RIL_TD_SCDMA_SignalStrength signalStrengthTdscdma; +} RIL_CellInfoTdscdma; + +// Must be the same as CellInfo.TYPE_XXX +typedef enum { + RIL_CELL_INFO_TYPE_NONE = 0, /* indicates no cell information */ + RIL_CELL_INFO_TYPE_GSM = 1, + RIL_CELL_INFO_TYPE_CDMA = 2, + RIL_CELL_INFO_TYPE_LTE = 3, + RIL_CELL_INFO_TYPE_WCDMA = 4, + RIL_CELL_INFO_TYPE_TD_SCDMA = 5 +} RIL_CellInfoType; + +// Must be the same as CellInfo.TIMESTAMP_TYPE_XXX +typedef enum { + RIL_TIMESTAMP_TYPE_UNKNOWN = 0, + RIL_TIMESTAMP_TYPE_ANTENNA = 1, + RIL_TIMESTAMP_TYPE_MODEM = 2, + RIL_TIMESTAMP_TYPE_OEM_RIL = 3, + RIL_TIMESTAMP_TYPE_JAVA_RIL = 4, +} RIL_TimeStampType; + +typedef struct { + RIL_CellInfoType cellInfoType; /* cell type for selecting from union CellInfo */ + int registered; /* !0 if this cell is registered 0 if not registered */ + RIL_TimeStampType timeStampType; /* type of time stamp represented by timeStamp */ + uint64_t timeStamp; /* Time in nanos as returned by ril_nano_time */ + union { + RIL_CellInfoGsm gsm; + RIL_CellInfoCdma cdma; + RIL_CellInfoLte lte; + RIL_CellInfoWcdma wcdma; + RIL_CellInfoTdscdma tdscdma; + } CellInfo; +} RIL_CellInfo; + +typedef struct { + RIL_CellInfoType cellInfoType; /* cell type for selecting from union CellInfo */ + int registered; /* !0 if this cell is registered 0 if not registered */ + RIL_TimeStampType timeStampType; /* type of time stamp represented by timeStamp */ + uint64_t timeStamp; /* Time in nanos as returned by ril_nano_time */ + union { + RIL_CellInfoGsm_v12 gsm; + RIL_CellInfoCdma cdma; + RIL_CellInfoLte_v12 lte; + RIL_CellInfoWcdma_v12 wcdma; + RIL_CellInfoTdscdma tdscdma; + } CellInfo; +} RIL_CellInfo_v12; + +typedef struct { + RIL_CellInfoType cellInfoType; /* cell type for selecting from union CellInfo */ + union { + RIL_CellIdentityGsm_v12 cellIdentityGsm; + RIL_CellIdentityWcdma_v12 cellIdentityWcdma; + RIL_CellIdentityLte_v12 cellIdentityLte; + RIL_CellIdentityTdscdma cellIdentityTdscdma; + RIL_CellIdentityCdma cellIdentityCdma; + }; +}RIL_CellIdentity_v16; + +typedef struct { + RIL_RegState regState; // Valid reg states are RIL_NOT_REG_AND_NOT_SEARCHING, + // REG_HOME, RIL_NOT_REG_AND_SEARCHING, REG_DENIED, + // UNKNOWN, REG_ROAMING defined in RegState + RIL_RadioTechnology rat; // indicates the available voice radio technology, + // valid values as defined by RadioTechnology. + int32_t cssSupported; // concurrent services support indicator. if + // registered on a CDMA system. + // 0 - Concurrent services not supported, + // 1 - Concurrent services supported + int32_t roamingIndicator; // TSB-58 Roaming Indicator if registered + // on a CDMA or EVDO system or -1 if not. + // Valid values are 0-255. + int32_t systemIsInPrl; // indicates whether the current system is in the + // PRL if registered on a CDMA or EVDO system or -1 if + // not. 0=not in the PRL, 1=in the PRL + int32_t defaultRoamingIndicator; // default Roaming Indicator from the PRL, + // if registered on a CDMA or EVDO system or -1 if not. + // Valid values are 0-255. + int32_t reasonForDenial; // reasonForDenial if registration state is 3 + // (Registration denied) this is an enumerated reason why + // registration was denied. See 3GPP TS 24.008, + // 10.5.3.6 and Annex G. + // 0 - General + // 1 - Authentication Failure + // 2 - IMSI unknown in HLR + // 3 - Illegal MS + // 4 - Illegal ME + // 5 - PLMN not allowed + // 6 - Location area not allowed + // 7 - Roaming not allowed + // 8 - No Suitable Cells in this Location Area + // 9 - Network failure + // 10 - Persistent location update reject + // 11 - PLMN not allowed + // 12 - Location area not allowed + // 13 - Roaming not allowed in this Location Area + // 15 - No Suitable Cells in this Location Area + // 17 - Network Failure + // 20 - MAC Failure + // 21 - Sync Failure + // 22 - Congestion + // 23 - GSM Authentication unacceptable + // 25 - Not Authorized for this CSG + // 32 - Service option not supported + // 33 - Requested service option not subscribed + // 34 - Service option temporarily out of order + // 38 - Call cannot be identified + // 48-63 - Retry upon entry into a new cell + // 95 - Semantically incorrect message + // 96 - Invalid mandatory information + // 97 - Message type non-existent or not implemented + // 98 - Message type not compatible with protocol state + // 99 - Information element non-existent or + // not implemented + // 100 - Conditional IE error + // 101 - Message not compatible with protocol state; + RIL_CellIdentity_v16 cellIdentity; // current cell information +}RIL_VoiceRegistrationStateResponse; + + +typedef struct { + RIL_RegState regState; // Valid reg states are RIL_NOT_REG_AND_NOT_SEARCHING, + // REG_HOME, RIL_NOT_REG_AND_SEARCHING, REG_DENIED, + // UNKNOWN, REG_ROAMING defined in RegState + RIL_RadioTechnology rat; // indicates the available data radio technology, + // valid values as defined by RadioTechnology. + int32_t reasonDataDenied; // if registration state is 3 (Registration + // denied) this is an enumerated reason why + // registration was denied. See 3GPP TS 24.008, + // Annex G.6 "Additional cause codes for GMM". + // 7 == GPRS services not allowed + // 8 == GPRS services and non-GPRS services not allowed + // 9 == MS identity cannot be derived by the network + // 10 == Implicitly detached + // 14 == GPRS services not allowed in this PLMN + // 16 == MSC temporarily not reachable + // 40 == No PDP context activated + int32_t maxDataCalls; // The maximum number of simultaneous Data Calls that + // must be established using setupDataCall(). + RIL_CellIdentity_v16 cellIdentity; // Current cell information +}RIL_DataRegistrationStateResponse; + +/* Names of the CDMA info records (C.S0005 section 3.7.5) */ +typedef enum { + RIL_CDMA_DISPLAY_INFO_REC, + RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC, + RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC, + RIL_CDMA_CONNECTED_NUMBER_INFO_REC, + RIL_CDMA_SIGNAL_INFO_REC, + RIL_CDMA_REDIRECTING_NUMBER_INFO_REC, + RIL_CDMA_LINE_CONTROL_INFO_REC, + RIL_CDMA_EXTENDED_DISPLAY_INFO_REC, + RIL_CDMA_T53_CLIR_INFO_REC, + RIL_CDMA_T53_RELEASE_INFO_REC, + RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC +} RIL_CDMA_InfoRecName; + +/* Display Info Rec as defined in C.S0005 section 3.7.5.1 + Extended Display Info Rec as defined in C.S0005 section 3.7.5.16 + Note: the Extended Display info rec contains multiple records of the + form: display_tag, display_len, and display_len occurrences of the + chari field if the display_tag is not 10000000 or 10000001. + To save space, the records are stored consecutively in a byte buffer. + The display_tag, display_len and chari fields are all 1 byte. +*/ + +typedef struct { + char alpha_len; + char alpha_buf[CDMA_ALPHA_INFO_BUFFER_LENGTH]; +} RIL_CDMA_DisplayInfoRecord; + +/* Called Party Number Info Rec as defined in C.S0005 section 3.7.5.2 + Calling Party Number Info Rec as defined in C.S0005 section 3.7.5.3 + Connected Number Info Rec as defined in C.S0005 section 3.7.5.4 +*/ + +typedef struct { + char len; + char buf[CDMA_NUMBER_INFO_BUFFER_LENGTH]; + char number_type; + char number_plan; + char pi; + char si; +} RIL_CDMA_NumberInfoRecord; + +/* Redirecting Number Information Record as defined in C.S0005 section 3.7.5.11 */ +typedef enum { + RIL_REDIRECTING_REASON_UNKNOWN = 0, + RIL_REDIRECTING_REASON_CALL_FORWARDING_BUSY = 1, + RIL_REDIRECTING_REASON_CALL_FORWARDING_NO_REPLY = 2, + RIL_REDIRECTING_REASON_CALLED_DTE_OUT_OF_ORDER = 9, + RIL_REDIRECTING_REASON_CALL_FORWARDING_BY_THE_CALLED_DTE = 10, + RIL_REDIRECTING_REASON_CALL_FORWARDING_UNCONDITIONAL = 15, + RIL_REDIRECTING_REASON_RESERVED +} RIL_CDMA_RedirectingReason; + +typedef struct { + RIL_CDMA_NumberInfoRecord redirectingNumber; + /* redirectingReason is set to RIL_REDIRECTING_REASON_UNKNOWN if not included */ + RIL_CDMA_RedirectingReason redirectingReason; +} RIL_CDMA_RedirectingNumberInfoRecord; + +/* Line Control Information Record as defined in C.S0005 section 3.7.5.15 */ +typedef struct { + char lineCtrlPolarityIncluded; + char lineCtrlToggle; + char lineCtrlReverse; + char lineCtrlPowerDenial; +} RIL_CDMA_LineControlInfoRecord; + +/* T53 CLIR Information Record */ +typedef struct { + char cause; +} RIL_CDMA_T53_CLIRInfoRecord; + +/* T53 Audio Control Information Record */ +typedef struct { + char upLink; + char downLink; +} RIL_CDMA_T53_AudioControlInfoRecord; + +typedef struct { + + RIL_CDMA_InfoRecName name; + + union { + /* Display and Extended Display Info Rec */ + RIL_CDMA_DisplayInfoRecord display; + + /* Called Party Number, Calling Party Number, Connected Number Info Rec */ + RIL_CDMA_NumberInfoRecord number; + + /* Signal Info Rec */ + RIL_CDMA_SignalInfoRecord signal; + + /* Redirecting Number Info Rec */ + RIL_CDMA_RedirectingNumberInfoRecord redir; + + /* Line Control Info Rec */ + RIL_CDMA_LineControlInfoRecord lineCtrl; + + /* T53 CLIR Info Rec */ + RIL_CDMA_T53_CLIRInfoRecord clir; + + /* T53 Audio Control Info Rec */ + RIL_CDMA_T53_AudioControlInfoRecord audioCtrl; + } rec; +} RIL_CDMA_InformationRecord; + +#define RIL_CDMA_MAX_NUMBER_OF_INFO_RECS 10 + +typedef struct { + char numberOfInfoRecs; + RIL_CDMA_InformationRecord infoRec[RIL_CDMA_MAX_NUMBER_OF_INFO_RECS]; +} RIL_CDMA_InformationRecords; + +/* See RIL_REQUEST_NV_READ_ITEM */ +typedef struct { + RIL_NV_Item itemID; +} RIL_NV_ReadItem; + +/* See RIL_REQUEST_NV_WRITE_ITEM */ +typedef struct { + RIL_NV_Item itemID; + char * value; +} RIL_NV_WriteItem; + +typedef enum { + HANDOVER_STARTED = 0, + HANDOVER_COMPLETED = 1, + HANDOVER_FAILED = 2, + HANDOVER_CANCELED = 3 +} RIL_SrvccState; + +/* hardware configuration reported to RILJ. */ +typedef enum { + RIL_HARDWARE_CONFIG_MODEM = 0, + RIL_HARDWARE_CONFIG_SIM = 1, +} RIL_HardwareConfig_Type; + +typedef enum { + RIL_HARDWARE_CONFIG_STATE_ENABLED = 0, + RIL_HARDWARE_CONFIG_STATE_STANDBY = 1, + RIL_HARDWARE_CONFIG_STATE_DISABLED = 2, +} RIL_HardwareConfig_State; + +typedef struct { + int rilModel; + uint32_t rat; /* bitset - ref. RIL_RadioTechnology. */ + int maxVoice; + int maxData; + int maxStandby; +} RIL_HardwareConfig_Modem; + +typedef struct { + char modemUuid[MAX_UUID_LENGTH]; +} RIL_HardwareConfig_Sim; + +typedef struct { + RIL_HardwareConfig_Type type; + char uuid[MAX_UUID_LENGTH]; + RIL_HardwareConfig_State state; + union { + RIL_HardwareConfig_Modem modem; + RIL_HardwareConfig_Sim sim; + } cfg; +} RIL_HardwareConfig; + +typedef enum { + SS_CFU, + SS_CF_BUSY, + SS_CF_NO_REPLY, + SS_CF_NOT_REACHABLE, + SS_CF_ALL, + SS_CF_ALL_CONDITIONAL, + SS_CLIP, + SS_CLIR, + SS_COLP, + SS_COLR, + SS_WAIT, + SS_BAOC, + SS_BAOIC, + SS_BAOIC_EXC_HOME, + SS_BAIC, + SS_BAIC_ROAMING, + SS_ALL_BARRING, + SS_OUTGOING_BARRING, + SS_INCOMING_BARRING +} RIL_SsServiceType; + +typedef enum { + SS_ACTIVATION, + SS_DEACTIVATION, + SS_INTERROGATION, + SS_REGISTRATION, + SS_ERASURE +} RIL_SsRequestType; + +typedef enum { + SS_ALL_TELE_AND_BEARER_SERVICES, + SS_ALL_TELESEVICES, + SS_TELEPHONY, + SS_ALL_DATA_TELESERVICES, + SS_SMS_SERVICES, + SS_ALL_TELESERVICES_EXCEPT_SMS +} RIL_SsTeleserviceType; + +#define SS_INFO_MAX 4 +#define NUM_SERVICE_CLASSES 7 + +typedef struct { + int numValidIndexes; /* This gives the number of valid values in cfInfo. + For example if voice is forwarded to one number and data + is forwarded to a different one then numValidIndexes will be + 2 indicating total number of valid values in cfInfo. + Similarly if all the services are forwarded to the same + number then the value of numValidIndexes will be 1. */ + + RIL_CallForwardInfo cfInfo[NUM_SERVICE_CLASSES]; /* This is the response data + for SS request to query call + forward status. see + RIL_REQUEST_QUERY_CALL_FORWARD_STATUS */ +} RIL_CfData; + +typedef struct { + RIL_SsServiceType serviceType; + RIL_SsRequestType requestType; + RIL_SsTeleserviceType teleserviceType; + int serviceClass; + RIL_Errno result; + + union { + int ssInfo[SS_INFO_MAX]; /* This is the response data for most of the SS GET/SET + RIL requests. E.g. RIL_REQUSET_GET_CLIR returns + two ints, so first two values of ssInfo[] will be + used for response if serviceType is SS_CLIR and + requestType is SS_INTERROGATION */ + + RIL_CfData cfData; + }; +} RIL_StkCcUnsolSsResponse; + +/** + * Data connection power state + */ +typedef enum { + RIL_DC_POWER_STATE_LOW = 1, // Low power state + RIL_DC_POWER_STATE_MEDIUM = 2, // Medium power state + RIL_DC_POWER_STATE_HIGH = 3, // High power state + RIL_DC_POWER_STATE_UNKNOWN = INT32_MAX // Unknown state +} RIL_DcPowerStates; + +/** + * Data connection real time info + */ +typedef struct { + uint64_t time; // Time in nanos as returned by ril_nano_time + RIL_DcPowerStates powerState; // Current power state +} RIL_DcRtInfo; + +/** + * Data profile to modem + */ +typedef struct { + /* id of the data profile */ + int profileId; + /* the APN to connect to */ + char* apn; + /** one of the PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + */ + char* protocol; + /** authentication protocol used for this PDP context + * (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) + */ + int authType; + /* the username for APN, or NULL */ + char* user; + /* the password for APN, or NULL */ + char* password; + /* the profile type, TYPE_COMMON-0, TYPE_3GPP-1, TYPE_3GPP2-2 */ + int type; + /* the period in seconds to limit the maximum connections */ + int maxConnsTime; + /* the maximum connections during maxConnsTime */ + int maxConns; + /** the required wait time in seconds after a successful UE initiated + * disconnect of a given PDN connection before the device can send + * a new PDN connection request for that given PDN + */ + int waitTime; + /* true to enable the profile, 0 to disable, 1 to enable */ + int enabled; +} RIL_DataProfileInfo; + +typedef struct { + /* id of the data profile */ + int profileId; + /* the APN to connect to */ + char* apn; + /** one of the PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + */ + char* protocol; + /** one of the PDP_type values in TS 27.007 section 10.1.1 used on roaming network. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + */ + char *roamingProtocol; + /** authentication protocol used for this PDP context + * (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) + */ + int authType; + /* the username for APN, or NULL */ + char* user; + /* the password for APN, or NULL */ + char* password; + /* the profile type, TYPE_COMMON-0, TYPE_3GPP-1, TYPE_3GPP2-2 */ + int type; + /* the period in seconds to limit the maximum connections */ + int maxConnsTime; + /* the maximum connections during maxConnsTime */ + int maxConns; + /** the required wait time in seconds after a successful UE initiated + * disconnect of a given PDN connection before the device can send + * a new PDN connection request for that given PDN + */ + int waitTime; + /* true to enable the profile, 0 to disable, 1 to enable */ + int enabled; + /* supported APN types bitmask. See RIL_ApnTypes for the value of each bit. */ + int supportedTypesBitmask; + /** the bearer bitmask. See RIL_RadioAccessFamily for the value of each bit. */ + int bearerBitmask; + /** maximum transmission unit (MTU) size in bytes */ + int mtu; + /** the MVNO type: possible values are "imsi", "gid", "spn" */ + char *mvnoType; + /** MVNO match data. Can be anything defined by the carrier. For example, + * SPN like: "A MOBILE", "BEN NL", etc... + * IMSI like: "302720x94", "2060188", etc... + * GID like: "4E", "33", etc... + */ + char *mvnoMatchData; +} RIL_DataProfileInfo_v15; + +/* Tx Power Levels */ +#define RIL_NUM_TX_POWER_LEVELS 5 + +/** + * Aggregate modem activity information + */ +typedef struct { + + /* total time (in ms) when modem is in a low power or + * sleep state + */ + uint32_t sleep_mode_time_ms; + + /* total time (in ms) when modem is awake but neither + * the transmitter nor receiver are active/awake */ + uint32_t idle_mode_time_ms; + + /* total time (in ms) during which the transmitter is active/awake, + * subdivided by manufacturer-defined device-specific + * contiguous increasing ranges of transmit power between + * 0 and the transmitter's maximum transmit power. + */ + uint32_t tx_mode_time_ms[RIL_NUM_TX_POWER_LEVELS]; + + /* total time (in ms) for which receiver is active/awake and + * the transmitter is inactive */ + uint32_t rx_mode_time_ms; +} RIL_ActivityStatsInfo; + +typedef enum { + RIL_APN_TYPE_UNKNOWN = 0x0, // Unknown + RIL_APN_TYPE_DEFAULT = 0x1, // APN type for default data traffic + RIL_APN_TYPE_MMS = 0x2, // APN type for MMS traffic + RIL_APN_TYPE_SUPL = 0x4, // APN type for SUPL assisted GPS + RIL_APN_TYPE_DUN = 0x8, // APN type for DUN traffic + RIL_APN_TYPE_HIPRI = 0x10, // APN type for HiPri traffic + RIL_APN_TYPE_FOTA = 0x20, // APN type for FOTA + RIL_APN_TYPE_IMS = 0x40, // APN type for IMS + RIL_APN_TYPE_CBS = 0x80, // APN type for CBS + RIL_APN_TYPE_IA = 0x100, // APN type for IA Initial Attach APN + RIL_APN_TYPE_EMERGENCY = 0x200, // APN type for Emergency PDN. This is not an IA apn, + // but is used for access to carrier services in an + // emergency call situation. + RIL_APN_TYPE_ALL = 0xFFFFFFFF // All APN types +} RIL_ApnTypes; + +typedef enum { + RIL_DST_POWER_SAVE_MODE, // Device power save mode (provided by PowerManager) + // True indicates the device is in power save mode. + RIL_DST_CHARGING_STATE, // Device charging state (provided by BatteryManager) + // True indicates the device is charging. + RIL_DST_LOW_DATA_EXPECTED // Low data expected mode. True indicates low data traffic + // is expected, for example, when the device is idle + // (e.g. not doing tethering in the background). Note + // this doesn't mean no data is expected. +} RIL_DeviceStateType; + +typedef enum { + RIL_UR_SIGNAL_STRENGTH = 0x01, // When this bit is set, modem should always send the + // signal strength update through + // RIL_UNSOL_SIGNAL_STRENGTH, otherwise suppress it. + RIL_UR_FULL_NETWORK_STATE = 0x02, // When this bit is set, modem should always send + // RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + // when any field in + // RIL_REQUEST_VOICE_REGISTRATION_STATE or + // RIL_REQUEST_DATA_REGISTRATION_STATE changes. When + // this bit is not set, modem should suppress + // RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + // only when insignificant fields change + // (e.g. cell info). + // Modem should continue sending + // RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + // when significant fields are updated even when this + // bit is not set. The following fields are + // considered significant, registration state and + // radio technology. + RIL_UR_DATA_CALL_DORMANCY_CHANGED = 0x04 // When this bit is set, modem should send the data + // call list changed unsolicited response + // RIL_UNSOL_DATA_CALL_LIST_CHANGED whenever any + // field in RIL_Data_Call_Response changes. + // Otherwise modem should suppress the unsolicited + // response when the only changed field is 'active' + // (for data dormancy). For all other fields change, + // modem should continue sending + // RIL_UNSOL_DATA_CALL_LIST_CHANGED regardless this + // bit is set or not. +} RIL_UnsolicitedResponseFilter; + +typedef struct { + char * aidPtr; /* AID value, See ETSI 102.221 and 101.220*/ + int p2; /* P2 parameter (described in ISO 7816-4) + P2Constants:NO_P2 if to be ignored */ +} RIL_OpenChannelParams; + +typedef enum { + RIL_ONE_SHOT = 0x01, // Performs the scan only once + RIL_PERIODIC = 0x02 // Performs the scan periodically until cancelled +} RIL_ScanType; + +typedef enum { + GERAN = 0x01, // GSM EDGE Radio Access Network + UTRAN = 0x02, // Universal Terrestrial Radio Access Network + EUTRAN = 0x03, // Evolved Universal Terrestrial Radio Access Network +} RIL_RadioAccessNetworks; + +typedef enum { + GERAN_BAND_T380 = 1, + GERAN_BAND_T410 = 2, + GERAN_BAND_450 = 3, + GERAN_BAND_480 = 4, + GERAN_BAND_710 = 5, + GERAN_BAND_750 = 6, + GERAN_BAND_T810 = 7, + GERAN_BAND_850 = 8, + GERAN_BAND_P900 = 9, + GERAN_BAND_E900 = 10, + GERAN_BAND_R900 = 11, + GERAN_BAND_DCS1800 = 12, + GERAN_BAND_PCS1900 = 13, + GERAN_BAND_ER900 = 14, +} RIL_GeranBands; + +typedef enum { + UTRAN_BAND_1 = 1, + UTRAN_BAND_2 = 2, + UTRAN_BAND_3 = 3, + UTRAN_BAND_4 = 4, + UTRAN_BAND_5 = 5, + UTRAN_BAND_6 = 6, + UTRAN_BAND_7 = 7, + UTRAN_BAND_8 = 8, + UTRAN_BAND_9 = 9, + UTRAN_BAND_10 = 10, + UTRAN_BAND_11 = 11, + UTRAN_BAND_12 = 12, + UTRAN_BAND_13 = 13, + UTRAN_BAND_14 = 14, + UTRAN_BAND_19 = 19, + UTRAN_BAND_20 = 20, + UTRAN_BAND_21 = 21, + UTRAN_BAND_22 = 22, + UTRAN_BAND_25 = 25, + UTRAN_BAND_26 = 26, +} RIL_UtranBands; + +typedef enum { + EUTRAN_BAND_1 = 1, + EUTRAN_BAND_2 = 2, + EUTRAN_BAND_3 = 3, + EUTRAN_BAND_4 = 4, + EUTRAN_BAND_5 = 5, + EUTRAN_BAND_6 = 6, + EUTRAN_BAND_7 = 7, + EUTRAN_BAND_8 = 8, + EUTRAN_BAND_9 = 9, + EUTRAN_BAND_10 = 10, + EUTRAN_BAND_11 = 11, + EUTRAN_BAND_12 = 12, + EUTRAN_BAND_13 = 13, + EUTRAN_BAND_14 = 14, + EUTRAN_BAND_17 = 17, + EUTRAN_BAND_18 = 18, + EUTRAN_BAND_19 = 19, + EUTRAN_BAND_20 = 20, + EUTRAN_BAND_21 = 21, + EUTRAN_BAND_22 = 22, + EUTRAN_BAND_23 = 23, + EUTRAN_BAND_24 = 24, + EUTRAN_BAND_25 = 25, + EUTRAN_BAND_26 = 26, + EUTRAN_BAND_27 = 27, + EUTRAN_BAND_28 = 28, + EUTRAN_BAND_30 = 30, + EUTRAN_BAND_31 = 31, + EUTRAN_BAND_33 = 33, + EUTRAN_BAND_34 = 34, + EUTRAN_BAND_35 = 35, + EUTRAN_BAND_36 = 36, + EUTRAN_BAND_37 = 37, + EUTRAN_BAND_38 = 38, + EUTRAN_BAND_39 = 39, + EUTRAN_BAND_40 = 40, + EUTRAN_BAND_41 = 41, + EUTRAN_BAND_42 = 42, + EUTRAN_BAND_43 = 43, + EUTRAN_BAND_44 = 44, + EUTRAN_BAND_45 = 45, + EUTRAN_BAND_46 = 46, + EUTRAN_BAND_47 = 47, + EUTRAN_BAND_48 = 48, + EUTRAN_BAND_65 = 65, + EUTRAN_BAND_66 = 66, + EUTRAN_BAND_68 = 68, + EUTRAN_BAND_70 = 70, +} RIL_EutranBands; + +typedef struct { + RIL_RadioAccessNetworks radio_access_network; // The type of network to scan. + uint32_t bands_length; // Length of bands + union { + RIL_GeranBands geran_bands[MAX_BANDS]; + RIL_UtranBands utran_bands[MAX_BANDS]; + RIL_EutranBands eutran_bands[MAX_BANDS]; + } bands; + uint32_t channels_length; // Length of channels + uint32_t channels[MAX_CHANNELS]; // Frequency channels to scan +} RIL_RadioAccessSpecifier; + +typedef struct { + RIL_ScanType type; // Type of the scan + int32_t interval; // Time interval in seconds + // between periodic scans, only + // valid when type=RIL_PERIODIC + uint32_t specifiers_length; // Length of specifiers + RIL_RadioAccessSpecifier specifiers[MAX_RADIO_ACCESS_NETWORKS]; // Radio access networks + // with bands/channels. +} RIL_NetworkScanRequest; + +typedef enum { + PARTIAL = 0x01, // The result contains a part of the scan results + COMPLETE = 0x02, // The result contains the last part of the scan results +} RIL_ScanStatus; + +typedef struct { + RIL_ScanStatus status; // The status of the scan + uint32_t network_infos_length; // Total length of RIL_CellInfo + RIL_CellInfo_v12* network_infos; // List of network information +} RIL_NetworkScanResult; + +/** + * RIL_REQUEST_GET_SIM_STATUS + * + * Requests status of the SIM interface and the SIM card + * + * "data" is NULL + * + * "response" is const RIL_CardStatus_v6 * + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GET_SIM_STATUS 1 + +/** + * RIL_REQUEST_ENTER_SIM_PIN + * + * Supplies SIM PIN. Only called if RIL_CardStatus has RIL_APPSTATE_PIN state + * + * "data" is const char ** + * ((const char **)data)[0] is PIN value + * ((const char **)data)[1] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PIN 2 + +/** + * RIL_REQUEST_ENTER_SIM_PUK + * + * Supplies SIM PUK and new PIN. + * + * "data" is const char ** + * ((const char **)data)[0] is PUK value + * ((const char **)data)[1] is new PIN value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (PUK is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PUK 3 + +/** + * RIL_REQUEST_ENTER_SIM_PIN2 + * + * Supplies SIM PIN2. Only called following operation where SIM_PIN2 was + * returned as a a failure from a previous operation. + * + * "data" is const char ** + * ((const char **)data)[0] is PIN2 value + * ((const char **)data)[1] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PIN2 4 + +/** + * RIL_REQUEST_ENTER_SIM_PUK2 + * + * Supplies SIM PUK2 and new PIN2. + * + * "data" is const char ** + * ((const char **)data)[0] is PUK2 value + * ((const char **)data)[1] is new PIN2 value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (PUK2 is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PUK2 5 + +/** + * RIL_REQUEST_CHANGE_SIM_PIN + * + * Supplies old SIM PIN and new PIN. + * + * "data" is const char ** + * ((const char **)data)[0] is old PIN value + * ((const char **)data)[1] is new PIN value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (old PIN is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_CHANGE_SIM_PIN 6 + + +/** + * RIL_REQUEST_CHANGE_SIM_PIN2 + * + * Supplies old SIM PIN2 and new PIN2. + * + * "data" is const char ** + * ((const char **)data)[0] is old PIN2 value + * ((const char **)data)[1] is new PIN2 value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (old PIN2 is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + * + */ + +#define RIL_REQUEST_CHANGE_SIM_PIN2 7 + +/** + * RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION + * + * Requests that network personlization be deactivated + * + * "data" is const char ** + * ((const char **)(data))[0]] is network depersonlization code + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (code is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION 8 + +/** + * RIL_REQUEST_GET_CURRENT_CALLS + * + * Requests current call list + * + * "data" is NULL + * + * "response" must be a "const RIL_Call **" + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * (request will be made again in a few hundred msec) + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_GET_CURRENT_CALLS 9 + + +/** + * RIL_REQUEST_DIAL + * + * Initiate voice call + * + * "data" is const RIL_Dial * + * "response" is NULL + * + * This method is never used for supplementary service codes + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * DIAL_MODIFIED_TO_USSD + * DIAL_MODIFIED_TO_SS + * DIAL_MODIFIED_TO_DIAL + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_STATE + * NO_RESOURCES + * INTERNAL_ERR + * FDN_CHECK_FAILURE + * MODEM_ERR + * NO_SUBSCRIPTION + * NO_NETWORK_FOUND + * INVALID_CALL_ID + * DEVICE_IN_USE + * OPERATION_NOT_ALLOWED + * ABORTED + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_DIAL 10 + +/** + * RIL_REQUEST_GET_IMSI + * + * Get the SIM IMSI + * + * Only valid when radio state is "RADIO_STATE_ON" + * + * "data" is const char ** + * ((const char **)data)[0] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * "response" is a const char * containing the IMSI + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_GET_IMSI 11 + +/** + * RIL_REQUEST_HANGUP + * + * Hang up a specific line (like AT+CHLD=1x) + * + * After this HANGUP request returns, RIL should show the connection is NOT + * active anymore in next RIL_REQUEST_GET_CURRENT_CALLS query. + * + * "data" is an int * + * (int *)data)[0] contains Connection index (value of 'x' in CHLD above) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_STATE + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_CALL_ID + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_HANGUP 12 + +/** + * RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND + * + * Hang up waiting or held (like AT+CHLD=0) + * + * After this HANGUP request returns, RIL should show the connection is NOT + * active anymore in next RIL_REQUEST_GET_CURRENT_CALLS query. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_CALL_ID + * NO_RESOURCES + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND 13 + +/** + * RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND + * + * Hang up waiting or held (like AT+CHLD=1) + * + * After this HANGUP request returns, RIL should show the connection is NOT + * active anymore in next RIL_REQUEST_GET_CURRENT_CALLS query. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND 14 + +/** + * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE + * + * Switch waiting or holding call and active call (like AT+CHLD=2) + * + * State transitions should be is follows: + * + * If call 1 is waiting and call 2 is active, then if this re + * + * BEFORE AFTER + * Call 1 Call 2 Call 1 Call 2 + * ACTIVE HOLDING HOLDING ACTIVE + * ACTIVE WAITING HOLDING ACTIVE + * HOLDING WAITING HOLDING ACTIVE + * ACTIVE IDLE HOLDING IDLE + * IDLE IDLE IDLE IDLE + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * INVALID_ARGUMENTS + * INVALID_CALL_ID + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE 15 +#define RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE 15 + +/** + * RIL_REQUEST_CONFERENCE + * + * Conference holding and active (like AT+CHLD=3) + + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * INVALID_CALL_ID + * INVALID_ARGUMENTS + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_CONFERENCE 16 + +/** + * RIL_REQUEST_UDUB + * + * Send UDUB (user determined used busy) to ringing or + * waiting call answer)(RIL_BasicRequest r); + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_RESOURCES + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_UDUB 17 + +/** + * RIL_REQUEST_LAST_CALL_FAIL_CAUSE + * + * Requests the failure cause code for the most recently terminated call + * + * "data" is NULL + * "response" is a const RIL_LastCallFailCauseInfo * + * RIL_LastCallFailCauseInfo contains LastCallFailCause and vendor cause. + * The vendor cause code must be used for debugging purpose only. + * The implementation must return one of the values of LastCallFailCause + * as mentioned below. + * + * GSM failure reasons codes for the cause codes defined in TS 24.008 Annex H + * where possible. + * CDMA failure reasons codes for the possible call failure scenarios + * described in the "CDMA IS-2000 Release A (C.S0005-A v6.0)" standard. + * Any of the following reason codes if the call is failed or dropped due to reason + * mentioned with in the braces. + * + * CALL_FAIL_RADIO_OFF (Radio is OFF) + * CALL_FAIL_OUT_OF_SERVICE (No cell coverage) + * CALL_FAIL_NO_VALID_SIM (No valid SIM) + * CALL_FAIL_RADIO_INTERNAL_ERROR (Modem hit unexpected error scenario) + * CALL_FAIL_NETWORK_RESP_TIMEOUT (No response from network) + * CALL_FAIL_NETWORK_REJECT (Explicit network reject) + * CALL_FAIL_RADIO_ACCESS_FAILURE (RRC connection failure. Eg.RACH) + * CALL_FAIL_RADIO_LINK_FAILURE (Radio Link Failure) + * CALL_FAIL_RADIO_LINK_LOST (Radio link lost due to poor coverage) + * CALL_FAIL_RADIO_UPLINK_FAILURE (Radio uplink failure) + * CALL_FAIL_RADIO_SETUP_FAILURE (RRC connection setup failure) + * CALL_FAIL_RADIO_RELEASE_NORMAL (RRC connection release, normal) + * CALL_FAIL_RADIO_RELEASE_ABNORMAL (RRC connection release, abnormal) + * CALL_FAIL_ACCESS_CLASS_BLOCKED (Access class barring) + * CALL_FAIL_NETWORK_DETACH (Explicit network detach) + * + * OEM causes (CALL_FAIL_OEM_CAUSE_XX) must be used for debug purpose only + * + * If the implementation does not have access to the exact cause codes, + * then it should return one of the values listed in RIL_LastCallFailCause, + * as the UI layer needs to distinguish these cases for tone generation or + * error notification. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE + */ +#define RIL_REQUEST_LAST_CALL_FAIL_CAUSE 18 + +/** + * RIL_REQUEST_SIGNAL_STRENGTH + * + * Requests current signal strength and associated information + * + * Must succeed if radio is on. + * + * "data" is NULL + * + * "response" is a const RIL_SignalStrength * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SIGNAL_STRENGTH 19 + +/** + * RIL_REQUEST_VOICE_REGISTRATION_STATE + * + * Request current registration state + * + * "data" is NULL + * "response" is a const RIL_VoiceRegistrationStateResponse * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_VOICE_REGISTRATION_STATE 20 + +/** + * RIL_REQUEST_DATA_REGISTRATION_STATE + * + * Request current DATA registration state + * + * "data" is NULL + * "response" is a const RIL_DataRegistrationStateResponse * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_DATA_REGISTRATION_STATE 21 + +/** + * RIL_REQUEST_OPERATOR + * + * Request current operator ONS or EONS + * + * "data" is NULL + * "response" is a "const char **" + * ((const char **)response)[0] is long alpha ONS or EONS + * or NULL if unregistered + * + * ((const char **)response)[1] is short alpha ONS or EONS + * or NULL if unregistered + * ((const char **)response)[2] is 5 or 6 digit numeric code (MCC + MNC) + * or NULL if unregistered + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_OPERATOR 22 + +/** + * RIL_REQUEST_RADIO_POWER + * + * Toggle radio on and off (for "airplane" mode) + * If the radio is is turned off/on the radio modem subsystem + * is expected return to an initialized state. For instance, + * any voice and data calls will be terminated and all associated + * lists emptied. + * + * "data" is int * + * ((int *)data)[0] is > 0 for "Radio On" + * ((int *)data)[0] is == 0 for "Radio Off" + * + * "response" is NULL + * + * Turn radio on if "on" > 0 + * Turn radio off if "on" == 0 + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * INVALID_STATE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * DEVICE_IN_USE + * OPERATION_NOT_ALLOWED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_RADIO_POWER 23 + +/** + * RIL_REQUEST_DTMF + * + * Send a DTMF tone + * + * If the implementation is currently playing a tone requested via + * RIL_REQUEST_DTMF_START, that tone should be cancelled and the new tone + * should be played instead + * + * "data" is a char * containing a single character with one of 12 values: 0-9,*,# + * "response" is NULL + * + * FIXME should this block/mute microphone? + * How does this interact with local DTMF feedback? + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_RESOURCES + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_DTMF_STOP, RIL_REQUEST_DTMF_START + * + */ +#define RIL_REQUEST_DTMF 24 + +/** + * RIL_REQUEST_SEND_SMS + * + * Send an SMS message + * + * "data" is const char ** + * ((const char **)data)[0] is SMSC address in GSM BCD format prefixed + * by a length byte (as expected by TS 27.005) or NULL for default SMSC + * ((const char **)data)[1] is SMS in PDU format as an ASCII hex string + * less the SMSC address + * TP-Layer-Length is be "strlen(((const char **)data)[1])/2" + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. SMS_SEND_FAIL_RETRY means retry (i.e. error cause is 332) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * FDN_CHECK_FAILURE + * NETWORK_REJECT + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * MODEM_ERR + * NETWORK_ERR + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * FIXME how do we specify TP-Message-Reference if we need to resend? + */ +#define RIL_REQUEST_SEND_SMS 25 + + +/** + * RIL_REQUEST_SEND_SMS_EXPECT_MORE + * + * Send an SMS message. Identical to RIL_REQUEST_SEND_SMS, + * except that more messages are expected to be sent soon. If possible, + * keep SMS relay protocol link open (eg TS 27.005 AT+CMMS command) + * + * "data" is const char ** + * ((const char **)data)[0] is SMSC address in GSM BCD format prefixed + * by a length byte (as expected by TS 27.005) or NULL for default SMSC + * ((const char **)data)[1] is SMS in PDU format as an ASCII hex string + * less the SMSC address + * TP-Layer-Length is be "strlen(((const char **)data)[1])/2" + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. SMS_SEND_FAIL_RETRY means retry (i.e. error cause is 332) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * NETWORK_REJECT + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * FDN_CHECK_FAILURE + * MODEM_ERR + * NETWORK_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_SEND_SMS_EXPECT_MORE 26 + + +/** + * RIL_REQUEST_SETUP_DATA_CALL + * + * Setup a packet data connection. If RIL_Data_Call_Response_v6.status + * return success it is added to the list of data calls and a + * RIL_UNSOL_DATA_CALL_LIST_CHANGED is sent. The call remains in the + * list until RIL_REQUEST_DEACTIVATE_DATA_CALL is issued or the + * radio is powered off/on. This list is returned by RIL_REQUEST_DATA_CALL_LIST + * and RIL_UNSOL_DATA_CALL_LIST_CHANGED. + * + * The RIL is expected to: + * - Create one data call context. + * - Create and configure a dedicated interface for the context + * - The interface must be point to point. + * - The interface is configured with one or more addresses and + * is capable of sending and receiving packets. The prefix length + * of the addresses must be /32 for IPv4 and /128 for IPv6. + * - Must NOT change the linux routing table. + * - Support up to RIL_REQUEST_DATA_REGISTRATION_STATE response[5] + * number of simultaneous data call contexts. + * + * "data" is a const char ** + * ((const char **)data)[0] Radio technology to use: 0-CDMA, 1-GSM/UMTS, 2... + * for values above 2 this is RIL_RadioTechnology + 2. + * ((const char **)data)[1] is a RIL_DataProfile (support is optional) + * ((const char **)data)[2] is the APN to connect to if radio technology is GSM/UMTS. This APN will + * override the one in the profile. NULL indicates no APN overrride. + * ((const char **)data)[3] is the username for APN, or NULL + * ((const char **)data)[4] is the password for APN, or NULL + * ((const char **)data)[5] is the PAP / CHAP auth type. Values: + * 0 => PAP and CHAP is never performed. + * 1 => PAP may be performed; CHAP is never performed. + * 2 => CHAP may be performed; PAP is never performed. + * 3 => PAP / CHAP may be performed - baseband dependent. + * ((const char **)data)[6] is the non-roaming/home connection type to request. Must be one of the + * PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + * ((const char **)data)[7] is the roaming connection type to request. Must be one of the + * PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + * ((const char **)data)[8] is the bitmask of APN type in decimal string format. The + * bitmask will encapsulate the following values: + * ia,mms,agps,supl,hipri,fota,dun,ims,default. + * ((const char **)data)[9] is the bearer bitmask in decimal string format. Each bit is a + * RIL_RadioAccessFamily. "0" or NULL indicates all RATs. + * ((const char **)data)[10] is the boolean in string format indicating the APN setting was + * sent to the modem through RIL_REQUEST_SET_DATA_PROFILE earlier. + * ((const char **)data)[11] is the mtu size in bytes of the mobile interface to which + * the apn is connected. + * ((const char **)data)[12] is the MVNO type: + * possible values are "imsi", "gid", "spn". + * ((const char **)data)[13] is MVNO match data in string. Can be anything defined by the carrier. + * For example, + * SPN like: "A MOBILE", "BEN NL", etc... + * IMSI like: "302720x94", "2060188", etc... + * GID like: "4E", "33", etc... + * ((const char **)data)[14] is the boolean string indicating data roaming is allowed or not. "1" + * indicates data roaming is enabled by the user, "0" indicates disabled. + * + * "response" is a RIL_Data_Call_Response_v11 + * + * FIXME may need way to configure QoS settings + * + * Valid errors: + * SUCCESS should be returned on both success and failure of setup with + * the RIL_Data_Call_Response_v6.status containing the actual status. + * For all other errors the RIL_Data_Call_Resonse_v6 is ignored. + * + * Other errors could include: + * RADIO_NOT_AVAILABLE, OP_NOT_ALLOWED_BEFORE_REG_TO_NW, + * OP_NOT_ALLOWED_DURING_VOICE_CALL, REQUEST_NOT_SUPPORTED, + * INVALID_ARGUMENTS, INTERNAL_ERR, NO_MEMORY, NO_RESOURCES + * and CANCELLED + * + * See also: RIL_REQUEST_DEACTIVATE_DATA_CALL + */ +#define RIL_REQUEST_SETUP_DATA_CALL 27 + + +/** + * RIL_REQUEST_SIM_IO + * + * Request SIM I/O operation. + * This is similar to the TS 27.007 "restricted SIM" operation + * where it assumes all of the EF selection will be done by the + * callee. + * + * "data" is a const RIL_SIM_IO_v6 * + * Please note that RIL_SIM_IO has a "PIN2" field which may be NULL, + * or may specify a PIN2 for operations that require a PIN2 (eg + * updating FDN records) + * + * "response" is a const RIL_SIM_IO_Response * + * + * Arguments and responses that are unused for certain + * values of "command" should be ignored or set to NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_PIN2 + * SIM_PUK2 + * INVALID_SIM_STATE + * SIM_ERR + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_IO 28 + +/** + * RIL_REQUEST_SEND_USSD + * + * Send a USSD message + * + * If a USSD session already exists, the message should be sent in the + * context of that session. Otherwise, a new session should be created. + * + * The network reply should be reported via RIL_UNSOL_ON_USSD + * + * Only one USSD session may exist at a time, and the session is assumed + * to exist until: + * a) The android system invokes RIL_REQUEST_CANCEL_USSD + * b) The implementation sends a RIL_UNSOL_ON_USSD with a type code + * of "0" (USSD-Notify/no further action) or "2" (session terminated) + * + * "data" is a const char * containing the USSD request in UTF-8 format + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * FDN_CHECK_FAILURE + * USSD_MODIFIED_TO_DIAL + * USSD_MODIFIED_TO_SS + * USSD_MODIFIED_TO_USSD + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * ABORTED + * SYSTEM_ERR + * INVALID_STATE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_CANCEL_USSD, RIL_UNSOL_ON_USSD + */ + +#define RIL_REQUEST_SEND_USSD 29 + +/** + * RIL_REQUEST_CANCEL_USSD + * + * Cancel the current USSD session if one exists + * + * "data" is null + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_STATE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_CANCEL_USSD 30 + +/** + * RIL_REQUEST_GET_CLIR + * + * Gets current CLIR status + * "data" is NULL + * "response" is int * + * ((int *)data)[0] is "n" parameter from TS 27.007 7.7 + * ((int *)data)[1] is "m" parameter from TS 27.007 7.7 + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * FDN_CHECK_FAILURE + * SYSTEM_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GET_CLIR 31 + +/** + * RIL_REQUEST_SET_CLIR + * + * "data" is int * + * ((int *)data)[0] is "n" parameter from TS 27.007 7.7 + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * SYSTEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_CLIR 32 + +/** + * RIL_REQUEST_QUERY_CALL_FORWARD_STATUS + * + * "data" is const RIL_CallForwardInfo * + * + * "response" is const RIL_CallForwardInfo ** + * "response" points to an array of RIL_CallForwardInfo *'s, one for + * each distinct registered phone number. + * + * For example, if data is forwarded to +18005551212 and voice is forwarded + * to +18005559999, then two separate RIL_CallForwardInfo's should be returned + * + * If, however, both data and voice are forwarded to +18005551212, then + * a single RIL_CallForwardInfo can be returned with the service class + * set to "data + voice = 3") + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_QUERY_CALL_FORWARD_STATUS 33 + + +/** + * RIL_REQUEST_SET_CALL_FORWARD + * + * Configure call forward rule + * + * "data" is const RIL_CallForwardInfo * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_CALL_FORWARD 34 + + +/** + * RIL_REQUEST_QUERY_CALL_WAITING + * + * Query current call waiting state + * + * "data" is const int * + * ((const int *)data)[0] is the TS 27.007 service class to query. + * "response" is a const int * + * ((const int *)response)[0] is 0 for "disabled" and 1 for "enabled" + * + * If ((const int *)response)[0] is = 1, then ((const int *)response)[1] + * must follow, with the TS 27.007 service class bit vector of services + * for which call waiting is enabled. + * + * For example, if ((const int *)response)[0] is 1 and + * ((const int *)response)[1] is 3, then call waiting is enabled for data + * and voice and disabled for everything else + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * FDN_CHECK_FAILURE + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_QUERY_CALL_WAITING 35 + + +/** + * RIL_REQUEST_SET_CALL_WAITING + * + * Configure current call waiting state + * + * "data" is const int * + * ((const int *)data)[0] is 0 for "disabled" and 1 for "enabled" + * ((const int *)data)[1] is the TS 27.007 service class bit vector of + * services to modify + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_CALL_WAITING 36 + +/** + * RIL_REQUEST_SMS_ACKNOWLEDGE + * + * Acknowledge successful or failed receipt of SMS previously indicated + * via RIL_UNSOL_RESPONSE_NEW_SMS + * + * "data" is int * + * ((int *)data)[0] is 1 on successful receipt + * (basically, AT+CNMA=1 from TS 27.005 + * is 0 on failed receipt + * (basically, AT+CNMA=2 from TS 27.005) + * ((int *)data)[1] if data[0] is 0, this contains the failure cause as defined + * in TS 23.040, 9.2.3.22. Currently only 0xD3 (memory + * capacity exceeded) and 0xFF (unspecified error) are + * reported. + * + * "response" is NULL + * + * FIXME would like request that specified RP-ACK/RP-ERROR PDU + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SMS_ACKNOWLEDGE 37 + +/** + * RIL_REQUEST_GET_IMEI - DEPRECATED + * + * Get the device IMEI, including check digit + * + * The request is DEPRECATED, use RIL_REQUEST_DEVICE_IDENTITY + * Valid when RadioState is not RADIO_STATE_UNAVAILABLE + * + * "data" is NULL + * "response" is a const char * containing the IMEI + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ + +#define RIL_REQUEST_GET_IMEI 38 + +/** + * RIL_REQUEST_GET_IMEISV - DEPRECATED + * + * Get the device IMEISV, which should be two decimal digits + * + * The request is DEPRECATED, use RIL_REQUEST_DEVICE_IDENTITY + * Valid when RadioState is not RADIO_STATE_UNAVAILABLE + * + * "data" is NULL + * "response" is a const char * containing the IMEISV + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ + +#define RIL_REQUEST_GET_IMEISV 39 + + +/** + * RIL_REQUEST_ANSWER + * + * Answer incoming call + * + * Will not be called for WAITING calls. + * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE will be used in this case + * instead + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ANSWER 40 + +/** + * RIL_REQUEST_DEACTIVATE_DATA_CALL + * + * Deactivate packet data connection and remove from the + * data call list if SUCCESS is returned. Any other return + * values should also try to remove the call from the list, + * but that may not be possible. In any event a + * RIL_REQUEST_RADIO_POWER off/on must clear the list. An + * RIL_UNSOL_DATA_CALL_LIST_CHANGED is not expected to be + * issued because of an RIL_REQUEST_DEACTIVATE_DATA_CALL. + * + * "data" is const char ** + * ((char**)data)[0] indicating CID + * ((char**)data)[1] indicating Disconnect Reason + * 0 => No specific reason specified + * 1 => Radio shutdown requested + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_CALL_ID + * INVALID_STATE + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SETUP_DATA_CALL + */ +#define RIL_REQUEST_DEACTIVATE_DATA_CALL 41 + +/** + * RIL_REQUEST_QUERY_FACILITY_LOCK + * + * Query the status of a facility lock state + * + * "data" is const char ** + * ((const char **)data)[0] is the facility string code from TS 27.007 7.4 + * (eg "AO" for BAOC, "SC" for SIM lock) + * ((const char **)data)[1] is the password, or "" if not required + * ((const char **)data)[2] is the TS 27.007 service class bit vector of + * services to query + * ((const char **)data)[3] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * This is only applicable in the case of Fixed Dialing Numbers + * (FDN) requests. + * + * "response" is an int * + * ((const int *)response) 0 is the TS 27.007 service class bit vector of + * services for which the specified barring facility + * is active. "0" means "disabled for all" + * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_QUERY_FACILITY_LOCK 42 + +/** + * RIL_REQUEST_SET_FACILITY_LOCK + * + * Enable/disable one facility lock + * + * "data" is const char ** + * + * ((const char **)data)[0] = facility string code from TS 27.007 7.4 + * (eg "AO" for BAOC) + * ((const char **)data)[1] = "0" for "unlock" and "1" for "lock" + * ((const char **)data)[2] = password + * ((const char **)data)[3] = string representation of decimal TS 27.007 + * service class bit vector. Eg, the string + * "1" means "set this facility for voice services" + * ((const char **)data)[4] = AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * This is only applicable in the case of Fixed Dialing Numbers + * (FDN) requests. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * INTERNAL_ERR + * NO_MEMORY + * MODEM_ERR + * INVALID_STATE + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_SET_FACILITY_LOCK 43 + +/** + * RIL_REQUEST_CHANGE_BARRING_PASSWORD + * + * Change call barring facility password + * + * "data" is const char ** + * + * ((const char **)data)[0] = facility string code from TS 27.007 7.4 + * (eg "AO" for BAOC) + * ((const char **)data)[1] = old password + * ((const char **)data)[2] = new password + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * SYSTEM_ERR + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CHANGE_BARRING_PASSWORD 44 + +/** + * RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE + * + * Query current network selectin mode + * + * "data" is NULL + * + * "response" is int * + * ((const int *)response)[0] is + * 0 for automatic selection + * 1 for manual selection + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE 45 + +/** + * RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC + * + * Specify that the network should be selected automatically + * + * "data" is NULL + * "response" is NULL + * + * This request must not respond until the new operator is selected + * and registered + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * ILLEGAL_SIM_OR_ME + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * Note: Returns ILLEGAL_SIM_OR_ME when the failure is permanent and + * no retries needed, such as illegal SIM or ME. + * + */ +#define RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC 46 + +/** + * RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL + * + * Manually select a specified network. + * + * "data" is const char * specifying MCCMNC of network to select (eg "310170") + * "response" is NULL + * + * This request must not respond until the new operator is selected + * and registered + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * ILLEGAL_SIM_OR_ME + * OPERATION_NOT_ALLOWED + * INVALID_STATE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * Note: Returns ILLEGAL_SIM_OR_ME when the failure is permanent and + * no retries needed, such as illegal SIM or ME. + * + */ +#define RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL 47 + +/** + * RIL_REQUEST_QUERY_AVAILABLE_NETWORKS + * + * Scans for available networks + * + * "data" is NULL + * "response" is const char ** that should be an array of n*4 strings, where + * n is the number of available networks + * For each available network: + * + * ((const char **)response)[n+0] is long alpha ONS or EONS + * ((const char **)response)[n+1] is short alpha ONS or EONS + * ((const char **)response)[n+2] is 5 or 6 digit numeric code (MCC + MNC) + * ((const char **)response)[n+3] is a string value of the status: + * "unknown" + * "available" + * "current" + * "forbidden" + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * ABORTED + * DEVICE_IN_USE + * INTERNAL_ERR + * NO_MEMORY + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * CANCELLED + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 48 + +/** + * RIL_REQUEST_DTMF_START + * + * Start playing a DTMF tone. Continue playing DTMF tone until + * RIL_REQUEST_DTMF_STOP is received + * + * If a RIL_REQUEST_DTMF_START is received while a tone is currently playing, + * it should cancel the previous tone and play the new one. + * + * "data" is a char * + * ((char *)data)[0] is a single character with one of 12 values: 0-9,*,# + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_RESOURCES + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_DTMF, RIL_REQUEST_DTMF_STOP + */ +#define RIL_REQUEST_DTMF_START 49 + +/** + * RIL_REQUEST_DTMF_STOP + * + * Stop playing a currently playing DTMF tone. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * NO_MEMORY + * INVALID_ARGUMENTS + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_DTMF, RIL_REQUEST_DTMF_START + */ +#define RIL_REQUEST_DTMF_STOP 50 + +/** + * RIL_REQUEST_BASEBAND_VERSION + * + * Return string value indicating baseband version, eg + * response from AT+CGMR + * + * "data" is NULL + * "response" is const char * containing version string for log reporting + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * EMPTY_RECORD + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_BASEBAND_VERSION 51 + +/** + * RIL_REQUEST_SEPARATE_CONNECTION + * + * Separate a party from a multiparty call placing the multiparty call + * (less the specified party) on hold and leaving the specified party + * as the only other member of the current (active) call + * + * Like AT+CHLD=2x + * + * See TS 22.084 1.3.8.2 (iii) + * TS 22.030 6.5.5 "Entering "2X followed by send" + * TS 27.007 "AT+CHLD=2x" + * + * "data" is an int * + * (int *)data)[0] contains Connection index (value of 'x' in CHLD above) "response" is NULL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_ARGUMENTS + * INVALID_STATE + * NO_RESOURCES + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * INVALID_STATE + * OPERATION_NOT_ALLOWED + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SEPARATE_CONNECTION 52 + + +/** + * RIL_REQUEST_SET_MUTE + * + * Turn on or off uplink (microphone) mute. + * + * Will only be sent while voice call is active. + * Will always be reset to "disable mute" when a new voice call is initiated + * + * "data" is an int * + * (int *)data)[0] is 1 for "enable mute" and 0 for "disable mute" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_SET_MUTE 53 + +/** + * RIL_REQUEST_GET_MUTE + * + * Queries the current state of the uplink mute setting + * + * "data" is NULL + * "response" is an int * + * (int *)response)[0] is 1 for "mute enabled" and 0 for "mute disabled" + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_GET_MUTE 54 + +/** + * RIL_REQUEST_QUERY_CLIP + * + * Queries the status of the CLIP supplementary service + * + * (for MMI code "*#30#") + * + * "data" is NULL + * "response" is an int * + * (int *)response)[0] is 1 for "CLIP provisioned" + * and 0 for "CLIP not provisioned" + * and 2 for "unknown, e.g. no network etc" + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_QUERY_CLIP 55 + +/** + * RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE - Deprecated use the status + * field in RIL_Data_Call_Response_v6. + * + * Requests the failure cause code for the most recently failed PDP + * context or CDMA data connection active + * replaces RIL_REQUEST_LAST_PDP_FAIL_CAUSE + * + * "data" is NULL + * + * "response" is a "int *" + * ((int *)response)[0] is an integer cause code defined in TS 24.008 + * section 6.1.3.1.3 or close approximation + * + * If the implementation does not have access to the exact cause codes, + * then it should return one of the values listed in + * RIL_DataCallFailCause, as the UI layer needs to distinguish these + * cases for error notification + * and potential retries. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_LAST_CALL_FAIL_CAUSE + * + * Deprecated use the status field in RIL_Data_Call_Response_v6. + */ + +#define RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE 56 + +/** + * RIL_REQUEST_DATA_CALL_LIST + * + * Returns the data call list. An entry is added when a + * RIL_REQUEST_SETUP_DATA_CALL is issued and removed on a + * RIL_REQUEST_DEACTIVATE_DATA_CALL. The list is emptied + * when RIL_REQUEST_RADIO_POWER off/on is issued. + * + * "data" is NULL + * "response" is an array of RIL_Data_Call_Response_v6 + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_UNSOL_DATA_CALL_LIST_CHANGED + */ + +#define RIL_REQUEST_DATA_CALL_LIST 57 + +/** + * RIL_REQUEST_RESET_RADIO - DEPRECATED + * + * Request a radio reset. The RIL implementation may postpone + * the reset until after this request is responded to if the baseband + * is presently busy. + * + * The request is DEPRECATED, use RIL_REQUEST_RADIO_POWER + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_RESET_RADIO 58 + +/** + * RIL_REQUEST_OEM_HOOK_RAW + * + * This request reserved for OEM-specific uses. It passes raw byte arrays + * back and forth. + * + * It can be invoked on the Java side from + * com.android.internal.telephony.Phone.invokeOemRilRequestRaw() + * + * "data" is a char * of bytes copied from the byte[] data argument in java + * "response" is a char * of bytes that will returned via the + * caller's "response" Message here: + * (byte[])(((AsyncResult)response.obj).result) + * + * An error response here will result in + * (((AsyncResult)response.obj).result) == null and + * (((AsyncResult)response.obj).exception) being an instance of + * com.android.internal.telephony.gsm.CommandException + * + * Valid errors: + * All + */ + +#define RIL_REQUEST_OEM_HOOK_RAW 59 + +/** + * RIL_REQUEST_OEM_HOOK_STRINGS + * + * This request reserved for OEM-specific uses. It passes strings + * back and forth. + * + * It can be invoked on the Java side from + * com.android.internal.telephony.Phone.invokeOemRilRequestStrings() + * + * "data" is a const char **, representing an array of null-terminated UTF-8 + * strings copied from the "String[] strings" argument to + * invokeOemRilRequestStrings() + * + * "response" is a const char **, representing an array of null-terminated UTF-8 + * stings that will be returned via the caller's response message here: + * + * (String[])(((AsyncResult)response.obj).result) + * + * An error response here will result in + * (((AsyncResult)response.obj).result) == null and + * (((AsyncResult)response.obj).exception) being an instance of + * com.android.internal.telephony.gsm.CommandException + * + * Valid errors: + * All + */ + +#define RIL_REQUEST_OEM_HOOK_STRINGS 60 + +/** + * RIL_REQUEST_SCREEN_STATE - DEPRECATED + * + * Indicates the current state of the screen. When the screen is off, the + * RIL should notify the baseband to suppress certain notifications (eg, + * signal strength and changes in LAC/CID or BID/SID/NID/latitude/longitude) + * in an effort to conserve power. These notifications should resume when the + * screen is on. + * + * Note this request is deprecated. Use RIL_REQUEST_SEND_DEVICE_STATE to report the device state + * to the modem and use RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER to turn on/off unsolicited + * response from the modem in different scenarios. + * + * "data" is int * + * ((int *)data)[0] is == 1 for "Screen On" + * ((int *)data)[0] is == 0 for "Screen Off" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SCREEN_STATE 61 + + +/** + * RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION + * + * Enables/disables supplementary service related notifications + * from the network. + * + * Notifications are reported via RIL_UNSOL_SUPP_SVC_NOTIFICATION. + * + * "data" is int * + * ((int *)data)[0] is == 1 for notifications enabled + * ((int *)data)[0] is == 0 for notifications disabled + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_BUSY + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_UNSOL_SUPP_SVC_NOTIFICATION. + */ +#define RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION 62 + +/** + * RIL_REQUEST_WRITE_SMS_TO_SIM + * + * Stores a SMS message to SIM memory. + * + * "data" is RIL_SMS_WriteArgs * + * + * "response" is int * + * ((const int *)response)[0] is the record index where the message is stored. + * + * Valid errors: + * SUCCESS + * SIM_FULL + * INVALID_ARGUMENTS + * INVALID_SMS_FORMAT + * INTERNAL_ERR + * MODEM_ERR + * ENCODING_ERR + * NO_MEMORY + * NO_RESOURCES + * INVALID_MODEM_STATE + * OPERATION_NOT_ALLOWED + * INVALID_SMSC_ADDRESS + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_WRITE_SMS_TO_SIM 63 + +/** + * RIL_REQUEST_DELETE_SMS_ON_SIM + * + * Deletes a SMS message from SIM memory. + * + * "data" is int * + * ((int *)data)[0] is the record index of the message to delete. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * SIM_FULL + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * MODEM_ERR + * NO_SUCH_ENTRY + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_DELETE_SMS_ON_SIM 64 + +/** + * RIL_REQUEST_SET_BAND_MODE + * + * Assign a specified band for RF configuration. + * + * "data" is int * + * ((int *)data)[0] is a RIL_RadioBandMode + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE + */ +#define RIL_REQUEST_SET_BAND_MODE 65 + +/** + * RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE + * + * Query the list of band mode supported by RF. + * + * "data" is NULL + * + * "response" is int * + * "response" points to an array of int's, the int[0] is the size of array; + * subsequent values are a list of RIL_RadioBandMode listing supported modes. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SET_BAND_MODE + */ +#define RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE 66 + +/** + * RIL_REQUEST_STK_GET_PROFILE + * + * Requests the profile of SIM tool kit. + * The profile indicates the SAT/USAT features supported by ME. + * The SAT/USAT features refer to 3GPP TS 11.14 and 3GPP TS 31.111 + * + * "data" is NULL + * + * "response" is a const char * containing SAT/USAT profile + * in hexadecimal format string starting with first byte of terminal profile + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_GET_PROFILE 67 + +/** + * RIL_REQUEST_STK_SET_PROFILE + * + * Download the STK terminal profile as part of SIM initialization + * procedure + * + * "data" is a const char * containing SAT/USAT profile + * in hexadecimal format string starting with first byte of terminal profile + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SET_PROFILE 68 + +/** + * RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND + * + * Requests to send a SAT/USAT envelope command to SIM. + * The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111 + * + * "data" is a const char * containing SAT/USAT command + * in hexadecimal format string starting with command tag + * + * "response" is a const char * containing SAT/USAT response + * in hexadecimal format string starting with first byte of response + * (May be NULL) + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND 69 + +/** + * RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE + * + * Requests to send a terminal response to SIM for a received + * proactive command + * + * "data" is a const char * containing SAT/USAT response + * in hexadecimal format string starting with first byte of response data + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * RIL_E_OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE 70 + +/** + * RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM + * + * When STK application gets RIL_UNSOL_STK_CALL_SETUP, the call actually has + * been initialized by ME already. (We could see the call has been in the 'call + * list') So, STK application needs to accept/reject the call according as user + * operations. + * + * "data" is int * + * ((int *)data)[0] is > 0 for "accept" the call setup + * ((int *)data)[0] is == 0 for "reject" the call setup + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * RIL_E_OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM 71 + +/** + * RIL_REQUEST_EXPLICIT_CALL_TRANSFER + * + * Connects the two calls and disconnects the subscriber from both calls. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_RESOURCES + * NO_MEMORY + * INVALID_ARGUMENTS + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * INVALID_STATE + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_EXPLICIT_CALL_TRANSFER 72 + +/** + * RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE + * + * Requests to set the preferred network type for searching and registering + * (CS/PS domain, RAT, and operation mode) + * + * "data" is int * which is RIL_PreferredNetworkType + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * OPERATION_NOT_ALLOWED + * MODE_NOT_SUPPORTED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE 73 + +/** + * RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE + * + * Query the preferred network type (CS/PS domain, RAT, and operation mode) + * for searching and registering + * + * "data" is NULL + * + * "response" is int * + * ((int *)reponse)[0] is == RIL_PreferredNetworkType + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE + */ +#define RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE 74 + +/** + * RIL_REQUEST_NEIGHBORING_CELL_IDS + * + * Request neighboring cell id in GSM network + * + * "data" is NULL + * "response" must be a " const RIL_NeighboringCell** " + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NO_NETWORK_FOUND + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_GET_NEIGHBORING_CELL_IDS 75 + +/** + * RIL_REQUEST_SET_LOCATION_UPDATES + * + * Enables/disables network state change notifications due to changes in + * LAC and/or CID (for GSM) or BID/SID/NID/latitude/longitude (for CDMA). + * Basically +CREG=2 vs. +CREG=1 (TS 27.007). + * + * Note: The RIL implementation should default to "updates enabled" + * when the screen is on and "updates disabled" when the screen is off. + * + * "data" is int * + * ((int *)data)[0] is == 1 for updates enabled (+CREG=2) + * ((int *)data)[0] is == 0 for updates disabled (+CREG=1) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SCREEN_STATE, RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED + */ +#define RIL_REQUEST_SET_LOCATION_UPDATES 76 + +/** + * RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE + * + * Request to set the location where the CDMA subscription shall + * be retrieved + * + * "data" is int * + * ((int *)data)[0] is == RIL_CdmaSubscriptionSource + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_ABSENT + * SUBSCRIPTION_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE + */ +#define RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE 77 + +/** + * RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE + * + * Request to set the roaming preferences in CDMA + * + * "data" is int * + * ((int *)data)[0] is == 0 for Home Networks only, as defined in PRL + * ((int *)data)[0] is == 1 for Roaming on Affiliated networks, as defined in PRL + * ((int *)data)[0] is == 2 for Roaming on Any Network, as defined in the PRL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE 78 + +/** + * RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE + * + * Request the actual setting of the roaming preferences in CDMA in the modem + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is == 0 for Home Networks only, as defined in PRL + * ((int *)response)[0] is == 1 for Roaming on Affiliated networks, as defined in PRL + * ((int *)response)[0] is == 2 for Roaming on Any Network, as defined in the PRL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE 79 + +/** + * RIL_REQUEST_SET_TTY_MODE + * + * Request to set the TTY mode + * + * "data" is int * + * ((int *)data)[0] is == 0 for TTY off + * ((int *)data)[0] is == 1 for TTY Full + * ((int *)data)[0] is == 2 for TTY HCO (hearing carryover) + * ((int *)data)[0] is == 3 for TTY VCO (voice carryover) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_ARGUMENTS + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_TTY_MODE 80 + +/** + * RIL_REQUEST_QUERY_TTY_MODE + * + * Request the setting of TTY mode + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is == 0 for TTY off + * ((int *)response)[0] is == 1 for TTY Full + * ((int *)response)[0] is == 2 for TTY HCO (hearing carryover) + * ((int *)response)[0] is == 3 for TTY VCO (voice carryover) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_QUERY_TTY_MODE 81 + +/** + * RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE + * + * Request to set the preferred voice privacy mode used in voice + * scrambling + * + * "data" is int * + * ((int *)data)[0] is == 0 for Standard Privacy Mode (Public Long Code Mask) + * ((int *)data)[0] is == 1 for Enhanced Privacy Mode (Private Long Code Mask) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE 82 + +/** + * RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE + * + * Request the setting of preferred voice privacy mode + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is == 0 for Standard Privacy Mode (Public Long Code Mask) + * ((int *)response)[0] is == 1 for Enhanced Privacy Mode (Private Long Code Mask) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE 83 + +/** + * RIL_REQUEST_CDMA_FLASH + * + * Send FLASH + * + * "data" is const char * + * ((const char *)data)[0] is a FLASH string + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * INVALID_STATE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_FLASH 84 + +/** + * RIL_REQUEST_CDMA_BURST_DTMF + * + * Send DTMF string + * + * "data" is const char ** + * ((const char **)data)[0] is a DTMF string + * ((const char **)data)[1] is the DTMF ON length in milliseconds, or 0 to use + * default + * ((const char **)data)[2] is the DTMF OFF length in milliseconds, or 0 to use + * default + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * OPERATION_NOT_ALLOWED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_BURST_DTMF 85 + +/** + * RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY + * + * Takes a 26 digit string (20 digit AKEY + 6 digit checksum). + * If the checksum is valid the 20 digit AKEY is written to NV, + * replacing the existing AKEY no matter what it was before. + * + * "data" is const char * + * ((const char *)data)[0] is a 26 digit string (ASCII digits '0'-'9') + * where the last 6 digits are a checksum of the + * first 20, as specified in TR45.AHAG + * "Common Cryptographic Algorithms, Revision D.1 + * Section 2.2" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY 86 + +/** + * RIL_REQUEST_CDMA_SEND_SMS + * + * Send a CDMA SMS message + * + * "data" is const RIL_CDMA_SMS_Message * + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. The CDMA error class is derived as follows, + * SUCCESS is error class 0 (no error) + * SMS_SEND_FAIL_RETRY is error class 2 (temporary failure) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * NETWORK_REJECT + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * FDN_CHECK_FAILURE + * MODEM_ERR + * NETWORK_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SEND_SMS 87 + +/** + * RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE + * + * Acknowledge the success or failure in the receipt of SMS + * previously indicated via RIL_UNSOL_RESPONSE_CDMA_NEW_SMS + * + * "data" is const RIL_CDMA_SMS_Ack * + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_SMS_TO_ACK + * INVALID_STATE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * MODEM_ERR + * INVALID_STATE + * OPERATION_NOT_ALLOWED + * NETWORK_NOT_READY + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE 88 + +/** + * RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG + * + * Request the setting of GSM/WCDMA Cell Broadcast SMS config. + * + * "data" is NULL + * + * "response" is a const RIL_GSM_BroadcastSmsConfigInfo ** + * "responselen" is count * sizeof (RIL_GSM_BroadcastSmsConfigInfo *) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * NO_RESOURCES + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG 89 + +/** + * RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG + * + * Set GSM/WCDMA Cell Broadcast SMS config + * + * "data" is a const RIL_GSM_BroadcastSmsConfigInfo ** + * "datalen" is count * sizeof(RIL_GSM_BroadcastSmsConfigInfo *) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG 90 + +/** + * RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION + * +* Enable or disable the reception of GSM/WCDMA Cell Broadcast SMS + * + * "data" is const int * + * (const int *)data[0] indicates to activate or turn off the + * reception of GSM/WCDMA Cell Broadcast SMS, 0-1, + * 0 - Activate, 1 - Turn off + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED +* MODEM_ERR +* INTERNAL_ERR +* NO_RESOURCES +* CANCELLED +* INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION 91 + +/** + * RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG + * + * Request the setting of CDMA Broadcast SMS config + * + * "data" is NULL + * + * "response" is a const RIL_CDMA_BroadcastSmsConfigInfo ** + * "responselen" is count * sizeof (RIL_CDMA_BroadcastSmsConfigInfo *) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * NO_RESOURCES + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG 92 + +/** + * RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG + * + * Set CDMA Broadcast SMS config + * + * "data" is a const RIL_CDMA_BroadcastSmsConfigInfo ** + * "datalen" is count * sizeof(const RIL_CDMA_BroadcastSmsConfigInfo *) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG 93 + +/** + * RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION + * + * Enable or disable the reception of CDMA Broadcast SMS + * + * "data" is const int * + * (const int *)data[0] indicates to activate or turn off the + * reception of CDMA Broadcast SMS, 0-1, + * 0 - Activate, 1 - Turn off + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION 94 + +/** + * RIL_REQUEST_CDMA_SUBSCRIPTION + * + * Request the device MDN / H_SID / H_NID. + * + * The request is only allowed when CDMA subscription is available. When CDMA + * subscription is changed, application layer should re-issue the request to + * update the subscription information. + * + * If a NULL value is returned for any of the device id, it means that error + * accessing the device. + * + * "response" is const char ** + * ((const char **)response)[0] is MDN if CDMA subscription is available + * ((const char **)response)[1] is a comma separated list of H_SID (Home SID) if + * CDMA subscription is available, in decimal format + * ((const char **)response)[2] is a comma separated list of H_NID (Home NID) if + * CDMA subscription is available, in decimal format + * ((const char **)response)[3] is MIN (10 digits, MIN2+MIN1) if CDMA subscription is available + * ((const char **)response)[4] is PRL version if CDMA subscription is available + * + * Valid errors: + * SUCCESS + * RIL_E_SUBSCRIPTION_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * + */ + +#define RIL_REQUEST_CDMA_SUBSCRIPTION 95 + +/** + * RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM + * + * Stores a CDMA SMS message to RUIM memory. + * + * "data" is RIL_CDMA_SMS_WriteArgs * + * + * "response" is int * + * ((const int *)response)[0] is the record index where the message is stored. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_FULL + * INVALID_ARGUMENTS + * INVALID_SMS_FORMAT + * INTERNAL_ERR + * MODEM_ERR + * ENCODING_ERR + * NO_MEMORY + * NO_RESOURCES + * INVALID_MODEM_STATE + * OPERATION_NOT_ALLOWED + * INVALID_SMSC_ADDRESS + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM 96 + +/** + * RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM + * + * Deletes a CDMA SMS message from RUIM memory. + * + * "data" is int * + * ((int *)data)[0] is the record index of the message to delete. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * MODEM_ERR + * NO_SUCH_ENTRY + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM 97 + +/** + * RIL_REQUEST_DEVICE_IDENTITY + * + * Request the device ESN / MEID / IMEI / IMEISV. + * + * The request is always allowed and contains GSM and CDMA device identity; + * it substitutes the deprecated requests RIL_REQUEST_GET_IMEI and + * RIL_REQUEST_GET_IMEISV. + * + * If a NULL value is returned for any of the device id, it means that error + * accessing the device. + * + * When CDMA subscription is changed the ESN/MEID may change. The application + * layer should re-issue the request to update the device identity in this case. + * + * "response" is const char ** + * ((const char **)response)[0] is IMEI if GSM subscription is available + * ((const char **)response)[1] is IMEISV if GSM subscription is available + * ((const char **)response)[2] is ESN if CDMA subscription is available + * ((const char **)response)[3] is MEID if CDMA subscription is available + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_DEVICE_IDENTITY 98 + +/** + * RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE + * + * Request the radio's system selection module to exit emergency + * callback mode. RIL will not respond with SUCCESS until the modem has + * completely exited from Emergency Callback Mode. + * + * "data" is NULL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE 99 + +/** + * RIL_REQUEST_GET_SMSC_ADDRESS + * + * Queries the default Short Message Service Center address on the device. + * + * "data" is NULL + * + * "response" is const char * containing the SMSC address. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * INTERNAL_ERR + * MODEM_ERR + * INVALID_ARGUMENTS + * INVALID_MODEM_STATE + * NOT_PROVISIONED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_GET_SMSC_ADDRESS 100 + +/** + * RIL_REQUEST_SET_SMSC_ADDRESS + * + * Sets the default Short Message Service Center address on the device. + * + * "data" is const char * containing the SMSC address. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * INVALID_SMS_FORMAT + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * NO_RESOURCES + * INTERNAL_ERR + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_SET_SMSC_ADDRESS 101 + +/** + * RIL_REQUEST_REPORT_SMS_MEMORY_STATUS + * + * Indicates whether there is storage available for new SMS messages. + * + * "data" is int * + * ((int *)data)[0] is 1 if memory is available for storing new messages + * is 0 if memory capacity is exceeded + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_STATE + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_REPORT_SMS_MEMORY_STATUS 102 + +/** + * RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING + * + * Indicates that the StkSerivce is running and is + * ready to receive RIL_UNSOL_STK_XXXXX commands. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING 103 + +/** + * RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE + * + * Request to query the location where the CDMA subscription shall + * be retrieved + * + * "data" is NULL + * + * "response" is int * + * ((int *)data)[0] is == RIL_CdmaSubscriptionSource + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SUBSCRIPTION_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE + */ +#define RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE 104 + +/** + * RIL_REQUEST_ISIM_AUTHENTICATION + * + * Request the ISIM application on the UICC to perform AKA + * challenge/response algorithm for IMS authentication + * + * "data" is a const char * containing the challenge string in Base64 format + * "response" is a const char * containing the response in Base64 format + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_ISIM_AUTHENTICATION 105 + +/** + * RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU + * + * Acknowledge successful or failed receipt of SMS previously indicated + * via RIL_UNSOL_RESPONSE_NEW_SMS, including acknowledgement TPDU to send + * as the RP-User-Data element of the RP-ACK or RP-ERROR PDU. + * + * "data" is const char ** + * ((const char **)data)[0] is "1" on successful receipt (send RP-ACK) + * is "0" on failed receipt (send RP-ERROR) + * ((const char **)data)[1] is the acknowledgement TPDU in hexadecimal format + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU 106 + +/** + * RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS + * + * Requests to send a SAT/USAT envelope command to SIM. + * The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111. + * + * This request has one difference from RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: + * the SW1 and SW2 status bytes from the UICC response are returned along with + * the response data, using the same structure as RIL_REQUEST_SIM_IO. + * + * The RIL implementation shall perform the normal processing of a '91XX' + * response in SW1/SW2 to retrieve the pending proactive command and send it + * as an unsolicited response, as RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND does. + * + * "data" is a const char * containing the SAT/USAT command + * in hexadecimal format starting with command tag + * + * "response" is a const RIL_SIM_IO_Response * + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS 107 + +/** + * RIL_REQUEST_VOICE_RADIO_TECH + * + * Query the radio technology type (3GPP/3GPP2) used for voice. Query is valid only + * when radio state is not RADIO_STATE_UNAVAILABLE + * + * "data" is NULL + * "response" is int * + * ((int *) response)[0] is of type const RIL_RadioTechnology + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_VOICE_RADIO_TECH 108 + +/** + * RIL_REQUEST_GET_CELL_INFO_LIST + * + * Request all of the current cell information known to the radio. The radio + * must a list of all current cells, including the neighboring cells. If for a particular + * cell information isn't known then the appropriate unknown value will be returned. + * This does not cause or change the rate of RIL_UNSOL_CELL_INFO_LIST. + * + * "data" is NULL + * + * "response" is an array of RIL_CellInfo_v12. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NO_NETWORK_FOUND + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_GET_CELL_INFO_LIST 109 + +/** + * RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE + * + * Sets the minimum time between when RIL_UNSOL_CELL_INFO_LIST should be invoked. + * A value of 0, means invoke RIL_UNSOL_CELL_INFO_LIST when any of the reported + * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue + * a RIL_UNSOL_CELL_INFO_LIST. + * + * "data" is int * + * ((int *)data)[0] is minimum time in milliseconds + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE 110 + +/** + * RIL_REQUEST_SET_INITIAL_ATTACH_APN + * + * Set an apn to initial attach network + * + * "data" is a const char ** + * ((const char **)data)[0] is the APN to connect if radio technology is LTE + * ((const char **)data)[1] is the connection type to request must be one of the + * PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + * ((const char **)data)[2] is the PAP / CHAP auth type. Values: + * 0 => PAP and CHAP is never performed. + * 1 => PAP may be performed; CHAP is never performed. + * 2 => CHAP may be performed; PAP is never performed. + * 3 => PAP / CHAP may be performed - baseband dependent. + * ((const char **)data)[3] is the username for APN, or NULL + * ((const char **)data)[4] is the password for APN, or NULL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SUBSCRIPTION_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_SET_INITIAL_ATTACH_APN 111 + +/** + * RIL_REQUEST_IMS_REGISTRATION_STATE + * + * This message is DEPRECATED and shall be removed in a future release (target: 2018); + * instead, provide IMS registration status via an IMS Service. + * + * Request current IMS registration state + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is registration state: + * 0 - Not registered + * 1 - Registered + * + * If ((int*)response)[0] is = 1, then ((int *) response)[1] + * must follow with IMS SMS format: + * + * ((int *) response)[1] is of type RIL_RadioTechnologyFamily + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_IMS_REGISTRATION_STATE 112 + +/** + * RIL_REQUEST_IMS_SEND_SMS + * + * Send a SMS message over IMS + * + * "data" is const RIL_IMS_SMS_Message * + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. SMS_SEND_FAIL_RETRY means retry, and other errors means no retry. + * In case of retry, data is encoded based on Voice Technology available. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * FDN_CHECK_FAILURE + * NETWORK_REJECT + * INVALID_ARGUMENTS + * INVALID_STATE + * NO_MEMORY + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * NETWORK_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_IMS_SEND_SMS 113 + +/** + * RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC + * + * Request APDU exchange on the basic channel. This command reflects TS 27.007 + * "generic SIM access" operation (+CSIM). The modem must ensure proper function + * of GSM/CDMA, and filter commands appropriately. It should filter + * channel management and SELECT by DF name commands. + * + * "data" is a const RIL_SIM_APDU * + * "sessionid" field should be ignored. + * + * "response" is a const RIL_SIM_IO_Response * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC 114 + +/** + * RIL_REQUEST_SIM_OPEN_CHANNEL + * + * Open a new logical channel and select the given application. This command + * reflects TS 27.007 "open logical channel" operation (+CCHO). This request + * also specifies the P2 parameter (described in ISO 7816-4). + * + * "data" is a const RIL_OpenChannelParam * + * + * "response" is int * + * ((int *)data)[0] contains the session id of the logical channel. + * ((int *)data)[1] onwards may optionally contain the select response for the + * open channel command with one byte per integer. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * MISSING_RESOURCE + * NO_SUCH_ELEMENT + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * SIM_ERR + * INVALID_SIM_STATE + * MISSING_RESOURCE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_OPEN_CHANNEL 115 + +/** + * RIL_REQUEST_SIM_CLOSE_CHANNEL + * + * Close a previously opened logical channel. This command reflects TS 27.007 + * "close logical channel" operation (+CCHC). + * + * "data" is int * + * ((int *)data)[0] is the session id of logical the channel to close. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_CLOSE_CHANNEL 116 + +/** + * RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL + * + * Exchange APDUs with a UICC over a previously opened logical channel. This + * command reflects TS 27.007 "generic logical channel access" operation + * (+CGLA). The modem should filter channel management and SELECT by DF name + * commands. + * + * "data" is a const RIL_SIM_APDU* + * + * "response" is a const RIL_SIM_IO_Response * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL 117 + +/** + * RIL_REQUEST_NV_READ_ITEM + * + * Read one of the radio NV items defined in RadioNVItems.java / ril_nv_items.h. + * This is used for device configuration by some CDMA operators. + * + * "data" is a const RIL_NV_ReadItem * + * + * "response" is const char * containing the contents of the NV item + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_READ_ITEM 118 + +/** + * RIL_REQUEST_NV_WRITE_ITEM + * + * Write one of the radio NV items defined in RadioNVItems.java / ril_nv_items.h. + * This is used for device configuration by some CDMA operators. + * + * "data" is a const RIL_NV_WriteItem * + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_WRITE_ITEM 119 + +/** + * RIL_REQUEST_NV_WRITE_CDMA_PRL + * + * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. + * This is used for device configuration by some CDMA operators. + * + * "data" is a const char * containing the PRL as a byte array + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_WRITE_CDMA_PRL 120 + +/** + * RIL_REQUEST_NV_RESET_CONFIG + * + * Reset the radio NV configuration to the factory state. + * This is used for device configuration by some CDMA operators. + * + * "data" is int * + * ((int *)data)[0] is 1 to reload all NV items + * ((int *)data)[0] is 2 for erase NV reset (SCRTN) + * ((int *)data)[0] is 3 for factory reset (RTN) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_RESET_CONFIG 121 + + /** RIL_REQUEST_SET_UICC_SUBSCRIPTION + * FIXME This API needs to have more documentation. + * + * Selection/de-selection of a subscription from a SIM card + * "data" is const RIL_SelectUiccSub* + + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SUBSCRIPTION_NOT_SUPPORTED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_SET_UICC_SUBSCRIPTION 122 + +/** + * RIL_REQUEST_ALLOW_DATA + * + * Tells the modem whether data calls are allowed or not + * + * "data" is int * + * FIXME slotId and aid will be added. + * ((int *)data)[0] is == 0 to allow data calls + * ((int *)data)[0] is == 1 to disallow data calls + * + * "response" is NULL + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * INVALID_ARGUMENTS + * DEVICE_IN_USE + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_ALLOW_DATA 123 + +/** + * RIL_REQUEST_GET_HARDWARE_CONFIG + * + * Request all of the current hardware (modem and sim) associated + * with the RIL. + * + * "data" is NULL + * + * "response" is an array of RIL_HardwareConfig. + * + * Valid errors: + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GET_HARDWARE_CONFIG 124 + +/** + * RIL_REQUEST_SIM_AUTHENTICATION + * + * Returns the response of SIM Authentication through RIL to a + * challenge request. + * + * "data" Base64 encoded string containing challenge: + * int authContext; P2 value of authentication command, see P2 parameter in + * 3GPP TS 31.102 7.1.2 + * char *authData; the challenge string in Base64 format, see 3GPP + * TS 31.102 7.1.2 + * char *aid; AID value, See ETSI 102.221 8.1 and 101.220 4, + * NULL if no value + * + * "response" Base64 encoded strings containing response: + * int sw1; Status bytes per 3GPP TS 31.102 section 7.3 + * int sw2; + * char *simResponse; Response in Base64 format, see 3GPP TS 31.102 7.1.2 + * + * Valid errors: + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * INVALID_ARGUMENTS + * SIM_ERR + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_AUTHENTICATION 125 + +/** + * RIL_REQUEST_GET_DC_RT_INFO + * + * The request is DEPRECATED, use RIL_REQUEST_GET_ACTIVITY_INFO + * Requests the Data Connection Real Time Info + * + * "data" is NULL + * + * "response" is the most recent RIL_DcRtInfo + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_UNSOL_DC_RT_INFO_CHANGED + */ +#define RIL_REQUEST_GET_DC_RT_INFO 126 + +/** + * RIL_REQUEST_SET_DC_RT_INFO_RATE + * + * The request is DEPRECATED + * This is the minimum number of milliseconds between successive + * RIL_UNSOL_DC_RT_INFO_CHANGED messages and defines the highest rate + * at which RIL_UNSOL_DC_RT_INFO_CHANGED's will be sent. A value of + * 0 means send as fast as possible. + * + * "data" The number of milliseconds as an int + * + * "response" is null + * + * Valid errors: + * SUCCESS must not fail + */ +#define RIL_REQUEST_SET_DC_RT_INFO_RATE 127 + +/** + * RIL_REQUEST_SET_DATA_PROFILE + * + * Set data profile in modem + * Modem should erase existed profiles from framework, and apply new profiles + * "data" is a const RIL_DataProfileInfo ** + * "datalen" is count * sizeof(const RIL_DataProfileInfo *) + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SUBSCRIPTION_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_DATA_PROFILE 128 + +/** + * RIL_REQUEST_SHUTDOWN + * + * Device is shutting down. All further commands are ignored + * and RADIO_NOT_AVAILABLE must be returned. + * + * "data" is null + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SHUTDOWN 129 + +/** + * RIL_REQUEST_GET_RADIO_CAPABILITY + * + * Used to get phone radio capablility. + * + * "data" is the RIL_RadioCapability structure + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * INVALID_STATE + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_GET_RADIO_CAPABILITY 130 + +/** + * RIL_REQUEST_SET_RADIO_CAPABILITY + * + * Used to set the phones radio capability. Be VERY careful + * using this request as it may cause some vendor modems to reset. Because + * of the possible modem reset any RIL commands after this one may not be + * processed. + * + * "data" is the RIL_RadioCapability structure + * + * "response" is the RIL_RadioCapability structure, used to feedback return status + * + * Valid errors: + * SUCCESS means a RIL_UNSOL_RADIO_CAPABILITY will be sent within 30 seconds. + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * INVALID_STATE + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_RADIO_CAPABILITY 131 + +/** + * RIL_REQUEST_START_LCE + * + * Start Link Capacity Estimate (LCE) service if supported by the radio. + * + * "data" is const int * + * ((const int*)data)[0] specifies the desired reporting interval (ms). + * ((const int*)data)[1] specifies the LCE service mode. 1: PULL; 0: PUSH. + * + * "response" is the RIL_LceStatusInfo. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * LCE_NOT_SUPPORTED + * INTERNAL_ERR + * REQUEST_NOT_SUPPORTED + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_START_LCE 132 + +/** + * RIL_REQUEST_STOP_LCE + * + * Stop Link Capacity Estimate (LCE) service, the STOP operation should be + * idempotent for the radio modem. + * + * "response" is the RIL_LceStatusInfo. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * LCE_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STOP_LCE 133 + +/** + * RIL_REQUEST_PULL_LCEDATA + * + * Pull LCE service for capacity information. + * + * "response" is the RIL_LceDataInfo. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * LCE_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_PULL_LCEDATA 134 + +/** + * RIL_REQUEST_GET_ACTIVITY_INFO + * + * Get modem activity information for power consumption estimation. + * + * Request clear-on-read statistics information that is used for + * estimating the per-millisecond power consumption of the cellular + * modem. + * + * "data" is null + * "response" is const RIL_ActivityStatsInfo * + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES CANCELLED + */ +#define RIL_REQUEST_GET_ACTIVITY_INFO 135 + +/** + * RIL_REQUEST_SET_CARRIER_RESTRICTIONS + * + * Set carrier restrictions for this sim slot. Expected modem behavior: + * If never receives this command + * - Must allow all carriers + * Receives this command with data being NULL + * - Must allow all carriers. If a previously allowed SIM is present, modem must not reload + * the SIM. If a previously disallowed SIM is present, reload the SIM and notify Android. + * Receives this command with a list of carriers + * - Only allow specified carriers, persist across power cycles and FDR. If a present SIM + * is in the allowed list, modem must not reload the SIM. If a present SIM is *not* in + * the allowed list, modem must detach from the registered network and only keep emergency + * service, and notify Android SIM refresh reset with new SIM state being + * RIL_CARDSTATE_RESTRICTED. Emergency service must be enabled. + * + * "data" is const RIL_CarrierRestrictions * + * A list of allowed carriers and possibly a list of excluded carriers. + * If data is NULL, means to clear previous carrier restrictions and allow all carriers + * + * "response" is int * + * ((int *)data)[0] contains the number of allowed carriers which have been set correctly. + * On success, it should match the length of list data->allowed_carriers. + * If data is NULL, the value must be 0. + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_INVALID_ARGUMENTS + * RIL_E_RADIO_NOT_AVAILABLE + * RIL_E_REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_CARRIER_RESTRICTIONS 136 + +/** + * RIL_REQUEST_GET_CARRIER_RESTRICTIONS + * + * Get carrier restrictions for this sim slot. Expected modem behavior: + * Return list of allowed carriers, or null if all carriers are allowed. + * + * "data" is NULL + * + * "response" is const RIL_CarrierRestrictions *. + * If response is NULL, it means all carriers are allowed. + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE + * RIL_E_REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_GET_CARRIER_RESTRICTIONS 137 + +/** + * RIL_REQUEST_SEND_DEVICE_STATE + * + * Send the updated device state. + * Modem can perform power saving based on the provided device state. + * "data" is const int * + * ((const int*)data)[0] A RIL_DeviceStateType that specifies the device state type. + * ((const int*)data)[1] Specifies the state. See RIL_DeviceStateType for the definition of each + * type. + * + * "datalen" is count * sizeof(const RIL_DeviceState *) + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SEND_DEVICE_STATE 138 + +/** + * RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER + * + * Set the unsolicited response filter + * This is used to prevent unnecessary application processor + * wake up for power saving purposes by suppressing the + * unsolicited responses in certain scenarios. + * + * "data" is an int * + * + * ((int *)data)[0] is a 32-bit bitmask of RIL_UnsolicitedResponseFilter + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * INVALID_ARGUMENTS (e.g. the requested filter doesn't exist) + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER 139 + + /** + * RIL_REQUEST_SET_SIM_CARD_POWER + * + * Set SIM card power up or down + * + * Request is equivalent to inserting and removing the card, with + * an additional effect where the ability to detect card removal/insertion + * is disabled when the SIM card is powered down. + * + * This will generate RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED + * as if the SIM had been inserted or removed. + * + * "data" is int * + * ((int *)data)[0] is 1 for "SIM POWER UP" + * ((int *)data)[0] is 0 for "SIM POWER DOWN" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + * SIM_ABSENT + * INVALID_ARGUMENTS + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_SIM_CARD_POWER 140 + +/** + * RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION + * + * Provide Carrier specific information to the modem that will be used to + * encrypt the IMSI and IMPI. Sent by the framework during boot, carrier + * switch and everytime we receive a new certificate. + * + * "data" is the RIL_CarrierInfoForImsiEncryption * structure. + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE + * SIM_ABSENT + * RIL_E_REQUEST_NOT_SUPPORTED + * INVALID_ARGUMENTS + * MODEM_INTERNAL_FAILURE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION 141 + +/** + * RIL_REQUEST_START_NETWORK_SCAN + * + * Starts a new network scan + * + * Request to start a network scan with specified radio access networks with frequency bands and/or + * channels. + * + * "data" is a const RIL_NetworkScanRequest *. + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * DEVICE_IN_USE + * INTERNAL_ERR + * NO_MEMORY + * MODEM_ERR + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_START_NETWORK_SCAN 142 + +/** + * RIL_REQUEST_STOP_NETWORK_SCAN + * + * Stops an ongoing network scan + * + * Request to stop the ongoing network scan. Since the modem can only perform one scan at a time, + * there is no parameter for this request. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * INTERNAL_ERR + * MODEM_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_STOP_NETWORK_SCAN 143 + +/** + * RIL_REQUEST_START_KEEPALIVE + * + * Start a keepalive session + * + * Request that the modem begin sending keepalive packets on a particular + * data call, with a specified source, destination, and format. + * + * "data" is a const RIL_RequestKeepalive + * "response" is RIL_KeepaliveStatus with a valid "handle" + * + * Valid errors: + * SUCCESS + * NO_RESOURCES + * INVALID_ARGUMENTS + * + */ +#define RIL_REQUEST_START_KEEPALIVE 144 + +/** + * RIL_REQUEST_STOP_KEEPALIVE + * + * Stops an ongoing keepalive session + * + * Requests that a keepalive session with the given handle be stopped. + * there is no parameter for this request. + * + * "data" is an integer handle + * "response" is NULL + * + * Valid errors: + * SUCCESS + * INVALID_ARGUMENTS + * + */ +#define RIL_REQUEST_STOP_KEEPALIVE 145 + +/***********************************************************************/ + +/** + * RIL_RESPONSE_ACKNOWLEDGEMENT + * + * This is used by Asynchronous solicited messages and Unsolicited messages + * to acknowledge the receipt of those messages in RIL.java so that the ack + * can be used to let ril.cpp to release wakelock. + * + * Valid errors + * SUCCESS + * RADIO_NOT_AVAILABLE + */ + +#define RIL_RESPONSE_ACKNOWLEDGEMENT 800 + +/***********************************************************************/ + + +#define RIL_UNSOL_RESPONSE_BASE 1000 + +/** + * RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED + * + * Indicate when value of RIL_RadioState has changed. + * + * Callee will invoke RIL_RadioStateRequest method on main thread + * + * "data" is NULL + */ + +#define RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED 1000 + + +/** + * RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED + * + * Indicate when call state has changed + * + * Callee will invoke RIL_REQUEST_GET_CURRENT_CALLS on main thread + * + * "data" is NULL + * + * Response should be invoked on, for example, + * "RING", "BUSY", "NO CARRIER", and also call state + * transitions (DIALING->ALERTING ALERTING->ACTIVE) + * + * Redundent or extraneous invocations are tolerated + */ +#define RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 1001 + + +/** + * RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + * + * Called when the voice network state changed + * + * Callee will invoke the following requests on main thread: + * + * RIL_REQUEST_VOICE_REGISTRATION_STATE + * RIL_REQUEST_OPERATOR + * + * "data" is NULL + * + * FIXME should this happen when SIM records are loaded? (eg, for + * EONS) + */ +#define RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 1002 + +/** + * RIL_UNSOL_RESPONSE_NEW_SMS + * + * Called when new SMS is received. + * + * "data" is const char * + * This is a pointer to a string containing the PDU of an SMS-DELIVER + * as an ascii string of hex digits. The PDU starts with the SMSC address + * per TS 27.005 (+CMT:) + * + * Callee will subsequently confirm the receipt of thei SMS with a + * RIL_REQUEST_SMS_ACKNOWLEDGE + * + * No new RIL_UNSOL_RESPONSE_NEW_SMS + * or RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT messages should be sent until a + * RIL_REQUEST_SMS_ACKNOWLEDGE has been received + */ + +#define RIL_UNSOL_RESPONSE_NEW_SMS 1003 + +/** + * RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT + * + * Called when new SMS Status Report is received. + * + * "data" is const char * + * This is a pointer to a string containing the PDU of an SMS-STATUS-REPORT + * as an ascii string of hex digits. The PDU starts with the SMSC address + * per TS 27.005 (+CDS:). + * + * Callee will subsequently confirm the receipt of the SMS with a + * RIL_REQUEST_SMS_ACKNOWLEDGE + * + * No new RIL_UNSOL_RESPONSE_NEW_SMS + * or RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT messages should be sent until a + * RIL_REQUEST_SMS_ACKNOWLEDGE has been received + */ + +#define RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT 1004 + +/** + * RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM + * + * Called when new SMS has been stored on SIM card + * + * "data" is const int * + * ((const int *)data)[0] contains the slot index on the SIM that contains + * the new message + */ + +#define RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM 1005 + +/** + * RIL_UNSOL_ON_USSD + * + * Called when a new USSD message is received. + * + * "data" is const char ** + * ((const char **)data)[0] points to a type code, which is + * one of these string values: + * "0" USSD-Notify -- text in ((const char **)data)[1] + * "1" USSD-Request -- text in ((const char **)data)[1] + * "2" Session terminated by network + * "3" other local client (eg, SIM Toolkit) has responded + * "4" Operation not supported + * "5" Network timeout + * + * The USSD session is assumed to persist if the type code is "1", otherwise + * the current session (if any) is assumed to have terminated. + * + * ((const char **)data)[1] points to a message string if applicable, which + * should always be in UTF-8. + */ +#define RIL_UNSOL_ON_USSD 1006 +/* Previously #define RIL_UNSOL_ON_USSD_NOTIFY 1006 */ + +/** + * RIL_UNSOL_ON_USSD_REQUEST + * + * Obsolete. Send via RIL_UNSOL_ON_USSD + */ +#define RIL_UNSOL_ON_USSD_REQUEST 1007 + +/** + * RIL_UNSOL_NITZ_TIME_RECEIVED + * + * Called when radio has received a NITZ time message + * + * "data" is const char * pointing to NITZ time string + * in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt" + */ +#define RIL_UNSOL_NITZ_TIME_RECEIVED 1008 + +/** + * RIL_UNSOL_SIGNAL_STRENGTH + * + * Radio may report signal strength rather han have it polled. + * + * "data" is a const RIL_SignalStrength * + */ +#define RIL_UNSOL_SIGNAL_STRENGTH 1009 + + +/** + * RIL_UNSOL_DATA_CALL_LIST_CHANGED + * + * "data" is an array of RIL_Data_Call_Response_v6 identical to that + * returned by RIL_REQUEST_DATA_CALL_LIST. It is the complete list + * of current data contexts including new contexts that have been + * activated. A data call is only removed from this list when the + * framework sends a RIL_REQUEST_DEACTIVATE_DATA_CALL or the radio + * is powered off/on. + * + * See also: RIL_REQUEST_DATA_CALL_LIST + */ + +#define RIL_UNSOL_DATA_CALL_LIST_CHANGED 1010 + +/** + * RIL_UNSOL_SUPP_SVC_NOTIFICATION + * + * Reports supplementary service related notification from the network. + * + * "data" is a const RIL_SuppSvcNotification * + * + */ + +#define RIL_UNSOL_SUPP_SVC_NOTIFICATION 1011 + +/** + * RIL_UNSOL_STK_SESSION_END + * + * Indicate when STK session is terminated by SIM. + * + * "data" is NULL + */ +#define RIL_UNSOL_STK_SESSION_END 1012 + +/** + * RIL_UNSOL_STK_PROACTIVE_COMMAND + * + * Indicate when SIM issue a STK proactive command to applications + * + * "data" is a const char * containing SAT/USAT proactive command + * in hexadecimal format string starting with command tag + * + */ +#define RIL_UNSOL_STK_PROACTIVE_COMMAND 1013 + +/** + * RIL_UNSOL_STK_EVENT_NOTIFY + * + * Indicate when SIM notifies applcations some event happens. + * Generally, application does not need to have any feedback to + * SIM but shall be able to indicate appropriate messages to users. + * + * "data" is a const char * containing SAT/USAT commands or responses + * sent by ME to SIM or commands handled by ME, in hexadecimal format string + * starting with first byte of response data or command tag + * + */ +#define RIL_UNSOL_STK_EVENT_NOTIFY 1014 + +/** + * RIL_UNSOL_STK_CALL_SETUP + * + * Indicate when SIM wants application to setup a voice call. + * + * "data" is const int * + * ((const int *)data)[0] contains timeout value (in milliseconds) + */ +#define RIL_UNSOL_STK_CALL_SETUP 1015 + +/** + * RIL_UNSOL_SIM_SMS_STORAGE_FULL + * + * Indicates that SMS storage on the SIM is full. Sent when the network + * attempts to deliver a new SMS message. Messages cannot be saved on the + * SIM until space is freed. In particular, incoming Class 2 messages + * cannot be stored. + * + * "data" is null + * + */ +#define RIL_UNSOL_SIM_SMS_STORAGE_FULL 1016 + +/** + * RIL_UNSOL_SIM_REFRESH + * + * Indicates that file(s) on the SIM have been updated, or the SIM + * has been reinitialized. + * + * In the case where RIL is version 6 or older: + * "data" is an int * + * ((int *)data)[0] is a RIL_SimRefreshResult. + * ((int *)data)[1] is the EFID of the updated file if the result is + * SIM_FILE_UPDATE or NULL for any other result. + * + * In the case where RIL is version 7: + * "data" is a RIL_SimRefreshResponse_v7 * + * + * Note: If the SIM state changes as a result of the SIM refresh (eg, + * SIM_READY -> SIM_LOCKED_OR_ABSENT), RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED + * should be sent. + */ +#define RIL_UNSOL_SIM_REFRESH 1017 + +/** + * RIL_UNSOL_CALL_RING + * + * Ring indication for an incoming call (eg, RING or CRING event). + * There must be at least one RIL_UNSOL_CALL_RING at the beginning + * of a call and sending multiple is optional. If the system property + * ro.telephony.call_ring.multiple is false then the upper layers + * will generate the multiple events internally. Otherwise the vendor + * ril must generate multiple RIL_UNSOL_CALL_RING if + * ro.telephony.call_ring.multiple is true or if it is absent. + * + * The rate of these events is controlled by ro.telephony.call_ring.delay + * and has a default value of 3000 (3 seconds) if absent. + * + * "data" is null for GSM + * "data" is const RIL_CDMA_SignalInfoRecord * if CDMA + */ +#define RIL_UNSOL_CALL_RING 1018 + +/** + * RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED + * + * Indicates that SIM state changes. + * + * Callee will invoke RIL_REQUEST_GET_SIM_STATUS on main thread + + * "data" is null + */ +#define RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED 1019 + +/** + * RIL_UNSOL_RESPONSE_CDMA_NEW_SMS + * + * Called when new CDMA SMS is received + * + * "data" is const RIL_CDMA_SMS_Message * + * + * Callee will subsequently confirm the receipt of the SMS with + * a RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE + * + * No new RIL_UNSOL_RESPONSE_CDMA_NEW_SMS should be sent until + * RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE has been received + * + */ +#define RIL_UNSOL_RESPONSE_CDMA_NEW_SMS 1020 + +/** + * RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS + * + * Called when new Broadcast SMS is received + * + * "data" can be one of the following: + * If received from GSM network, "data" is const char of 88 bytes + * which indicates each page of a CBS Message sent to the MS by the + * BTS as coded in 3GPP 23.041 Section 9.4.1.2. + * If received from UMTS network, "data" is const char of 90 up to 1252 + * bytes which contain between 1 and 15 CBS Message pages sent as one + * packet to the MS by the BTS as coded in 3GPP 23.041 Section 9.4.2.2. + * + */ +#define RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS 1021 + +/** + * RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL + * + * Indicates that SMS storage on the RUIM is full. Messages + * cannot be saved on the RUIM until space is freed. + * + * "data" is null + * + */ +#define RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL 1022 + +/** + * RIL_UNSOL_RESTRICTED_STATE_CHANGED + * + * Indicates a restricted state change (eg, for Domain Specific Access Control). + * + * Radio need send this msg after radio off/on cycle no matter it is changed or not. + * + * "data" is an int * + * ((int *)data)[0] contains a bitmask of RIL_RESTRICTED_STATE_* values. + */ +#define RIL_UNSOL_RESTRICTED_STATE_CHANGED 1023 + +/** + * RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE + * + * Indicates that the radio system selection module has + * autonomously entered emergency callback mode. + * + * "data" is null + * + */ +#define RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE 1024 + +/** + * RIL_UNSOL_CDMA_CALL_WAITING + * + * Called when CDMA radio receives a call waiting indication. + * + * "data" is const RIL_CDMA_CallWaiting * + * + */ +#define RIL_UNSOL_CDMA_CALL_WAITING 1025 + +/** + * RIL_UNSOL_CDMA_OTA_PROVISION_STATUS + * + * Called when CDMA radio receives an update of the progress of an + * OTASP/OTAPA call. + * + * "data" is const int * + * For CDMA this is an integer OTASP/OTAPA status listed in + * RIL_CDMA_OTA_ProvisionStatus. + * + */ +#define RIL_UNSOL_CDMA_OTA_PROVISION_STATUS 1026 + +/** + * RIL_UNSOL_CDMA_INFO_REC + * + * Called when CDMA radio receives one or more info recs. + * + * "data" is const RIL_CDMA_InformationRecords * + * + */ +#define RIL_UNSOL_CDMA_INFO_REC 1027 + +/** + * RIL_UNSOL_OEM_HOOK_RAW + * + * This is for OEM specific use. + * + * "data" is a byte[] + */ +#define RIL_UNSOL_OEM_HOOK_RAW 1028 + +/** + * RIL_UNSOL_RINGBACK_TONE + * + * Indicates that nework doesn't have in-band information, need to + * play out-band tone. + * + * "data" is an int * + * ((int *)data)[0] == 0 for stop play ringback tone. + * ((int *)data)[0] == 1 for start play ringback tone. + */ +#define RIL_UNSOL_RINGBACK_TONE 1029 + +/** + * RIL_UNSOL_RESEND_INCALL_MUTE + * + * Indicates that framework/application need reset the uplink mute state. + * + * There may be situations where the mute state becomes out of sync + * between the application and device in some GSM infrastructures. + * + * "data" is null + */ +#define RIL_UNSOL_RESEND_INCALL_MUTE 1030 + +/** + * RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED + * + * Called when CDMA subscription source changed. + * + * "data" is int * + * ((int *)data)[0] is == RIL_CdmaSubscriptionSource + */ +#define RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED 1031 + +/** + * RIL_UNSOL_CDMA_PRL_CHANGED + * + * Called when PRL (preferred roaming list) changes. + * + * "data" is int * + * ((int *)data)[0] is PRL_VERSION as would be returned by RIL_REQUEST_CDMA_SUBSCRIPTION + */ +#define RIL_UNSOL_CDMA_PRL_CHANGED 1032 + +/** + * RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE + * + * Called when Emergency Callback Mode Ends + * + * Indicates that the radio system selection module has + * proactively exited emergency callback mode. + * + * "data" is NULL + * + */ +#define RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE 1033 + +/** + * RIL_UNSOL_RIL_CONNECTED + * + * Called the ril connects and returns the version + * + * "data" is int * + * ((int *)data)[0] is RIL_VERSION + */ +#define RIL_UNSOL_RIL_CONNECTED 1034 + +/** + * RIL_UNSOL_VOICE_RADIO_TECH_CHANGED + * + * Indicates that voice technology has changed. Contains new radio technology + * as a data in the message. + * + * "data" is int * + * ((int *)data)[0] is of type const RIL_RadioTechnology + * + */ +#define RIL_UNSOL_VOICE_RADIO_TECH_CHANGED 1035 + +/** + * RIL_UNSOL_CELL_INFO_LIST + * + * Same information as returned by RIL_REQUEST_GET_CELL_INFO_LIST, but returned + * at the rate no greater than specified by RIL_REQUEST_SET_UNSOL_CELL_INFO_RATE. + * + * "data" is NULL + * + * "response" is an array of RIL_CellInfo_v12. + */ +#define RIL_UNSOL_CELL_INFO_LIST 1036 + +/** + * RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED + * + * This message is DEPRECATED and shall be removed in a future release (target: 2018); + * instead, provide IMS registration status via an IMS Service. + * + * Called when IMS registration state has changed + * + * To get IMS registration state and IMS SMS format, callee needs to invoke the + * following request on main thread: + * + * RIL_REQUEST_IMS_REGISTRATION_STATE + * + * "data" is NULL + * + */ +#define RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED 1037 + +/** + * RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED + * + * Indicated when there is a change in subscription status. + * This event will be sent in the following scenarios + * - subscription readiness at modem, which was selected by telephony layer + * - when subscription is deactivated by modem due to UICC card removal + * - When network invalidates the subscription i.e. attach reject due to authentication reject + * + * "data" is const int * + * ((const int *)data)[0] == 0 for Subscription Deactivated + * ((const int *)data)[0] == 1 for Subscription Activated + * + */ +#define RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED 1038 + +/** + * RIL_UNSOL_SRVCC_STATE_NOTIFY + * + * Called when Single Radio Voice Call Continuity(SRVCC) + * progress state has changed + * + * "data" is int * + * ((int *)data)[0] is of type const RIL_SrvccState + * + */ + +#define RIL_UNSOL_SRVCC_STATE_NOTIFY 1039 + +/** + * RIL_UNSOL_HARDWARE_CONFIG_CHANGED + * + * Called when the hardware configuration associated with the RILd changes + * + * "data" is an array of RIL_HardwareConfig + * + */ +#define RIL_UNSOL_HARDWARE_CONFIG_CHANGED 1040 + +/** + * RIL_UNSOL_DC_RT_INFO_CHANGED + * + * The message is DEPRECATED, use RIL_REQUEST_GET_ACTIVITY_INFO + * Sent when the DC_RT_STATE changes but the time + * between these messages must not be less than the + * value set by RIL_REQUEST_SET_DC_RT_RATE. + * + * "data" is the most recent RIL_DcRtInfo + * + */ +#define RIL_UNSOL_DC_RT_INFO_CHANGED 1041 + +/** + * RIL_UNSOL_RADIO_CAPABILITY + * + * Sent when RIL_REQUEST_SET_RADIO_CAPABILITY completes. + * Returns the phone radio capability exactly as + * RIL_REQUEST_GET_RADIO_CAPABILITY and should be the + * same set as sent by RIL_REQUEST_SET_RADIO_CAPABILITY. + * + * "data" is the RIL_RadioCapability structure + */ +#define RIL_UNSOL_RADIO_CAPABILITY 1042 + +/* + * RIL_UNSOL_ON_SS + * + * Called when SS response is received when DIAL/USSD/SS is changed to SS by + * call control. + * + * "data" is const RIL_StkCcUnsolSsResponse * + * + */ +#define RIL_UNSOL_ON_SS 1043 + +/** + * RIL_UNSOL_STK_CC_ALPHA_NOTIFY + * + * Called when there is an ALPHA from UICC during Call Control. + * + * "data" is const char * containing ALPHA string from UICC in UTF-8 format. + * + */ +#define RIL_UNSOL_STK_CC_ALPHA_NOTIFY 1044 + +/** + * RIL_UNSOL_LCEDATA_RECV + * + * Called when there is an incoming Link Capacity Estimate (LCE) info report. + * + * "data" is the RIL_LceDataInfo structure. + * + */ +#define RIL_UNSOL_LCEDATA_RECV 1045 + + /** + * RIL_UNSOL_PCO_DATA + * + * Called when there is new Carrier PCO data received for a data call. Ideally + * only new data will be forwarded, though this is not required. Multiple + * boxes of carrier PCO data for a given call should result in a series of + * RIL_UNSOL_PCO_DATA calls. + * + * "data" is the RIL_PCO_Data structure. + * + */ +#define RIL_UNSOL_PCO_DATA 1046 + + /** + * RIL_UNSOL_MODEM_RESTART + * + * Called when there is a modem reset. + * + * "reason" is "const char *" containing the reason for the reset. It + * could be a crash signature if the restart was due to a crash or some + * string such as "user-initiated restart" or "AT command initiated + * restart" that explains the cause of the modem restart. + * + * When modem restarts, one of the following radio state transitions will happen + * 1) RADIO_STATE_ON->RADIO_STATE_UNAVAILABLE->RADIO_STATE_ON or + * 2) RADIO_STATE_OFF->RADIO_STATE_UNAVAILABLE->RADIO_STATE_OFF + * This message can be sent either just before the RADIO_STATE changes to RADIO_STATE_UNAVAILABLE + * or just after but should never be sent after the RADIO_STATE changes from UNAVAILABLE to + * AVAILABLE(RADIO_STATE_ON/RADIO_STATE_OFF) again. + * + * It should NOT be sent after the RADIO_STATE changes to AVAILABLE after the + * modem restart as that could be interpreted as a second modem reset by the + * framework. + */ +#define RIL_UNSOL_MODEM_RESTART 1047 + +/** + * RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION + * + * Called when the modem needs Carrier specific information that will + * be used to encrypt IMSI and IMPI. + * + * "data" is NULL + * + */ +#define RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION 1048 + +/** + * RIL_UNSOL_NETWORK_SCAN_RESULT + * + * Returns incremental result for the network scan which is started by + * RIL_REQUEST_START_NETWORK_SCAN, sent to report results, status, or errors. + * + * "data" is NULL + * "response" is a const RIL_NetworkScanResult * + */ +#define RIL_UNSOL_NETWORK_SCAN_RESULT 1049 + +/** + * RIL_UNSOL_KEEPALIVE_STATUS + * + * "data" is NULL + * "response" is a const RIL_KeepaliveStatus * + */ +#define RIL_UNSOL_KEEPALIVE_STATUS 1050 + +/***********************************************************************/ + + +#if defined(ANDROID_MULTI_SIM) +/** + * RIL_Request Function pointer + * + * @param request is one of RIL_REQUEST_* + * @param data is pointer to data defined for that RIL_REQUEST_* + * data is owned by caller, and should not be modified or freed by callee + * structures passed as data may contain pointers to non-contiguous memory + * @param t should be used in subsequent call to RIL_onResponse + * @param datalen is the length of "data" which is defined as other argument. It may or may + * not be equal to sizeof(data). Refer to the documentation of individual structures + * to find if pointers listed in the structure are contiguous and counted in the datalen + * length or not. + * (Eg: RIL_IMS_SMS_Message where we don't have datalen equal to sizeof(data)) + * + */ +typedef void (*RIL_RequestFunc) (int request, void *data, + size_t datalen, RIL_Token t, RIL_SOCKET_ID socket_id); + +/** + * This function should return the current radio state synchronously + */ +typedef RIL_RadioState (*RIL_RadioStateRequest)(RIL_SOCKET_ID socket_id); + +#else +/* Backward compatible */ + +/** + * RIL_Request Function pointer + * + * @param request is one of RIL_REQUEST_* + * @param data is pointer to data defined for that RIL_REQUEST_* + * data is owned by caller, and should not be modified or freed by callee + * structures passed as data may contain pointers to non-contiguous memory + * @param t should be used in subsequent call to RIL_onResponse + * @param datalen is the length of "data" which is defined as other argument. It may or may + * not be equal to sizeof(data). Refer to the documentation of individual structures + * to find if pointers listed in the structure are contiguous and counted in the datalen + * length or not. + * (Eg: RIL_IMS_SMS_Message where we don't have datalen equal to sizeof(data)) + * + */ +typedef void (*RIL_RequestFunc) (int request, void *data, + size_t datalen, RIL_Token t); + +/** + * This function should return the current radio state synchronously + */ +typedef RIL_RadioState (*RIL_RadioStateRequest)(); + +#endif + + +/** + * This function returns "1" if the specified RIL_REQUEST code is + * supported and 0 if it is not + * + * @param requestCode is one of RIL_REQUEST codes + */ + +typedef int (*RIL_Supports)(int requestCode); + +/** + * This function is called from a separate thread--not the + * thread that calls RIL_RequestFunc--and indicates that a pending + * request should be cancelled. + * + * On cancel, the callee should do its best to abandon the request and + * call RIL_onRequestComplete with RIL_Errno CANCELLED at some later point. + * + * Subsequent calls to RIL_onRequestComplete for this request with + * other results will be tolerated but ignored. (That is, it is valid + * to ignore the cancellation request) + * + * RIL_Cancel calls should return immediately, and not wait for cancellation + * + * Please see ITU v.250 5.6.1 for how one might implement this on a TS 27.007 + * interface + * + * @param t token wants to be canceled + */ + +typedef void (*RIL_Cancel)(RIL_Token t); + +typedef void (*RIL_TimedCallback) (void *param); + +/** + * Return a version string for your RIL implementation + */ +typedef const char * (*RIL_GetVersion) (void); + +typedef struct { + int version; /* set to RIL_VERSION */ + RIL_RequestFunc onRequest; + RIL_RadioStateRequest onStateRequest; + RIL_Supports supports; + RIL_Cancel onCancel; + RIL_GetVersion getVersion; +} RIL_RadioFunctions; + +typedef struct { + char *apn; /* the APN to connect to */ + char *protocol; /* one of the PDP_type values in TS 27.007 section 10.1.1 used on + roaming network. For example, "IP", "IPV6", "IPV4V6", or "PPP".*/ + int authtype; /* authentication protocol used for this PDP context + (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) */ + char *username; /* the username for APN, or NULL */ + char *password; /* the password for APN, or NULL */ +} RIL_InitialAttachApn; + +typedef struct { + char *apn; /* the APN to connect to */ + char *protocol; /* one of the PDP_type values in TS 27.007 section 10.1.1 used on + home network. For example, "IP", "IPV6", "IPV4V6", or "PPP". */ + char *roamingProtocol; /* one of the PDP_type values in TS 27.007 section 10.1.1 used on + roaming network. For example, "IP", "IPV6", "IPV4V6", or "PPP".*/ + int authtype; /* authentication protocol used for this PDP context + (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) */ + char *username; /* the username for APN, or NULL */ + char *password; /* the password for APN, or NULL */ + int supportedTypesBitmask; /* supported APN types bitmask. See RIL_ApnTypes for the value of + each bit. */ + int bearerBitmask; /* the bearer bitmask. See RIL_RadioAccessFamily for the value of + each bit. */ + int modemCognitive; /* indicating the APN setting was sent to the modem through + setDataProfile earlier. */ + int mtu; /* maximum transmission unit (MTU) size in bytes */ + char *mvnoType; /* the MVNO type: possible values are "imsi", "gid", "spn" */ + char *mvnoMatchData; /* MVNO match data. Can be anything defined by the carrier. + For example, + SPN like: "A MOBILE", "BEN NL", etc... + IMSI like: "302720x94", "2060188", etc... + GID like: "4E", "33", etc... */ +} RIL_InitialAttachApn_v15; + +typedef struct { + int authContext; /* P2 value of authentication command, see P2 parameter in + 3GPP TS 31.102 7.1.2 */ + char *authData; /* the challenge string in Base64 format, see 3GPP + TS 31.102 7.1.2 */ + char *aid; /* AID value, See ETSI 102.221 8.1 and 101.220 4, + NULL if no value. */ +} RIL_SimAuthentication; + +typedef struct { + int cid; /* Context ID, uniquely identifies this call */ + char *bearer_proto; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6". */ + int pco_id; /* The protocol ID for this box. Note that only IDs from + FF00H - FFFFH are accepted. If more than one is included + from the network, multiple calls should be made to send all + of them. */ + int contents_length; /* The number of octets in the contents. */ + char *contents; /* Carrier-defined content. It is binary, opaque and + loosely defined in LTE Layer 3 spec 24.008 */ +} RIL_PCO_Data; + +typedef enum { + NATT_IPV4 = 0, /* Keepalive specified by RFC 3948 Sec. 2.3 using IPv4 */ + NATT_IPV6 = 1 /* Keepalive specified by RFC 3948 Sec. 2.3 using IPv6 */ +} RIL_KeepaliveType; + +#define MAX_INADDR_LEN 16 +typedef struct { + RIL_KeepaliveType type; /* Type of keepalive packet */ + char sourceAddress[MAX_INADDR_LEN]; /* Source address in network-byte order */ + int sourcePort; /* Source port if applicable, or 0x7FFFFFFF; + the maximum value is 65535 */ + char destinationAddress[MAX_INADDR_LEN]; /* Destination address in network-byte order */ + int destinationPort; /* Destination port if applicable or 0x7FFFFFFF; + the maximum value is 65535 */ + int maxKeepaliveIntervalMillis; /* Maximum milliseconds between two packets */ + int cid; /* Context ID, uniquely identifies this call */ +} RIL_KeepaliveRequest; + +typedef enum { + KEEPALIVE_ACTIVE, /* Keepalive session is active */ + KEEPALIVE_INACTIVE, /* Keepalive session is inactive */ + KEEPALIVE_PENDING /* Keepalive session status not available */ +} RIL_KeepaliveStatusCode; + +typedef struct { + uint32_t sessionHandle; + RIL_KeepaliveStatusCode code; +} RIL_KeepaliveStatus; + +#ifdef RIL_SHLIB +struct RIL_Env { + /** + * "t" is parameter passed in on previous call to RIL_Notification + * routine. + * + * If "e" != SUCCESS, then response can be null/is ignored + * + * "response" is owned by caller, and should not be modified or + * freed by callee + * + * RIL_onRequestComplete will return as soon as possible + */ + void (*OnRequestComplete)(RIL_Token t, RIL_Errno e, + void *response, size_t responselen); + +#if defined(ANDROID_MULTI_SIM) + /** + * "unsolResponse" is one of RIL_UNSOL_RESPONSE_* + * "data" is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * + * "data" is owned by caller, and should not be modified or freed by callee + */ + void (*OnUnsolicitedResponse)(int unsolResponse, const void *data, size_t datalen, RIL_SOCKET_ID socket_id); +#else + /** + * "unsolResponse" is one of RIL_UNSOL_RESPONSE_* + * "data" is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * + * "data" is owned by caller, and should not be modified or freed by callee + */ + void (*OnUnsolicitedResponse)(int unsolResponse, const void *data, size_t datalen); +#endif + /** + * Call user-specifed "callback" function on on the same thread that + * RIL_RequestFunc is called. If "relativeTime" is specified, then it specifies + * a relative time value at which the callback is invoked. If relativeTime is + * NULL or points to a 0-filled structure, the callback will be invoked as + * soon as possible + */ + + void (*RequestTimedCallback) (RIL_TimedCallback callback, + void *param, const struct timeval *relativeTime); + /** + * "t" is parameter passed in on previous call RIL_Notification routine + * + * RIL_onRequestAck will be called by vendor when an Async RIL request was received + * by them and an ack needs to be sent back to java ril. + */ + void (*OnRequestAck) (RIL_Token t); +}; + + +/** + * RIL implementations must defined RIL_Init + * argc and argv will be command line arguments intended for the RIL implementation + * Return NULL on error + * + * @param env is environment point defined as RIL_Env + * @param argc number of arguments + * @param argv list fo arguments + * + */ +const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv); + +/** + * If BT SAP(SIM Access Profile) is supported, then RIL implementations must define RIL_SAP_Init + * for initializing RIL_RadioFunctions used for BT SAP communcations. It is called whenever RILD + * starts or modem restarts. Returns handlers for SAP related request that are made on SAP + * sepecific socket, analogous to the RIL_RadioFunctions returned by the call to RIL_Init + * and used on the general RIL socket. + * argc and argv will be command line arguments intended for the RIL implementation + * Return NULL on error. + * + * @param env is environment point defined as RIL_Env + * @param argc number of arguments + * @param argv list fo arguments + * + */ +const RIL_RadioFunctions *RIL_SAP_Init(const struct RIL_Env *env, int argc, char **argv); + +#else /* RIL_SHLIB */ + +/** + * Call this once at startup to register notification routine + * + * @param callbacks user-specifed callback function + */ +void RIL_register (const RIL_RadioFunctions *callbacks); + +void rilc_thread_pool(); + + +/** + * + * RIL_onRequestComplete will return as soon as possible + * + * @param t is parameter passed in on previous call to RIL_Notification + * routine. + * @param e error code + * if "e" != SUCCESS, then response can be null/is ignored + * @param response is owned by caller, and should not be modified or + * freed by callee + * @param responselen the length of response in byte + */ +void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, + void *response, size_t responselen); + +/** + * RIL_onRequestAck will be called by vendor when an Async RIL request was received by them and + * an ack needs to be sent back to java ril. This doesn't mark the end of the command or it's + * results, just that the command was received and will take a while. After sending this Ack + * its vendor's responsibility to make sure that AP is up whenever needed while command is + * being processed. + * + * @param t is parameter passed in on previous call to RIL_Notification + * routine. + */ +void RIL_onRequestAck(RIL_Token t); + +#if defined(ANDROID_MULTI_SIM) +/** + * @param unsolResponse is one of RIL_UNSOL_RESPONSE_* + * @param data is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * "data" is owned by caller, and should not be modified or freed by callee + * @param datalen the length of data in byte + */ + +void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen, RIL_SOCKET_ID socket_id); +#else +/** + * @param unsolResponse is one of RIL_UNSOL_RESPONSE_* + * @param data is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * "data" is owned by caller, and should not be modified or freed by callee + * @param datalen the length of data in byte + */ + +void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen); +#endif + +/** + * Call user-specifed "callback" function on on the same thread that + * RIL_RequestFunc is called. If "relativeTime" is specified, then it specifies + * a relative time value at which the callback is invoked. If relativeTime is + * NULL or points to a 0-filled structure, the callback will be invoked as + * soon as possible + * + * @param callback user-specifed callback function + * @param param parameter list + * @param relativeTime a relative time value at which the callback is invoked + */ + +void RIL_requestTimedCallback (RIL_TimedCallback callback, + void *param, const struct timeval *relativeTime); + +#endif /* RIL_SHLIB */ + +#ifdef __cplusplus +} +#endif + +#endif /*ANDROID_RIL_H*/ diff --git a/keylayout/Button_Jack.kl b/keylayout/Button_Jack.kl new file mode 100644 index 0000000..ddb0dbf --- /dev/null +++ b/keylayout/Button_Jack.kl @@ -0,0 +1,3 @@ +key 256 HEADSETHOOK +key 257 VOLUME_UP +key 258 VOLUME_DOWN diff --git a/keylayout/gpio-keys.kl b/keylayout/gpio-keys.kl new file mode 100644 index 0000000..56774d5 --- /dev/null +++ b/keylayout/gpio-keys.kl @@ -0,0 +1,35 @@ +# Copyright (c) 2012, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + +key 115 VOLUME_UP +key 114 VOLUME_DOWN +key 172 HOME +key 528 FOCUS +key 766 CAMERA +key 116 POWER +key 139 MENU +key 158 BACK +key 254 APP_SWITCH diff --git a/keylayout/sec_touchkey.kl b/keylayout/sec_touchkey.kl new file mode 100644 index 0000000..f50e99f --- /dev/null +++ b/keylayout/sec_touchkey.kl @@ -0,0 +1,5 @@ +key 139 MENU VIRTUAL +key 158 BACK VIRTUAL +key 102 HOME +key 217 SEARCH +key 254 APP_SWITCH VIRTUAL diff --git a/keylayout/synaptics_rmi4_i2c.kl b/keylayout/synaptics_rmi4_i2c.kl new file mode 100644 index 0000000..8b1fe3f --- /dev/null +++ b/keylayout/synaptics_rmi4_i2c.kl @@ -0,0 +1,30 @@ +# Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + +key 139 MENU +key 102 HOME +key 158 BACK +key 217 SEARCH diff --git a/liblights/Android.mk b/liblights/Android.mk new file mode 100644 index 0000000..1fe0c88 --- /dev/null +++ b/liblights/Android.mk @@ -0,0 +1,27 @@ +# +# Copyright (C) 2014 The CyanogenMod 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. + +LOCAL_PATH:= $(call my-dir) +# HAL module implemenation stored in +# hw/..so +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := lights.c +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SHARED_LIBRARIES := liblog libhardware +LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM) +LOCAL_MODULE_TAGS := optional +LOCAL_VENDOR_MODULE := true +include $(BUILD_SHARED_LIBRARY) diff --git a/liblights/NOTICE b/liblights/NOTICE new file mode 100644 index 0000000..316b4eb --- /dev/null +++ b/liblights/NOTICE @@ -0,0 +1,190 @@ + + Copyright (c) 2014, 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. + + 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. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/liblights/lights.c b/liblights/lights.c new file mode 100644 index 0000000..3e1088c --- /dev/null +++ b/liblights/lights.c @@ -0,0 +1,362 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2013 The CyanogenMod 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. + */ + +//#define LOG_NDEBUG 0 +#define LOG_TAG "lights" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define UNUSED __attribute__((unused)) + +static pthread_once_t g_init = PTHREAD_ONCE_INIT; +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; + +char const*const PANEL_FILE = "/sys/class/leds/lcd-backlight/brightness"; +char const*const BUTTON_FILE = "/sys/class/leds/button-backlight/brightness"; + +char const*const LED_BLINK = "/sys/class/sec/led/led_blink"; + +struct led_config { + unsigned int color; + int delay_on, delay_off; +}; + +static struct led_config g_leds[3]; // For battery, notifications, and attention. +static int g_cur_led = -1; // Presently showing LED of the above. + +void init_g_lock(void) +{ + pthread_mutex_init(&g_lock, NULL); +} + +static int write_int(char const *path, int value) +{ + int fd; + static int already_warned; + + already_warned = 0; + + ALOGV("write_int: path %s, value %d", path, value); + fd = open(path, O_RDWR); + + if (fd >= 0) { + char buffer[20]; + int bytes = sprintf(buffer, "%d\n", value); + int amt = write(fd, buffer, bytes); + close(fd); + return amt == -1 ? -errno : 0; + } else { + if (already_warned == 0) { + ALOGE("write_int failed to open %s\n", path); + already_warned = 1; + } + return -errno; + } +} + +/* Currently unused. +static int read_int(char const *path) +{ + int fd; + char buffer[2]; + + fd = open(path, O_RDONLY); + + if (fd >= 0) { + read(fd, buffer, 1); + } + close(fd); + + return atoi(buffer); +} +*/ + +static int write_str(char const *path, const char* value) +{ + int fd; + static int already_warned; + + already_warned = 0; + + ALOGV("write_str: path %s, value %s", path, value); + fd = open(path, O_RDWR); + + if (fd >= 0) { + int amt = write(fd, value, strlen(value)); + close(fd); + return amt == -1 ? -errno : 0; + } else { + if (already_warned == 0) { + ALOGE("write_str failed to open %s\n", path); + already_warned = 1; + } + return -errno; + } +} + +static int rgb_to_brightness(struct light_state_t const *state) +{ + int color = state->color & 0x00ffffff; + + return ((77*((color>>16) & 0x00ff)) + + (150*((color>>8) & 0x00ff)) + (29*(color & 0x00ff))) >> 8; +} + +/* Previously used by set_light_leds. +static int get_calibrated_color(struct light_state_t const *state, int brightness) +{ + int red = (state->color >> 16) & 0xFF; + int green = ((state->color >> 8) & 0xFF) * 0.7; + int blue = (state->color & 0x00FF) * 0.8; + + return (((red * brightness) / 255) << 16) + (((green * brightness) / 255) << 8) + ((blue * brightness) / 255); +} +*/ + +static int is_lit(struct light_state_t const* state) +{ + return state->color & 0x00ffffff; +} + +static int set_light_backlight(UNUSED struct light_device_t *dev, + struct light_state_t const *state) +{ + int err = 0; + int brightness = rgb_to_brightness(state); + + pthread_mutex_lock(&g_lock); + err = write_int(PANEL_FILE, brightness); + + pthread_mutex_unlock(&g_lock); + return err; +} + +static int +set_light_buttons(UNUSED struct light_device_t* dev, + struct light_state_t const* state) +{ + int err = 0; + int on = is_lit(state); + + pthread_mutex_lock(&g_lock); + err = write_int(BUTTON_FILE, on?1:0); + pthread_mutex_unlock(&g_lock); + + return err; + +} + +static int close_lights(struct light_device_t *dev) +{ + ALOGV("close_light is called"); + if (dev) + free(dev); + + return 0; +} + +/* LEDs */ +static int write_leds(const struct led_config *led) +{ + static const struct led_config led_off = {0, 0, 0}; + + char blink[32]; + int count, err; + + if (led == NULL) + led = &led_off; + + if ((count = snprintf(blink, sizeof(blink)-1, "0x%08x %d %d", led->color, + led->delay_on, led->delay_off)) < 0) { + return -errno; + } else if ((unsigned int)count >= sizeof(blink)-1) { + ALOGE("%s: Truncated string: blink=\"%s\".", __func__, blink); + return -EINVAL; + } + + ALOGD("%s: color=0x%08x, delay_on=%d, delay_off=%d, blink=\"%s\".", + __func__, led->color, led->delay_on, led->delay_off, blink); + + /* Add '\n' here to make the above log message clean. */ + blink[count] = '\n'; + blink[count+1] = '\0'; + + pthread_mutex_lock(&g_lock); + err = write_str(LED_BLINK, blink); + pthread_mutex_unlock(&g_lock); + + return err; +} + +static int set_light_leds(struct light_state_t const *state, int type) +{ + struct led_config *led; + int err = 0; + + ALOGD("%s: type=%d, color=0x%010x, fM=%d, fOnMS=%d, fOffMs=%d.", __func__, + type, state->color,state->flashMode, state->flashOnMS, state->flashOffMS); + + if (type < 0 || (unsigned int)type >= sizeof(g_leds)/sizeof(g_leds[0])) + return -EINVAL; + + /* type is one of: + * 0. battery + * 1. notifications + * 2. attention + * which are multiplexed onto the same physical LED in the above order. */ + led = &g_leds[type]; + + switch (state->flashMode) { + case LIGHT_FLASH_NONE: + /* Set LED to a solid color, spec is unclear on the exact behavior here. */ + led->delay_on = led->delay_off = 0; + break; + case LIGHT_FLASH_TIMED: + case LIGHT_FLASH_HARDWARE: + led->delay_on = state->flashOnMS; + led->delay_off = state->flashOffMS; + break; + default: + return -EINVAL; + } + + led->color = state->color & 0x00ffffff; + + if (led->color > 0) { + /* This LED is lit. */ + if (type >= g_cur_led) { + /* And it has the highest priority, so show it. */ + err = write_leds(led); + g_cur_led = type; + } + } else { + /* This LED is not (any longer) lit. */ + if (type == g_cur_led) { + /* But it is currently showing, switch to a lower-priority LED. */ + int i; + + for (i = type-1; i >= 0; i--) { + if (g_leds[i].color > 0) { + /* Found a lower-priority LED to switch to. */ + err = write_leds(&g_leds[i]); + goto switched; + } + } + + /* No LEDs are lit, turn off. */ + err = write_leds(NULL); +switched: + g_cur_led = i; + } + } + + return err; +} + +static int set_light_leds_battery(UNUSED struct light_device_t *dev, + struct light_state_t const *state) +{ + return set_light_leds(state, 0); +} + +static int set_light_leds_notifications(UNUSED struct light_device_t *dev, + struct light_state_t const *state) +{ + return set_light_leds(state, 1); +} + +static int set_light_leds_attention(UNUSED struct light_device_t *dev, + struct light_state_t const *state) +{ + struct light_state_t fixed; + + memcpy(&fixed, state, sizeof(fixed)); + + /* The framework does odd things with the attention lights, fix them up to + * do something sensible here. */ + switch (fixed.flashMode) { + case LIGHT_FLASH_NONE: + /* LightsService.Light::stopFlashing calls with non-zero color. */ + fixed.color = 0; + break; + case LIGHT_FLASH_HARDWARE: + /* PowerManagerService::setAttentionLight calls with onMS=3, offMS=0, which + * just makes for a slightly-dimmer LED. */ + if (fixed.flashOnMS > 0 && fixed.flashOffMS == 0) + fixed.flashMode = LIGHT_FLASH_NONE; + break; + } + + return set_light_leds(&fixed, 2); +} + +static int open_lights(const struct hw_module_t *module, char const *name, + struct hw_device_t **device) +{ + int (*set_light)(struct light_device_t *dev, + struct light_state_t const *state); + + if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) + set_light = set_light_backlight; + else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) + set_light = set_light_buttons; + else if (0 == strcmp(LIGHT_ID_BATTERY, name)) + set_light = set_light_leds_battery; + else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) + set_light = set_light_leds_notifications; + else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) + set_light = set_light_leds_attention; + else + return -EINVAL; + + pthread_once(&g_init, init_g_lock); + + struct light_device_t *dev = malloc(sizeof(struct light_device_t)); + memset(dev, 0, sizeof(*dev)); + + dev->common.tag = HARDWARE_DEVICE_TAG; + dev->common.version = 0; + dev->common.module = (struct hw_module_t *)module; + dev->common.close = (int (*)(struct hw_device_t *))close_lights; + dev->set_light = set_light; + + *device = (struct hw_device_t *)dev; + + return 0; +} + +static struct hw_module_methods_t lights_module_methods = { + .open = open_lights, +}; + +struct hw_module_t HAL_MODULE_INFO_SYM = { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = LIGHTS_HARDWARE_MODULE_ID, + .name = "D2 Lights Module", + .author = "The CyanogenMod Project", + .methods = &lights_module_methods, +}; diff --git a/libsecnativefeature/Android.mk b/libsecnativefeature/Android.mk new file mode 100644 index 0000000..7b78946 --- /dev/null +++ b/libsecnativefeature/Android.mk @@ -0,0 +1,21 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := \ + SecNativeFeatureCIf.cpp \ + SecNativeFeatureCppIf.cpp + +LOCAL_C_INCLUDES += \ + external/expat/lib + +LOCAL_SHARED_LIBRARIES := \ + libexpat + +LOCAL_CFLAGS := -Wall -Werror + +LOCAL_MODULE := libsecnativefeature +LOCAL_PROPRIETARY_MODULE := true + +include $(BUILD_SHARED_LIBRARY) diff --git a/libsecnativefeature/SecNativeFeature.h b/libsecnativefeature/SecNativeFeature.h new file mode 100644 index 0000000..4de0283 --- /dev/null +++ b/libsecnativefeature/SecNativeFeature.h @@ -0,0 +1,31 @@ +#ifndef SEC_NATIVE_FEATURE_H +#define SEC_NATIVE_FEATURE_H + +#include "SecNativeFeatureTagAll.h" + +// define TAG for default value +/* +#define Str_NoTag "" +#define Bool_NoTag false +#define Int_NoTag (0) + +#define TAG_BOOLEAN_TEST_TRUE "CscFeature_BooleanTestTrue" +#define TAG_BOOLEAN_TEST_FALSE "CscFeature_BooleanTestFalse" +#define TAG_BOOLEAN_TEST_NULL "CscFeature_BooleanTestNull" +#define TAG_STRING_TEST "CscFeature_StringTest" +#define TAG_STRING_TEST_NULL "CscFeature_StringTestNull" +#define TAG_INTEGER_TEST "CscFeature_IntegerTest" +#define TAG_INTEGER_TEST_NULL "CscFeature_IntegerTestNull" + +#define TAG_FMRADIO_RTPLUS "CscFeature_FMRadioRTPlus" +#define TAG_FMRADIO_SEASETTING "CscFeature_FMRadioSEASetting" +*/ + +#ifdef __cplusplus +#include "SecNativeFeatureCppIf.h" +#else +#include "SecNativeFeatureCIf.h" +#endif + +#endif // SEC_NATIVE_FEATURE_H + diff --git a/libsecnativefeature/SecNativeFeatureCIf.cpp b/libsecnativefeature/SecNativeFeatureCIf.cpp new file mode 100644 index 0000000..88a5405 --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureCIf.cpp @@ -0,0 +1,85 @@ +#include +#include +#include "SecNativeFeatureCppIf.h" +#include "SecNativeFeatureCIf.h" +#include +#include + + +int +SecNativeFeature_getEnableStatus(const char* tag) +{ + SecNativeFeature* instance = SecNativeFeature::getInstance(); + + if (instance) + { + return instance->getEnableStatus(tag); + } + + return 0; +} + +int +SecNativeFeature_getEnableStatusWithDefault(const char* tag, int defaultValue) +{ + SecNativeFeature* instance = SecNativeFeature::getInstance(); + + if (instance) + { + return instance->getEnableStatus(tag, defaultValue); + } + + return defaultValue; +} + +int +SecNativeFeature_getInteger(const char* tag) +{ + SecNativeFeature* instance = SecNativeFeature::getInstance(); + + if (instance) + { + return instance->getInteger(tag); + } + + return -1; +} + +int +SecNativeFeature_getIntegerWithDefault(const char* tag, int defaultValue) +{ + SecNativeFeature* instance = SecNativeFeature::getInstance(); + + if (instance) + { + return instance->getInteger(tag, defaultValue); + } + + return defaultValue; +} + +const char* +SecNativeFeature_getString(const char* tag) +{ + SecNativeFeature* instance = SecNativeFeature::getInstance(); + + if (instance) + { + return instance->getString(tag); + } + + return NULL; +} + +const char* +SecNativeFeature_getStringWithDefault(const char* tag, char* defaultValue) +{ + SecNativeFeature* instance = SecNativeFeature::getInstance(); + + if (instance) + { + return instance->getString(tag, defaultValue); + } + + return defaultValue; +} diff --git a/libsecnativefeature/SecNativeFeatureCIf.h b/libsecnativefeature/SecNativeFeatureCIf.h new file mode 100644 index 0000000..3d26168 --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureCIf.h @@ -0,0 +1,24 @@ +#ifndef SEC_NATIVE_FEATURE_CIF_H +#define SEC_NATIVE_FEATURE_CIF_H + +#ifdef __cplusplus +#define DECLARE_BEGIN_C extern "C" { +#define DECLARE_END_C } +#else +#define DECLARE_BEGIN_C +#define DECLARE_END_C +#endif + +DECLARE_BEGIN_C + +int SecNativeFeature_getEnableStatus(const char* tag); +int SecNativeFeature_getEnableStatusWithDefault(const char* tag, int defaultValue); +int SecNativeFeature_getInteger(const char* tag); +int SecNativeFeature_getIntegerWithDefault(const char* tag, int defaultValue); +const char* SecNativeFeature_getString(const char* tag); +const char* SecNativeFeature_getStringWithDefault(const char* tag, char* defaultValue); + +DECLARE_END_C + +#endif // SEC_NATIVE_FEATURE_CIF_H + diff --git a/libsecnativefeature/SecNativeFeatureCppIf.cpp b/libsecnativefeature/SecNativeFeatureCppIf.cpp new file mode 100644 index 0000000..d70ebe7 --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureCppIf.cpp @@ -0,0 +1,187 @@ +#include +#include +#include "SecNativeFeatureCppIf.h" +#include +#include + +// feature file location (which should be "/system/csc/feature.xml") +#define FEATURE_FILE "/system/csc/feature.xml" +// feature file location (which should be "/system/csc/others.xml") +#define MPS_FEATURE_FILE "/system/csc/others.xml" + +// XML parsing using expat lib - handlers +typedef struct{ + std::string curr_name; + std::map *pFeatures; + int depth; +} ParserUserData; + +static void XMLCALL +charDataHandler(void *userData, const char *s, int len){ + ParserUserData* pData = (ParserUserData*)userData; + std::string value(s, len); + std::string curr_name = pData->curr_name; + + if(!curr_name.empty()){ + std::map::iterator result = (*pData->pFeatures).find(curr_name); + + if (result != (*pData->pFeatures).end()) { + value = result->second + value; + (*pData->pFeatures).erase(curr_name); + } + + std::map::iterator begin; + begin = (*pData->pFeatures).begin(); + std::pair feature(curr_name,value); + (*pData->pFeatures).insert(begin, feature); + } + // else{ + // // printf("no name\n"); + // } +} + +static void XMLCALL +startElement(void *userData, const char *name, const char **atts __unused) +{ + ParserUserData* pData = (ParserUserData*)userData; + pData->curr_name.assign(name); + pData->depth += 1; +} + +static void XMLCALL +endElement(void *userData, const char *name __unused) +{ + ParserUserData* pData = (ParserUserData*)userData; + pData->curr_name.clear(); + pData->depth -= 1; +} + +// SecNativeFeture class implementation +SecNativeFeature* SecNativeFeature::_instance = NULL; +SecNativeFeature::SecNativeFeature() { + int load_result = 0; + _features.clear(); + load_result = _loadFeature(); + if (load_result == -1){ + // todo : handle _loadFeature errors here. + } +} + +SecNativeFeature::~SecNativeFeature() { + delete _instance; +} +SecNativeFeature* SecNativeFeature::getInstance() { + if(_instance == NULL) { + _instance = new SecNativeFeature(); + } + return _instance; +} + +bool SecNativeFeature::getEnableStatus(const char* tag) { + std::map::iterator found; + found = _features.find(tag); + + if(found == _features.end()) { + return false; + } + + if(found->second.compare("true") == 0 || found->second.compare("TRUE") == 0) { + return true; + } + return false; +} + +bool SecNativeFeature::getEnableStatus(const char* tag, bool defaultValue) { + std::map::iterator found; + found = _features.find(tag); + + if(found == _features.end()) { + return defaultValue; + } + + if(found->second.compare("true") == 0 || found->second.compare("TRUE") == 0) { + return true; + } + return defaultValue; +} + +const char* SecNativeFeature::getString(const char* tag) { + std::map::iterator found; + found = _features.find(tag); + + if(found == _features.end()) { + return ""; + } + return found->second.c_str(); +} + +const char* SecNativeFeature::getString(const char* tag, char* defaultValue) { + std::map::iterator found; + found = _features.find(tag); + + if(found == _features.end()) { + return defaultValue; + } + return found->second.c_str(); +} + +int SecNativeFeature::getInteger(const char* tag) { + std::map::iterator found; + found = _features.find(tag); + + if(found == _features.end()) { + return -1; + } + std::string raw_value = _features.find(tag)->second; + return atoi(raw_value.c_str()); +} + +int SecNativeFeature::getInteger(const char* tag, int defaultValue) { + std::map::iterator found; + found = _features.find(tag); + + if(found == _features.end()) { + return defaultValue; + } + std::string raw_value = _features.find(tag)->second; + return atoi(raw_value.c_str()); +} + +int SecNativeFeature::_loadFeature(){ + char buf[BUFSIZ]; + XML_Parser parser = XML_ParserCreate(NULL); + int done; + FILE * pFeatureFile = NULL; + ParserUserData userData; + userData.curr_name = std::string (); + userData.pFeatures = &_features; + userData.depth = 0; + + pFeatureFile = fopen(FEATURE_FILE, "r"); + if (pFeatureFile == NULL) { + pFeatureFile = fopen(MPS_FEATURE_FILE, "r"); + if (pFeatureFile == NULL) { + return -1; + } + } + XML_SetUserData(parser, &userData); + XML_SetElementHandler(parser, startElement, endElement); + XML_SetCharacterDataHandler(parser, charDataHandler); + do { + size_t len = fread(buf, 1, sizeof(buf), pFeatureFile); + if ((len != sizeof(buf)) && (ferror(pFeatureFile))){ + fclose(pFeatureFile); + return -1; + } + done = len < sizeof(buf); + if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { + if(pFeatureFile) { + fclose(pFeatureFile); + } + return -1; + } + } while (!done); + XML_ParserFree(parser); + fclose(pFeatureFile); + return 0; +} diff --git a/libsecnativefeature/SecNativeFeatureCppIf.h b/libsecnativefeature/SecNativeFeatureCppIf.h new file mode 100644 index 0000000..37cb085 --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureCppIf.h @@ -0,0 +1,27 @@ +#ifndef SEC_NATIVE_FEATURE_CPPIF_H +#define SEC_NATIVE_FEATURE_CPPIF_H + +#include +#include + +class SecNativeFeature { +public: + bool getEnableStatus(const char* tag); + bool getEnableStatus(const char* tag, bool defaultValue); + const char* getString(const char* tag); + const char* getString(const char* tag, char* defaultValue); + int getInteger(const char* tag); + int getInteger(const char* tag, int defaultValue); + + static SecNativeFeature* getInstance(); +private: + static SecNativeFeature* _instance; + SecNativeFeature(); + ~SecNativeFeature(); + int _loadFeature(); + int _loadDefault(); + std::map _features; +}; + +#endif // SEC_NATIVE_FEATURE_CPPIF_H + diff --git a/libsecnativefeature/SecNativeFeatureTagAll.h b/libsecnativefeature/SecNativeFeatureTagAll.h new file mode 100644 index 0000000..1bbc23f --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureTagAll.h @@ -0,0 +1,20 @@ +/* + * CSC Features + * Auto generated by gen_cscfeaturetag_ih.pl + * DO NOT EDIT THIS FILE + */ + +/* +#include "SecNativeFeatureTagGMS.h" +#include "SecNativeFeatureTagIMS.h" +#include "SecNativeFeatureTagMediaProvider.h" +#include "SecNativeFeatureTagNFC.h" +#include "SecNativeFeatureTagRIL.h" +#include "SecNativeFeatureTagStreaming.h" +#include "SecNativeFeatureTagWiFi.h" +#include "SecNativeFeatureTagBT.h" +*/ + +#include "SecNativeFeatureTagFramework.h" +#include "SecNativeFeatureTagCommon.h" +#include "SecNativeFeatureTagWeb.h" diff --git a/libsecnativefeature/SecNativeFeatureTagCommon.h b/libsecnativefeature/SecNativeFeatureTagCommon.h new file mode 100644 index 0000000..7439806 --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureTagCommon.h @@ -0,0 +1,9 @@ +#ifndef SEC_NATIVE_FEATURE_TAG_COMMON_H +#define SEC_NATIVE_FEATURE_TAG_COMMON_H + +// Note +// The string must be same as the string in CSCFeatureTagCommon.java +// Because one feature coulde be implemented both in java layer and in native layer +#define TAG_CSCFEATURE_COMMON_USECHAMELEON "CscFeature_Common_UseChameleon" + +#endif // SEC_NATIVE_FEATURE_TAG_COMMON_H diff --git a/libsecnativefeature/SecNativeFeatureTagFramework.h b/libsecnativefeature/SecNativeFeatureTagFramework.h new file mode 100644 index 0000000..a29d67c --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureTagFramework.h @@ -0,0 +1,16 @@ +#ifndef SEC_NATIVE_FEATURE_TAG_FRAMEWORK_H +#define SEC_NATIVE_FEATURE_TAG_FRAMEWORK_H + + +// Note +// The string must be same as the string in CSCFeatureTagFramework.java +// Because one feature coulde be implemented both in java layer and in native layer + + +#define TAG_CSCFEATURE_FRAMEWORK_ENABLEBIDIRECTION "CscFeature_Framework_EnableBidirection" + +#define TAG_CSCFEATURE_FRAMEWORK_ENABLEHARFBUZZ "CscFeature_Framework_EnableHarfbuzz" + +#define TAG_CSCFEATURE_FRAMEWORK_ENABLETHAIVIETRESHAPING "CscFeature_Framework_EnableThaiVietReshaping" + +#endif // SEC_NATIVE_FEATURE_TAG_FRAMEWORK_H diff --git a/libsecnativefeature/SecNativeFeatureTagWeb.h b/libsecnativefeature/SecNativeFeatureTagWeb.h new file mode 100644 index 0000000..100448a --- /dev/null +++ b/libsecnativefeature/SecNativeFeatureTagWeb.h @@ -0,0 +1,150 @@ +#ifndef SEC_NATIVE_FEATURE_TAG_WEB_H +#define SEC_NATIVE_FEATURE_TAG_WEB_H + + +// Note +// The string must be same as the string in CSCFeatureTagWeb.java +// Because one feature coulde be implemented both in java layer and in native layer + +// The default values for each types +// This means the specified TAG is not defined +#define CSCFeatureTagWeb_Str_NoTag "" +#define CSCFeatureTagWeb_Bool_NoTag false +#define CSCFeatureTagWeb_Int_NoTag 0 + +// To define custom UserAgent string +// If this value is not defined, the default Android UserAgent will be sent to server +#define CSCFeatureTagWeb_SetUserAgent "CscFeature_Web_SetUserAgent" + + +// To define UAProfile string +// If this value is not defined, UAProfile will not be sent to server +#define CSCFeatureTagWeb_SetUAProfile "CscFeature_Web_SetUAProfile" + +// Change homepage_base regardless language and APN +#define CscFeatureTagWeb_SetHomepageURL "CscFeature_Web_SetHomepageURL" +// Disable RSS button on the url bar +#define CscFeatureTagWeb_DisableRSS "CscFeature_Web_DisableRSS" +// Remove voicesearch button on the url bar +#define CscFeatureTagWeb_DisableVoiceSearch "CscFeature_Web_DisableVoiceSearch" +// Disable showing activity chooser on redirecting in case when 3rd party browser also installed +#define CscFeatureTagWeb_DisableRedirectionChooser "CscFeature_Web_DisableRedirectionChooser" + +// Enable UAProfile in Header +#define CscFeatureTagWeb_Bool_EnableUAProfile "CscFeature_Web_Bool_EnableUAProfile" + +// To Enable the GateConfig Logs(USA STA requirement for stability test) +#define CscFeatureTagWeb_Bool_EnableGateConfig "CscFeature_Web_EnableLogStabililtyTest" + +//add for Handling Operator UA +#define CscFeature_Web_OverrideUserAgent "CscFeature_Web_OverrideUserAgent" + +// add menu clear today history +#define CscFeatureTagWeb_EnableDeletingTodayHistory "CscFeature_Web_EnableDeletingTodayHistory" + + // To enable bookmark overwrite +#define CscFeatureTagWeb_EnableOverwritingBookmark "CscFeature_Web_EnableOverwritingBookmark" + +// To enable downloaded folder notification +#define CscFeatureTagWeb_EnableDownloadedFolderInNotificationBar "CscFeature_Web_EnableDownloadedFolderInNotificationBar" + + //Enable DeviceID at Header(USA ATT Requirement) +#define CscFeatureTag_Web_Bool_DeviceID "CscFeature_Web_UseDeviceIdInHeader" + +// support uploading contacts in VCard format (China-Telecom requirement) +#define CscFeatureTagWeb_SupportVcfUpload "CscFeature_Web_SupportVcfUpload" +//Parse XHTML document as HTML (ignore parse error. China-Telecom requirement) +#define CscFeatureTagWeb_ParseXHtmlToHtml "CscFeature_Web_ParseXHtmlToHtml" + + //Block SD & CD download ( NAGSM common requirement) +#define CscFeatureTag_Web_Bool_BlockSDCDDownload "CscFeature_Web_BlockSDCDDownload" + +// display download progress on notification bar (China-Telecom requirement) +#define CscFeatureTagWeb_ShowDownloadProgressOnNotification "CscFeature_Web_ShowDownloadProgressOnNotification" + +// show browser version in browser settings (China-Telecom requirement) +#define CscFeatureTagWeb_ShowVersionInSetting "CscFeature_Web_ShowVersionInSetting" + +// support "exit browser" option (China-Telecom requirement) +#define CscFeatureTagWeb_AddOptionToTerminate "CscFeature_Web_AddOptionToTerminate" +// Add "Delete-all" function at Download list (China-Telecom requirement) +#define CscFeatureTagWeb_EnableDeleteAllOnDownloadList "CscFeature_Web_EnableDeleteAllOnDownloadList" +// Support save-as function and default folder by mime-type (China-Telecom requirement) +#define CscFeatureTagWeb_SupportDownloadSaveAs "CscFeature_Web_SupportDownloadSaveAs" +// support delete-all option in bookmarks page (China-Telecom requirement) +#define CscFeatureTagWeb_EnableDeleteAllBookmarks "CscFeature_Web_EnableDeleteAllBookmarks" +// Add "FullHandwriting IME issue "(China-Common requirement) +#define CscFeatureTagWeb_EnableOptionEditTextDuringFullHwr "CscFeature_Web_EnableOptionEditTextDuringFullHwr" +// support offline-startup page includes bookmarks, history, search dialog (China-Telecom requirement) +#define CscFeatureTagWeb_SupportOfflineStartupPage "CscFeature_Web_SupportOfflineStartupPage" + +// support not to set factory-reset-homepage to PREF_HOMEPAGE +#define CscFeatureTagWeb_Bool_DisableSetFactoryResetHomeToPrefHome "CscFeature_Web_Bool_DisableSetFactoryResetHomeToPrefHome" + +// Show roaming dialog (ATT Requirement) +#define CscFeatureTagWeb_Bool_ShowRoamingDialog "CscFeature_Web_EnableRoamingDialog" + +// set download folder by mime-type for China-Telecom requirement +#define CscFeatureTagWeb_SetDownloadFolderNameByMimeType "CscFeature_Web_SetDownloadFolderNameByMimeType" + +// Disable showing activity chooser for defined string +#define CscFeature_Web_DisableChooser4 "CscFeature_Web_DisableChooser4" + +// Enable download hebrew filename +#define CscFeature_Web_SupportHebrewFileName "CscFeature_Web_SupportHebrewFileName" + +// remove google in search engine list +#define CscFeatureTagWeb_DisableGoogleInBrowserSearchEngine "CscFeature_Web_DisableGoogleInBrowserSearchEngine" + +// set off overview mode as default (CTC Requirement) +#define CscFeatureTagWeb_SetOffOverviewModeAsDefault "CscFeature_Web_SetOffOverviewModeAsDefault" + +// Disable setting homepage as it is set in APN when SIM changed +#define CscFeature_Web_EnableAutoSimHomeUrlInProfile "CscFeature_Web_EnableAutoSimHomeUrlInProfile" + +// Add download file name decode feature for China region +#define CscFeatureTagWeb_SupportDownloadedFileNameInChineseChar "CscFeature_Web_SupportDownloadedFileNameInChineseChar" + +// support multiAPN (CMCC Requirement) +#define CscFeatureTagWeb_EnableMultipleApn4 "CscFeature_Web_EnableMultipleApn4" + +// Enable Ask to exit on back (CMCC Requirement) +#define CscFeatureTagWeb_EnablePromptToExit "CscFeature_Web_EnablePromptToExit" + + +// Enable EMOJI for JPN +#define CscFeatureTagWeb_EnableEmoji "CscFeature_Web_Bool_EnableEmoji" + +// Show Wifi AP List when WIFI switch is on (CMCC Requirement) +#define CscFeatureTagWeb_ShowWifiAPList "CscFeature_Web_ShowWifiAPList" + + // Enable Operator's toolbar (ATT Requirement) +#define CscFeatureTagWeb_EnableOperatorToolbar "CscFeature_Web_EnableOperatorToolbar" + +// Set TCP Connection timout (China Requirement) +#define CscFeatureTagWeb_SetTcpConnTimeoutAs "CscFeature_Web_SetTcpConnTimeoutAs" + +// Add WML mime type to Accept Header (CMCC Requirement) +#define CscFeatureTagWeb_AddWmlToHttpAcceptHeader4 "CscFeature_Web_AddWmlToHttpAcceptHeader4" + +// change block zoom method to position based touch block zoom (Australia Requirement) +#define CscFeature_Web_BlockZoomBaseOnTouchPosition "CscFeature_Web_BlockZoomBaseOnTouchPosition" + +// Remove Partial View During Horizontal Scroll in Nav Screen (Australia Requirement) +#define CscFeature_Web_RemovePartialViewDuringHorizontalScroll "CscFeature_Web_RemovePartialViewDuringHorizontalScroll" + +// Show Popup for MaxLength reached during Url input (CMCC Requirement) +#define CscFeatureTagWeb_EnablePopup4MaxLengthReachedDuringUrlInput "CscFeature_Web_EnablePopup4MaxLengthReachedDuringUrlInput" + +// Support Tel Number in the page to go to dialing app (KOR Requirement) +#define CscFeature_Web_RecognizeTelNumber "CscFeature_Web_RecognizeTelNumber" + +// Large file transfer in Internet download (VZW Requirement) +#define CscFeature_Web_EnableWifiOption4LargeFileDownload "CscFeature_Web_EnableWifiOption4LargeFileDownload" + +// Add additional accept charset to Accept Header (CTC Requirement) +#define CscFeature_Web_AddCharSetToHttpHeader "CscFeature_Web_AddCharSetToHttpHeader" + +// max connection per host for performance +#define CscFeature_Web_MaxConnectionPerHost "CscFeature_Web_MaxConnectionPerHost" +#endif // SEC_NATIVE_FEATURE_TAG_WEB_H diff --git a/libwcnss_qmi/Android.mk b/libwcnss_qmi/Android.mk new file mode 100644 index 0000000..cba678f --- /dev/null +++ b/libwcnss_qmi/Android.mk @@ -0,0 +1,29 @@ +# Copyright (C) 2015 The CyanogenMod 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. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := wcnss_qmi_client.c + +LOCAL_C_INCLUDES += hardware/qcom/wlan/wcnss_service +LOCAL_CFLAGS += -Wall + +LOCAL_SHARED_LIBRARIES := libc libcutils libutils liblog + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libwcnss_qmi +LOCAL_VENDOR_MODULE := true + +include $(BUILD_SHARED_LIBRARY) diff --git a/libwcnss_qmi/wcnss_qmi_client.c b/libwcnss_qmi/wcnss_qmi_client.c new file mode 100644 index 0000000..fdc60fa --- /dev/null +++ b/libwcnss_qmi/wcnss_qmi_client.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015, The CyanogenMod 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. + */ + +//#define LOG_NDEBUG 0 + +#define LOG_TAG "wcnss_qmi" + +#define SUCCESS 0 +#define FAILED -1 + +#define MAC_INFO_FILE "/efs/wifi/.mac.info" + +#include +#include + +int wcnss_init_qmi(void) +{ + /* empty */ + return SUCCESS; +} + +int wcnss_qmi_get_wlan_address(unsigned char *mac) +{ + int i; + int tmp[6]; + FILE *f; + + if ((f = fopen(MAC_INFO_FILE, "r")) == NULL) { + ALOGE("%s: failed to open %s", __func__, MAC_INFO_FILE); + return FAILED; + } + + if (fscanf(f, "%02X:%02X:%02X:%02X:%02X:%02X", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]) != 6) { + ALOGE("%s: %s: file contents are not valid", __func__, MAC_INFO_FILE); + fclose(f); + return FAILED; + } else { + for (i = 0; i < 6; i++) mac[i] = tmp[i]; + } + + fclose(f); + return SUCCESS; +} + +void wcnss_qmi_deinit(void) +{ + /* empty */ +} diff --git a/lineage.dependencies b/lineage.dependencies new file mode 100644 index 0000000..e0e0967 --- /dev/null +++ b/lineage.dependencies @@ -0,0 +1,14 @@ +[ + { + "repository": "android_device_qcom_common", + "target_path": "device/qcom/common" + }, + { + "repository": "android_device_samsung_qcom-common", + "target_path": "device/samsung/qcom-common" + }, + { + "repository": "android_external_sony_boringssl-compat", + "target_path": "external/sony/boringssl-compat" + } +] diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 0000000..95f2fad --- /dev/null +++ b/manifest.xml @@ -0,0 +1,253 @@ + + + android.hardware.audio + hwbinder + 2.0 + + IDevicesFactory + default + + + + android.hardware.audio.effect + hwbinder + 2.0 + + IEffectsFactory + default + + + + android.hardware.bluetooth + hwbinder + 1.0 + + IBluetoothHci + default + + + + android.hardware.broadcastradio + passthrough + 1.0 + + + android.hardware.cas + hwbinder + 1.0 + + IMediaCasService + default + + + + android.hardware.configstore + hwbinder + 1.0 + + ISurfaceFlingerConfigs + default + + + + android.hardware.drm + hwbinder + 1.0 + + ICryptoFactory + default + + + IDrmFactory + default + + + + android.hardware.gnss + hwbinder + 1.0 + + IGnss + default + + + + android.hardware.graphics.allocator + hwbinder + 2.0 + + IAllocator + default + + + + android.hardware.graphics.composer + hwbinder + 2.1 + + IComposer + default + + + + android.hardware.graphics.mapper + passthrough + 2.0 + + IMapper + default + + + + android.hardware.keymaster + hwbinder + 3.0 + + IKeymasterDevice + default + + + + android.hardware.light + hwbinder + 2.0 + + ILight + default + + + + android.hardware.media.omx + hwbinder + 1.0 + + IOmx + default + + + IOmxStore + default + + + + android.hardware.memtrack + hwbinder + 1.0 + + IMemtrack + default + + + + android.hardware.nfc + hwbinder + 1.0 + + INfc + default + + + + android.hardware.power + hwbinder + 1.0 + + IPower + default + + + + android.hardware.radio + hwbinder + 1.1 + + IRadio + slot1 + + + ISap + slot1 + + + + android.hardware.radio.deprecated + hwbinder + 1.0 + + IOemHook + slot1 + + + + android.hardware.renderscript + passthrough + 1.0 + + IDevice + default + + + + android.hardware.sensors + hwbinder + 1.0 + + ISensors + default + + + + android.hardware.soundtrigger + hwbinder + 2.0 + + ISoundTriggerHw + default + + + + android.hardware.usb + hwbinder + 1.0 + + IUsb + default + + + + android.hardware.vibrator + hwbinder + 1.0 + + IVibrator + default + + + + android.hardware.wifi + hwbinder + 1.1 + + IWifi + default + + + + android.hardware.wifi.supplicant + hwbinder + 1.0 + + ISupplicant + default + + + + android.hardware.gatekeeper + passthrough + 1.0 + + IGatekeeper + default + + + diff --git a/msm8226.mk b/msm8226.mk new file mode 100644 index 0000000..2d36263 --- /dev/null +++ b/msm8226.mk @@ -0,0 +1,269 @@ +# Copyright (C) 2014 The CyanogenMod 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. + +$(call inherit-product, $(SRC_TARGET_DIR)/product/languages_full.mk) + +# Seccomp policy +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/seccomp_policy/mediacodec.policy:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediacodec.policy \ + $(LOCAL_PATH)/seccomp_policy/mediaextractor.policy:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediaextractor.policy + +# Overlay +DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay + +# HIDL +PRODUCT_PACKAGES += \ + android.hidl.base@1.0 \ + android.hidl.manager@1.0 + +# Screen density +PRODUCT_AAPT_CONFIG := normal +PRODUCT_AAPT_PREF_CONFIG := xhdpi + +# Boot animation +TARGET_SCREEN_HEIGHT := 1280 +TARGET_SCREEN_WIDTH := 720 + +# Audio +PRODUCT_PACKAGES += \ + android.hardware.audio@2.0-impl \ + android.hardware.audio@2.0-service \ + android.hardware.audio.effect@2.0-impl \ + android.hardware.audio.effect@2.0-service \ + android.hardware.broadcastradio@1.0-impl \ + android.hardware.soundtrigger@2.0-impl \ + android.hardware.soundtrigger@2.0-service \ + audio_policy.msm8226 \ + audio.a2dp.default \ + audio.primary.msm8226 \ + audio.r_submix.default \ + audio.usb.default \ + libaudio-resampler \ + libqcomvisualizer \ + libqcompostprocbundle \ + libqcomvoiceprocessing \ + tinymix + +# System properties +PRODUCT_PROPERTY_OVERRIDES += \ + audio.offload.buffer.size.kb=32 \ + audio.offload.gapless.enabled=false \ + av.offload.enable=true + +PRODUCT_PACKAGES += \ + libimx175_shim + +# Security +PRODUCT_PACKAGES += \ + android.hardware.weaver@1.0 + +# Camera +PRODUCT_PACKAGES += \ + libboringssl-compat \ + libxml2 + +# CRDA +PRODUCT_PACKAGES += \ + crda \ + linville.key.pub.pem \ + regdbdump \ + regulatory.bin + +# Display +PRODUCT_PACKAGES += \ + copybit.msm8226 \ + gralloc.msm8226 \ + hwcomposer.msm8226 \ + memtrack.msm8226 \ + android.hardware.graphics.allocator@2.0-impl \ + android.hardware.graphics.allocator@2.0-service \ + android.hardware.graphics.composer@2.1-impl \ + android.hardware.graphics.composer@2.1-service \ + android.hardware.graphics.mapper@2.0-impl \ + android.hardware.memtrack@1.0-impl \ + android.hardware.memtrack@1.0-service + +# RenderScript HAL +PRODUCT_PACKAGES += \ + android.hardware.renderscript@1.0-impl + +# Ebtables +PRODUCT_PACKAGES += \ + ebtables \ + ethertypes \ + libebtc + +# FM +PRODUCT_PACKAGES += \ + FMRadio \ + libfmjni + +# VNDK +PRODUCT_PACKAGES += \ + s3ve3g-vndk-extra + +# GPS +PRODUCT_PACKAGES += \ + gps.msm8226 + +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/gps/etc/gps.conf:$(TARGET_COPY_OUT_VENDOR)/etc/gps.conf \ + $(LOCAL_PATH)/gps/etc/flp.conf:$(TARGET_COPY_OUT_VENDOR)/etc/flp.conf \ + $(LOCAL_PATH)/gps/etc/izat.conf:$(TARGET_COPY_OUT_VENDOR)/etc/izat.conf \ + $(LOCAL_PATH)/gps/etc/sap.conf:$(TARGET_COPY_OUT_VENDOR)/etc/sap.conf + +PRODUCT_PACKAGES += \ + android.hardware.gnss@1.0-impl \ + android.hardware.gnss@1.0-service + +# Keylayouts +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/keylayout/Button_Jack.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/Button_Jack.kl \ + $(LOCAL_PATH)/keylayout/gpio-keys.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/gpio-keys.kl \ + $(LOCAL_PATH)/keylayout/sec_touchkey.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/sec_touchkey.kl \ + $(LOCAL_PATH)/keylayout/synaptics_rmi4_i2c.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/synaptics_rmi4_i2c.kl + +# Keystore +PRODUCT_PACKAGES += \ + keystore.msm8226 + +# Media +PRODUCT_COPY_FILES += \ + frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_audio.xml \ + frameworks/av/media/libstagefright/data/media_codecs_google_telephony.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_telephony.xml \ + frameworks/av/media/libstagefright/data/media_codecs_google_video.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_video.xml \ + $(LOCAL_PATH)/configs/media_codecs_performance.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_performance.xml \ + $(LOCAL_PATH)/configs/media_codecs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs.xml + +# OMX +PRODUCT_PACKAGES += \ + libOmxCore \ + libOmxVdec \ + libOmxVenc \ + libstagefrighthw + +# DRM +PRODUCT_PACKAGES += \ + android.hardware.drm@1.0-impl \ + android.hardware.drm@1.0-service + +# Permissions +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.audio.low_latency.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.low_latency.xml \ + frameworks/native/data/etc/android.hardware.bluetooth.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth.xml \ + frameworks/native/data/etc/android.hardware.bluetooth_le.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth_le.xml \ + frameworks/native/data/etc/android.hardware.camera.autofocus.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.autofocus.xml \ + frameworks/native/data/etc/android.hardware.camera.flash-autofocus.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.flash-autofocus.xml \ + frameworks/native/data/etc/android.hardware.camera.front.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.front.xml \ + frameworks/native/data/etc/android.hardware.camera.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.xml \ + frameworks/native/data/etc/android.hardware.location.gps.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.location.gps.xml \ + frameworks/native/data/etc/android.hardware.sensor.accelerometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.accelerometer.xml \ + frameworks/native/data/etc/android.hardware.sensor.compass.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.compass.xml \ + frameworks/native/data/etc/android.hardware.sensor.light.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.light.xml \ + frameworks/native/data/etc/android.hardware.sensor.proximity.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.proximity.xml \ + frameworks/native/data/etc/android.hardware.telephony.cdma.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.cdma.xml \ + frameworks/native/data/etc/android.hardware.telephony.gsm.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.gsm.xml \ + frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \ + frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \ + frameworks/native/data/etc/android.hardware.usb.host.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.host.xml \ + frameworks/native/data/etc/android.hardware.wifi.direct.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.direct.xml \ + frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml \ + frameworks/native/data/etc/android.software.sip.voip.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.sip.voip.xml \ + frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml \ + frameworks/native/data/etc/android.software.midi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.midi.xml + +# GPS HAL +PRODUCT_PACKAGES += \ + gps.msm8226 \ + android.hardware.gnss@1.0-impl + +# Sensor HAL +PRODUCT_PACKAGES += \ + android.hardware.sensors@1.0-impl \ + android.hardware.sensors@1.0-service.s3ve3g \ + sensors.msm8226 + +# Sensors +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/configs/_hals.conf:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/_hals.conf + +# Bluetooth +PRODUCT_PACKAGES += \ + libbt-vendor \ + android.hardware.bluetooth@1.0-impl \ + android.hardware.bluetooth@1.0-service + +# Keymaster HAL +PRODUCT_PACKAGES += \ + android.hardware.keymaster@3.0-impl \ + android.hardware.keymaster@3.0-service + +# Vibrator +PRODUCT_PACKAGES += \ + android.hardware.vibrator@1.0-service.lineage + +# USB HAL +PRODUCT_PACKAGES += \ + android.hardware.usb@1.0-service + +# Power +PRODUCT_PACKAGES += \ + android.hardware.power@1.0-impl \ + android.hardware.power@1.0-service \ + power.msm8226 + +# Radio +PRODUCT_PACKAGES += \ + libsecnativefeature + +# Ramdisk +PRODUCT_PACKAGES += \ + init.qcom.bt.sh \ + init.firmware.sh \ + init.ril.sh + +PRODUCT_PACKAGES += \ + init.qcom.power.rc \ + init.qcom.rc \ + init.qcom.usb.rc \ + init.recovery.qcom.rc \ + ueventd.qcom.rc + +# Lights +PRODUCT_PACKAGES += \ + android.hardware.light@2.0-impl \ + android.hardware.light@2.0-service \ + lights.msm8226 + +# Wifi +PRODUCT_PACKAGES += \ + dhcpcd.conf \ + hostapd \ + wificond \ + wpa_supplicant \ + wpa_supplicant.conf \ + libwpa_client \ + android.hardware.wifi@1.0-service + +# Torch +PRODUCT_PACKAGES += \ + Torch + +PRODUCT_PACKAGES += \ + libcurl \ + libwcnss_qmi \ + wcnss_service + +# Inherit from qcom-common +$(call inherit-product, device/samsung/qcom-common/qcom-common.mk) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml new file mode 100644 index 0000000..88ba24f --- /dev/null +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -0,0 +1,26 @@ + + + + + + + 3300 + + + + "/system/framework/arm/boot-framework.oat" + "/system/framework/arm/boot-framework.vdex" + "/system/framework/oat/arm/services.odex" + "/system/framework/oat/arm/services.vdex" + "/system/framework/arm/boot.oat" + "/system/framework/arm/boot.vdex" + "/system/framework/arm/boot-core-libart.oat" + "/system/framework/arm/boot-core-libart.vdex" + + + + true + false + + diff --git a/overlay/frameworks/base/packages/SettingsProvider/res/values/config.xml b/overlay/frameworks/base/packages/SettingsProvider/res/values/config.xml new file mode 100644 index 0000000..3d32c73 --- /dev/null +++ b/overlay/frameworks/base/packages/SettingsProvider/res/values/config.xml @@ -0,0 +1,22 @@ + + + + true + true + diff --git a/overlay/packages/apps/Dialer/res/values/config.xml b/overlay/packages/apps/Dialer/res/values/config.xml new file mode 100644 index 0000000..f225ddb --- /dev/null +++ b/overlay/packages/apps/Dialer/res/values/config.xml @@ -0,0 +1,17 @@ + + + + true + 4 + diff --git a/overlay/packages/apps/Mms/res/xml/mms_config.xml b/overlay/packages/apps/Mms/res/xml/mms_config.xml new file mode 100644 index 0000000..ccb9e61 --- /dev/null +++ b/overlay/packages/apps/Mms/res/xml/mms_config.xml @@ -0,0 +1,72 @@ + + + + + + + + true + + + 307200 + + + 1944 + + + 2592 + + + 10000 + + + 1000 + + + 10 + + + 5000 + + + http://gsm.lge.com/html/gsm/Nexus5-M3.xml + + + -1 + + + true + + + -1 + + + Nexus5 + + diff --git a/overlay/packages/apps/Settings/res/values/bools.xml b/overlay/packages/apps/Settings/res/values/bools.xml new file mode 100644 index 0000000..b756a0b --- /dev/null +++ b/overlay/packages/apps/Settings/res/values/bools.xml @@ -0,0 +1,22 @@ + + + + + true + diff --git a/overlay/packages/apps/Snap/res/values/config.xml b/overlay/packages/apps/Snap/res/values/config.xml new file mode 100644 index 0000000..0db5ee0 --- /dev/null +++ b/overlay/packages/apps/Snap/res/values/config.xml @@ -0,0 +1,28 @@ + + + + + + false + + + false + + + true + + + true + diff --git a/overlay/packages/apps/Torch/res/values/config.xml b/overlay/packages/apps/Torch/res/values/config.xml new file mode 100644 index 0000000..e6abfae --- /dev/null +++ b/overlay/packages/apps/Torch/res/values/config.xml @@ -0,0 +1,33 @@ + + + + + /sys/class/leds/led:flash_torch/brightness + + + 5 + + 175 + + 255 + + + true + + diff --git a/power/Android.mk b/power/Android.mk new file mode 100644 index 0000000..3e2da09 --- /dev/null +++ b/power/Android.mk @@ -0,0 +1,26 @@ +# +# Copyright 2016 The CyanogenMod 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. +# + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) +LOCAL_C_INCLUDES := $(TARGET_POWERHAL_HEADER_PATH) +LOCAL_SRC_FILES := power.c +LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := power.msm8226 +LOCAL_PROPRIETARY_MODULE := true +include $(BUILD_SHARED_LIBRARY) diff --git a/power/power.c b/power/power.c new file mode 100644 index 0000000..21bcf87 --- /dev/null +++ b/power/power.c @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2016 The CyanogenMod 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. + */ +#define LOG_TAG "PowerHAL" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "power.h" + +#define CPUFREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/" +#define INTERACTIVE_PATH "/sys/devices/system/cpu/cpufreq/interactive/" + +/* touchkeys */ +#define TK_POWER "/sys/class/input/input1/enabled" +/* touchscreen */ +#define TS_POWER "/sys/class/input/input2/enabled" + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +static int boostpulse_fd = -1; + +// Balanced profile by default +static int current_power_profile = 1; +static int requested_power_profile = -1; + +static int sysfs_write_str(char *path, char *s) +{ + char buf[80]; + int len; + int ret = 0; + int fd; + + fd = open(path, O_WRONLY); + if (fd < 0) { + strerror_r(errno, buf, sizeof(buf)); + ALOGE("Error opening %s: %s\n", path, buf); + return -1 ; + } + + len = write(fd, s, strlen(s)); + if (len < 0) { + strerror_r(errno, buf, sizeof(buf)); + ALOGE("Error writing to %s: %s\n", path, buf); + ret = -1; + } + + close(fd); + + return ret; +} + +static int sysfs_write_int(char *path, int value) +{ + char buf[80]; + snprintf(buf, 80, "%d", value); + return sysfs_write_str(path, buf); +} + +static int is_profile_valid(int profile) +{ + return profile >= 0 && profile < PROFILE_MAX; +} + +static void power_init(__attribute__((unused)) struct power_module *module) +{ + ALOGI("%s", __func__); +} + +static int boostpulse_open() +{ + pthread_mutex_lock(&lock); + if (boostpulse_fd < 0) { + boostpulse_fd = open(INTERACTIVE_PATH "boostpulse", O_WRONLY); + } + pthread_mutex_unlock(&lock); + + return boostpulse_fd; +} + +static void power_set_interactive_ext(int on) { + ALOGD("%s: %s input devices", __func__, on ? "enabling" : "disabling"); + sysfs_write_str(TK_POWER, on ? "1" : "0"); + sysfs_write_str(TS_POWER, on ? "1" : "0"); +} + +static void power_set_interactive(__attribute__((unused)) struct power_module *module, int on) +{ + /* We want to first set the input device state otherwise + * it never gets turned off/on when our HAL isnt compatible with the power_profiles from + * our framework + */ + power_set_interactive_ext(on); +} + +static void set_power_profile(__attribute__((unused)) int profile) +{ + return; +} + +static void power_hint(__attribute__((unused)) struct power_module *module, + power_hint_t hint, void *data) +{ + char buf[80]; + int len; + + switch (hint) { + case POWER_HINT_INTERACTION: + case POWER_HINT_SET_PROFILE: + pthread_mutex_lock(&lock); + set_power_profile(*(int32_t *)data); + pthread_mutex_unlock(&lock); + break; + case POWER_HINT_LOW_POWER: + /* This hint is handled by the framework */ + break; + default: + break; + } +} + +static int get_feature(__attribute__((unused)) struct power_module *module, + feature_t feature) +{ + if (feature == POWER_FEATURE_SUPPORTED_PROFILES) { + return PROFILE_MAX; + } + return -1; +} + +static int power_open(const hw_module_t* module, const char* name, + hw_device_t** device) +{ + ALOGD("%s: enter; name=%s", __FUNCTION__, name); + + if (strcmp(name, POWER_HARDWARE_MODULE_ID)) { + return -EINVAL; + } + + power_module_t *dev = (power_module_t *)calloc(1, + sizeof(power_module_t)); + + if (!dev) { + ALOGD("%s: failed to allocate memory", __FUNCTION__); + return -ENOMEM; + } + + dev->common.tag = HARDWARE_MODULE_TAG; + dev->common.module_api_version = POWER_MODULE_API_VERSION_0_2; + dev->common.hal_api_version = HARDWARE_HAL_API_VERSION; + + dev->init = power_init; + dev->powerHint = power_hint; // This is handled by framework + dev->setInteractive = power_set_interactive; + dev->getFeature = get_feature; + + *device = (hw_device_t*)dev; + + ALOGD("%s: exit", __FUNCTION__); + + return 0; +} + +static struct hw_module_methods_t power_module_methods = { + .open = power_open, +}; + +struct power_module HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .module_api_version = POWER_MODULE_API_VERSION_0_2, + .hal_api_version = HARDWARE_HAL_API_VERSION, + .id = POWER_HARDWARE_MODULE_ID, + .name = "MSM8226 Power HAL", + .author = "The LineageOS Project", + .methods = &power_module_methods, + }, + + .init = power_init, + .setInteractive = power_set_interactive, + .powerHint = power_hint, + .getFeature = get_feature +}; diff --git a/power/power.h b/power/power.h new file mode 100644 index 0000000..baba258 --- /dev/null +++ b/power/power.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2016 The CyanogenMod 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. + */ + +enum { + PROFILE_POWER_SAVE = 0, + PROFILE_BALANCED, + PROFILE_HIGH_PERFORMANCE, + PROFILE_BIAS_POWER_SAVE, + PROFILE_MAX +}; + +typedef struct governor_settings { + int is_interactive; + int boost; + int boostpulse_duration; + int go_hispeed_load; + int go_hispeed_load_off; + int hispeed_freq; + int hispeed_freq_off; + int min_sample_time; + int timer_rate; + int above_hispeed_delay; + int target_loads; + int target_loads_off; + int scaling_max_freq; + int scaling_min_freq; + int scaling_min_freq_off; +} power_profile; + +static power_profile profiles[PROFILE_MAX] = { + [PROFILE_POWER_SAVE] = { + .boost = 0, + .boostpulse_duration = 0, + .go_hispeed_load = 90, + .go_hispeed_load_off = 90, + .hispeed_freq = 787200, + .hispeed_freq_off = 787200, + .min_sample_time = 60000, + .timer_rate = 20000, + .above_hispeed_delay = 20000, + .target_loads = 90, + .target_loads_off = 90, + .scaling_max_freq = 998400, + .scaling_min_freq = 384000, + .scaling_min_freq_off = 300000, + }, + [PROFILE_BALANCED] = { + .boost = 0, + .boostpulse_duration = 60000, + .go_hispeed_load = 80, + .go_hispeed_load_off = 90, + .hispeed_freq = 998400, + .hispeed_freq_off = 787200, + .min_sample_time = 60000, + .timer_rate = 20000, + .above_hispeed_delay = 20000, + .target_loads = 80, + .target_loads_off = 90, + .scaling_max_freq = 1401600, + // Our scaling_min_freq shouldnt be above our minimum any time! + .scaling_min_freq = 384000, + .scaling_min_freq_off = 300000, + }, + [PROFILE_HIGH_PERFORMANCE] = { + .boost = 1, + /* The CPU is already boosted, set duration to zero + * to avoid unneccessary writes to boostpulse */ + .boostpulse_duration = 0, + .go_hispeed_load = 60, + .go_hispeed_load_off = 70, + .hispeed_freq = 998400, + .hispeed_freq_off = 998400, + .min_sample_time = 60000, + .timer_rate = 20000, + .above_hispeed_delay = 20000, + .target_loads = 60, + .target_loads_off = 70, + .scaling_max_freq = 1401600, + .scaling_min_freq = 787200, + .scaling_min_freq_off = 300000, + }, + [PROFILE_BIAS_POWER_SAVE] = { + .boost = 0, + .boostpulse_duration = 40000, + .go_hispeed_load = 90, + .go_hispeed_load_off = 90, + .hispeed_freq = 787200, + .hispeed_freq_off = 787200, + .min_sample_time = 60000, + .timer_rate = 20000, + .above_hispeed_delay = 20000, + .target_loads = 90, + .target_loads_off = 90, + .scaling_max_freq = 1190400, + .scaling_min_freq = 384000, + .scaling_min_freq_off = 300000, + }, +}; diff --git a/ril/Android.mk b/ril/Android.mk new file mode 100644 index 0000000..5dcfbb5 --- /dev/null +++ b/ril/Android.mk @@ -0,0 +1,17 @@ +# +# Copyright (C) 2018 The LineageOS 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. +# + +include $(call first-makefiles-under,$(call my-dir)) diff --git a/ril/include/libril/ril_ex.h b/ril/include/libril/ril_ex.h new file mode 100644 index 0000000..757bcf9 --- /dev/null +++ b/ril/include/libril/ril_ex.h @@ -0,0 +1,49 @@ +/* +* Copyright (C) 2014 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. +*/ + +#ifndef RIL_EX_H_INCLUDED +#define RIL_EX_H_INCLUDED + +#include +#include + +#define NUM_ELEMS_SOCKET(a) (sizeof (a) / sizeof (a)[0]) + +struct ril_event; + +void rilEventAddWakeup_helper(struct ril_event *ev); +int blockingWrite_helper(int fd, void* data, size_t len); + +enum SocketWakeType {DONT_WAKE, WAKE_PARTIAL}; + +typedef enum { + RIL_TELEPHONY_SOCKET, + RIL_SAP_SOCKET +} RIL_SOCKET_TYPE; + +typedef struct SocketListenParam { + RIL_SOCKET_ID socket_id; + int fdListen; + int fdCommand; + const char* processName; + struct ril_event* commands_event; + struct ril_event* listen_event; + void (*processCommandsCallback)(int fd, short flags, void *param); + RecordStream *p_rs; + RIL_SOCKET_TYPE type; +} SocketListenParam; + +#endif diff --git a/ril/include/samsung_ril.h b/ril/include/samsung_ril.h new file mode 100644 index 0000000..952dbf0 --- /dev/null +++ b/ril/include/samsung_ril.h @@ -0,0 +1,19 @@ +/* +** +** Copyright 2018, The LineageOS 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. +*/ + +static inline void remapUnsol(int *unsol __unused) { +} diff --git a/ril/include/telephony/ril.h b/ril/include/telephony/ril.h new file mode 100644 index 0000000..734a12b --- /dev/null +++ b/ril/include/telephony/ril.h @@ -0,0 +1,7360 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * Copyright (C) 2018 The LineageOS 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. + */ + +#ifndef ANDROID_RIL_H +#define ANDROID_RIL_H 1 + +#include +#include +#include +#include +#include + +#ifndef FEATURE_UNIT_TEST +#include +#endif /* !FEATURE_UNIT_TEST */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef SIM_COUNT +#if defined(ANDROID_SIM_COUNT_2) +#define SIM_COUNT 2 +#elif defined(ANDROID_SIM_COUNT_3) +#define SIM_COUNT 3 +#elif defined(ANDROID_SIM_COUNT_4) +#define SIM_COUNT 4 +#else +#define SIM_COUNT 1 +#endif + +#ifndef ANDROID_MULTI_SIM +#define SIM_COUNT 1 +#endif +#endif + +/* + * RIL version. + * Value of RIL_VERSION should not be changed in future. Here onwards, + * when a new change is supposed to be introduced which could involve new + * schemes added like Wakelocks, data structures added/updated, etc, we would + * just document RIL version associated with that change below. When OEM updates its + * RIL with those changes, they would return that new RIL version during RIL_REGISTER. + * We should make use of the returned version by vendor to identify appropriate scheme + * or data structure version to use. + * + * Documentation of RIL version and associated changes + * RIL_VERSION = 12 : This version corresponds to updated data structures namely + * RIL_Data_Call_Response_v11, RIL_SIM_IO_v6, RIL_CardStatus_v6, + * RIL_SimRefreshResponse_v7, RIL_CDMA_CallWaiting_v6, + * RIL_LTE_SignalStrength_v8, RIL_SignalStrength_v10, RIL_CellIdentityGsm_v12 + * RIL_CellIdentityWcdma_v12, RIL_CellIdentityLte_v12,RIL_CellInfoGsm_v12, + * RIL_CellInfoWcdma_v12, RIL_CellInfoLte_v12, RIL_CellInfo_v12. + * + * RIL_VERSION = 13 : This version includes new wakelock semantics and as the first + * strongly versioned version it enforces structure use. + * + * RIL_VERSION = 14 : New data structures are added, namely RIL_CarrierMatchType, + * RIL_Carrier, RIL_CarrierRestrictions and RIL_PCO_Data. + * New commands added: RIL_REQUEST_SET_CARRIER_RESTRICTIONS, + * RIL_REQUEST_SET_CARRIER_RESTRICTIONS and RIL_UNSOL_PCO_DATA. + * + * RIL_VERSION = 15 : New commands added: + * RIL_UNSOL_MODEM_RESTART, + * RIL_REQUEST_SEND_DEVICE_STATE, + * RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, + * RIL_REQUEST_SET_SIM_CARD_POWER, + * RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, + * RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION + * The new parameters for RIL_REQUEST_SETUP_DATA_CALL, + * Updated data structures: RIL_DataProfileInfo_v15, RIL_InitialAttachApn_v15 + * New data structure RIL_DataRegistrationStateResponse, + * RIL_VoiceRegistrationStateResponse same is + * used in RIL_REQUEST_DATA_REGISTRATION_STATE and + * RIL_REQUEST_VOICE_REGISTRATION_STATE respectively. + * New data structure RIL_OpenChannelParams. + * RIL_REQUEST_START_NETWORK_SCAN + * RIL_REQUEST_STOP_NETWORK_SCAN + * RIL_UNSOL_NETWORK_SCAN_RESULT + */ +#define RIL_VERSION 12 +#define LAST_IMPRECISE_RIL_VERSION 12 // Better self-documented name +#define RIL_VERSION_MIN 6 /* Minimum RIL_VERSION supported */ + +#define CDMA_ALPHA_INFO_BUFFER_LENGTH 64 +#define CDMA_NUMBER_INFO_BUFFER_LENGTH 81 + +#define MAX_RILDS 3 +#define MAX_SERVICE_NAME_LENGTH 6 +#define MAX_CLIENT_ID_LENGTH 2 +#define MAX_DEBUG_SOCKET_NAME_LENGTH 12 +#define MAX_QEMU_PIPE_NAME_LENGTH 11 +#define MAX_UUID_LENGTH 64 +#define MAX_BANDS 8 +#define MAX_CHANNELS 32 +#define MAX_RADIO_ACCESS_NETWORKS 8 + + +typedef void * RIL_Token; + +typedef enum { + RIL_SOCKET_1, +#if (SIM_COUNT >= 2) + RIL_SOCKET_2, +#if (SIM_COUNT >= 3) + RIL_SOCKET_3, +#endif +#if (SIM_COUNT >= 4) + RIL_SOCKET_4, +#endif +#endif + RIL_SOCKET_NUM +} RIL_SOCKET_ID; + + +typedef enum { + RIL_E_SUCCESS = 0, + RIL_E_RADIO_NOT_AVAILABLE = 1, /* If radio did not start or is resetting */ + RIL_E_GENERIC_FAILURE = 2, + RIL_E_PASSWORD_INCORRECT = 3, /* for PIN/PIN2 methods only! */ + RIL_E_SIM_PIN2 = 4, /* Operation requires SIM PIN2 to be entered */ + RIL_E_SIM_PUK2 = 5, /* Operation requires SIM PIN2 to be entered */ + RIL_E_REQUEST_NOT_SUPPORTED = 6, + RIL_E_CANCELLED = 7, + RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL = 8, /* data ops are not allowed during voice + call on a Class C GPRS device */ + RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW = 9, /* data ops are not allowed before device + registers in network */ + RIL_E_SMS_SEND_FAIL_RETRY = 10, /* fail to send sms and need retry */ + RIL_E_SIM_ABSENT = 11, /* fail to set the location where CDMA subscription + shall be retrieved because of SIM or RUIM + card absent */ + RIL_E_SUBSCRIPTION_NOT_AVAILABLE = 12, /* fail to find CDMA subscription from specified + location */ + RIL_E_MODE_NOT_SUPPORTED = 13, /* HW does not support preferred network type */ + RIL_E_FDN_CHECK_FAILURE = 14, /* command failed because recipient is not on FDN list */ + RIL_E_ILLEGAL_SIM_OR_ME = 15, /* network selection failed due to + illegal SIM or ME */ + RIL_E_MISSING_RESOURCE = 16, /* no logical channel available */ + RIL_E_NO_SUCH_ELEMENT = 17, /* application not found on SIM */ + RIL_E_DIAL_MODIFIED_TO_USSD = 18, /* DIAL request modified to USSD */ + RIL_E_DIAL_MODIFIED_TO_SS = 19, /* DIAL request modified to SS */ + RIL_E_DIAL_MODIFIED_TO_DIAL = 20, /* DIAL request modified to DIAL with different + data */ + RIL_E_USSD_MODIFIED_TO_DIAL = 21, /* USSD request modified to DIAL */ + RIL_E_USSD_MODIFIED_TO_SS = 22, /* USSD request modified to SS */ + RIL_E_USSD_MODIFIED_TO_USSD = 23, /* USSD request modified to different USSD + request */ + RIL_E_SS_MODIFIED_TO_DIAL = 24, /* SS request modified to DIAL */ + RIL_E_SS_MODIFIED_TO_USSD = 25, /* SS request modified to USSD */ + RIL_E_SUBSCRIPTION_NOT_SUPPORTED = 26, /* Subscription not supported by RIL */ + RIL_E_SS_MODIFIED_TO_SS = 27, /* SS request modified to different SS request */ + RIL_E_LCE_NOT_SUPPORTED = 36, /* LCE service not supported(36 in RILConstants.java) */ + RIL_E_NO_MEMORY = 37, /* Not sufficient memory to process the request */ + RIL_E_INTERNAL_ERR = 38, /* Modem hit unexpected error scenario while handling + this request */ + RIL_E_SYSTEM_ERR = 39, /* Hit platform or system error */ + RIL_E_MODEM_ERR = 40, /* Vendor RIL got unexpected or incorrect response + from modem for this request */ + RIL_E_INVALID_STATE = 41, /* Unexpected request for the current state */ + RIL_E_NO_RESOURCES = 42, /* Not sufficient resource to process the request */ + RIL_E_SIM_ERR = 43, /* Received error from SIM card */ + RIL_E_INVALID_ARGUMENTS = 44, /* Received invalid arguments in request */ + RIL_E_INVALID_SIM_STATE = 45, /* Can not process the request in current SIM state */ + RIL_E_INVALID_MODEM_STATE = 46, /* Can not process the request in current Modem state */ + RIL_E_INVALID_CALL_ID = 47, /* Received invalid call id in request */ + RIL_E_NO_SMS_TO_ACK = 48, /* ACK received when there is no SMS to ack */ + RIL_E_NETWORK_ERR = 49, /* Received error from network */ + RIL_E_REQUEST_RATE_LIMITED = 50, /* Operation denied due to overly-frequent requests */ + RIL_E_SIM_BUSY = 51, /* SIM is busy */ + RIL_E_SIM_FULL = 52, /* The target EF is full */ + RIL_E_NETWORK_REJECT = 53, /* Request is rejected by network */ + RIL_E_OPERATION_NOT_ALLOWED = 54, /* Not allowed the request now */ + RIL_E_EMPTY_RECORD = 55, /* The request record is empty */ + RIL_E_INVALID_SMS_FORMAT = 56, /* Invalid sms format */ + RIL_E_ENCODING_ERR = 57, /* Message not encoded properly */ + RIL_E_INVALID_SMSC_ADDRESS = 58, /* SMSC address specified is invalid */ + RIL_E_NO_SUCH_ENTRY = 59, /* No such entry present to perform the request */ + RIL_E_NETWORK_NOT_READY = 60, /* Network is not ready to perform the request */ + RIL_E_NOT_PROVISIONED = 61, /* Device doesnot have this value provisioned */ + RIL_E_NO_SUBSCRIPTION = 62, /* Device doesnot have subscription */ + RIL_E_NO_NETWORK_FOUND = 63, /* Network cannot be found */ + RIL_E_DEVICE_IN_USE = 64, /* Operation cannot be performed because the device + is currently in use */ + RIL_E_ABORTED = 65, /* Operation aborted */ + RIL_E_INVALID_RESPONSE = 66, /* Invalid response sent by vendor code */ + // OEM specific error codes. To be used by OEM when they don't want to reveal + // specific error codes which would be replaced by Generic failure. + RIL_E_OEM_ERROR_1 = 501, + RIL_E_OEM_ERROR_2 = 502, + RIL_E_OEM_ERROR_3 = 503, + RIL_E_OEM_ERROR_4 = 504, + RIL_E_OEM_ERROR_5 = 505, + RIL_E_OEM_ERROR_6 = 506, + RIL_E_OEM_ERROR_7 = 507, + RIL_E_OEM_ERROR_8 = 508, + RIL_E_OEM_ERROR_9 = 509, + RIL_E_OEM_ERROR_10 = 510, + RIL_E_OEM_ERROR_11 = 511, + RIL_E_OEM_ERROR_12 = 512, + RIL_E_OEM_ERROR_13 = 513, + RIL_E_OEM_ERROR_14 = 514, + RIL_E_OEM_ERROR_15 = 515, + RIL_E_OEM_ERROR_16 = 516, + RIL_E_OEM_ERROR_17 = 517, + RIL_E_OEM_ERROR_18 = 518, + RIL_E_OEM_ERROR_19 = 519, + RIL_E_OEM_ERROR_20 = 520, + RIL_E_OEM_ERROR_21 = 521, + RIL_E_OEM_ERROR_22 = 522, + RIL_E_OEM_ERROR_23 = 523, + RIL_E_OEM_ERROR_24 = 524, + RIL_E_OEM_ERROR_25 = 525 +} RIL_Errno; + +typedef enum { + RIL_CALL_ACTIVE = 0, + RIL_CALL_HOLDING = 1, + RIL_CALL_DIALING = 2, /* MO call only */ + RIL_CALL_ALERTING = 3, /* MO call only */ + RIL_CALL_INCOMING = 4, /* MT call only */ + RIL_CALL_WAITING = 5 /* MT call only */ +} RIL_CallState; + +typedef enum { + RADIO_STATE_OFF = 0, /* Radio explictly powered off (eg CFUN=0) */ + RADIO_STATE_UNAVAILABLE = 1, /* Radio unavailable (eg, resetting or not booted) */ + RADIO_STATE_ON = 10 /* Radio is on */ +} RIL_RadioState; + +typedef enum { + RADIO_TECH_UNKNOWN = 0, + RADIO_TECH_GPRS = 1, + RADIO_TECH_EDGE = 2, + RADIO_TECH_UMTS = 3, + RADIO_TECH_IS95A = 4, + RADIO_TECH_IS95B = 5, + RADIO_TECH_1xRTT = 6, + RADIO_TECH_EVDO_0 = 7, + RADIO_TECH_EVDO_A = 8, + RADIO_TECH_HSDPA = 9, + RADIO_TECH_HSUPA = 10, + RADIO_TECH_HSPA = 11, + RADIO_TECH_EVDO_B = 12, + RADIO_TECH_EHRPD = 13, + RADIO_TECH_LTE = 14, + RADIO_TECH_HSPAP = 15, // HSPA+ + RADIO_TECH_GSM = 16, // Only supports voice + RADIO_TECH_TD_SCDMA = 17, + RADIO_TECH_IWLAN = 18, + RADIO_TECH_LTE_CA = 19 +} RIL_RadioTechnology; + +typedef enum { + RAF_UNKNOWN = (1 << RADIO_TECH_UNKNOWN), + RAF_GPRS = (1 << RADIO_TECH_GPRS), + RAF_EDGE = (1 << RADIO_TECH_EDGE), + RAF_UMTS = (1 << RADIO_TECH_UMTS), + RAF_IS95A = (1 << RADIO_TECH_IS95A), + RAF_IS95B = (1 << RADIO_TECH_IS95B), + RAF_1xRTT = (1 << RADIO_TECH_1xRTT), + RAF_EVDO_0 = (1 << RADIO_TECH_EVDO_0), + RAF_EVDO_A = (1 << RADIO_TECH_EVDO_A), + RAF_HSDPA = (1 << RADIO_TECH_HSDPA), + RAF_HSUPA = (1 << RADIO_TECH_HSUPA), + RAF_HSPA = (1 << RADIO_TECH_HSPA), + RAF_EVDO_B = (1 << RADIO_TECH_EVDO_B), + RAF_EHRPD = (1 << RADIO_TECH_EHRPD), + RAF_LTE = (1 << RADIO_TECH_LTE), + RAF_HSPAP = (1 << RADIO_TECH_HSPAP), + RAF_GSM = (1 << RADIO_TECH_GSM), + RAF_TD_SCDMA = (1 << RADIO_TECH_TD_SCDMA), + RAF_LTE_CA = (1 << RADIO_TECH_LTE_CA) +} RIL_RadioAccessFamily; + +typedef enum { + BAND_MODE_UNSPECIFIED = 0, //"unspecified" (selected by baseband automatically) + BAND_MODE_EURO = 1, //"EURO band" (GSM-900 / DCS-1800 / WCDMA-IMT-2000) + BAND_MODE_USA = 2, //"US band" (GSM-850 / PCS-1900 / WCDMA-850 / WCDMA-PCS-1900) + BAND_MODE_JPN = 3, //"JPN band" (WCDMA-800 / WCDMA-IMT-2000) + BAND_MODE_AUS = 4, //"AUS band" (GSM-900 / DCS-1800 / WCDMA-850 / WCDMA-IMT-2000) + BAND_MODE_AUS_2 = 5, //"AUS band 2" (GSM-900 / DCS-1800 / WCDMA-850) + BAND_MODE_CELL_800 = 6, //"Cellular" (800-MHz Band) + BAND_MODE_PCS = 7, //"PCS" (1900-MHz Band) + BAND_MODE_JTACS = 8, //"Band Class 3" (JTACS Band) + BAND_MODE_KOREA_PCS = 9, //"Band Class 4" (Korean PCS Band) + BAND_MODE_5_450M = 10, //"Band Class 5" (450-MHz Band) + BAND_MODE_IMT2000 = 11, //"Band Class 6" (2-GMHz IMT2000 Band) + BAND_MODE_7_700M_2 = 12, //"Band Class 7" (Upper 700-MHz Band) + BAND_MODE_8_1800M = 13, //"Band Class 8" (1800-MHz Band) + BAND_MODE_9_900M = 14, //"Band Class 9" (900-MHz Band) + BAND_MODE_10_800M_2 = 15, //"Band Class 10" (Secondary 800-MHz Band) + BAND_MODE_EURO_PAMR_400M = 16, //"Band Class 11" (400-MHz European PAMR Band) + BAND_MODE_AWS = 17, //"Band Class 15" (AWS Band) + BAND_MODE_USA_2500M = 18 //"Band Class 16" (US 2.5-GHz Band) +} RIL_RadioBandMode; + +typedef enum { + RC_PHASE_CONFIGURED = 0, // LM is configured is initial value and value after FINISH completes + RC_PHASE_START = 1, // START is sent before Apply and indicates that an APPLY will be + // forthcoming with these same parameters + RC_PHASE_APPLY = 2, // APPLY is sent after all LM's receive START and returned + // RIL_RadioCapability.status = 0, if any START's fail no + // APPLY will be sent + RC_PHASE_UNSOL_RSP = 3, // UNSOL_RSP is sent with RIL_UNSOL_RADIO_CAPABILITY + RC_PHASE_FINISH = 4 // FINISH is sent after all commands have completed. If an error + // occurs in any previous command the RIL_RadioAccessesFamily and + // logicalModemUuid fields will be the prior configuration thus + // restoring the configuration to the previous value. An error + // returned by this command will generally be ignored or may + // cause that logical modem to be removed from service. +} RadioCapabilityPhase; + +typedef enum { + RC_STATUS_NONE = 0, // This parameter has no meaning with RC_PHASE_START, + // RC_PHASE_APPLY + RC_STATUS_SUCCESS = 1, // Tell modem the action transaction of set radio + // capability was success with RC_PHASE_FINISH + RC_STATUS_FAIL = 2, // Tell modem the action transaction of set radio + // capability is fail with RC_PHASE_FINISH. +} RadioCapabilityStatus; + +#define RIL_RADIO_CAPABILITY_VERSION 1 +typedef struct { + int version; // Version of structure, RIL_RADIO_CAPABILITY_VERSION + int session; // Unique session value defined by framework returned in all "responses/unsol" + int phase; // CONFIGURED, START, APPLY, FINISH + int rat; // RIL_RadioAccessFamily for the radio + char logicalModemUuid[MAX_UUID_LENGTH]; // A UUID typically "com.xxxx.lmX where X is the logical modem. + int status; // Return status and an input parameter for RC_PHASE_FINISH +} RIL_RadioCapability; + +// Do we want to split Data from Voice and the use +// RIL_RadioTechnology for get/setPreferredVoice/Data ? +typedef enum { + PREF_NET_TYPE_GSM_WCDMA = 0, /* GSM/WCDMA (WCDMA preferred) */ + PREF_NET_TYPE_GSM_ONLY = 1, /* GSM only */ + PREF_NET_TYPE_WCDMA = 2, /* WCDMA */ + PREF_NET_TYPE_GSM_WCDMA_AUTO = 3, /* GSM/WCDMA (auto mode, according to PRL) */ + PREF_NET_TYPE_CDMA_EVDO_AUTO = 4, /* CDMA and EvDo (auto mode, according to PRL) */ + PREF_NET_TYPE_CDMA_ONLY = 5, /* CDMA only */ + PREF_NET_TYPE_EVDO_ONLY = 6, /* EvDo only */ + PREF_NET_TYPE_GSM_WCDMA_CDMA_EVDO_AUTO = 7, /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL) */ + PREF_NET_TYPE_LTE_CDMA_EVDO = 8, /* LTE, CDMA and EvDo */ + PREF_NET_TYPE_LTE_GSM_WCDMA = 9, /* LTE, GSM/WCDMA */ + PREF_NET_TYPE_LTE_CMDA_EVDO_GSM_WCDMA = 10, /* LTE, CDMA, EvDo, GSM/WCDMA */ + PREF_NET_TYPE_LTE_ONLY = 11, /* LTE only */ + PREF_NET_TYPE_LTE_WCDMA = 12, /* LTE/WCDMA */ + PREF_NET_TYPE_TD_SCDMA_ONLY = 13, /* TD-SCDMA only */ + PREF_NET_TYPE_TD_SCDMA_WCDMA = 14, /* TD-SCDMA and WCDMA */ + PREF_NET_TYPE_TD_SCDMA_LTE = 15, /* TD-SCDMA and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM = 16, /* TD-SCDMA and GSM */ + PREF_NET_TYPE_TD_SCDMA_GSM_LTE = 17, /* TD-SCDMA,GSM and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM_WCDMA = 18, /* TD-SCDMA, GSM/WCDMA */ + PREF_NET_TYPE_TD_SCDMA_WCDMA_LTE = 19, /* TD-SCDMA, WCDMA and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM_WCDMA_LTE = 20, /* TD-SCDMA, GSM/WCDMA and LTE */ + PREF_NET_TYPE_TD_SCDMA_GSM_WCDMA_CDMA_EVDO_AUTO = 21, /* TD-SCDMA, GSM/WCDMA, CDMA and EvDo */ + PREF_NET_TYPE_TD_SCDMA_LTE_CDMA_EVDO_GSM_WCDMA = 22 /* TD-SCDMA, LTE, CDMA, EvDo GSM/WCDMA */ +} RIL_PreferredNetworkType; + +/* Source for cdma subscription */ +typedef enum { + CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM = 0, + CDMA_SUBSCRIPTION_SOURCE_NV = 1 +} RIL_CdmaSubscriptionSource; + +/* User-to-User signaling Info activation types derived from 3GPP 23.087 v8.0 */ +typedef enum { + RIL_UUS_TYPE1_IMPLICIT = 0, + RIL_UUS_TYPE1_REQUIRED = 1, + RIL_UUS_TYPE1_NOT_REQUIRED = 2, + RIL_UUS_TYPE2_REQUIRED = 3, + RIL_UUS_TYPE2_NOT_REQUIRED = 4, + RIL_UUS_TYPE3_REQUIRED = 5, + RIL_UUS_TYPE3_NOT_REQUIRED = 6 +} RIL_UUS_Type; + +/* User-to-User Signaling Information data coding schemes. Possible values for + * Octet 3 (Protocol Discriminator field) in the UUIE. The values have been + * specified in section 10.5.4.25 of 3GPP TS 24.008 */ +typedef enum { + RIL_UUS_DCS_USP = 0, /* User specified protocol */ + RIL_UUS_DCS_OSIHLP = 1, /* OSI higher layer protocol */ + RIL_UUS_DCS_X244 = 2, /* X.244 */ + RIL_UUS_DCS_RMCF = 3, /* Reserved for system mangement + convergence function */ + RIL_UUS_DCS_IA5c = 4 /* IA5 characters */ +} RIL_UUS_DCS; + +/* User-to-User Signaling Information defined in 3GPP 23.087 v8.0 + * This data is passed in RIL_ExtensionRecord and rec contains this + * structure when type is RIL_UUS_INFO_EXT_REC */ +typedef struct { + RIL_UUS_Type uusType; /* UUS Type */ + RIL_UUS_DCS uusDcs; /* UUS Data Coding Scheme */ + int uusLength; /* Length of UUS Data */ + char * uusData; /* UUS Data */ +} RIL_UUS_Info; + +/* CDMA Signal Information Record as defined in C.S0005 section 3.7.5.5 */ +typedef struct { + char isPresent; /* non-zero if signal information record is present */ + char signalType; /* as defined 3.7.5.5-1 */ + char alertPitch; /* as defined 3.7.5.5-2 */ + char signal; /* as defined 3.7.5.5-3, 3.7.5.5-4 or 3.7.5.5-5 */ +} RIL_CDMA_SignalInfoRecord; + +typedef struct { + RIL_CallState state; + unsigned char index; /* Connection Index for use with, eg, AT+CHLD */ + unsigned char call_id; /* Samsung field */ + unsigned char pad; /* Unsigned gap padding */ + char pad1; /* Signed gap padding */ + int toa; /* type of address, eg 145 = intl */ + char isMpty; /* nonzero if is mpty call */ + char isMT; /* nonzero if call is mobile terminated */ + char als; /* ALS line indicator if available + (0 = line 1) */ + char isVoice; /* nonzero if this is is a voice call */ + char isVoicePrivacy; /* nonzero if CDMA voice privacy mode is active */ + char * number; /* Remote party number */ + int numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown 3=Payphone */ + char * name; /* Remote party name */ + int namePresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown 3=Payphone */ + void * call_details1; /* Padding for Samsung's call detail fields */ + void * call_details2; /* Padding for Samsung's call detail fields */ + RIL_UUS_Info * uusInfo; /* NULL or Pointer to User-User Signaling Information */ +} RIL_Call; + +/* Deprecated, use RIL_Data_Call_Response_v6 */ +typedef struct { + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". */ + char * apn; /* ignored */ + char * address; /* An address, e.g., "192.0.1.3" or "2001:db8::1". */ +} RIL_Data_Call_Response_v4; + +/* + * Returned by RIL_REQUEST_SETUP_DATA_CALL, RIL_REQUEST_DATA_CALL_LIST + * and RIL_UNSOL_DATA_CALL_LIST_CHANGED, on error status != 0. + */ +typedef struct { + int status; /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */ + int suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry + back-off timer value RIL wants to override the one + pre-configured in FW. + The unit is miliseconds. + The value < 0 means no value is suggested. + The value 0 means retry should be done ASAP. + The value of INT_MAX(0x7fffffff) means no retry. */ + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". If status is + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported + such as "IP" or "IPV6" */ + char * ifname; /* The network interface name */ + char * addresses; /* A space-delimited list of addresses with optional "/" prefix length, + e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". + May not be empty, typically 1 IPv4 or 1 IPv6 or + one of each. If the prefix length is absent the addresses + are assumed to be point to point with IPv4 having a prefix + length of 32 and IPv6 128. */ + char * dnses; /* A space-delimited list of DNS server addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty. */ + char * gateways; /* A space-delimited list of default gateway addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty in which case the addresses represent point + to point connections. */ +} RIL_Data_Call_Response_v6; + +typedef struct { + int status; /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */ + int suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry + back-off timer value RIL wants to override the one + pre-configured in FW. + The unit is miliseconds. + The value < 0 means no value is suggested. + The value 0 means retry should be done ASAP. + The value of INT_MAX(0x7fffffff) means no retry. */ + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". If status is + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported + such as "IP" or "IPV6" */ + char * ifname; /* The network interface name */ + char * addresses; /* A space-delimited list of addresses with optional "/" prefix length, + e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". + May not be empty, typically 1 IPv4 or 1 IPv6 or + one of each. If the prefix length is absent the addresses + are assumed to be point to point with IPv4 having a prefix + length of 32 and IPv6 128. */ + char * dnses; /* A space-delimited list of DNS server addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty. */ + char * gateways; /* A space-delimited list of default gateway addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty in which case the addresses represent point + to point connections. */ + char * pcscf; /* the Proxy Call State Control Function address + via PCO(Protocol Configuration Option) for IMS client. */ +} RIL_Data_Call_Response_v9; + +typedef struct { + int status; /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */ + int suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry + back-off timer value RIL wants to override the one + pre-configured in FW. + The unit is miliseconds. + The value < 0 means no value is suggested. + The value 0 means retry should be done ASAP. + The value of INT_MAX(0x7fffffff) means no retry. */ + int cid; /* Context ID, uniquely identifies this call */ + int active; /* 0=inactive, 1=active/physical link down, 2=active/physical link up */ + char * type; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6", or "PPP". If status is + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported + such as "IP" or "IPV6" */ + char * ifname; /* The network interface name */ + char * addresses; /* A space-delimited list of addresses with optional "/" prefix length, + e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". + May not be empty, typically 1 IPv4 or 1 IPv6 or + one of each. If the prefix length is absent the addresses + are assumed to be point to point with IPv4 having a prefix + length of 32 and IPv6 128. */ + char * dnses; /* A space-delimited list of DNS server addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty. */ + char * gateways; /* A space-delimited list of default gateway addresses, + e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1". + May be empty in which case the addresses represent point + to point connections. */ + char * pcscf; /* the Proxy Call State Control Function address + via PCO(Protocol Configuration Option) for IMS client. */ + int mtu; /* MTU received from network + Value <= 0 means network has either not sent a value or + sent an invalid value */ +} RIL_Data_Call_Response_v11; + +typedef enum { + RADIO_TECH_3GPP = 1, /* 3GPP Technologies - GSM, WCDMA */ + RADIO_TECH_3GPP2 = 2 /* 3GPP2 Technologies - CDMA */ +} RIL_RadioTechnologyFamily; + +typedef struct { + RIL_RadioTechnologyFamily tech; + unsigned char retry; /* 0 == not retry, nonzero == retry */ + int messageRef; /* Valid field if retry is set to nonzero. + Contains messageRef from RIL_SMS_Response + corresponding to failed MO SMS. + */ + + union { + /* Valid field if tech is RADIO_TECH_3GPP2. See RIL_REQUEST_CDMA_SEND_SMS */ + RIL_CDMA_SMS_Message* cdmaMessage; + + /* Valid field if tech is RADIO_TECH_3GPP. See RIL_REQUEST_SEND_SMS */ + char** gsmMessage; /* This is an array of pointers where pointers + are contiguous but elements pointed by those pointers + are not contiguous + */ + } message; +} RIL_IMS_SMS_Message; + +typedef struct { + int messageRef; /* TP-Message-Reference for GSM, + and BearerData MessageId for CDMA + (See 3GPP2 C.S0015-B, v2.0, table 4.5-1). */ + char *ackPDU; /* or NULL if n/a */ + int errorCode; /* See 3GPP 27.005, 3.2.5 for GSM/UMTS, + 3GPP2 N.S0005 (IS-41C) Table 171 for CDMA, + -1 if unknown or not applicable*/ +} RIL_SMS_Response; + +typedef struct { + RIL_SMS_Response response; + int retryCount; /* Samsung */ +} RIL_SMS_Response_Ext; + +/** Used by RIL_REQUEST_WRITE_SMS_TO_SIM */ +typedef struct { + int status; /* Status of message. See TS 27.005 3.1, "": */ + /* 0 = "REC UNREAD" */ + /* 1 = "REC READ" */ + /* 2 = "STO UNSENT" */ + /* 3 = "STO SENT" */ + char * pdu; /* PDU of message to write, as an ASCII hex string less the SMSC address, + the TP-layer length is "strlen(pdu)/2". */ + char * smsc; /* SMSC address in GSM BCD format prefixed by a length byte + (as expected by TS 27.005) or NULL for default SMSC */ +} RIL_SMS_WriteArgs; + +/** Used by RIL_REQUEST_DIAL */ +typedef struct { + char * address; + int clir; + /* (same as 'n' paremeter in TS 27.007 7.7 "+CLIR" + * clir == 0 on "use subscription default value" + * clir == 1 on "CLIR invocation" (restrict CLI presentation) + * clir == 2 on "CLIR suppression" (allow CLI presentation) + */ + RIL_UUS_Info * uusInfo; /* NULL or Pointer to User-User Signaling Information */ +} RIL_Dial; + +typedef struct { + int command; /* one of the commands listed for TS 27.007 +CRSM*/ + int fileid; /* EF id */ + char *path; /* "pathid" from TS 27.007 +CRSM command. + Path is in hex asciii format eg "7f205f70" + Path must always be provided. + */ + int p1; + int p2; + int p3; + char *data; /* May be NULL*/ + char *pin2; /* May be NULL*/ +} RIL_SIM_IO_v5; + +typedef struct { + int command; /* one of the commands listed for TS 27.007 +CRSM*/ + int fileid; /* EF id */ + char *path; /* "pathid" from TS 27.007 +CRSM command. + Path is in hex asciii format eg "7f205f70" + Path must always be provided. + */ + int p1; + int p2; + int p3; + char *data; /* May be NULL*/ + char *pin2; /* May be NULL*/ + char *aidPtr; /* AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. */ +} RIL_SIM_IO_v6; + +/* Used by RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL and + * RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC. */ +typedef struct { + int sessionid; /* "sessionid" from TS 27.007 +CGLA command. Should be + ignored for +CSIM command. */ + + /* Following fields are used to derive the APDU ("command" and "length" + values in TS 27.007 +CSIM and +CGLA commands). */ + int cla; + int instruction; + int p1; + int p2; + int p3; /* A negative P3 implies a 4 byte APDU. */ + char *data; /* May be NULL. In hex string format. */ +} RIL_SIM_APDU; + +typedef struct { + int sw1; + int sw2; + char *simResponse; /* In hex string format ([a-fA-F0-9]*), except for SIM_AUTHENTICATION + response for which it is in Base64 format, see 3GPP TS 31.102 7.1.2 */ +} RIL_SIM_IO_Response; + +/* See also com.android.internal.telephony.gsm.CallForwardInfo */ + +typedef struct { + int status; /* + * For RIL_REQUEST_QUERY_CALL_FORWARD_STATUS + * status 1 = active, 0 = not active + * + * For RIL_REQUEST_SET_CALL_FORWARD: + * status is: + * 0 = disable + * 1 = enable + * 2 = interrogate + * 3 = registeration + * 4 = erasure + */ + + int reason; /* from TS 27.007 7.11 "reason" */ + int serviceClass;/* From 27.007 +CCFC/+CLCK "class" + See table for Android mapping from + MMI service code + 0 means user doesn't input class */ + int toa; /* "type" from TS 27.007 7.11 */ + char * number; /* "number" from TS 27.007 7.11. May be NULL */ + int timeSeconds; /* for CF no reply only */ +}RIL_CallForwardInfo; + +typedef struct { + char * cid; /* Combination of LAC and Cell Id in 32 bits in GSM. + * Upper 16 bits is LAC and lower 16 bits + * is CID (as described in TS 27.005) + * Primary Scrambling Code (as described in TS 25.331) + * in 9 bits in UMTS + * Valid values are hexadecimal 0x0000 - 0xffffffff. + */ + int rssi; /* Received RSSI in GSM, + * Level index of CPICH Received Signal Code Power in UMTS + */ +} RIL_NeighboringCell; + +typedef struct { + char lce_status; /* LCE service status: + * -1 = not supported; + * 0 = stopped; + * 1 = active. + */ + unsigned int actual_interval_ms; /* actual LCE reporting interval, + * meaningful only if LCEStatus = 1. + */ +} RIL_LceStatusInfo; + +typedef struct { + unsigned int last_hop_capacity_kbps; /* last-hop cellular capacity: kilobits/second. */ + unsigned char confidence_level; /* capacity estimate confidence: 0-100 */ + unsigned char lce_suspended; /* LCE report going to be suspended? (e.g., radio + * moves to inactive state or network type change) + * 1 = suspended; + * 0 = not suspended. + */ +} RIL_LceDataInfo; + +typedef enum { + RIL_MATCH_ALL = 0, /* Apply to all carriers with the same mcc/mnc */ + RIL_MATCH_SPN = 1, /* Use SPN and mcc/mnc to identify the carrier */ + RIL_MATCH_IMSI_PREFIX = 2, /* Use IMSI prefix and mcc/mnc to identify the carrier */ + RIL_MATCH_GID1 = 3, /* Use GID1 and mcc/mnc to identify the carrier */ + RIL_MATCH_GID2 = 4, /* Use GID2 and mcc/mnc to identify the carrier */ +} RIL_CarrierMatchType; + +typedef struct { + const char * mcc; + const char * mnc; + RIL_CarrierMatchType match_type; /* Specify match type for the carrier. + * If it's RIL_MATCH_ALL, match_data is null; + * otherwise, match_data is the value for the match type. + */ + const char * match_data; +} RIL_Carrier; + +typedef struct { + int32_t len_allowed_carriers; /* length of array allowed_carriers */ + int32_t len_excluded_carriers; /* length of array excluded_carriers */ + RIL_Carrier * allowed_carriers; /* whitelist for allowed carriers */ + RIL_Carrier * excluded_carriers; /* blacklist for explicitly excluded carriers + * which match allowed_carriers. Eg. allowed_carriers match + * mcc/mnc, excluded_carriers has same mcc/mnc and gid1 + * is ABCD. It means except the carrier whose gid1 is ABCD, + * all carriers with the same mcc/mnc are allowed. + */ +} RIL_CarrierRestrictions; + +typedef struct { + char * mcc; /* MCC of the Carrier. */ + char * mnc ; /* MNC of the Carrier. */ + uint8_t * carrierKey; /* Public Key from the Carrier used to encrypt the + * IMSI/IMPI. + */ + char * keyIdentifier; /* The keyIdentifier Attribute value pair that helps + * a server locate the private key to decrypt the + * permanent identity. + */ + int64_t expirationTime; /* Date-Time (in UTC) when the key will expire. */ + +} RIL_CarrierInfoForImsiEncryption; + +/* See RIL_REQUEST_LAST_CALL_FAIL_CAUSE */ +typedef enum { + CALL_FAIL_UNOBTAINABLE_NUMBER = 1, + CALL_FAIL_NO_ROUTE_TO_DESTINATION = 3, + CALL_FAIL_CHANNEL_UNACCEPTABLE = 6, + CALL_FAIL_OPERATOR_DETERMINED_BARRING = 8, + CALL_FAIL_NORMAL = 16, + CALL_FAIL_BUSY = 17, + CALL_FAIL_NO_USER_RESPONDING = 18, + CALL_FAIL_NO_ANSWER_FROM_USER = 19, + CALL_FAIL_CALL_REJECTED = 21, + CALL_FAIL_NUMBER_CHANGED = 22, + CALL_FAIL_PREEMPTION = 25, + CALL_FAIL_DESTINATION_OUT_OF_ORDER = 27, + CALL_FAIL_INVALID_NUMBER_FORMAT = 28, + CALL_FAIL_FACILITY_REJECTED = 29, + CALL_FAIL_RESP_TO_STATUS_ENQUIRY = 30, + CALL_FAIL_NORMAL_UNSPECIFIED = 31, + CALL_FAIL_CONGESTION = 34, + CALL_FAIL_NETWORK_OUT_OF_ORDER = 38, + CALL_FAIL_TEMPORARY_FAILURE = 41, + CALL_FAIL_SWITCHING_EQUIPMENT_CONGESTION = 42, + CALL_FAIL_ACCESS_INFORMATION_DISCARDED = 43, + CALL_FAIL_REQUESTED_CIRCUIT_OR_CHANNEL_NOT_AVAILABLE = 44, + CALL_FAIL_RESOURCES_UNAVAILABLE_OR_UNSPECIFIED = 47, + CALL_FAIL_QOS_UNAVAILABLE = 49, + CALL_FAIL_REQUESTED_FACILITY_NOT_SUBSCRIBED = 50, + CALL_FAIL_INCOMING_CALLS_BARRED_WITHIN_CUG = 55, + CALL_FAIL_BEARER_CAPABILITY_NOT_AUTHORIZED = 57, + CALL_FAIL_BEARER_CAPABILITY_UNAVAILABLE = 58, + CALL_FAIL_SERVICE_OPTION_NOT_AVAILABLE = 63, + CALL_FAIL_BEARER_SERVICE_NOT_IMPLEMENTED = 65, + CALL_FAIL_ACM_LIMIT_EXCEEDED = 68, + CALL_FAIL_REQUESTED_FACILITY_NOT_IMPLEMENTED = 69, + CALL_FAIL_ONLY_DIGITAL_INFORMATION_BEARER_AVAILABLE = 70, + CALL_FAIL_SERVICE_OR_OPTION_NOT_IMPLEMENTED = 79, + CALL_FAIL_INVALID_TRANSACTION_IDENTIFIER = 81, + CALL_FAIL_USER_NOT_MEMBER_OF_CUG = 87, + CALL_FAIL_INCOMPATIBLE_DESTINATION = 88, + CALL_FAIL_INVALID_TRANSIT_NW_SELECTION = 91, + CALL_FAIL_SEMANTICALLY_INCORRECT_MESSAGE = 95, + CALL_FAIL_INVALID_MANDATORY_INFORMATION = 96, + CALL_FAIL_MESSAGE_TYPE_NON_IMPLEMENTED = 97, + CALL_FAIL_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE = 98, + CALL_FAIL_INFORMATION_ELEMENT_NON_EXISTENT = 99, + CALL_FAIL_CONDITIONAL_IE_ERROR = 100, + CALL_FAIL_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE = 101, + CALL_FAIL_RECOVERY_ON_TIMER_EXPIRED = 102, + CALL_FAIL_PROTOCOL_ERROR_UNSPECIFIED = 111, + CALL_FAIL_INTERWORKING_UNSPECIFIED = 127, + CALL_FAIL_CALL_BARRED = 240, + CALL_FAIL_FDN_BLOCKED = 241, + CALL_FAIL_IMSI_UNKNOWN_IN_VLR = 242, + CALL_FAIL_IMEI_NOT_ACCEPTED = 243, + CALL_FAIL_DIAL_MODIFIED_TO_USSD = 244, /* STK Call Control */ + CALL_FAIL_DIAL_MODIFIED_TO_SS = 245, + CALL_FAIL_DIAL_MODIFIED_TO_DIAL = 246, + CALL_FAIL_RADIO_OFF = 247, /* Radio is OFF */ + CALL_FAIL_OUT_OF_SERVICE = 248, /* No cellular coverage */ + CALL_FAIL_NO_VALID_SIM = 249, /* No valid SIM is present */ + CALL_FAIL_RADIO_INTERNAL_ERROR = 250, /* Internal error at Modem */ + CALL_FAIL_NETWORK_RESP_TIMEOUT = 251, /* No response from network */ + CALL_FAIL_NETWORK_REJECT = 252, /* Explicit network reject */ + CALL_FAIL_RADIO_ACCESS_FAILURE = 253, /* RRC connection failure. Eg.RACH */ + CALL_FAIL_RADIO_LINK_FAILURE = 254, /* Radio Link Failure */ + CALL_FAIL_RADIO_LINK_LOST = 255, /* Radio link lost due to poor coverage */ + CALL_FAIL_RADIO_UPLINK_FAILURE = 256, /* Radio uplink failure */ + CALL_FAIL_RADIO_SETUP_FAILURE = 257, /* RRC connection setup failure */ + CALL_FAIL_RADIO_RELEASE_NORMAL = 258, /* RRC connection release, normal */ + CALL_FAIL_RADIO_RELEASE_ABNORMAL = 259, /* RRC connection release, abnormal */ + CALL_FAIL_ACCESS_CLASS_BLOCKED = 260, /* Access class barring */ + CALL_FAIL_NETWORK_DETACH = 261, /* Explicit network detach */ + CALL_FAIL_CDMA_LOCKED_UNTIL_POWER_CYCLE = 1000, + CALL_FAIL_CDMA_DROP = 1001, + CALL_FAIL_CDMA_INTERCEPT = 1002, + CALL_FAIL_CDMA_REORDER = 1003, + CALL_FAIL_CDMA_SO_REJECT = 1004, + CALL_FAIL_CDMA_RETRY_ORDER = 1005, + CALL_FAIL_CDMA_ACCESS_FAILURE = 1006, + CALL_FAIL_CDMA_PREEMPTED = 1007, + CALL_FAIL_CDMA_NOT_EMERGENCY = 1008, /* For non-emergency number dialed + during emergency callback mode */ + CALL_FAIL_CDMA_ACCESS_BLOCKED = 1009, /* CDMA network access probes blocked */ + + /* OEM specific error codes. Used to distinguish error from + * CALL_FAIL_ERROR_UNSPECIFIED and help assist debugging */ + CALL_FAIL_OEM_CAUSE_1 = 0xf001, + CALL_FAIL_OEM_CAUSE_2 = 0xf002, + CALL_FAIL_OEM_CAUSE_3 = 0xf003, + CALL_FAIL_OEM_CAUSE_4 = 0xf004, + CALL_FAIL_OEM_CAUSE_5 = 0xf005, + CALL_FAIL_OEM_CAUSE_6 = 0xf006, + CALL_FAIL_OEM_CAUSE_7 = 0xf007, + CALL_FAIL_OEM_CAUSE_8 = 0xf008, + CALL_FAIL_OEM_CAUSE_9 = 0xf009, + CALL_FAIL_OEM_CAUSE_10 = 0xf00a, + CALL_FAIL_OEM_CAUSE_11 = 0xf00b, + CALL_FAIL_OEM_CAUSE_12 = 0xf00c, + CALL_FAIL_OEM_CAUSE_13 = 0xf00d, + CALL_FAIL_OEM_CAUSE_14 = 0xf00e, + CALL_FAIL_OEM_CAUSE_15 = 0xf00f, + + CALL_FAIL_ERROR_UNSPECIFIED = 0xffff /* This error will be deprecated soon, + vendor code should make sure to map error + code to specific error */ +} RIL_LastCallFailCause; + +typedef struct { + RIL_LastCallFailCause cause_code; + char * vendor_cause; +} RIL_LastCallFailCauseInfo; + +/* See RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE */ +typedef enum { + PDP_FAIL_NONE = 0, /* No error, connection ok */ + + /* an integer cause code defined in TS 24.008 + section 6.1.3.1.3 or TS 24.301 Release 8+ Annex B. + If the implementation does not have access to the exact cause codes, + then it should return one of the following values, + as the UI layer needs to distinguish these + cases for error notification and potential retries. */ + PDP_FAIL_OPERATOR_BARRED = 0x08, /* no retry */ + PDP_FAIL_NAS_SIGNALLING = 0x0E, + PDP_FAIL_LLC_SNDCP = 0x19, + PDP_FAIL_INSUFFICIENT_RESOURCES = 0x1A, + PDP_FAIL_MISSING_UKNOWN_APN = 0x1B, /* no retry */ + PDP_FAIL_UNKNOWN_PDP_ADDRESS_TYPE = 0x1C, /* no retry */ + PDP_FAIL_USER_AUTHENTICATION = 0x1D, /* no retry */ + PDP_FAIL_ACTIVATION_REJECT_GGSN = 0x1E, /* no retry */ + PDP_FAIL_ACTIVATION_REJECT_UNSPECIFIED = 0x1F, + PDP_FAIL_SERVICE_OPTION_NOT_SUPPORTED = 0x20, /* no retry */ + PDP_FAIL_SERVICE_OPTION_NOT_SUBSCRIBED = 0x21, /* no retry */ + PDP_FAIL_SERVICE_OPTION_OUT_OF_ORDER = 0x22, + PDP_FAIL_NSAPI_IN_USE = 0x23, /* no retry */ + PDP_FAIL_REGULAR_DEACTIVATION = 0x24, /* possibly restart radio, + based on framework config */ + PDP_FAIL_QOS_NOT_ACCEPTED = 0x25, + PDP_FAIL_NETWORK_FAILURE = 0x26, + PDP_FAIL_UMTS_REACTIVATION_REQ = 0x27, + PDP_FAIL_FEATURE_NOT_SUPP = 0x28, + PDP_FAIL_TFT_SEMANTIC_ERROR = 0x29, + PDP_FAIL_TFT_SYTAX_ERROR = 0x2A, + PDP_FAIL_UNKNOWN_PDP_CONTEXT = 0x2B, + PDP_FAIL_FILTER_SEMANTIC_ERROR = 0x2C, + PDP_FAIL_FILTER_SYTAX_ERROR = 0x2D, + PDP_FAIL_PDP_WITHOUT_ACTIVE_TFT = 0x2E, + PDP_FAIL_ONLY_IPV4_ALLOWED = 0x32, /* no retry */ + PDP_FAIL_ONLY_IPV6_ALLOWED = 0x33, /* no retry */ + PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED = 0x34, + PDP_FAIL_ESM_INFO_NOT_RECEIVED = 0x35, + PDP_FAIL_PDN_CONN_DOES_NOT_EXIST = 0x36, + PDP_FAIL_MULTI_CONN_TO_SAME_PDN_NOT_ALLOWED = 0x37, + PDP_FAIL_MAX_ACTIVE_PDP_CONTEXT_REACHED = 0x41, + PDP_FAIL_UNSUPPORTED_APN_IN_CURRENT_PLMN = 0x42, + PDP_FAIL_INVALID_TRANSACTION_ID = 0x51, + PDP_FAIL_MESSAGE_INCORRECT_SEMANTIC = 0x5F, + PDP_FAIL_INVALID_MANDATORY_INFO = 0x60, + PDP_FAIL_MESSAGE_TYPE_UNSUPPORTED = 0x61, + PDP_FAIL_MSG_TYPE_NONCOMPATIBLE_STATE = 0x62, + PDP_FAIL_UNKNOWN_INFO_ELEMENT = 0x63, + PDP_FAIL_CONDITIONAL_IE_ERROR = 0x64, + PDP_FAIL_MSG_AND_PROTOCOL_STATE_UNCOMPATIBLE = 0x65, + PDP_FAIL_PROTOCOL_ERRORS = 0x6F, /* no retry */ + PDP_FAIL_APN_TYPE_CONFLICT = 0x70, + PDP_FAIL_INVALID_PCSCF_ADDR = 0x71, + PDP_FAIL_INTERNAL_CALL_PREEMPT_BY_HIGH_PRIO_APN = 0x72, + PDP_FAIL_EMM_ACCESS_BARRED = 0x73, + PDP_FAIL_EMERGENCY_IFACE_ONLY = 0x74, + PDP_FAIL_IFACE_MISMATCH = 0x75, + PDP_FAIL_COMPANION_IFACE_IN_USE = 0x76, + PDP_FAIL_IP_ADDRESS_MISMATCH = 0x77, + PDP_FAIL_IFACE_AND_POL_FAMILY_MISMATCH = 0x78, + PDP_FAIL_EMM_ACCESS_BARRED_INFINITE_RETRY = 0x79, + PDP_FAIL_AUTH_FAILURE_ON_EMERGENCY_CALL = 0x7A, + + // OEM specific error codes. To be used by OEMs when they don't want to + // reveal error code which would be replaced by PDP_FAIL_ERROR_UNSPECIFIED + PDP_FAIL_OEM_DCFAILCAUSE_1 = 0x1001, + PDP_FAIL_OEM_DCFAILCAUSE_2 = 0x1002, + PDP_FAIL_OEM_DCFAILCAUSE_3 = 0x1003, + PDP_FAIL_OEM_DCFAILCAUSE_4 = 0x1004, + PDP_FAIL_OEM_DCFAILCAUSE_5 = 0x1005, + PDP_FAIL_OEM_DCFAILCAUSE_6 = 0x1006, + PDP_FAIL_OEM_DCFAILCAUSE_7 = 0x1007, + PDP_FAIL_OEM_DCFAILCAUSE_8 = 0x1008, + PDP_FAIL_OEM_DCFAILCAUSE_9 = 0x1009, + PDP_FAIL_OEM_DCFAILCAUSE_10 = 0x100A, + PDP_FAIL_OEM_DCFAILCAUSE_11 = 0x100B, + PDP_FAIL_OEM_DCFAILCAUSE_12 = 0x100C, + PDP_FAIL_OEM_DCFAILCAUSE_13 = 0x100D, + PDP_FAIL_OEM_DCFAILCAUSE_14 = 0x100E, + PDP_FAIL_OEM_DCFAILCAUSE_15 = 0x100F, + + /* Not mentioned in the specification */ + PDP_FAIL_VOICE_REGISTRATION_FAIL = -1, + PDP_FAIL_DATA_REGISTRATION_FAIL = -2, + + /* reasons for data call drop - network/modem disconnect */ + PDP_FAIL_SIGNAL_LOST = -3, + PDP_FAIL_PREF_RADIO_TECH_CHANGED = -4,/* preferred technology has changed, should retry + with parameters appropriate for new technology */ + PDP_FAIL_RADIO_POWER_OFF = -5, /* data call was disconnected because radio was resetting, + powered off - no retry */ + PDP_FAIL_TETHERED_CALL_ACTIVE = -6, /* data call was disconnected by modem because tethered + mode was up on same APN/data profile - no retry until + tethered call is off */ + + PDP_FAIL_ERROR_UNSPECIFIED = 0xffff, /* retry silently. Will be deprecated soon as + new error codes are added making this unnecessary */ +} RIL_DataCallFailCause; + +/* See RIL_REQUEST_SETUP_DATA_CALL */ +typedef enum { + RIL_DATA_PROFILE_DEFAULT = 0, + RIL_DATA_PROFILE_TETHERED = 1, + RIL_DATA_PROFILE_IMS = 2, + RIL_DATA_PROFILE_FOTA = 3, + RIL_DATA_PROFILE_CBS = 4, + RIL_DATA_PROFILE_OEM_BASE = 1000, /* Start of OEM-specific profiles */ + RIL_DATA_PROFILE_INVALID = 0xFFFFFFFF +} RIL_DataProfile; + +/* Used by RIL_UNSOL_SUPP_SVC_NOTIFICATION */ +typedef struct { + int notificationType; /* + * 0 = MO intermediate result code + * 1 = MT unsolicited result code + */ + int code; /* See 27.007 7.17 + "code1" for MO + "code2" for MT. */ + int index; /* CUG index. See 27.007 7.17. */ + int type; /* "type" from 27.007 7.17 (MT only). */ + char * number; /* "number" from 27.007 7.17 + (MT only, may be NULL). */ +} RIL_SuppSvcNotification; + +#define RIL_CARD_MAX_APPS 8 + +typedef enum { + RIL_CARDSTATE_ABSENT = 0, + RIL_CARDSTATE_PRESENT = 1, + RIL_CARDSTATE_ERROR = 2, + RIL_CARDSTATE_RESTRICTED = 3 /* card is present but not usable due to carrier restrictions.*/ +} RIL_CardState; + +typedef enum { + RIL_PERSOSUBSTATE_UNKNOWN = 0, /* initial state */ + RIL_PERSOSUBSTATE_IN_PROGRESS = 1, /* in between each lock transition */ + RIL_PERSOSUBSTATE_READY = 2, /* when either SIM or RUIM Perso is finished + since each app can only have 1 active perso + involved */ + RIL_PERSOSUBSTATE_SIM_NETWORK = 3, + RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET = 4, + RIL_PERSOSUBSTATE_SIM_CORPORATE = 5, + RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER = 6, + RIL_PERSOSUBSTATE_SIM_SIM = 7, + RIL_PERSOSUBSTATE_SIM_NETWORK_PUK = 8, /* The corresponding perso lock is blocked */ + RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK = 9, + RIL_PERSOSUBSTATE_SIM_CORPORATE_PUK = 10, + RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK = 11, + RIL_PERSOSUBSTATE_SIM_SIM_PUK = 12, + RIL_PERSOSUBSTATE_RUIM_NETWORK1 = 13, + RIL_PERSOSUBSTATE_RUIM_NETWORK2 = 14, + RIL_PERSOSUBSTATE_RUIM_HRPD = 15, + RIL_PERSOSUBSTATE_RUIM_CORPORATE = 16, + RIL_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER = 17, + RIL_PERSOSUBSTATE_RUIM_RUIM = 18, + RIL_PERSOSUBSTATE_RUIM_NETWORK1_PUK = 19, /* The corresponding perso lock is blocked */ + RIL_PERSOSUBSTATE_RUIM_NETWORK2_PUK = 20, + RIL_PERSOSUBSTATE_RUIM_HRPD_PUK = 21, + RIL_PERSOSUBSTATE_RUIM_CORPORATE_PUK = 22, + RIL_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK = 23, + RIL_PERSOSUBSTATE_RUIM_RUIM_PUK = 24 +} RIL_PersoSubstate; + +typedef enum { + RIL_APPSTATE_UNKNOWN = 0, + RIL_APPSTATE_DETECTED = 1, + RIL_APPSTATE_PIN = 2, /* If PIN1 or UPin is required */ + RIL_APPSTATE_PUK = 3, /* If PUK1 or Puk for UPin is required */ + RIL_APPSTATE_SUBSCRIPTION_PERSO = 4, /* perso_substate should be look at + when app_state is assigned to this value */ + RIL_APPSTATE_READY = 5 +} RIL_AppState; + +typedef enum { + RIL_PINSTATE_UNKNOWN = 0, + RIL_PINSTATE_ENABLED_NOT_VERIFIED = 1, + RIL_PINSTATE_ENABLED_VERIFIED = 2, + RIL_PINSTATE_DISABLED = 3, + RIL_PINSTATE_ENABLED_BLOCKED = 4, + RIL_PINSTATE_ENABLED_PERM_BLOCKED = 5 +} RIL_PinState; + +typedef enum { + RIL_APPTYPE_UNKNOWN = 0, + RIL_APPTYPE_SIM = 1, + RIL_APPTYPE_USIM = 2, + RIL_APPTYPE_RUIM = 3, + RIL_APPTYPE_CSIM = 4, + RIL_APPTYPE_ISIM = 5 +} RIL_AppType; + +/* + * Please note that registration state UNKNOWN is + * treated as "out of service" in the Android telephony. + * Registration state REG_DENIED must be returned if Location Update + * Reject (with cause 17 - Network Failure) is received + * repeatedly from the network, to facilitate + * "managed roaming" + */ +typedef enum { + RIL_NOT_REG_AND_NOT_SEARCHING = 0, // Not registered, MT is not currently searching + // a new operator to register + RIL_REG_HOME = 1, // Registered, home network + RIL_NOT_REG_AND_SEARCHING = 2, // Not registered, but MT is currently searching + // a new operator to register + RIL_REG_DENIED = 3, // Registration denied + RIL_UNKNOWN = 4, // Unknown + RIL_REG_ROAMING = 5, // Registered, roaming + RIL_NOT_REG_AND_EMERGENCY_AVAILABLE_AND_NOT_SEARCHING = 10, // Same as + // RIL_NOT_REG_AND_NOT_SEARCHING but indicates that + // emergency calls are enabled. + RIL_NOT_REG_AND_EMERGENCY_AVAILABLE_AND_SEARCHING = 12, // Same as RIL_NOT_REG_AND_SEARCHING + // but indicates that + // emergency calls are enabled. + RIL_REG_DENIED_AND_EMERGENCY_AVAILABLE = 13, // Same as REG_DENIED but indicates that + // emergency calls are enabled. + RIL_UNKNOWN_AND_EMERGENCY_AVAILABLE = 14, // Same as UNKNOWN but indicates that + // emergency calls are enabled. +} RIL_RegState; + +typedef struct +{ + RIL_AppType app_type; + RIL_AppState app_state; + RIL_PersoSubstate perso_substate; /* applicable only if app_state == + RIL_APPSTATE_SUBSCRIPTION_PERSO */ + char *aid_ptr; /* null terminated string, e.g., from 0xA0, 0x00 -> 0x41, + 0x30, 0x30, 0x30 */ + char *app_label_ptr; /* null terminated string */ + int pin1_replaced; /* applicable to USIM, CSIM & ISIM */ + RIL_PinState pin1; + RIL_PinState pin2; + /* Samsung SIM PIN/Unlock fields */ + int pin1_num_retries; + int puk1_num_retries; + int pin2_num_retries; + int puk2_num_retries; + int perso_unblock_retries; +} RIL_AppStatus; + +/* Deprecated, use RIL_CardStatus_v6 */ +typedef struct +{ + RIL_CardState card_state; + RIL_PinState universal_pin_state; /* applicable to USIM and CSIM: RIL_PINSTATE_xxx */ + int gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int cdma_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int num_applications; /* value <= RIL_CARD_MAX_APPS */ + RIL_AppStatus applications[RIL_CARD_MAX_APPS]; +} RIL_CardStatus_v5; + +typedef struct +{ + RIL_CardState card_state; + RIL_PinState universal_pin_state; /* applicable to USIM and CSIM: RIL_PINSTATE_xxx */ + int gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int cdma_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int ims_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */ + int num_applications; /* value <= RIL_CARD_MAX_APPS */ + RIL_AppStatus applications[RIL_CARD_MAX_APPS]; +} RIL_CardStatus_v6; + +/** The result of a SIM refresh, returned in data[0] of RIL_UNSOL_SIM_REFRESH + * or as part of RIL_SimRefreshResponse_v7 + */ +typedef enum { + /* A file on SIM has been updated. data[1] contains the EFID. */ + SIM_FILE_UPDATE = 0, + /* SIM initialized. All files should be re-read. */ + SIM_INIT = 1, + /* SIM reset. SIM power required, SIM may be locked and all files should be re-read. */ + SIM_RESET = 2 +} RIL_SimRefreshResult; + +typedef struct { + RIL_SimRefreshResult result; + int ef_id; /* is the EFID of the updated file if the result is */ + /* SIM_FILE_UPDATE or 0 for any other result. */ + char * aid; /* is AID(application ID) of the card application */ + /* See ETSI 102.221 8.1 and 101.220 4 */ + /* For SIM_FILE_UPDATE result it can be set to AID of */ + /* application in which updated EF resides or it can be */ + /* NULL if EF is outside of an application. */ + /* For SIM_INIT result this field is set to AID of */ + /* application that caused REFRESH */ + /* For SIM_RESET result it is NULL. */ +} RIL_SimRefreshResponse_v7; + +/* Deprecated, use RIL_CDMA_CallWaiting_v6 */ +typedef struct { + char * number; /* Remote party number */ + int numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown */ + char * name; /* Remote party name */ + RIL_CDMA_SignalInfoRecord signalInfoRecord; +} RIL_CDMA_CallWaiting_v5; + +typedef struct { + char * number; /* Remote party number */ + int numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown */ + char * name; /* Remote party name */ + RIL_CDMA_SignalInfoRecord signalInfoRecord; + /* Number type/Number plan required to support International Call Waiting */ + int number_type; /* 0=Unknown, 1=International, 2=National, + 3=Network specific, 4=subscriber */ + int number_plan; /* 0=Unknown, 1=ISDN, 3=Data, 4=Telex, 8=Nat'l, 9=Private */ +} RIL_CDMA_CallWaiting_v6; + +/** + * Which types of Cell Broadcast Message (CBM) are to be received by the ME + * + * uFromServiceID - uToServiceID defines a range of CBM message identifiers + * whose value is 0x0000 - 0xFFFF as defined in TS 23.041 9.4.1.2.2 for GMS + * and 9.4.4.2.2 for UMTS. All other values can be treated as empty + * CBM message ID. + * + * uFromCodeScheme - uToCodeScheme defines a range of CBM data coding schemes + * whose value is 0x00 - 0xFF as defined in TS 23.041 9.4.1.2.3 for GMS + * and 9.4.4.2.3 for UMTS. + * All other values can be treated as empty CBM data coding scheme. + * + * selected 0 means message types specified in + * and are not accepted, while 1 means accepted. + * + * Used by RIL_REQUEST_GSM_GET_BROADCAST_CONFIG and + * RIL_REQUEST_GSM_SET_BROADCAST_CONFIG. + */ +typedef struct { + int fromServiceId; + int toServiceId; + int fromCodeScheme; + int toCodeScheme; + unsigned char selected; +} RIL_GSM_BroadcastSmsConfigInfo; + +/* No restriction at all including voice/SMS/USSD/SS/AV64 and packet data. */ +#define RIL_RESTRICTED_STATE_NONE 0x00 +/* Block emergency call due to restriction. But allow all normal voice/SMS/USSD/SS/AV64. */ +#define RIL_RESTRICTED_STATE_CS_EMERGENCY 0x01 +/* Block all normal voice/SMS/USSD/SS/AV64 due to restriction. Only Emergency call allowed. */ +#define RIL_RESTRICTED_STATE_CS_NORMAL 0x02 +/* Block all voice/SMS/USSD/SS/AV64 including emergency call due to restriction.*/ +#define RIL_RESTRICTED_STATE_CS_ALL 0x04 +/* Block packet data access due to restriction. */ +#define RIL_RESTRICTED_STATE_PS_ALL 0x10 + +/* The status for an OTASP/OTAPA session */ +typedef enum { + CDMA_OTA_PROVISION_STATUS_SPL_UNLOCKED, + CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED, + CDMA_OTA_PROVISION_STATUS_A_KEY_EXCHANGED, + CDMA_OTA_PROVISION_STATUS_SSD_UPDATED, + CDMA_OTA_PROVISION_STATUS_NAM_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_MDN_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_IMSI_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_PRL_DOWNLOADED, + CDMA_OTA_PROVISION_STATUS_COMMITTED, + CDMA_OTA_PROVISION_STATUS_OTAPA_STARTED, + CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED, + CDMA_OTA_PROVISION_STATUS_OTAPA_ABORTED +} RIL_CDMA_OTA_ProvisionStatus; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int bitErrorRate; /* bit error rate (0-7, 99) as defined in TS 27.007 8.5 */ +} RIL_GW_SignalStrength; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int bitErrorRate; /* bit error rate (0-7, 99) as defined in TS 27.007 8.5 */ + int timingAdvance; /* Timing Advance in bit periods. 1 bit period = 48/13 us. + * INT_MAX denotes invalid value */ +} RIL_GSM_SignalStrength_v12; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int bitErrorRate; /* bit error rate (0-7, 99) as defined in TS 27.007 8.5 */ +} RIL_SignalStrengthWcdma; + +typedef struct { + int dbm; /* Valid values are positive integers. This value is the actual RSSI value + * multiplied by -1. Example: If the actual RSSI is -75, then this response + * value will be 75. + */ + int ecio; /* Valid values are positive integers. This value is the actual Ec/Io multiplied + * by -10. Example: If the actual Ec/Io is -12.5 dB, then this response value + * will be 125. + */ +} RIL_CDMA_SignalStrength; + + +typedef struct { + int dbm; /* Valid values are positive integers. This value is the actual RSSI value + * multiplied by -1. Example: If the actual RSSI is -75, then this response + * value will be 75. + */ + int ecio; /* Valid values are positive integers. This value is the actual Ec/Io multiplied + * by -10. Example: If the actual Ec/Io is -12.5 dB, then this response value + * will be 125. + */ + int signalNoiseRatio; /* Valid values are 0-8. 8 is the highest signal to noise ratio. */ +} RIL_EVDO_SignalStrength; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int rsrp; /* The current Reference Signal Receive Power in dBm multipled by -1. + * Range: 44 to 140 dBm + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.4 */ + int rsrq; /* The current Reference Signal Receive Quality in dB multiplied by -1. + * Range: 20 to 3 dB. + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.7 */ + int rssnr; /* The current reference signal signal-to-noise ratio in 0.1 dB units. + * Range: -200 to +300 (-200 = -20.0 dB, +300 = 30dB). + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 8.1.1 */ + int cqi; /* The current Channel Quality Indicator. + * Range: 0 to 15. + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 9.2, 9.3, A.4 */ +} RIL_LTE_SignalStrength; + +typedef struct { + int signalStrength; /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */ + int rsrp; /* The current Reference Signal Receive Power in dBm multipled by -1. + * Range: 44 to 140 dBm + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.4 */ + int rsrq; /* The current Reference Signal Receive Quality in dB multiplied by -1. + * Range: 20 to 3 dB. + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.133 9.1.7 */ + int rssnr; /* The current reference signal signal-to-noise ratio in 0.1 dB units. + * Range: -200 to +300 (-200 = -20.0 dB, +300 = 30dB). + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 8.1.1 */ + int cqi; /* The current Channel Quality Indicator. + * Range: 0 to 15. + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 36.101 9.2, 9.3, A.4 */ + int timingAdvance; /* timing advance in micro seconds for a one way trip from cell to device. + * Approximate distance can be calculated using 300m/us * timingAdvance. + * Range: 0 to 0x7FFFFFFE + * INT_MAX : 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP 36.321 section 6.1.3.5 + * also: http://www.cellular-planningoptimization.com/2010/02/timing-advance-with-calculation.html */ +} RIL_LTE_SignalStrength_v8; + +typedef struct { + int rscp; /* The Received Signal Code Power in dBm multipled by -1. + * Range : 25 to 120 + * INT_MAX: 0x7FFFFFFF denotes invalid value. + * Reference: 3GPP TS 25.123, section 9.1.1.1 */ +} RIL_TD_SCDMA_SignalStrength; + +/* Deprecated, use RIL_SignalStrength_v6 */ +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; +} RIL_SignalStrength_v5; + +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; + RIL_LTE_SignalStrength LTE_SignalStrength; +} RIL_SignalStrength_v6; + +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; + RIL_LTE_SignalStrength_v8 LTE_SignalStrength; +} RIL_SignalStrength_v8; + +typedef struct { + RIL_GW_SignalStrength GW_SignalStrength; + RIL_CDMA_SignalStrength CDMA_SignalStrength; + RIL_EVDO_SignalStrength EVDO_SignalStrength; + RIL_LTE_SignalStrength_v8 LTE_SignalStrength; + RIL_TD_SCDMA_SignalStrength TD_SCDMA_SignalStrength; +} RIL_SignalStrength_v10; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 16-bit GSM Cell Identity described in TS 27.007, 0..65535, INT_MAX if unknown */ +} RIL_CellIdentityGsm; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 16-bit GSM Cell Identity described in TS 27.007, 0..65535, INT_MAX if unknown */ + int arfcn; /* 16-bit GSM Absolute RF channel number; this value must be reported */ + uint8_t bsic; /* 6-bit Base Station Identity Code; 0xFF if unknown */ +} RIL_CellIdentityGsm_v12; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ + int psc; /* 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, INT_MAX if unknown */ +} RIL_CellIdentityWcdma; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ + int psc; /* 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511; this value must be reported */ + int uarfcn; /* 16-bit UMTS Absolute RF Channel Number; this value must be reported */ +} RIL_CellIdentityWcdma_v12; + +typedef struct { + int networkId; /* Network Id 0..65535, INT_MAX if unknown */ + int systemId; /* CDMA System Id 0..32767, INT_MAX if unknown */ + int basestationId; /* Base Station Id 0..65535, INT_MAX if unknown */ + int longitude; /* Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. + * It is represented in units of 0.25 seconds and ranges from -2592000 + * to 2592000, both values inclusive (corresponding to a range of -180 + * to +180 degrees). INT_MAX if unknown */ + + int latitude; /* Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. + * It is represented in units of 0.25 seconds and ranges from -1296000 + * to 1296000, both values inclusive (corresponding to a range of -90 + * to +90 degrees). INT_MAX if unknown */ +} RIL_CellIdentityCdma; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int ci; /* 28-bit Cell Identity described in TS ???, INT_MAX if unknown */ + int pci; /* physical cell id 0..503, INT_MAX if unknown */ + int tac; /* 16-bit tracking area code, INT_MAX if unknown */ +} RIL_CellIdentityLte; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int ci; /* 28-bit Cell Identity described in TS ???, INT_MAX if unknown */ + int pci; /* physical cell id 0..503; this value must be reported */ + int tac; /* 16-bit tracking area code, INT_MAX if unknown */ + int earfcn; /* 18-bit LTE Absolute RF Channel Number; this value must be reported */ +} RIL_CellIdentityLte_v12; + +typedef struct { + int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ + int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ + int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ + int cpid; /* 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown */ +} RIL_CellIdentityTdscdma; + +typedef struct { + RIL_CellIdentityGsm cellIdentityGsm; + RIL_GW_SignalStrength signalStrengthGsm; +} RIL_CellInfoGsm; + +typedef struct { + RIL_CellIdentityGsm_v12 cellIdentityGsm; + RIL_GSM_SignalStrength_v12 signalStrengthGsm; +} RIL_CellInfoGsm_v12; + +typedef struct { + RIL_CellIdentityWcdma cellIdentityWcdma; + RIL_SignalStrengthWcdma signalStrengthWcdma; +} RIL_CellInfoWcdma; + +typedef struct { + RIL_CellIdentityWcdma_v12 cellIdentityWcdma; + RIL_SignalStrengthWcdma signalStrengthWcdma; +} RIL_CellInfoWcdma_v12; + +typedef struct { + RIL_CellIdentityCdma cellIdentityCdma; + RIL_CDMA_SignalStrength signalStrengthCdma; + RIL_EVDO_SignalStrength signalStrengthEvdo; +} RIL_CellInfoCdma; + +typedef struct { + RIL_CellIdentityLte cellIdentityLte; + RIL_LTE_SignalStrength_v8 signalStrengthLte; +} RIL_CellInfoLte; + +typedef struct { + RIL_CellIdentityLte_v12 cellIdentityLte; + RIL_LTE_SignalStrength_v8 signalStrengthLte; +} RIL_CellInfoLte_v12; + +typedef struct { + RIL_CellIdentityTdscdma cellIdentityTdscdma; + RIL_TD_SCDMA_SignalStrength signalStrengthTdscdma; +} RIL_CellInfoTdscdma; + +// Must be the same as CellInfo.TYPE_XXX +typedef enum { + RIL_CELL_INFO_TYPE_NONE = 0, /* indicates no cell information */ + RIL_CELL_INFO_TYPE_GSM = 1, + RIL_CELL_INFO_TYPE_CDMA = 2, + RIL_CELL_INFO_TYPE_LTE = 3, + RIL_CELL_INFO_TYPE_WCDMA = 4, + RIL_CELL_INFO_TYPE_TD_SCDMA = 5 +} RIL_CellInfoType; + +// Must be the same as CellInfo.TIMESTAMP_TYPE_XXX +typedef enum { + RIL_TIMESTAMP_TYPE_UNKNOWN = 0, + RIL_TIMESTAMP_TYPE_ANTENNA = 1, + RIL_TIMESTAMP_TYPE_MODEM = 2, + RIL_TIMESTAMP_TYPE_OEM_RIL = 3, + RIL_TIMESTAMP_TYPE_JAVA_RIL = 4, +} RIL_TimeStampType; + +typedef struct { + RIL_CellInfoType cellInfoType; /* cell type for selecting from union CellInfo */ + int registered; /* !0 if this cell is registered 0 if not registered */ + RIL_TimeStampType timeStampType; /* type of time stamp represented by timeStamp */ + uint64_t timeStamp; /* Time in nanos as returned by ril_nano_time */ + union { + RIL_CellInfoGsm gsm; + RIL_CellInfoCdma cdma; + RIL_CellInfoLte lte; + RIL_CellInfoWcdma wcdma; + RIL_CellInfoTdscdma tdscdma; + } CellInfo; +} RIL_CellInfo; + +typedef struct { + RIL_CellInfoType cellInfoType; /* cell type for selecting from union CellInfo */ + int registered; /* !0 if this cell is registered 0 if not registered */ + RIL_TimeStampType timeStampType; /* type of time stamp represented by timeStamp */ + uint64_t timeStamp; /* Time in nanos as returned by ril_nano_time */ + union { + RIL_CellInfoGsm_v12 gsm; + RIL_CellInfoCdma cdma; + RIL_CellInfoLte_v12 lte; + RIL_CellInfoWcdma_v12 wcdma; + RIL_CellInfoTdscdma tdscdma; + } CellInfo; +} RIL_CellInfo_v12; + +typedef struct { + RIL_CellInfoType cellInfoType; /* cell type for selecting from union CellInfo */ + union { + RIL_CellIdentityGsm_v12 cellIdentityGsm; + RIL_CellIdentityWcdma_v12 cellIdentityWcdma; + RIL_CellIdentityLte_v12 cellIdentityLte; + RIL_CellIdentityTdscdma cellIdentityTdscdma; + RIL_CellIdentityCdma cellIdentityCdma; + }; +}RIL_CellIdentity_v16; + +typedef struct { + RIL_RegState regState; // Valid reg states are RIL_NOT_REG_AND_NOT_SEARCHING, + // REG_HOME, RIL_NOT_REG_AND_SEARCHING, REG_DENIED, + // UNKNOWN, REG_ROAMING defined in RegState + RIL_RadioTechnology rat; // indicates the available voice radio technology, + // valid values as defined by RadioTechnology. + int32_t cssSupported; // concurrent services support indicator. if + // registered on a CDMA system. + // 0 - Concurrent services not supported, + // 1 - Concurrent services supported + int32_t roamingIndicator; // TSB-58 Roaming Indicator if registered + // on a CDMA or EVDO system or -1 if not. + // Valid values are 0-255. + int32_t systemIsInPrl; // indicates whether the current system is in the + // PRL if registered on a CDMA or EVDO system or -1 if + // not. 0=not in the PRL, 1=in the PRL + int32_t defaultRoamingIndicator; // default Roaming Indicator from the PRL, + // if registered on a CDMA or EVDO system or -1 if not. + // Valid values are 0-255. + int32_t reasonForDenial; // reasonForDenial if registration state is 3 + // (Registration denied) this is an enumerated reason why + // registration was denied. See 3GPP TS 24.008, + // 10.5.3.6 and Annex G. + // 0 - General + // 1 - Authentication Failure + // 2 - IMSI unknown in HLR + // 3 - Illegal MS + // 4 - Illegal ME + // 5 - PLMN not allowed + // 6 - Location area not allowed + // 7 - Roaming not allowed + // 8 - No Suitable Cells in this Location Area + // 9 - Network failure + // 10 - Persistent location update reject + // 11 - PLMN not allowed + // 12 - Location area not allowed + // 13 - Roaming not allowed in this Location Area + // 15 - No Suitable Cells in this Location Area + // 17 - Network Failure + // 20 - MAC Failure + // 21 - Sync Failure + // 22 - Congestion + // 23 - GSM Authentication unacceptable + // 25 - Not Authorized for this CSG + // 32 - Service option not supported + // 33 - Requested service option not subscribed + // 34 - Service option temporarily out of order + // 38 - Call cannot be identified + // 48-63 - Retry upon entry into a new cell + // 95 - Semantically incorrect message + // 96 - Invalid mandatory information + // 97 - Message type non-existent or not implemented + // 98 - Message type not compatible with protocol state + // 99 - Information element non-existent or + // not implemented + // 100 - Conditional IE error + // 101 - Message not compatible with protocol state; + RIL_CellIdentity_v16 cellIdentity; // current cell information +}RIL_VoiceRegistrationStateResponse; + + +typedef struct { + RIL_RegState regState; // Valid reg states are RIL_NOT_REG_AND_NOT_SEARCHING, + // REG_HOME, RIL_NOT_REG_AND_SEARCHING, REG_DENIED, + // UNKNOWN, REG_ROAMING defined in RegState + RIL_RadioTechnology rat; // indicates the available data radio technology, + // valid values as defined by RadioTechnology. + int32_t reasonDataDenied; // if registration state is 3 (Registration + // denied) this is an enumerated reason why + // registration was denied. See 3GPP TS 24.008, + // Annex G.6 "Additional cause codes for GMM". + // 7 == GPRS services not allowed + // 8 == GPRS services and non-GPRS services not allowed + // 9 == MS identity cannot be derived by the network + // 10 == Implicitly detached + // 14 == GPRS services not allowed in this PLMN + // 16 == MSC temporarily not reachable + // 40 == No PDP context activated + int32_t maxDataCalls; // The maximum number of simultaneous Data Calls that + // must be established using setupDataCall(). + RIL_CellIdentity_v16 cellIdentity; // Current cell information +}RIL_DataRegistrationStateResponse; + +/* Names of the CDMA info records (C.S0005 section 3.7.5) */ +typedef enum { + RIL_CDMA_DISPLAY_INFO_REC, + RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC, + RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC, + RIL_CDMA_CONNECTED_NUMBER_INFO_REC, + RIL_CDMA_SIGNAL_INFO_REC, + RIL_CDMA_REDIRECTING_NUMBER_INFO_REC, + RIL_CDMA_LINE_CONTROL_INFO_REC, + RIL_CDMA_EXTENDED_DISPLAY_INFO_REC, + RIL_CDMA_T53_CLIR_INFO_REC, + RIL_CDMA_T53_RELEASE_INFO_REC, + RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC +} RIL_CDMA_InfoRecName; + +/* Display Info Rec as defined in C.S0005 section 3.7.5.1 + Extended Display Info Rec as defined in C.S0005 section 3.7.5.16 + Note: the Extended Display info rec contains multiple records of the + form: display_tag, display_len, and display_len occurrences of the + chari field if the display_tag is not 10000000 or 10000001. + To save space, the records are stored consecutively in a byte buffer. + The display_tag, display_len and chari fields are all 1 byte. +*/ + +typedef struct { + char alpha_len; + char alpha_buf[CDMA_ALPHA_INFO_BUFFER_LENGTH]; +} RIL_CDMA_DisplayInfoRecord; + +/* Called Party Number Info Rec as defined in C.S0005 section 3.7.5.2 + Calling Party Number Info Rec as defined in C.S0005 section 3.7.5.3 + Connected Number Info Rec as defined in C.S0005 section 3.7.5.4 +*/ + +typedef struct { + char len; + char buf[CDMA_NUMBER_INFO_BUFFER_LENGTH]; + char number_type; + char number_plan; + char pi; + char si; +} RIL_CDMA_NumberInfoRecord; + +/* Redirecting Number Information Record as defined in C.S0005 section 3.7.5.11 */ +typedef enum { + RIL_REDIRECTING_REASON_UNKNOWN = 0, + RIL_REDIRECTING_REASON_CALL_FORWARDING_BUSY = 1, + RIL_REDIRECTING_REASON_CALL_FORWARDING_NO_REPLY = 2, + RIL_REDIRECTING_REASON_CALLED_DTE_OUT_OF_ORDER = 9, + RIL_REDIRECTING_REASON_CALL_FORWARDING_BY_THE_CALLED_DTE = 10, + RIL_REDIRECTING_REASON_CALL_FORWARDING_UNCONDITIONAL = 15, + RIL_REDIRECTING_REASON_RESERVED +} RIL_CDMA_RedirectingReason; + +typedef struct { + RIL_CDMA_NumberInfoRecord redirectingNumber; + /* redirectingReason is set to RIL_REDIRECTING_REASON_UNKNOWN if not included */ + RIL_CDMA_RedirectingReason redirectingReason; +} RIL_CDMA_RedirectingNumberInfoRecord; + +/* Line Control Information Record as defined in C.S0005 section 3.7.5.15 */ +typedef struct { + char lineCtrlPolarityIncluded; + char lineCtrlToggle; + char lineCtrlReverse; + char lineCtrlPowerDenial; +} RIL_CDMA_LineControlInfoRecord; + +/* T53 CLIR Information Record */ +typedef struct { + char cause; +} RIL_CDMA_T53_CLIRInfoRecord; + +/* T53 Audio Control Information Record */ +typedef struct { + char upLink; + char downLink; +} RIL_CDMA_T53_AudioControlInfoRecord; + +typedef struct { + + RIL_CDMA_InfoRecName name; + + union { + /* Display and Extended Display Info Rec */ + RIL_CDMA_DisplayInfoRecord display; + + /* Called Party Number, Calling Party Number, Connected Number Info Rec */ + RIL_CDMA_NumberInfoRecord number; + + /* Signal Info Rec */ + RIL_CDMA_SignalInfoRecord signal; + + /* Redirecting Number Info Rec */ + RIL_CDMA_RedirectingNumberInfoRecord redir; + + /* Line Control Info Rec */ + RIL_CDMA_LineControlInfoRecord lineCtrl; + + /* T53 CLIR Info Rec */ + RIL_CDMA_T53_CLIRInfoRecord clir; + + /* T53 Audio Control Info Rec */ + RIL_CDMA_T53_AudioControlInfoRecord audioCtrl; + } rec; +} RIL_CDMA_InformationRecord; + +#define RIL_CDMA_MAX_NUMBER_OF_INFO_RECS 10 + +typedef struct { + char numberOfInfoRecs; + RIL_CDMA_InformationRecord infoRec[RIL_CDMA_MAX_NUMBER_OF_INFO_RECS]; +} RIL_CDMA_InformationRecords; + +/* See RIL_REQUEST_NV_READ_ITEM */ +typedef struct { + RIL_NV_Item itemID; +} RIL_NV_ReadItem; + +/* See RIL_REQUEST_NV_WRITE_ITEM */ +typedef struct { + RIL_NV_Item itemID; + char * value; +} RIL_NV_WriteItem; + +typedef enum { + HANDOVER_STARTED = 0, + HANDOVER_COMPLETED = 1, + HANDOVER_FAILED = 2, + HANDOVER_CANCELED = 3 +} RIL_SrvccState; + +/* hardware configuration reported to RILJ. */ +typedef enum { + RIL_HARDWARE_CONFIG_MODEM = 0, + RIL_HARDWARE_CONFIG_SIM = 1, +} RIL_HardwareConfig_Type; + +typedef enum { + RIL_HARDWARE_CONFIG_STATE_ENABLED = 0, + RIL_HARDWARE_CONFIG_STATE_STANDBY = 1, + RIL_HARDWARE_CONFIG_STATE_DISABLED = 2, +} RIL_HardwareConfig_State; + +typedef struct { + int rilModel; + uint32_t rat; /* bitset - ref. RIL_RadioTechnology. */ + int maxVoice; + int maxData; + int maxStandby; +} RIL_HardwareConfig_Modem; + +typedef struct { + char modemUuid[MAX_UUID_LENGTH]; +} RIL_HardwareConfig_Sim; + +typedef struct { + RIL_HardwareConfig_Type type; + char uuid[MAX_UUID_LENGTH]; + RIL_HardwareConfig_State state; + union { + RIL_HardwareConfig_Modem modem; + RIL_HardwareConfig_Sim sim; + } cfg; +} RIL_HardwareConfig; + +typedef enum { + SS_CFU, + SS_CF_BUSY, + SS_CF_NO_REPLY, + SS_CF_NOT_REACHABLE, + SS_CF_ALL, + SS_CF_ALL_CONDITIONAL, + SS_CLIP, + SS_CLIR, + SS_COLP, + SS_COLR, + SS_WAIT, + SS_BAOC, + SS_BAOIC, + SS_BAOIC_EXC_HOME, + SS_BAIC, + SS_BAIC_ROAMING, + SS_ALL_BARRING, + SS_OUTGOING_BARRING, + SS_INCOMING_BARRING +} RIL_SsServiceType; + +typedef enum { + SS_ACTIVATION, + SS_DEACTIVATION, + SS_INTERROGATION, + SS_REGISTRATION, + SS_ERASURE +} RIL_SsRequestType; + +typedef enum { + SS_ALL_TELE_AND_BEARER_SERVICES, + SS_ALL_TELESEVICES, + SS_TELEPHONY, + SS_ALL_DATA_TELESERVICES, + SS_SMS_SERVICES, + SS_ALL_TELESERVICES_EXCEPT_SMS +} RIL_SsTeleserviceType; + +#define SS_INFO_MAX 4 +#define NUM_SERVICE_CLASSES 7 + +typedef struct { + int numValidIndexes; /* This gives the number of valid values in cfInfo. + For example if voice is forwarded to one number and data + is forwarded to a different one then numValidIndexes will be + 2 indicating total number of valid values in cfInfo. + Similarly if all the services are forwarded to the same + number then the value of numValidIndexes will be 1. */ + + RIL_CallForwardInfo cfInfo[NUM_SERVICE_CLASSES]; /* This is the response data + for SS request to query call + forward status. see + RIL_REQUEST_QUERY_CALL_FORWARD_STATUS */ +} RIL_CfData; + +typedef struct { + RIL_SsServiceType serviceType; + RIL_SsRequestType requestType; + RIL_SsTeleserviceType teleserviceType; + int serviceClass; + RIL_Errno result; + + union { + int ssInfo[SS_INFO_MAX]; /* This is the response data for most of the SS GET/SET + RIL requests. E.g. RIL_REQUSET_GET_CLIR returns + two ints, so first two values of ssInfo[] will be + used for response if serviceType is SS_CLIR and + requestType is SS_INTERROGATION */ + + RIL_CfData cfData; + }; +} RIL_StkCcUnsolSsResponse; + +/** + * Data connection power state + */ +typedef enum { + RIL_DC_POWER_STATE_LOW = 1, // Low power state + RIL_DC_POWER_STATE_MEDIUM = 2, // Medium power state + RIL_DC_POWER_STATE_HIGH = 3, // High power state + RIL_DC_POWER_STATE_UNKNOWN = INT32_MAX // Unknown state +} RIL_DcPowerStates; + +/** + * Data connection real time info + */ +typedef struct { + uint64_t time; // Time in nanos as returned by ril_nano_time + RIL_DcPowerStates powerState; // Current power state +} RIL_DcRtInfo; + +/** + * Data profile to modem + */ +typedef struct { + /* id of the data profile */ + int profileId; + /* the APN to connect to */ + char* apn; + /** one of the PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + */ + char* protocol; + /** authentication protocol used for this PDP context + * (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) + */ + int authType; + /* the username for APN, or NULL */ + char* user; + /* the password for APN, or NULL */ + char* password; + /* the profile type, TYPE_COMMON-0, TYPE_3GPP-1, TYPE_3GPP2-2 */ + int type; + /* the period in seconds to limit the maximum connections */ + int maxConnsTime; + /* the maximum connections during maxConnsTime */ + int maxConns; + /** the required wait time in seconds after a successful UE initiated + * disconnect of a given PDN connection before the device can send + * a new PDN connection request for that given PDN + */ + int waitTime; + /* true to enable the profile, 0 to disable, 1 to enable */ + int enabled; +} RIL_DataProfileInfo; + +typedef struct { + /* id of the data profile */ + int profileId; + /* the APN to connect to */ + char* apn; + /** one of the PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + */ + char* protocol; + /** one of the PDP_type values in TS 27.007 section 10.1.1 used on roaming network. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + */ + char *roamingProtocol; + /** authentication protocol used for this PDP context + * (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) + */ + int authType; + /* the username for APN, or NULL */ + char* user; + /* the password for APN, or NULL */ + char* password; + /* the profile type, TYPE_COMMON-0, TYPE_3GPP-1, TYPE_3GPP2-2 */ + int type; + /* the period in seconds to limit the maximum connections */ + int maxConnsTime; + /* the maximum connections during maxConnsTime */ + int maxConns; + /** the required wait time in seconds after a successful UE initiated + * disconnect of a given PDN connection before the device can send + * a new PDN connection request for that given PDN + */ + int waitTime; + /* true to enable the profile, 0 to disable, 1 to enable */ + int enabled; + /* supported APN types bitmask. See RIL_ApnTypes for the value of each bit. */ + int supportedTypesBitmask; + /** the bearer bitmask. See RIL_RadioAccessFamily for the value of each bit. */ + int bearerBitmask; + /** maximum transmission unit (MTU) size in bytes */ + int mtu; + /** the MVNO type: possible values are "imsi", "gid", "spn" */ + char *mvnoType; + /** MVNO match data. Can be anything defined by the carrier. For example, + * SPN like: "A MOBILE", "BEN NL", etc... + * IMSI like: "302720x94", "2060188", etc... + * GID like: "4E", "33", etc... + */ + char *mvnoMatchData; +} RIL_DataProfileInfo_v15; + +/* Tx Power Levels */ +#define RIL_NUM_TX_POWER_LEVELS 5 + +/** + * Aggregate modem activity information + */ +typedef struct { + + /* total time (in ms) when modem is in a low power or + * sleep state + */ + uint32_t sleep_mode_time_ms; + + /* total time (in ms) when modem is awake but neither + * the transmitter nor receiver are active/awake */ + uint32_t idle_mode_time_ms; + + /* total time (in ms) during which the transmitter is active/awake, + * subdivided by manufacturer-defined device-specific + * contiguous increasing ranges of transmit power between + * 0 and the transmitter's maximum transmit power. + */ + uint32_t tx_mode_time_ms[RIL_NUM_TX_POWER_LEVELS]; + + /* total time (in ms) for which receiver is active/awake and + * the transmitter is inactive */ + uint32_t rx_mode_time_ms; +} RIL_ActivityStatsInfo; + +typedef enum { + RIL_APN_TYPE_UNKNOWN = 0x0, // Unknown + RIL_APN_TYPE_DEFAULT = 0x1, // APN type for default data traffic + RIL_APN_TYPE_MMS = 0x2, // APN type for MMS traffic + RIL_APN_TYPE_SUPL = 0x4, // APN type for SUPL assisted GPS + RIL_APN_TYPE_DUN = 0x8, // APN type for DUN traffic + RIL_APN_TYPE_HIPRI = 0x10, // APN type for HiPri traffic + RIL_APN_TYPE_FOTA = 0x20, // APN type for FOTA + RIL_APN_TYPE_IMS = 0x40, // APN type for IMS + RIL_APN_TYPE_CBS = 0x80, // APN type for CBS + RIL_APN_TYPE_IA = 0x100, // APN type for IA Initial Attach APN + RIL_APN_TYPE_EMERGENCY = 0x200, // APN type for Emergency PDN. This is not an IA apn, + // but is used for access to carrier services in an + // emergency call situation. + RIL_APN_TYPE_ALL = 0xFFFFFFFF // All APN types +} RIL_ApnTypes; + +typedef enum { + RIL_DST_POWER_SAVE_MODE, // Device power save mode (provided by PowerManager) + // True indicates the device is in power save mode. + RIL_DST_CHARGING_STATE, // Device charging state (provided by BatteryManager) + // True indicates the device is charging. + RIL_DST_LOW_DATA_EXPECTED // Low data expected mode. True indicates low data traffic + // is expected, for example, when the device is idle + // (e.g. not doing tethering in the background). Note + // this doesn't mean no data is expected. +} RIL_DeviceStateType; + +typedef enum { + RIL_UR_SIGNAL_STRENGTH = 0x01, // When this bit is set, modem should always send the + // signal strength update through + // RIL_UNSOL_SIGNAL_STRENGTH, otherwise suppress it. + RIL_UR_FULL_NETWORK_STATE = 0x02, // When this bit is set, modem should always send + // RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + // when any field in + // RIL_REQUEST_VOICE_REGISTRATION_STATE or + // RIL_REQUEST_DATA_REGISTRATION_STATE changes. When + // this bit is not set, modem should suppress + // RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + // only when insignificant fields change + // (e.g. cell info). + // Modem should continue sending + // RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + // when significant fields are updated even when this + // bit is not set. The following fields are + // considered significant, registration state and + // radio technology. + RIL_UR_DATA_CALL_DORMANCY_CHANGED = 0x04 // When this bit is set, modem should send the data + // call list changed unsolicited response + // RIL_UNSOL_DATA_CALL_LIST_CHANGED whenever any + // field in RIL_Data_Call_Response changes. + // Otherwise modem should suppress the unsolicited + // response when the only changed field is 'active' + // (for data dormancy). For all other fields change, + // modem should continue sending + // RIL_UNSOL_DATA_CALL_LIST_CHANGED regardless this + // bit is set or not. +} RIL_UnsolicitedResponseFilter; + +typedef struct { + char * aidPtr; /* AID value, See ETSI 102.221 and 101.220*/ + int p2; /* P2 parameter (described in ISO 7816-4) + P2Constants:NO_P2 if to be ignored */ +} RIL_OpenChannelParams; + +typedef enum { + RIL_ONE_SHOT = 0x01, // Performs the scan only once + RIL_PERIODIC = 0x02 // Performs the scan periodically until cancelled +} RIL_ScanType; + +typedef enum { + GERAN = 0x01, // GSM EDGE Radio Access Network + UTRAN = 0x02, // Universal Terrestrial Radio Access Network + EUTRAN = 0x03, // Evolved Universal Terrestrial Radio Access Network +} RIL_RadioAccessNetworks; + +typedef enum { + GERAN_BAND_T380 = 1, + GERAN_BAND_T410 = 2, + GERAN_BAND_450 = 3, + GERAN_BAND_480 = 4, + GERAN_BAND_710 = 5, + GERAN_BAND_750 = 6, + GERAN_BAND_T810 = 7, + GERAN_BAND_850 = 8, + GERAN_BAND_P900 = 9, + GERAN_BAND_E900 = 10, + GERAN_BAND_R900 = 11, + GERAN_BAND_DCS1800 = 12, + GERAN_BAND_PCS1900 = 13, + GERAN_BAND_ER900 = 14, +} RIL_GeranBands; + +typedef enum { + UTRAN_BAND_1 = 1, + UTRAN_BAND_2 = 2, + UTRAN_BAND_3 = 3, + UTRAN_BAND_4 = 4, + UTRAN_BAND_5 = 5, + UTRAN_BAND_6 = 6, + UTRAN_BAND_7 = 7, + UTRAN_BAND_8 = 8, + UTRAN_BAND_9 = 9, + UTRAN_BAND_10 = 10, + UTRAN_BAND_11 = 11, + UTRAN_BAND_12 = 12, + UTRAN_BAND_13 = 13, + UTRAN_BAND_14 = 14, + UTRAN_BAND_19 = 19, + UTRAN_BAND_20 = 20, + UTRAN_BAND_21 = 21, + UTRAN_BAND_22 = 22, + UTRAN_BAND_25 = 25, + UTRAN_BAND_26 = 26, +} RIL_UtranBands; + +typedef enum { + EUTRAN_BAND_1 = 1, + EUTRAN_BAND_2 = 2, + EUTRAN_BAND_3 = 3, + EUTRAN_BAND_4 = 4, + EUTRAN_BAND_5 = 5, + EUTRAN_BAND_6 = 6, + EUTRAN_BAND_7 = 7, + EUTRAN_BAND_8 = 8, + EUTRAN_BAND_9 = 9, + EUTRAN_BAND_10 = 10, + EUTRAN_BAND_11 = 11, + EUTRAN_BAND_12 = 12, + EUTRAN_BAND_13 = 13, + EUTRAN_BAND_14 = 14, + EUTRAN_BAND_17 = 17, + EUTRAN_BAND_18 = 18, + EUTRAN_BAND_19 = 19, + EUTRAN_BAND_20 = 20, + EUTRAN_BAND_21 = 21, + EUTRAN_BAND_22 = 22, + EUTRAN_BAND_23 = 23, + EUTRAN_BAND_24 = 24, + EUTRAN_BAND_25 = 25, + EUTRAN_BAND_26 = 26, + EUTRAN_BAND_27 = 27, + EUTRAN_BAND_28 = 28, + EUTRAN_BAND_30 = 30, + EUTRAN_BAND_31 = 31, + EUTRAN_BAND_33 = 33, + EUTRAN_BAND_34 = 34, + EUTRAN_BAND_35 = 35, + EUTRAN_BAND_36 = 36, + EUTRAN_BAND_37 = 37, + EUTRAN_BAND_38 = 38, + EUTRAN_BAND_39 = 39, + EUTRAN_BAND_40 = 40, + EUTRAN_BAND_41 = 41, + EUTRAN_BAND_42 = 42, + EUTRAN_BAND_43 = 43, + EUTRAN_BAND_44 = 44, + EUTRAN_BAND_45 = 45, + EUTRAN_BAND_46 = 46, + EUTRAN_BAND_47 = 47, + EUTRAN_BAND_48 = 48, + EUTRAN_BAND_65 = 65, + EUTRAN_BAND_66 = 66, + EUTRAN_BAND_68 = 68, + EUTRAN_BAND_70 = 70, +} RIL_EutranBands; + +typedef struct { + RIL_RadioAccessNetworks radio_access_network; // The type of network to scan. + uint32_t bands_length; // Length of bands + union { + RIL_GeranBands geran_bands[MAX_BANDS]; + RIL_UtranBands utran_bands[MAX_BANDS]; + RIL_EutranBands eutran_bands[MAX_BANDS]; + } bands; + uint32_t channels_length; // Length of channels + uint32_t channels[MAX_CHANNELS]; // Frequency channels to scan +} RIL_RadioAccessSpecifier; + +typedef struct { + RIL_ScanType type; // Type of the scan + int32_t interval; // Time interval in seconds + // between periodic scans, only + // valid when type=RIL_PERIODIC + uint32_t specifiers_length; // Length of specifiers + RIL_RadioAccessSpecifier specifiers[MAX_RADIO_ACCESS_NETWORKS]; // Radio access networks + // with bands/channels. +} RIL_NetworkScanRequest; + +typedef enum { + PARTIAL = 0x01, // The result contains a part of the scan results + COMPLETE = 0x02, // The result contains the last part of the scan results +} RIL_ScanStatus; + +typedef struct { + RIL_ScanStatus status; // The status of the scan + uint32_t network_infos_length; // Total length of RIL_CellInfo + RIL_CellInfo_v12* network_infos; // List of network information +} RIL_NetworkScanResult; + +/** + * RIL_REQUEST_GET_SIM_STATUS + * + * Requests status of the SIM interface and the SIM card + * + * "data" is NULL + * + * "response" is const RIL_CardStatus_v6 * + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GET_SIM_STATUS 1 + +/** + * RIL_REQUEST_ENTER_SIM_PIN + * + * Supplies SIM PIN. Only called if RIL_CardStatus has RIL_APPSTATE_PIN state + * + * "data" is const char ** + * ((const char **)data)[0] is PIN value + * ((const char **)data)[1] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PIN 2 + +/** + * RIL_REQUEST_ENTER_SIM_PUK + * + * Supplies SIM PUK and new PIN. + * + * "data" is const char ** + * ((const char **)data)[0] is PUK value + * ((const char **)data)[1] is new PIN value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (PUK is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PUK 3 + +/** + * RIL_REQUEST_ENTER_SIM_PIN2 + * + * Supplies SIM PIN2. Only called following operation where SIM_PIN2 was + * returned as a a failure from a previous operation. + * + * "data" is const char ** + * ((const char **)data)[0] is PIN2 value + * ((const char **)data)[1] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PIN2 4 + +/** + * RIL_REQUEST_ENTER_SIM_PUK2 + * + * Supplies SIM PUK2 and new PIN2. + * + * "data" is const char ** + * ((const char **)data)[0] is PUK2 value + * ((const char **)data)[1] is new PIN2 value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (PUK2 is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_SIM_PUK2 5 + +/** + * RIL_REQUEST_CHANGE_SIM_PIN + * + * Supplies old SIM PIN and new PIN. + * + * "data" is const char ** + * ((const char **)data)[0] is old PIN value + * ((const char **)data)[1] is new PIN value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (old PIN is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_CHANGE_SIM_PIN 6 + + +/** + * RIL_REQUEST_CHANGE_SIM_PIN2 + * + * Supplies old SIM PIN2 and new PIN2. + * + * "data" is const char ** + * ((const char **)data)[0] is old PIN2 value + * ((const char **)data)[1] is new PIN2 value + * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (old PIN2 is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + * + */ + +#define RIL_REQUEST_CHANGE_SIM_PIN2 7 + +/** + * RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION + * + * Requests that network personlization be deactivated + * + * "data" is const char ** + * ((const char **)(data))[0]] is network depersonlization code + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * PASSWORD_INCORRECT + * (code is invalid) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION 8 + +/** + * RIL_REQUEST_GET_CURRENT_CALLS + * + * Requests current call list + * + * "data" is NULL + * + * "response" must be a "const RIL_Call **" + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * (request will be made again in a few hundred msec) + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_GET_CURRENT_CALLS 9 + + +/** + * RIL_REQUEST_DIAL + * + * Initiate voice call + * + * "data" is const RIL_Dial * + * "response" is NULL + * + * This method is never used for supplementary service codes + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * DIAL_MODIFIED_TO_USSD + * DIAL_MODIFIED_TO_SS + * DIAL_MODIFIED_TO_DIAL + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_STATE + * NO_RESOURCES + * INTERNAL_ERR + * FDN_CHECK_FAILURE + * MODEM_ERR + * NO_SUBSCRIPTION + * NO_NETWORK_FOUND + * INVALID_CALL_ID + * DEVICE_IN_USE + * OPERATION_NOT_ALLOWED + * ABORTED + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_DIAL 10 + +/** + * RIL_REQUEST_GET_IMSI + * + * Get the SIM IMSI + * + * Only valid when radio state is "RADIO_STATE_ON" + * + * "data" is const char ** + * ((const char **)data)[0] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * "response" is a const char * containing the IMSI + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_SIM_STATE + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_GET_IMSI 11 + +/** + * RIL_REQUEST_HANGUP + * + * Hang up a specific line (like AT+CHLD=1x) + * + * After this HANGUP request returns, RIL should show the connection is NOT + * active anymore in next RIL_REQUEST_GET_CURRENT_CALLS query. + * + * "data" is an int * + * (int *)data)[0] contains Connection index (value of 'x' in CHLD above) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_STATE + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_CALL_ID + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_HANGUP 12 + +/** + * RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND + * + * Hang up waiting or held (like AT+CHLD=0) + * + * After this HANGUP request returns, RIL should show the connection is NOT + * active anymore in next RIL_REQUEST_GET_CURRENT_CALLS query. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_CALL_ID + * NO_RESOURCES + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND 13 + +/** + * RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND + * + * Hang up waiting or held (like AT+CHLD=1) + * + * After this HANGUP request returns, RIL should show the connection is NOT + * active anymore in next RIL_REQUEST_GET_CURRENT_CALLS query. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND 14 + +/** + * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE + * + * Switch waiting or holding call and active call (like AT+CHLD=2) + * + * State transitions should be is follows: + * + * If call 1 is waiting and call 2 is active, then if this re + * + * BEFORE AFTER + * Call 1 Call 2 Call 1 Call 2 + * ACTIVE HOLDING HOLDING ACTIVE + * ACTIVE WAITING HOLDING ACTIVE + * HOLDING WAITING HOLDING ACTIVE + * ACTIVE IDLE HOLDING IDLE + * IDLE IDLE IDLE IDLE + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * INVALID_ARGUMENTS + * INVALID_CALL_ID + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE 15 +#define RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE 15 + +/** + * RIL_REQUEST_CONFERENCE + * + * Conference holding and active (like AT+CHLD=3) + + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * INVALID_CALL_ID + * INVALID_ARGUMENTS + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_CONFERENCE 16 + +/** + * RIL_REQUEST_UDUB + * + * Send UDUB (user determined used busy) to ringing or + * waiting call answer)(RIL_BasicRequest r); + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_RESOURCES + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_UDUB 17 + +/** + * RIL_REQUEST_LAST_CALL_FAIL_CAUSE + * + * Requests the failure cause code for the most recently terminated call + * + * "data" is NULL + * "response" is a const RIL_LastCallFailCauseInfo * + * RIL_LastCallFailCauseInfo contains LastCallFailCause and vendor cause. + * The vendor cause code must be used for debugging purpose only. + * The implementation must return one of the values of LastCallFailCause + * as mentioned below. + * + * GSM failure reasons codes for the cause codes defined in TS 24.008 Annex H + * where possible. + * CDMA failure reasons codes for the possible call failure scenarios + * described in the "CDMA IS-2000 Release A (C.S0005-A v6.0)" standard. + * Any of the following reason codes if the call is failed or dropped due to reason + * mentioned with in the braces. + * + * CALL_FAIL_RADIO_OFF (Radio is OFF) + * CALL_FAIL_OUT_OF_SERVICE (No cell coverage) + * CALL_FAIL_NO_VALID_SIM (No valid SIM) + * CALL_FAIL_RADIO_INTERNAL_ERROR (Modem hit unexpected error scenario) + * CALL_FAIL_NETWORK_RESP_TIMEOUT (No response from network) + * CALL_FAIL_NETWORK_REJECT (Explicit network reject) + * CALL_FAIL_RADIO_ACCESS_FAILURE (RRC connection failure. Eg.RACH) + * CALL_FAIL_RADIO_LINK_FAILURE (Radio Link Failure) + * CALL_FAIL_RADIO_LINK_LOST (Radio link lost due to poor coverage) + * CALL_FAIL_RADIO_UPLINK_FAILURE (Radio uplink failure) + * CALL_FAIL_RADIO_SETUP_FAILURE (RRC connection setup failure) + * CALL_FAIL_RADIO_RELEASE_NORMAL (RRC connection release, normal) + * CALL_FAIL_RADIO_RELEASE_ABNORMAL (RRC connection release, abnormal) + * CALL_FAIL_ACCESS_CLASS_BLOCKED (Access class barring) + * CALL_FAIL_NETWORK_DETACH (Explicit network detach) + * + * OEM causes (CALL_FAIL_OEM_CAUSE_XX) must be used for debug purpose only + * + * If the implementation does not have access to the exact cause codes, + * then it should return one of the values listed in RIL_LastCallFailCause, + * as the UI layer needs to distinguish these cases for tone generation or + * error notification. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE + */ +#define RIL_REQUEST_LAST_CALL_FAIL_CAUSE 18 + +/** + * RIL_REQUEST_SIGNAL_STRENGTH + * + * Requests current signal strength and associated information + * + * Must succeed if radio is on. + * + * "data" is NULL + * + * "response" is a const RIL_SignalStrength * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SIGNAL_STRENGTH 19 + +/** + * RIL_REQUEST_VOICE_REGISTRATION_STATE + * + * Request current registration state + * + * "data" is NULL + * "response" is a const RIL_VoiceRegistrationStateResponse * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_VOICE_REGISTRATION_STATE 20 + +/** + * RIL_REQUEST_DATA_REGISTRATION_STATE + * + * Request current DATA registration state + * + * "data" is NULL + * "response" is a const RIL_DataRegistrationStateResponse * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_DATA_REGISTRATION_STATE 21 + +/** + * RIL_REQUEST_OPERATOR + * + * Request current operator ONS or EONS + * + * "data" is NULL + * "response" is a "const char **" + * ((const char **)response)[0] is long alpha ONS or EONS + * or NULL if unregistered + * + * ((const char **)response)[1] is short alpha ONS or EONS + * or NULL if unregistered + * ((const char **)response)[2] is 5 or 6 digit numeric code (MCC + MNC) + * or NULL if unregistered + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_OPERATOR 22 + +/** + * RIL_REQUEST_RADIO_POWER + * + * Toggle radio on and off (for "airplane" mode) + * If the radio is is turned off/on the radio modem subsystem + * is expected return to an initialized state. For instance, + * any voice and data calls will be terminated and all associated + * lists emptied. + * + * "data" is int * + * ((int *)data)[0] is > 0 for "Radio On" + * ((int *)data)[0] is == 0 for "Radio Off" + * + * "response" is NULL + * + * Turn radio on if "on" > 0 + * Turn radio off if "on" == 0 + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * INVALID_STATE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * DEVICE_IN_USE + * OPERATION_NOT_ALLOWED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_RADIO_POWER 23 + +/** + * RIL_REQUEST_DTMF + * + * Send a DTMF tone + * + * If the implementation is currently playing a tone requested via + * RIL_REQUEST_DTMF_START, that tone should be cancelled and the new tone + * should be played instead + * + * "data" is a char * containing a single character with one of 12 values: 0-9,*,# + * "response" is NULL + * + * FIXME should this block/mute microphone? + * How does this interact with local DTMF feedback? + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_RESOURCES + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_DTMF_STOP, RIL_REQUEST_DTMF_START + * + */ +#define RIL_REQUEST_DTMF 24 + +/** + * RIL_REQUEST_SEND_SMS + * + * Send an SMS message + * + * "data" is const char ** + * ((const char **)data)[0] is SMSC address in GSM BCD format prefixed + * by a length byte (as expected by TS 27.005) or NULL for default SMSC + * ((const char **)data)[1] is SMS in PDU format as an ASCII hex string + * less the SMSC address + * TP-Layer-Length is be "strlen(((const char **)data)[1])/2" + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. SMS_SEND_FAIL_RETRY means retry (i.e. error cause is 332) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * FDN_CHECK_FAILURE + * NETWORK_REJECT + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * MODEM_ERR + * NETWORK_ERR + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * FIXME how do we specify TP-Message-Reference if we need to resend? + */ +#define RIL_REQUEST_SEND_SMS 25 + + +/** + * RIL_REQUEST_SEND_SMS_EXPECT_MORE + * + * Send an SMS message. Identical to RIL_REQUEST_SEND_SMS, + * except that more messages are expected to be sent soon. If possible, + * keep SMS relay protocol link open (eg TS 27.005 AT+CMMS command) + * + * "data" is const char ** + * ((const char **)data)[0] is SMSC address in GSM BCD format prefixed + * by a length byte (as expected by TS 27.005) or NULL for default SMSC + * ((const char **)data)[1] is SMS in PDU format as an ASCII hex string + * less the SMSC address + * TP-Layer-Length is be "strlen(((const char **)data)[1])/2" + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. SMS_SEND_FAIL_RETRY means retry (i.e. error cause is 332) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * NETWORK_REJECT + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * FDN_CHECK_FAILURE + * MODEM_ERR + * NETWORK_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_SEND_SMS_EXPECT_MORE 26 + + +/** + * RIL_REQUEST_SETUP_DATA_CALL + * + * Setup a packet data connection. If RIL_Data_Call_Response_v6.status + * return success it is added to the list of data calls and a + * RIL_UNSOL_DATA_CALL_LIST_CHANGED is sent. The call remains in the + * list until RIL_REQUEST_DEACTIVATE_DATA_CALL is issued or the + * radio is powered off/on. This list is returned by RIL_REQUEST_DATA_CALL_LIST + * and RIL_UNSOL_DATA_CALL_LIST_CHANGED. + * + * The RIL is expected to: + * - Create one data call context. + * - Create and configure a dedicated interface for the context + * - The interface must be point to point. + * - The interface is configured with one or more addresses and + * is capable of sending and receiving packets. The prefix length + * of the addresses must be /32 for IPv4 and /128 for IPv6. + * - Must NOT change the linux routing table. + * - Support up to RIL_REQUEST_DATA_REGISTRATION_STATE response[5] + * number of simultaneous data call contexts. + * + * "data" is a const char ** + * ((const char **)data)[0] Radio technology to use: 0-CDMA, 1-GSM/UMTS, 2... + * for values above 2 this is RIL_RadioTechnology + 2. + * ((const char **)data)[1] is a RIL_DataProfile (support is optional) + * ((const char **)data)[2] is the APN to connect to if radio technology is GSM/UMTS. This APN will + * override the one in the profile. NULL indicates no APN overrride. + * ((const char **)data)[3] is the username for APN, or NULL + * ((const char **)data)[4] is the password for APN, or NULL + * ((const char **)data)[5] is the PAP / CHAP auth type. Values: + * 0 => PAP and CHAP is never performed. + * 1 => PAP may be performed; CHAP is never performed. + * 2 => CHAP may be performed; PAP is never performed. + * 3 => PAP / CHAP may be performed - baseband dependent. + * ((const char **)data)[6] is the non-roaming/home connection type to request. Must be one of the + * PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + * ((const char **)data)[7] is the roaming connection type to request. Must be one of the + * PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + * ((const char **)data)[8] is the bitmask of APN type in decimal string format. The + * bitmask will encapsulate the following values: + * ia,mms,agps,supl,hipri,fota,dun,ims,default. + * ((const char **)data)[9] is the bearer bitmask in decimal string format. Each bit is a + * RIL_RadioAccessFamily. "0" or NULL indicates all RATs. + * ((const char **)data)[10] is the boolean in string format indicating the APN setting was + * sent to the modem through RIL_REQUEST_SET_DATA_PROFILE earlier. + * ((const char **)data)[11] is the mtu size in bytes of the mobile interface to which + * the apn is connected. + * ((const char **)data)[12] is the MVNO type: + * possible values are "imsi", "gid", "spn". + * ((const char **)data)[13] is MVNO match data in string. Can be anything defined by the carrier. + * For example, + * SPN like: "A MOBILE", "BEN NL", etc... + * IMSI like: "302720x94", "2060188", etc... + * GID like: "4E", "33", etc... + * ((const char **)data)[14] is the boolean string indicating data roaming is allowed or not. "1" + * indicates data roaming is enabled by the user, "0" indicates disabled. + * + * "response" is a RIL_Data_Call_Response_v11 + * + * FIXME may need way to configure QoS settings + * + * Valid errors: + * SUCCESS should be returned on both success and failure of setup with + * the RIL_Data_Call_Response_v6.status containing the actual status. + * For all other errors the RIL_Data_Call_Resonse_v6 is ignored. + * + * Other errors could include: + * RADIO_NOT_AVAILABLE, OP_NOT_ALLOWED_BEFORE_REG_TO_NW, + * OP_NOT_ALLOWED_DURING_VOICE_CALL, REQUEST_NOT_SUPPORTED, + * INVALID_ARGUMENTS, INTERNAL_ERR, NO_MEMORY, NO_RESOURCES + * and CANCELLED + * + * See also: RIL_REQUEST_DEACTIVATE_DATA_CALL + */ +#define RIL_REQUEST_SETUP_DATA_CALL 27 + + +/** + * RIL_REQUEST_SIM_IO + * + * Request SIM I/O operation. + * This is similar to the TS 27.007 "restricted SIM" operation + * where it assumes all of the EF selection will be done by the + * callee. + * + * "data" is a const RIL_SIM_IO_v6 * + * Please note that RIL_SIM_IO has a "PIN2" field which may be NULL, + * or may specify a PIN2 for operations that require a PIN2 (eg + * updating FDN records) + * + * "response" is a const RIL_SIM_IO_Response * + * + * Arguments and responses that are unused for certain + * values of "command" should be ignored or set to NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_PIN2 + * SIM_PUK2 + * INVALID_SIM_STATE + * SIM_ERR + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_IO 28 + +/** + * RIL_REQUEST_SEND_USSD + * + * Send a USSD message + * + * If a USSD session already exists, the message should be sent in the + * context of that session. Otherwise, a new session should be created. + * + * The network reply should be reported via RIL_UNSOL_ON_USSD + * + * Only one USSD session may exist at a time, and the session is assumed + * to exist until: + * a) The android system invokes RIL_REQUEST_CANCEL_USSD + * b) The implementation sends a RIL_UNSOL_ON_USSD with a type code + * of "0" (USSD-Notify/no further action) or "2" (session terminated) + * + * "data" is a const char * containing the USSD request in UTF-8 format + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * FDN_CHECK_FAILURE + * USSD_MODIFIED_TO_DIAL + * USSD_MODIFIED_TO_SS + * USSD_MODIFIED_TO_USSD + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * INVALID_ARGUMENTS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * ABORTED + * SYSTEM_ERR + * INVALID_STATE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_CANCEL_USSD, RIL_UNSOL_ON_USSD + */ + +#define RIL_REQUEST_SEND_USSD 29 + +/** + * RIL_REQUEST_CANCEL_USSD + * + * Cancel the current USSD session if one exists + * + * "data" is null + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_STATE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_CANCEL_USSD 30 + +/** + * RIL_REQUEST_GET_CLIR + * + * Gets current CLIR status + * "data" is NULL + * "response" is int * + * ((int *)data)[0] is "n" parameter from TS 27.007 7.7 + * ((int *)data)[1] is "m" parameter from TS 27.007 7.7 + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * FDN_CHECK_FAILURE + * SYSTEM_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GET_CLIR 31 + +/** + * RIL_REQUEST_SET_CLIR + * + * "data" is int * + * ((int *)data)[0] is "n" parameter from TS 27.007 7.7 + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * SYSTEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_CLIR 32 + +/** + * RIL_REQUEST_QUERY_CALL_FORWARD_STATUS + * + * "data" is const RIL_CallForwardInfo * + * + * "response" is const RIL_CallForwardInfo ** + * "response" points to an array of RIL_CallForwardInfo *'s, one for + * each distinct registered phone number. + * + * For example, if data is forwarded to +18005551212 and voice is forwarded + * to +18005559999, then two separate RIL_CallForwardInfo's should be returned + * + * If, however, both data and voice are forwarded to +18005551212, then + * a single RIL_CallForwardInfo can be returned with the service class + * set to "data + voice = 3") + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_QUERY_CALL_FORWARD_STATUS 33 + + +/** + * RIL_REQUEST_SET_CALL_FORWARD + * + * Configure call forward rule + * + * "data" is const RIL_CallForwardInfo * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_CALL_FORWARD 34 + + +/** + * RIL_REQUEST_QUERY_CALL_WAITING + * + * Query current call waiting state + * + * "data" is const int * + * ((const int *)data)[0] is the TS 27.007 service class to query. + * "response" is a const int * + * ((const int *)response)[0] is 0 for "disabled" and 1 for "enabled" + * + * If ((const int *)response)[0] is = 1, then ((const int *)response)[1] + * must follow, with the TS 27.007 service class bit vector of services + * for which call waiting is enabled. + * + * For example, if ((const int *)response)[0] is 1 and + * ((const int *)response)[1] is 3, then call waiting is enabled for data + * and voice and disabled for everything else + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * FDN_CHECK_FAILURE + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_QUERY_CALL_WAITING 35 + + +/** + * RIL_REQUEST_SET_CALL_WAITING + * + * Configure current call waiting state + * + * "data" is const int * + * ((const int *)data)[0] is 0 for "disabled" and 1 for "enabled" + * ((const int *)data)[1] is the TS 27.007 service class bit vector of + * services to modify + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * INVALID_STATE + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_CALL_WAITING 36 + +/** + * RIL_REQUEST_SMS_ACKNOWLEDGE + * + * Acknowledge successful or failed receipt of SMS previously indicated + * via RIL_UNSOL_RESPONSE_NEW_SMS + * + * "data" is int * + * ((int *)data)[0] is 1 on successful receipt + * (basically, AT+CNMA=1 from TS 27.005 + * is 0 on failed receipt + * (basically, AT+CNMA=2 from TS 27.005) + * ((int *)data)[1] if data[0] is 0, this contains the failure cause as defined + * in TS 23.040, 9.2.3.22. Currently only 0xD3 (memory + * capacity exceeded) and 0xFF (unspecified error) are + * reported. + * + * "response" is NULL + * + * FIXME would like request that specified RP-ACK/RP-ERROR PDU + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SMS_ACKNOWLEDGE 37 + +/** + * RIL_REQUEST_GET_IMEI - DEPRECATED + * + * Get the device IMEI, including check digit + * + * The request is DEPRECATED, use RIL_REQUEST_DEVICE_IDENTITY + * Valid when RadioState is not RADIO_STATE_UNAVAILABLE + * + * "data" is NULL + * "response" is a const char * containing the IMEI + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ + +#define RIL_REQUEST_GET_IMEI 38 + +/** + * RIL_REQUEST_GET_IMEISV - DEPRECATED + * + * Get the device IMEISV, which should be two decimal digits + * + * The request is DEPRECATED, use RIL_REQUEST_DEVICE_IDENTITY + * Valid when RadioState is not RADIO_STATE_UNAVAILABLE + * + * "data" is NULL + * "response" is a const char * containing the IMEISV + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ + +#define RIL_REQUEST_GET_IMEISV 39 + + +/** + * RIL_REQUEST_ANSWER + * + * Answer incoming call + * + * Will not be called for WAITING calls. + * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE will be used in this case + * instead + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_ANSWER 40 + +/** + * RIL_REQUEST_DEACTIVATE_DATA_CALL + * + * Deactivate packet data connection and remove from the + * data call list if SUCCESS is returned. Any other return + * values should also try to remove the call from the list, + * but that may not be possible. In any event a + * RIL_REQUEST_RADIO_POWER off/on must clear the list. An + * RIL_UNSOL_DATA_CALL_LIST_CHANGED is not expected to be + * issued because of an RIL_REQUEST_DEACTIVATE_DATA_CALL. + * + * "data" is const char ** + * ((char**)data)[0] indicating CID + * ((char**)data)[1] indicating Disconnect Reason + * 0 => No specific reason specified + * 1 => Radio shutdown requested + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_CALL_ID + * INVALID_STATE + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SETUP_DATA_CALL + */ +#define RIL_REQUEST_DEACTIVATE_DATA_CALL 41 + +/** + * RIL_REQUEST_QUERY_FACILITY_LOCK + * + * Query the status of a facility lock state + * + * "data" is const char ** + * ((const char **)data)[0] is the facility string code from TS 27.007 7.4 + * (eg "AO" for BAOC, "SC" for SIM lock) + * ((const char **)data)[1] is the password, or "" if not required + * ((const char **)data)[2] is the TS 27.007 service class bit vector of + * services to query + * ((const char **)data)[3] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * This is only applicable in the case of Fixed Dialing Numbers + * (FDN) requests. + * + * "response" is an int * + * ((const int *)response) 0 is the TS 27.007 service class bit vector of + * services for which the specified barring facility + * is active. "0" means "disabled for all" + * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_QUERY_FACILITY_LOCK 42 + +/** + * RIL_REQUEST_SET_FACILITY_LOCK + * + * Enable/disable one facility lock + * + * "data" is const char ** + * + * ((const char **)data)[0] = facility string code from TS 27.007 7.4 + * (eg "AO" for BAOC) + * ((const char **)data)[1] = "0" for "unlock" and "1" for "lock" + * ((const char **)data)[2] = password + * ((const char **)data)[3] = string representation of decimal TS 27.007 + * service class bit vector. Eg, the string + * "1" means "set this facility for voice services" + * ((const char **)data)[4] = AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. + * This is only applicable in the case of Fixed Dialing Numbers + * (FDN) requests. + * + * "response" is int * + * ((int *)response)[0] is the number of retries remaining, or -1 if unknown + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * INTERNAL_ERR + * NO_MEMORY + * MODEM_ERR + * INVALID_STATE + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_SET_FACILITY_LOCK 43 + +/** + * RIL_REQUEST_CHANGE_BARRING_PASSWORD + * + * Change call barring facility password + * + * "data" is const char ** + * + * ((const char **)data)[0] = facility string code from TS 27.007 7.4 + * (eg "AO" for BAOC) + * ((const char **)data)[1] = old password + * ((const char **)data)[2] = new password + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * INVALID_ARGUMENTS + * NO_MEMORY + * MODEM_ERR + * INTERNAL_ERR + * SYSTEM_ERR + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CHANGE_BARRING_PASSWORD 44 + +/** + * RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE + * + * Query current network selectin mode + * + * "data" is NULL + * + * "response" is int * + * ((const int *)response)[0] is + * 0 for automatic selection + * 1 for manual selection + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE 45 + +/** + * RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC + * + * Specify that the network should be selected automatically + * + * "data" is NULL + * "response" is NULL + * + * This request must not respond until the new operator is selected + * and registered + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * ILLEGAL_SIM_OR_ME + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * Note: Returns ILLEGAL_SIM_OR_ME when the failure is permanent and + * no retries needed, such as illegal SIM or ME. + * + */ +#define RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC 46 + +/** + * RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL + * + * Manually select a specified network. + * + * "data" is const char * specifying MCCMNC of network to select (eg "310170") + * "response" is NULL + * + * This request must not respond until the new operator is selected + * and registered + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * ILLEGAL_SIM_OR_ME + * OPERATION_NOT_ALLOWED + * INVALID_STATE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * Note: Returns ILLEGAL_SIM_OR_ME when the failure is permanent and + * no retries needed, such as illegal SIM or ME. + * + */ +#define RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL 47 + +/** + * RIL_REQUEST_QUERY_AVAILABLE_NETWORKS + * + * Scans for available networks + * + * "data" is NULL + * "response" is const char ** that should be an array of n*4 strings, where + * n is the number of available networks + * For each available network: + * + * ((const char **)response)[n+0] is long alpha ONS or EONS + * ((const char **)response)[n+1] is short alpha ONS or EONS + * ((const char **)response)[n+2] is 5 or 6 digit numeric code (MCC + MNC) + * ((const char **)response)[n+3] is a string value of the status: + * "unknown" + * "available" + * "current" + * "forbidden" + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * ABORTED + * DEVICE_IN_USE + * INTERNAL_ERR + * NO_MEMORY + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * CANCELLED + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 48 + +/** + * RIL_REQUEST_DTMF_START + * + * Start playing a DTMF tone. Continue playing DTMF tone until + * RIL_REQUEST_DTMF_STOP is received + * + * If a RIL_REQUEST_DTMF_START is received while a tone is currently playing, + * it should cancel the previous tone and play the new one. + * + * "data" is a char * + * ((char *)data)[0] is a single character with one of 12 values: 0-9,*,# + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_RESOURCES + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_DTMF, RIL_REQUEST_DTMF_STOP + */ +#define RIL_REQUEST_DTMF_START 49 + +/** + * RIL_REQUEST_DTMF_STOP + * + * Stop playing a currently playing DTMF tone. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * NO_MEMORY + * INVALID_ARGUMENTS + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_DTMF, RIL_REQUEST_DTMF_START + */ +#define RIL_REQUEST_DTMF_STOP 50 + +/** + * RIL_REQUEST_BASEBAND_VERSION + * + * Return string value indicating baseband version, eg + * response from AT+CGMR + * + * "data" is NULL + * "response" is const char * containing version string for log reporting + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * EMPTY_RECORD + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_BASEBAND_VERSION 51 + +/** + * RIL_REQUEST_SEPARATE_CONNECTION + * + * Separate a party from a multiparty call placing the multiparty call + * (less the specified party) on hold and leaving the specified party + * as the only other member of the current (active) call + * + * Like AT+CHLD=2x + * + * See TS 22.084 1.3.8.2 (iii) + * TS 22.030 6.5.5 "Entering "2X followed by send" + * TS 27.007 "AT+CHLD=2x" + * + * "data" is an int * + * (int *)data)[0] contains Connection index (value of 'x' in CHLD above) "response" is NULL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_ARGUMENTS + * INVALID_STATE + * NO_RESOURCES + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * INVALID_STATE + * OPERATION_NOT_ALLOWED + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SEPARATE_CONNECTION 52 + + +/** + * RIL_REQUEST_SET_MUTE + * + * Turn on or off uplink (microphone) mute. + * + * Will only be sent while voice call is active. + * Will always be reset to "disable mute" when a new voice call is initiated + * + * "data" is an int * + * (int *)data)[0] is 1 for "enable mute" and 0 for "disable mute" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_SET_MUTE 53 + +/** + * RIL_REQUEST_GET_MUTE + * + * Queries the current state of the uplink mute setting + * + * "data" is NULL + * "response" is an int * + * (int *)response)[0] is 1 for "mute enabled" and 0 for "mute disabled" + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SS_MODIFIED_TO_DIAL + * SS_MODIFIED_TO_USSD + * SS_MODIFIED_TO_SS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_GET_MUTE 54 + +/** + * RIL_REQUEST_QUERY_CLIP + * + * Queries the status of the CLIP supplementary service + * + * (for MMI code "*#30#") + * + * "data" is NULL + * "response" is an int * + * (int *)response)[0] is 1 for "CLIP provisioned" + * and 0 for "CLIP not provisioned" + * and 2 for "unknown, e.g. no network etc" + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * FDN_CHECK_FAILURE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_QUERY_CLIP 55 + +/** + * RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE - Deprecated use the status + * field in RIL_Data_Call_Response_v6. + * + * Requests the failure cause code for the most recently failed PDP + * context or CDMA data connection active + * replaces RIL_REQUEST_LAST_PDP_FAIL_CAUSE + * + * "data" is NULL + * + * "response" is a "int *" + * ((int *)response)[0] is an integer cause code defined in TS 24.008 + * section 6.1.3.1.3 or close approximation + * + * If the implementation does not have access to the exact cause codes, + * then it should return one of the values listed in + * RIL_DataCallFailCause, as the UI layer needs to distinguish these + * cases for error notification + * and potential retries. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_LAST_CALL_FAIL_CAUSE + * + * Deprecated use the status field in RIL_Data_Call_Response_v6. + */ + +#define RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE 56 + +/** + * RIL_REQUEST_DATA_CALL_LIST + * + * Returns the data call list. An entry is added when a + * RIL_REQUEST_SETUP_DATA_CALL is issued and removed on a + * RIL_REQUEST_DEACTIVATE_DATA_CALL. The list is emptied + * when RIL_REQUEST_RADIO_POWER off/on is issued. + * + * "data" is NULL + * "response" is an array of RIL_Data_Call_Response_v6 + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_UNSOL_DATA_CALL_LIST_CHANGED + */ + +#define RIL_REQUEST_DATA_CALL_LIST 57 + +/** + * RIL_REQUEST_RESET_RADIO - DEPRECATED + * + * Request a radio reset. The RIL implementation may postpone + * the reset until after this request is responded to if the baseband + * is presently busy. + * + * The request is DEPRECATED, use RIL_REQUEST_RADIO_POWER + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * REQUEST_NOT_SUPPORTED + */ + +#define RIL_REQUEST_RESET_RADIO 58 + +/** + * RIL_REQUEST_OEM_HOOK_RAW + * + * This request reserved for OEM-specific uses. It passes raw byte arrays + * back and forth. + * + * It can be invoked on the Java side from + * com.android.internal.telephony.Phone.invokeOemRilRequestRaw() + * + * "data" is a char * of bytes copied from the byte[] data argument in java + * "response" is a char * of bytes that will returned via the + * caller's "response" Message here: + * (byte[])(((AsyncResult)response.obj).result) + * + * An error response here will result in + * (((AsyncResult)response.obj).result) == null and + * (((AsyncResult)response.obj).exception) being an instance of + * com.android.internal.telephony.gsm.CommandException + * + * Valid errors: + * All + */ + +#define RIL_REQUEST_OEM_HOOK_RAW 59 + +/** + * RIL_REQUEST_OEM_HOOK_STRINGS + * + * This request reserved for OEM-specific uses. It passes strings + * back and forth. + * + * It can be invoked on the Java side from + * com.android.internal.telephony.Phone.invokeOemRilRequestStrings() + * + * "data" is a const char **, representing an array of null-terminated UTF-8 + * strings copied from the "String[] strings" argument to + * invokeOemRilRequestStrings() + * + * "response" is a const char **, representing an array of null-terminated UTF-8 + * stings that will be returned via the caller's response message here: + * + * (String[])(((AsyncResult)response.obj).result) + * + * An error response here will result in + * (((AsyncResult)response.obj).result) == null and + * (((AsyncResult)response.obj).exception) being an instance of + * com.android.internal.telephony.gsm.CommandException + * + * Valid errors: + * All + */ + +#define RIL_REQUEST_OEM_HOOK_STRINGS 60 + +/** + * RIL_REQUEST_SCREEN_STATE - DEPRECATED + * + * Indicates the current state of the screen. When the screen is off, the + * RIL should notify the baseband to suppress certain notifications (eg, + * signal strength and changes in LAC/CID or BID/SID/NID/latitude/longitude) + * in an effort to conserve power. These notifications should resume when the + * screen is on. + * + * Note this request is deprecated. Use RIL_REQUEST_SEND_DEVICE_STATE to report the device state + * to the modem and use RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER to turn on/off unsolicited + * response from the modem in different scenarios. + * + * "data" is int * + * ((int *)data)[0] is == 1 for "Screen On" + * ((int *)data)[0] is == 0 for "Screen Off" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SCREEN_STATE 61 + + +/** + * RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION + * + * Enables/disables supplementary service related notifications + * from the network. + * + * Notifications are reported via RIL_UNSOL_SUPP_SVC_NOTIFICATION. + * + * "data" is int * + * ((int *)data)[0] is == 1 for notifications enabled + * ((int *)data)[0] is == 0 for notifications disabled + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_BUSY + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_UNSOL_SUPP_SVC_NOTIFICATION. + */ +#define RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION 62 + +/** + * RIL_REQUEST_WRITE_SMS_TO_SIM + * + * Stores a SMS message to SIM memory. + * + * "data" is RIL_SMS_WriteArgs * + * + * "response" is int * + * ((const int *)response)[0] is the record index where the message is stored. + * + * Valid errors: + * SUCCESS + * SIM_FULL + * INVALID_ARGUMENTS + * INVALID_SMS_FORMAT + * INTERNAL_ERR + * MODEM_ERR + * ENCODING_ERR + * NO_MEMORY + * NO_RESOURCES + * INVALID_MODEM_STATE + * OPERATION_NOT_ALLOWED + * INVALID_SMSC_ADDRESS + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_WRITE_SMS_TO_SIM 63 + +/** + * RIL_REQUEST_DELETE_SMS_ON_SIM + * + * Deletes a SMS message from SIM memory. + * + * "data" is int * + * ((int *)data)[0] is the record index of the message to delete. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * SIM_FULL + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * MODEM_ERR + * NO_SUCH_ENTRY + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_DELETE_SMS_ON_SIM 64 + +/** + * RIL_REQUEST_SET_BAND_MODE + * + * Assign a specified band for RF configuration. + * + * "data" is int * + * ((int *)data)[0] is a RIL_RadioBandMode + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE + */ +#define RIL_REQUEST_SET_BAND_MODE 65 + +/** + * RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE + * + * Query the list of band mode supported by RF. + * + * "data" is NULL + * + * "response" is int * + * "response" points to an array of int's, the int[0] is the size of array; + * subsequent values are a list of RIL_RadioBandMode listing supported modes. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SET_BAND_MODE + */ +#define RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE 66 + +/** + * RIL_REQUEST_STK_GET_PROFILE + * + * Requests the profile of SIM tool kit. + * The profile indicates the SAT/USAT features supported by ME. + * The SAT/USAT features refer to 3GPP TS 11.14 and 3GPP TS 31.111 + * + * "data" is NULL + * + * "response" is a const char * containing SAT/USAT profile + * in hexadecimal format string starting with first byte of terminal profile + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_GET_PROFILE 67 + +/** + * RIL_REQUEST_STK_SET_PROFILE + * + * Download the STK terminal profile as part of SIM initialization + * procedure + * + * "data" is a const char * containing SAT/USAT profile + * in hexadecimal format string starting with first byte of terminal profile + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SET_PROFILE 68 + +/** + * RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND + * + * Requests to send a SAT/USAT envelope command to SIM. + * The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111 + * + * "data" is a const char * containing SAT/USAT command + * in hexadecimal format string starting with command tag + * + * "response" is a const char * containing SAT/USAT response + * in hexadecimal format string starting with first byte of response + * (May be NULL) + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND 69 + +/** + * RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE + * + * Requests to send a terminal response to SIM for a received + * proactive command + * + * "data" is a const char * containing SAT/USAT response + * in hexadecimal format string starting with first byte of response data + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * RIL_E_OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE 70 + +/** + * RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM + * + * When STK application gets RIL_UNSOL_STK_CALL_SETUP, the call actually has + * been initialized by ME already. (We could see the call has been in the 'call + * list') So, STK application needs to accept/reject the call according as user + * operations. + * + * "data" is int * + * ((int *)data)[0] is > 0 for "accept" the call setup + * ((int *)data)[0] is == 0 for "reject" the call setup + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * RIL_E_OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM 71 + +/** + * RIL_REQUEST_EXPLICIT_CALL_TRANSFER + * + * Connects the two calls and disconnects the subscriber from both calls. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * INVALID_STATE + * NO_RESOURCES + * NO_MEMORY + * INVALID_ARGUMENTS + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * INVALID_STATE + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_EXPLICIT_CALL_TRANSFER 72 + +/** + * RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE + * + * Requests to set the preferred network type for searching and registering + * (CS/PS domain, RAT, and operation mode) + * + * "data" is int * which is RIL_PreferredNetworkType + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * OPERATION_NOT_ALLOWED + * MODE_NOT_SUPPORTED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE 73 + +/** + * RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE + * + * Query the preferred network type (CS/PS domain, RAT, and operation mode) + * for searching and registering + * + * "data" is NULL + * + * "response" is int * + * ((int *)reponse)[0] is == RIL_PreferredNetworkType + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE + */ +#define RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE 74 + +/** + * RIL_REQUEST_NEIGHBORING_CELL_IDS + * + * Request neighboring cell id in GSM network + * + * "data" is NULL + * "response" must be a " const RIL_NeighboringCell** " + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NO_NETWORK_FOUND + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_GET_NEIGHBORING_CELL_IDS 75 + +/** + * RIL_REQUEST_SET_LOCATION_UPDATES + * + * Enables/disables network state change notifications due to changes in + * LAC and/or CID (for GSM) or BID/SID/NID/latitude/longitude (for CDMA). + * Basically +CREG=2 vs. +CREG=1 (TS 27.007). + * + * Note: The RIL implementation should default to "updates enabled" + * when the screen is on and "updates disabled" when the screen is off. + * + * "data" is int * + * ((int *)data)[0] is == 1 for updates enabled (+CREG=2) + * ((int *)data)[0] is == 0 for updates disabled (+CREG=1) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_REQUEST_SCREEN_STATE, RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED + */ +#define RIL_REQUEST_SET_LOCATION_UPDATES 76 + +/** + * RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE + * + * Request to set the location where the CDMA subscription shall + * be retrieved + * + * "data" is int * + * ((int *)data)[0] is == RIL_CdmaSubscriptionSource + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_ABSENT + * SUBSCRIPTION_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE + */ +#define RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE 77 + +/** + * RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE + * + * Request to set the roaming preferences in CDMA + * + * "data" is int * + * ((int *)data)[0] is == 0 for Home Networks only, as defined in PRL + * ((int *)data)[0] is == 1 for Roaming on Affiliated networks, as defined in PRL + * ((int *)data)[0] is == 2 for Roaming on Any Network, as defined in the PRL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE 78 + +/** + * RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE + * + * Request the actual setting of the roaming preferences in CDMA in the modem + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is == 0 for Home Networks only, as defined in PRL + * ((int *)response)[0] is == 1 for Roaming on Affiliated networks, as defined in PRL + * ((int *)response)[0] is == 2 for Roaming on Any Network, as defined in the PRL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE 79 + +/** + * RIL_REQUEST_SET_TTY_MODE + * + * Request to set the TTY mode + * + * "data" is int * + * ((int *)data)[0] is == 0 for TTY off + * ((int *)data)[0] is == 1 for TTY Full + * ((int *)data)[0] is == 2 for TTY HCO (hearing carryover) + * ((int *)data)[0] is == 3 for TTY VCO (voice carryover) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_ARGUMENTS + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_TTY_MODE 80 + +/** + * RIL_REQUEST_QUERY_TTY_MODE + * + * Request the setting of TTY mode + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is == 0 for TTY off + * ((int *)response)[0] is == 1 for TTY Full + * ((int *)response)[0] is == 2 for TTY HCO (hearing carryover) + * ((int *)response)[0] is == 3 for TTY VCO (voice carryover) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_QUERY_TTY_MODE 81 + +/** + * RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE + * + * Request to set the preferred voice privacy mode used in voice + * scrambling + * + * "data" is int * + * ((int *)data)[0] is == 0 for Standard Privacy Mode (Public Long Code Mask) + * ((int *)data)[0] is == 1 for Enhanced Privacy Mode (Private Long Code Mask) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE 82 + +/** + * RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE + * + * Request the setting of preferred voice privacy mode + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is == 0 for Standard Privacy Mode (Public Long Code Mask) + * ((int *)response)[0] is == 1 for Enhanced Privacy Mode (Private Long Code Mask) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * MODEM_ERR + * INTERNAL_ERR + * NO_MEMORY + * INVALID_ARGUMENTS + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE 83 + +/** + * RIL_REQUEST_CDMA_FLASH + * + * Send FLASH + * + * "data" is const char * + * ((const char *)data)[0] is a FLASH string + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * INVALID_STATE + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_FLASH 84 + +/** + * RIL_REQUEST_CDMA_BURST_DTMF + * + * Send DTMF string + * + * "data" is const char ** + * ((const char **)data)[0] is a DTMF string + * ((const char **)data)[1] is the DTMF ON length in milliseconds, or 0 to use + * default + * ((const char **)data)[2] is the DTMF OFF length in milliseconds, or 0 to use + * default + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * MODEM_ERR + * INTERNAL_ERR + * INVALID_CALL_ID + * NO_RESOURCES + * CANCELLED + * OPERATION_NOT_ALLOWED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_BURST_DTMF 85 + +/** + * RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY + * + * Takes a 26 digit string (20 digit AKEY + 6 digit checksum). + * If the checksum is valid the 20 digit AKEY is written to NV, + * replacing the existing AKEY no matter what it was before. + * + * "data" is const char * + * ((const char *)data)[0] is a 26 digit string (ASCII digits '0'-'9') + * where the last 6 digits are a checksum of the + * first 20, as specified in TR45.AHAG + * "Common Cryptographic Algorithms, Revision D.1 + * Section 2.2" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY 86 + +/** + * RIL_REQUEST_CDMA_SEND_SMS + * + * Send a CDMA SMS message + * + * "data" is const RIL_CDMA_SMS_Message * + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. The CDMA error class is derived as follows, + * SUCCESS is error class 0 (no error) + * SMS_SEND_FAIL_RETRY is error class 2 (temporary failure) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * NETWORK_REJECT + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * FDN_CHECK_FAILURE + * MODEM_ERR + * NETWORK_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * OPERATION_NOT_ALLOWED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SEND_SMS 87 + +/** + * RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE + * + * Acknowledge the success or failure in the receipt of SMS + * previously indicated via RIL_UNSOL_RESPONSE_CDMA_NEW_SMS + * + * "data" is const RIL_CDMA_SMS_Ack * + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_SMS_TO_ACK + * INVALID_STATE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * MODEM_ERR + * INVALID_STATE + * OPERATION_NOT_ALLOWED + * NETWORK_NOT_READY + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE 88 + +/** + * RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG + * + * Request the setting of GSM/WCDMA Cell Broadcast SMS config. + * + * "data" is NULL + * + * "response" is a const RIL_GSM_BroadcastSmsConfigInfo ** + * "responselen" is count * sizeof (RIL_GSM_BroadcastSmsConfigInfo *) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * NO_RESOURCES + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG 89 + +/** + * RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG + * + * Set GSM/WCDMA Cell Broadcast SMS config + * + * "data" is a const RIL_GSM_BroadcastSmsConfigInfo ** + * "datalen" is count * sizeof(RIL_GSM_BroadcastSmsConfigInfo *) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG 90 + +/** + * RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION + * +* Enable or disable the reception of GSM/WCDMA Cell Broadcast SMS + * + * "data" is const int * + * (const int *)data[0] indicates to activate or turn off the + * reception of GSM/WCDMA Cell Broadcast SMS, 0-1, + * 0 - Activate, 1 - Turn off + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED +* MODEM_ERR +* INTERNAL_ERR +* NO_RESOURCES +* CANCELLED +* INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION 91 + +/** + * RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG + * + * Request the setting of CDMA Broadcast SMS config + * + * "data" is NULL + * + * "response" is a const RIL_CDMA_BroadcastSmsConfigInfo ** + * "responselen" is count * sizeof (RIL_CDMA_BroadcastSmsConfigInfo *) + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * NO_RESOURCES + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG 92 + +/** + * RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG + * + * Set CDMA Broadcast SMS config + * + * "data" is a const RIL_CDMA_BroadcastSmsConfigInfo ** + * "datalen" is count * sizeof(const RIL_CDMA_BroadcastSmsConfigInfo *) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * SYSTEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG 93 + +/** + * RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION + * + * Enable or disable the reception of CDMA Broadcast SMS + * + * "data" is const int * + * (const int *)data[0] indicates to activate or turn off the + * reception of CDMA Broadcast SMS, 0-1, + * 0 - Activate, 1 - Turn off + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_STATE + * INVALID_ARGUMENTS + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION 94 + +/** + * RIL_REQUEST_CDMA_SUBSCRIPTION + * + * Request the device MDN / H_SID / H_NID. + * + * The request is only allowed when CDMA subscription is available. When CDMA + * subscription is changed, application layer should re-issue the request to + * update the subscription information. + * + * If a NULL value is returned for any of the device id, it means that error + * accessing the device. + * + * "response" is const char ** + * ((const char **)response)[0] is MDN if CDMA subscription is available + * ((const char **)response)[1] is a comma separated list of H_SID (Home SID) if + * CDMA subscription is available, in decimal format + * ((const char **)response)[2] is a comma separated list of H_NID (Home NID) if + * CDMA subscription is available, in decimal format + * ((const char **)response)[3] is MIN (10 digits, MIN2+MIN1) if CDMA subscription is available + * ((const char **)response)[4] is PRL version if CDMA subscription is available + * + * Valid errors: + * SUCCESS + * RIL_E_SUBSCRIPTION_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * + */ + +#define RIL_REQUEST_CDMA_SUBSCRIPTION 95 + +/** + * RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM + * + * Stores a CDMA SMS message to RUIM memory. + * + * "data" is RIL_CDMA_SMS_WriteArgs * + * + * "response" is int * + * ((const int *)response)[0] is the record index where the message is stored. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SIM_FULL + * INVALID_ARGUMENTS + * INVALID_SMS_FORMAT + * INTERNAL_ERR + * MODEM_ERR + * ENCODING_ERR + * NO_MEMORY + * NO_RESOURCES + * INVALID_MODEM_STATE + * OPERATION_NOT_ALLOWED + * INVALID_SMSC_ADDRESS + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM 96 + +/** + * RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM + * + * Deletes a CDMA SMS message from RUIM memory. + * + * "data" is int * + * ((int *)data)[0] is the record index of the message to delete. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * MODEM_ERR + * NO_SUCH_ENTRY + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM 97 + +/** + * RIL_REQUEST_DEVICE_IDENTITY + * + * Request the device ESN / MEID / IMEI / IMEISV. + * + * The request is always allowed and contains GSM and CDMA device identity; + * it substitutes the deprecated requests RIL_REQUEST_GET_IMEI and + * RIL_REQUEST_GET_IMEISV. + * + * If a NULL value is returned for any of the device id, it means that error + * accessing the device. + * + * When CDMA subscription is changed the ESN/MEID may change. The application + * layer should re-issue the request to update the device identity in this case. + * + * "response" is const char ** + * ((const char **)response)[0] is IMEI if GSM subscription is available + * ((const char **)response)[1] is IMEISV if GSM subscription is available + * ((const char **)response)[2] is ESN if CDMA subscription is available + * ((const char **)response)[3] is MEID if CDMA subscription is available + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_DEVICE_IDENTITY 98 + +/** + * RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE + * + * Request the radio's system selection module to exit emergency + * callback mode. RIL will not respond with SUCCESS until the modem has + * completely exited from Emergency Callback Mode. + * + * "data" is NULL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE 99 + +/** + * RIL_REQUEST_GET_SMSC_ADDRESS + * + * Queries the default Short Message Service Center address on the device. + * + * "data" is NULL + * + * "response" is const char * containing the SMSC address. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * REQUEST_RATE_LIMITED + * SYSTEM_ERR + * INTERNAL_ERR + * MODEM_ERR + * INVALID_ARGUMENTS + * INVALID_MODEM_STATE + * NOT_PROVISIONED + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_GET_SMSC_ADDRESS 100 + +/** + * RIL_REQUEST_SET_SMSC_ADDRESS + * + * Sets the default Short Message Service Center address on the device. + * + * "data" is const char * containing the SMSC address. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * INVALID_SMS_FORMAT + * NO_MEMORY + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * NO_RESOURCES + * INTERNAL_ERR + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_SET_SMSC_ADDRESS 101 + +/** + * RIL_REQUEST_REPORT_SMS_MEMORY_STATUS + * + * Indicates whether there is storage available for new SMS messages. + * + * "data" is int * + * ((int *)data)[0] is 1 if memory is available for storing new messages + * is 0 if memory capacity is exceeded + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INVALID_ARGUMENTS + * NO_MEMORY + * INVALID_STATE + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_REPORT_SMS_MEMORY_STATUS 102 + +/** + * RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING + * + * Indicates that the StkSerivce is running and is + * ready to receive RIL_UNSOL_STK_XXXXX commands. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING 103 + +/** + * RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE + * + * Request to query the location where the CDMA subscription shall + * be retrieved + * + * "data" is NULL + * + * "response" is int * + * ((int *)data)[0] is == RIL_CdmaSubscriptionSource + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SUBSCRIPTION_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + * See also: RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE + */ +#define RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE 104 + +/** + * RIL_REQUEST_ISIM_AUTHENTICATION + * + * Request the ISIM application on the UICC to perform AKA + * challenge/response algorithm for IMS authentication + * + * "data" is a const char * containing the challenge string in Base64 format + * "response" is a const char * containing the response in Base64 format + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_ISIM_AUTHENTICATION 105 + +/** + * RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU + * + * Acknowledge successful or failed receipt of SMS previously indicated + * via RIL_UNSOL_RESPONSE_NEW_SMS, including acknowledgement TPDU to send + * as the RP-User-Data element of the RP-ACK or RP-ERROR PDU. + * + * "data" is const char ** + * ((const char **)data)[0] is "1" on successful receipt (send RP-ACK) + * is "0" on failed receipt (send RP-ERROR) + * ((const char **)data)[1] is the acknowledgement TPDU in hexadecimal format + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU 106 + +/** + * RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS + * + * Requests to send a SAT/USAT envelope command to SIM. + * The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111. + * + * This request has one difference from RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: + * the SW1 and SW2 status bytes from the UICC response are returned along with + * the response data, using the same structure as RIL_REQUEST_SIM_IO. + * + * The RIL implementation shall perform the normal processing of a '91XX' + * response in SW1/SW2 to retrieve the pending proactive command and send it + * as an unsolicited response, as RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND does. + * + * "data" is a const char * containing the SAT/USAT command + * in hexadecimal format starting with command tag + * + * "response" is a const RIL_SIM_IO_Response * + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE (radio resetting) + * SIM_BUSY + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS 107 + +/** + * RIL_REQUEST_VOICE_RADIO_TECH + * + * Query the radio technology type (3GPP/3GPP2) used for voice. Query is valid only + * when radio state is not RADIO_STATE_UNAVAILABLE + * + * "data" is NULL + * "response" is int * + * ((int *) response)[0] is of type const RIL_RadioTechnology + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_VOICE_RADIO_TECH 108 + +/** + * RIL_REQUEST_GET_CELL_INFO_LIST + * + * Request all of the current cell information known to the radio. The radio + * must a list of all current cells, including the neighboring cells. If for a particular + * cell information isn't known then the appropriate unknown value will be returned. + * This does not cause or change the rate of RIL_UNSOL_CELL_INFO_LIST. + * + * "data" is NULL + * + * "response" is an array of RIL_CellInfo_v12. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NO_NETWORK_FOUND + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_GET_CELL_INFO_LIST 109 + +/** + * RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE + * + * Sets the minimum time between when RIL_UNSOL_CELL_INFO_LIST should be invoked. + * A value of 0, means invoke RIL_UNSOL_CELL_INFO_LIST when any of the reported + * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue + * a RIL_UNSOL_CELL_INFO_LIST. + * + * "data" is int * + * ((int *)data)[0] is minimum time in milliseconds + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE 110 + +/** + * RIL_REQUEST_SET_INITIAL_ATTACH_APN + * + * Set an apn to initial attach network + * + * "data" is a const char ** + * ((const char **)data)[0] is the APN to connect if radio technology is LTE + * ((const char **)data)[1] is the connection type to request must be one of the + * PDP_type values in TS 27.007 section 10.1.1. + * For example, "IP", "IPV6", "IPV4V6", or "PPP". + * ((const char **)data)[2] is the PAP / CHAP auth type. Values: + * 0 => PAP and CHAP is never performed. + * 1 => PAP may be performed; CHAP is never performed. + * 2 => CHAP may be performed; PAP is never performed. + * 3 => PAP / CHAP may be performed - baseband dependent. + * ((const char **)data)[3] is the username for APN, or NULL + * ((const char **)data)[4] is the password for APN, or NULL + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SUBSCRIPTION_NOT_AVAILABLE + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_SET_INITIAL_ATTACH_APN 111 + +/** + * RIL_REQUEST_IMS_REGISTRATION_STATE + * + * This message is DEPRECATED and shall be removed in a future release (target: 2018); + * instead, provide IMS registration status via an IMS Service. + * + * Request current IMS registration state + * + * "data" is NULL + * + * "response" is int * + * ((int *)response)[0] is registration state: + * 0 - Not registered + * 1 - Registered + * + * If ((int*)response)[0] is = 1, then ((int *) response)[1] + * must follow with IMS SMS format: + * + * ((int *) response)[1] is of type RIL_RadioTechnologyFamily + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_IMS_REGISTRATION_STATE 112 + +/** + * RIL_REQUEST_IMS_SEND_SMS + * + * Send a SMS message over IMS + * + * "data" is const RIL_IMS_SMS_Message * + * + * "response" is a const RIL_SMS_Response * + * + * Based on the return error, caller decides to resend if sending sms + * fails. SMS_SEND_FAIL_RETRY means retry, and other errors means no retry. + * In case of retry, data is encoded based on Voice Technology available. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * SMS_SEND_FAIL_RETRY + * FDN_CHECK_FAILURE + * NETWORK_REJECT + * INVALID_ARGUMENTS + * INVALID_STATE + * NO_MEMORY + * INVALID_SMS_FORMAT + * SYSTEM_ERR + * REQUEST_RATE_LIMITED + * MODEM_ERR + * NETWORK_ERR + * ENCODING_ERR + * INVALID_SMSC_ADDRESS + * OPERATION_NOT_ALLOWED + * INTERNAL_ERR + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_IMS_SEND_SMS 113 + +/** + * RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC + * + * Request APDU exchange on the basic channel. This command reflects TS 27.007 + * "generic SIM access" operation (+CSIM). The modem must ensure proper function + * of GSM/CDMA, and filter commands appropriately. It should filter + * channel management and SELECT by DF name commands. + * + * "data" is a const RIL_SIM_APDU * + * "sessionid" field should be ignored. + * + * "response" is a const RIL_SIM_IO_Response * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC 114 + +/** + * RIL_REQUEST_SIM_OPEN_CHANNEL + * + * Open a new logical channel and select the given application. This command + * reflects TS 27.007 "open logical channel" operation (+CCHO). This request + * also specifies the P2 parameter (described in ISO 7816-4). + * + * "data" is a const RIL_OpenChannelParam * + * + * "response" is int * + * ((int *)data)[0] contains the session id of the logical channel. + * ((int *)data)[1] onwards may optionally contain the select response for the + * open channel command with one byte per integer. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * MISSING_RESOURCE + * NO_SUCH_ELEMENT + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * SIM_ERR + * INVALID_SIM_STATE + * MISSING_RESOURCE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_OPEN_CHANNEL 115 + +/** + * RIL_REQUEST_SIM_CLOSE_CHANNEL + * + * Close a previously opened logical channel. This command reflects TS 27.007 + * "close logical channel" operation (+CCHC). + * + * "data" is int * + * ((int *)data)[0] is the session id of logical the channel to close. + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_CLOSE_CHANNEL 116 + +/** + * RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL + * + * Exchange APDUs with a UICC over a previously opened logical channel. This + * command reflects TS 27.007 "generic logical channel access" operation + * (+CGLA). The modem should filter channel management and SELECT by DF name + * commands. + * + * "data" is a const RIL_SIM_APDU* + * + * "response" is a const RIL_SIM_IO_Response * + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL 117 + +/** + * RIL_REQUEST_NV_READ_ITEM + * + * Read one of the radio NV items defined in RadioNVItems.java / ril_nv_items.h. + * This is used for device configuration by some CDMA operators. + * + * "data" is a const RIL_NV_ReadItem * + * + * "response" is const char * containing the contents of the NV item + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_READ_ITEM 118 + +/** + * RIL_REQUEST_NV_WRITE_ITEM + * + * Write one of the radio NV items defined in RadioNVItems.java / ril_nv_items.h. + * This is used for device configuration by some CDMA operators. + * + * "data" is a const RIL_NV_WriteItem * + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_WRITE_ITEM 119 + +/** + * RIL_REQUEST_NV_WRITE_CDMA_PRL + * + * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. + * This is used for device configuration by some CDMA operators. + * + * "data" is a const char * containing the PRL as a byte array + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_WRITE_CDMA_PRL 120 + +/** + * RIL_REQUEST_NV_RESET_CONFIG + * + * Reset the radio NV configuration to the factory state. + * This is used for device configuration by some CDMA operators. + * + * "data" is int * + * ((int *)data)[0] is 1 to reload all NV items + * ((int *)data)[0] is 2 for erase NV reset (SCRTN) + * ((int *)data)[0] is 3 for factory reset (RTN) + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_NV_RESET_CONFIG 121 + + /** RIL_REQUEST_SET_UICC_SUBSCRIPTION + * FIXME This API needs to have more documentation. + * + * Selection/de-selection of a subscription from a SIM card + * "data" is const RIL_SelectUiccSub* + + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SUBSCRIPTION_NOT_SUPPORTED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_SET_UICC_SUBSCRIPTION 122 + +/** + * RIL_REQUEST_ALLOW_DATA + * + * Tells the modem whether data calls are allowed or not + * + * "data" is int * + * FIXME slotId and aid will be added. + * ((int *)data)[0] is == 0 to allow data calls + * ((int *)data)[0] is == 1 to disallow data calls + * + * "response" is NULL + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * INVALID_ARGUMENTS + * DEVICE_IN_USE + * INVALID_MODEM_STATE + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_ALLOW_DATA 123 + +/** + * RIL_REQUEST_GET_HARDWARE_CONFIG + * + * Request all of the current hardware (modem and sim) associated + * with the RIL. + * + * "data" is NULL + * + * "response" is an array of RIL_HardwareConfig. + * + * Valid errors: + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_GET_HARDWARE_CONFIG 124 + +/** + * RIL_REQUEST_SIM_AUTHENTICATION + * + * Returns the response of SIM Authentication through RIL to a + * challenge request. + * + * "data" Base64 encoded string containing challenge: + * int authContext; P2 value of authentication command, see P2 parameter in + * 3GPP TS 31.102 7.1.2 + * char *authData; the challenge string in Base64 format, see 3GPP + * TS 31.102 7.1.2 + * char *aid; AID value, See ETSI 102.221 8.1 and 101.220 4, + * NULL if no value + * + * "response" Base64 encoded strings containing response: + * int sw1; Status bytes per 3GPP TS 31.102 section 7.3 + * int sw2; + * char *simResponse; Response in Base64 format, see 3GPP TS 31.102 7.1.2 + * + * Valid errors: + * RADIO_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * INVALID_MODEM_STATE + * INVALID_ARGUMENTS + * SIM_ERR + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SIM_AUTHENTICATION 125 + +/** + * RIL_REQUEST_GET_DC_RT_INFO + * + * The request is DEPRECATED, use RIL_REQUEST_GET_ACTIVITY_INFO + * Requests the Data Connection Real Time Info + * + * "data" is NULL + * + * "response" is the most recent RIL_DcRtInfo + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * + * See also: RIL_UNSOL_DC_RT_INFO_CHANGED + */ +#define RIL_REQUEST_GET_DC_RT_INFO 126 + +/** + * RIL_REQUEST_SET_DC_RT_INFO_RATE + * + * The request is DEPRECATED + * This is the minimum number of milliseconds between successive + * RIL_UNSOL_DC_RT_INFO_CHANGED messages and defines the highest rate + * at which RIL_UNSOL_DC_RT_INFO_CHANGED's will be sent. A value of + * 0 means send as fast as possible. + * + * "data" The number of milliseconds as an int + * + * "response" is null + * + * Valid errors: + * SUCCESS must not fail + */ +#define RIL_REQUEST_SET_DC_RT_INFO_RATE 127 + +/** + * RIL_REQUEST_SET_DATA_PROFILE + * + * Set data profile in modem + * Modem should erase existed profiles from framework, and apply new profiles + * "data" is a const RIL_DataProfileInfo ** + * "datalen" is count * sizeof(const RIL_DataProfileInfo *) + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * SUBSCRIPTION_NOT_AVAILABLE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_SET_DATA_PROFILE 128 + +/** + * RIL_REQUEST_SHUTDOWN + * + * Device is shutting down. All further commands are ignored + * and RADIO_NOT_AVAILABLE must be returned. + * + * "data" is null + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SHUTDOWN 129 + +/** + * RIL_REQUEST_GET_RADIO_CAPABILITY + * + * Used to get phone radio capablility. + * + * "data" is the RIL_RadioCapability structure + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * INVALID_STATE + * REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_GET_RADIO_CAPABILITY 130 + +/** + * RIL_REQUEST_SET_RADIO_CAPABILITY + * + * Used to set the phones radio capability. Be VERY careful + * using this request as it may cause some vendor modems to reset. Because + * of the possible modem reset any RIL commands after this one may not be + * processed. + * + * "data" is the RIL_RadioCapability structure + * + * "response" is the RIL_RadioCapability structure, used to feedback return status + * + * Valid errors: + * SUCCESS means a RIL_UNSOL_RADIO_CAPABILITY will be sent within 30 seconds. + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * MODEM_ERR + * INVALID_STATE + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_RADIO_CAPABILITY 131 + +/** + * RIL_REQUEST_START_LCE + * + * Start Link Capacity Estimate (LCE) service if supported by the radio. + * + * "data" is const int * + * ((const int*)data)[0] specifies the desired reporting interval (ms). + * ((const int*)data)[1] specifies the LCE service mode. 1: PULL; 0: PUSH. + * + * "response" is the RIL_LceStatusInfo. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * LCE_NOT_SUPPORTED + * INTERNAL_ERR + * REQUEST_NOT_SUPPORTED + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_START_LCE 132 + +/** + * RIL_REQUEST_STOP_LCE + * + * Stop Link Capacity Estimate (LCE) service, the STOP operation should be + * idempotent for the radio modem. + * + * "response" is the RIL_LceStatusInfo. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * LCE_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_STOP_LCE 133 + +/** + * RIL_REQUEST_PULL_LCEDATA + * + * Pull LCE service for capacity information. + * + * "response" is the RIL_LceDataInfo. + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * LCE_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + */ +#define RIL_REQUEST_PULL_LCEDATA 134 + +/** + * RIL_REQUEST_GET_ACTIVITY_INFO + * + * Get modem activity information for power consumption estimation. + * + * Request clear-on-read statistics information that is used for + * estimating the per-millisecond power consumption of the cellular + * modem. + * + * "data" is null + * "response" is const RIL_ActivityStatsInfo * + * + * Valid errors: + * + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * MODEM_ERR + * NOT_PROVISIONED + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES CANCELLED + */ +#define RIL_REQUEST_GET_ACTIVITY_INFO 135 + +/** + * RIL_REQUEST_SET_CARRIER_RESTRICTIONS + * + * Set carrier restrictions for this sim slot. Expected modem behavior: + * If never receives this command + * - Must allow all carriers + * Receives this command with data being NULL + * - Must allow all carriers. If a previously allowed SIM is present, modem must not reload + * the SIM. If a previously disallowed SIM is present, reload the SIM and notify Android. + * Receives this command with a list of carriers + * - Only allow specified carriers, persist across power cycles and FDR. If a present SIM + * is in the allowed list, modem must not reload the SIM. If a present SIM is *not* in + * the allowed list, modem must detach from the registered network and only keep emergency + * service, and notify Android SIM refresh reset with new SIM state being + * RIL_CARDSTATE_RESTRICTED. Emergency service must be enabled. + * + * "data" is const RIL_CarrierRestrictions * + * A list of allowed carriers and possibly a list of excluded carriers. + * If data is NULL, means to clear previous carrier restrictions and allow all carriers + * + * "response" is int * + * ((int *)data)[0] contains the number of allowed carriers which have been set correctly. + * On success, it should match the length of list data->allowed_carriers. + * If data is NULL, the value must be 0. + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_INVALID_ARGUMENTS + * RIL_E_RADIO_NOT_AVAILABLE + * RIL_E_REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_CARRIER_RESTRICTIONS 136 + +/** + * RIL_REQUEST_GET_CARRIER_RESTRICTIONS + * + * Get carrier restrictions for this sim slot. Expected modem behavior: + * Return list of allowed carriers, or null if all carriers are allowed. + * + * "data" is NULL + * + * "response" is const RIL_CarrierRestrictions *. + * If response is NULL, it means all carriers are allowed. + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE + * RIL_E_REQUEST_NOT_SUPPORTED + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_GET_CARRIER_RESTRICTIONS 137 + +/** + * RIL_REQUEST_SEND_DEVICE_STATE + * + * Send the updated device state. + * Modem can perform power saving based on the provided device state. + * "data" is const int * + * ((const int*)data)[0] A RIL_DeviceStateType that specifies the device state type. + * ((const int*)data)[1] Specifies the state. See RIL_DeviceStateType for the definition of each + * type. + * + * "datalen" is count * sizeof(const RIL_DeviceState *) + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SEND_DEVICE_STATE 138 + +/** + * RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER + * + * Set the unsolicited response filter + * This is used to prevent unnecessary application processor + * wake up for power saving purposes by suppressing the + * unsolicited responses in certain scenarios. + * + * "data" is an int * + * + * ((int *)data)[0] is a 32-bit bitmask of RIL_UnsolicitedResponseFilter + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * INVALID_ARGUMENTS (e.g. the requested filter doesn't exist) + * RADIO_NOT_AVAILABLE (radio resetting) + * NO_MEMORY + * INTERNAL_ERR + * SYSTEM_ERR + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER 139 + + /** + * RIL_REQUEST_SET_SIM_CARD_POWER + * + * Set SIM card power up or down + * + * Request is equivalent to inserting and removing the card, with + * an additional effect where the ability to detect card removal/insertion + * is disabled when the SIM card is powered down. + * + * This will generate RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED + * as if the SIM had been inserted or removed. + * + * "data" is int * + * ((int *)data)[0] is 1 for "SIM POWER UP" + * ((int *)data)[0] is 0 for "SIM POWER DOWN" + * + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * REQUEST_NOT_SUPPORTED + * SIM_ABSENT + * INVALID_ARGUMENTS + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_SIM_CARD_POWER 140 + +/** + * RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION + * + * Provide Carrier specific information to the modem that will be used to + * encrypt the IMSI and IMPI. Sent by the framework during boot, carrier + * switch and everytime we receive a new certificate. + * + * "data" is the RIL_CarrierInfoForImsiEncryption * structure. + * + * "response" is NULL + * + * Valid errors: + * RIL_E_SUCCESS + * RIL_E_RADIO_NOT_AVAILABLE + * SIM_ABSENT + * RIL_E_REQUEST_NOT_SUPPORTED + * INVALID_ARGUMENTS + * MODEM_INTERNAL_FAILURE + * INTERNAL_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + */ +#define RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION 141 + +/** + * RIL_REQUEST_START_NETWORK_SCAN + * + * Starts a new network scan + * + * Request to start a network scan with specified radio access networks with frequency bands and/or + * channels. + * + * "data" is a const RIL_NetworkScanRequest *. + * "response" is NULL + * + * Valid errors: + * SUCCESS + * RADIO_NOT_AVAILABLE + * OPERATION_NOT_ALLOWED + * DEVICE_IN_USE + * INTERNAL_ERR + * NO_MEMORY + * MODEM_ERR + * INVALID_ARGUMENTS + * REQUEST_NOT_SUPPORTED + * NO_RESOURCES + * CANCELLED + * + */ +#define RIL_REQUEST_START_NETWORK_SCAN 142 + +/** + * RIL_REQUEST_STOP_NETWORK_SCAN + * + * Stops an ongoing network scan + * + * Request to stop the ongoing network scan. Since the modem can only perform one scan at a time, + * there is no parameter for this request. + * + * "data" is NULL + * "response" is NULL + * + * Valid errors: + * SUCCESS + * INTERNAL_ERR + * MODEM_ERR + * NO_MEMORY + * NO_RESOURCES + * CANCELLED + * REQUEST_NOT_SUPPORTED + * + */ +#define RIL_REQUEST_STOP_NETWORK_SCAN 143 + +/** + * RIL_REQUEST_START_KEEPALIVE + * + * Start a keepalive session + * + * Request that the modem begin sending keepalive packets on a particular + * data call, with a specified source, destination, and format. + * + * "data" is a const RIL_RequestKeepalive + * "response" is RIL_KeepaliveStatus with a valid "handle" + * + * Valid errors: + * SUCCESS + * NO_RESOURCES + * INVALID_ARGUMENTS + * + */ +#define RIL_REQUEST_START_KEEPALIVE 144 + +/** + * RIL_REQUEST_STOP_KEEPALIVE + * + * Stops an ongoing keepalive session + * + * Requests that a keepalive session with the given handle be stopped. + * there is no parameter for this request. + * + * "data" is an integer handle + * "response" is NULL + * + * Valid errors: + * SUCCESS + * INVALID_ARGUMENTS + * + */ +#define RIL_REQUEST_STOP_KEEPALIVE 145 + +/***********************************************************************/ + +/** + * RIL_RESPONSE_ACKNOWLEDGEMENT + * + * This is used by Asynchronous solicited messages and Unsolicited messages + * to acknowledge the receipt of those messages in RIL.java so that the ack + * can be used to let ril.cpp to release wakelock. + * + * Valid errors + * SUCCESS + * RADIO_NOT_AVAILABLE + */ + +#define RIL_RESPONSE_ACKNOWLEDGEMENT 800 + +/***********************************************************************/ + + +#define RIL_UNSOL_RESPONSE_BASE 1000 + +/** + * RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED + * + * Indicate when value of RIL_RadioState has changed. + * + * Callee will invoke RIL_RadioStateRequest method on main thread + * + * "data" is NULL + */ + +#define RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED 1000 + + +/** + * RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED + * + * Indicate when call state has changed + * + * Callee will invoke RIL_REQUEST_GET_CURRENT_CALLS on main thread + * + * "data" is NULL + * + * Response should be invoked on, for example, + * "RING", "BUSY", "NO CARRIER", and also call state + * transitions (DIALING->ALERTING ALERTING->ACTIVE) + * + * Redundent or extraneous invocations are tolerated + */ +#define RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 1001 + + +/** + * RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED + * + * Called when the voice network state changed + * + * Callee will invoke the following requests on main thread: + * + * RIL_REQUEST_VOICE_REGISTRATION_STATE + * RIL_REQUEST_OPERATOR + * + * "data" is NULL + * + * FIXME should this happen when SIM records are loaded? (eg, for + * EONS) + */ +#define RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 1002 + +/** + * RIL_UNSOL_RESPONSE_NEW_SMS + * + * Called when new SMS is received. + * + * "data" is const char * + * This is a pointer to a string containing the PDU of an SMS-DELIVER + * as an ascii string of hex digits. The PDU starts with the SMSC address + * per TS 27.005 (+CMT:) + * + * Callee will subsequently confirm the receipt of thei SMS with a + * RIL_REQUEST_SMS_ACKNOWLEDGE + * + * No new RIL_UNSOL_RESPONSE_NEW_SMS + * or RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT messages should be sent until a + * RIL_REQUEST_SMS_ACKNOWLEDGE has been received + */ + +#define RIL_UNSOL_RESPONSE_NEW_SMS 1003 + +/** + * RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT + * + * Called when new SMS Status Report is received. + * + * "data" is const char * + * This is a pointer to a string containing the PDU of an SMS-STATUS-REPORT + * as an ascii string of hex digits. The PDU starts with the SMSC address + * per TS 27.005 (+CDS:). + * + * Callee will subsequently confirm the receipt of the SMS with a + * RIL_REQUEST_SMS_ACKNOWLEDGE + * + * No new RIL_UNSOL_RESPONSE_NEW_SMS + * or RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT messages should be sent until a + * RIL_REQUEST_SMS_ACKNOWLEDGE has been received + */ + +#define RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT 1004 + +/** + * RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM + * + * Called when new SMS has been stored on SIM card + * + * "data" is const int * + * ((const int *)data)[0] contains the slot index on the SIM that contains + * the new message + */ + +#define RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM 1005 + +/** + * RIL_UNSOL_ON_USSD + * + * Called when a new USSD message is received. + * + * "data" is const char ** + * ((const char **)data)[0] points to a type code, which is + * one of these string values: + * "0" USSD-Notify -- text in ((const char **)data)[1] + * "1" USSD-Request -- text in ((const char **)data)[1] + * "2" Session terminated by network + * "3" other local client (eg, SIM Toolkit) has responded + * "4" Operation not supported + * "5" Network timeout + * + * The USSD session is assumed to persist if the type code is "1", otherwise + * the current session (if any) is assumed to have terminated. + * + * ((const char **)data)[1] points to a message string if applicable, which + * should always be in UTF-8. + */ +#define RIL_UNSOL_ON_USSD 1006 +/* Previously #define RIL_UNSOL_ON_USSD_NOTIFY 1006 */ + +/** + * RIL_UNSOL_ON_USSD_REQUEST + * + * Obsolete. Send via RIL_UNSOL_ON_USSD + */ +#define RIL_UNSOL_ON_USSD_REQUEST 1007 + +/** + * RIL_UNSOL_NITZ_TIME_RECEIVED + * + * Called when radio has received a NITZ time message + * + * "data" is const char * pointing to NITZ time string + * in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt" + */ +#define RIL_UNSOL_NITZ_TIME_RECEIVED 1008 + +/** + * RIL_UNSOL_SIGNAL_STRENGTH + * + * Radio may report signal strength rather han have it polled. + * + * "data" is a const RIL_SignalStrength * + */ +#define RIL_UNSOL_SIGNAL_STRENGTH 1009 + + +/** + * RIL_UNSOL_DATA_CALL_LIST_CHANGED + * + * "data" is an array of RIL_Data_Call_Response_v6 identical to that + * returned by RIL_REQUEST_DATA_CALL_LIST. It is the complete list + * of current data contexts including new contexts that have been + * activated. A data call is only removed from this list when the + * framework sends a RIL_REQUEST_DEACTIVATE_DATA_CALL or the radio + * is powered off/on. + * + * See also: RIL_REQUEST_DATA_CALL_LIST + */ + +#define RIL_UNSOL_DATA_CALL_LIST_CHANGED 1010 + +/** + * RIL_UNSOL_SUPP_SVC_NOTIFICATION + * + * Reports supplementary service related notification from the network. + * + * "data" is a const RIL_SuppSvcNotification * + * + */ + +#define RIL_UNSOL_SUPP_SVC_NOTIFICATION 1011 + +/** + * RIL_UNSOL_STK_SESSION_END + * + * Indicate when STK session is terminated by SIM. + * + * "data" is NULL + */ +#define RIL_UNSOL_STK_SESSION_END 1012 + +/** + * RIL_UNSOL_STK_PROACTIVE_COMMAND + * + * Indicate when SIM issue a STK proactive command to applications + * + * "data" is a const char * containing SAT/USAT proactive command + * in hexadecimal format string starting with command tag + * + */ +#define RIL_UNSOL_STK_PROACTIVE_COMMAND 1013 + +/** + * RIL_UNSOL_STK_EVENT_NOTIFY + * + * Indicate when SIM notifies applcations some event happens. + * Generally, application does not need to have any feedback to + * SIM but shall be able to indicate appropriate messages to users. + * + * "data" is a const char * containing SAT/USAT commands or responses + * sent by ME to SIM or commands handled by ME, in hexadecimal format string + * starting with first byte of response data or command tag + * + */ +#define RIL_UNSOL_STK_EVENT_NOTIFY 1014 + +/** + * RIL_UNSOL_STK_CALL_SETUP + * + * Indicate when SIM wants application to setup a voice call. + * + * "data" is const int * + * ((const int *)data)[0] contains timeout value (in milliseconds) + */ +#define RIL_UNSOL_STK_CALL_SETUP 1015 + +/** + * RIL_UNSOL_SIM_SMS_STORAGE_FULL + * + * Indicates that SMS storage on the SIM is full. Sent when the network + * attempts to deliver a new SMS message. Messages cannot be saved on the + * SIM until space is freed. In particular, incoming Class 2 messages + * cannot be stored. + * + * "data" is null + * + */ +#define RIL_UNSOL_SIM_SMS_STORAGE_FULL 1016 + +/** + * RIL_UNSOL_SIM_REFRESH + * + * Indicates that file(s) on the SIM have been updated, or the SIM + * has been reinitialized. + * + * In the case where RIL is version 6 or older: + * "data" is an int * + * ((int *)data)[0] is a RIL_SimRefreshResult. + * ((int *)data)[1] is the EFID of the updated file if the result is + * SIM_FILE_UPDATE or NULL for any other result. + * + * In the case where RIL is version 7: + * "data" is a RIL_SimRefreshResponse_v7 * + * + * Note: If the SIM state changes as a result of the SIM refresh (eg, + * SIM_READY -> SIM_LOCKED_OR_ABSENT), RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED + * should be sent. + */ +#define RIL_UNSOL_SIM_REFRESH 1017 + +/** + * RIL_UNSOL_CALL_RING + * + * Ring indication for an incoming call (eg, RING or CRING event). + * There must be at least one RIL_UNSOL_CALL_RING at the beginning + * of a call and sending multiple is optional. If the system property + * ro.telephony.call_ring.multiple is false then the upper layers + * will generate the multiple events internally. Otherwise the vendor + * ril must generate multiple RIL_UNSOL_CALL_RING if + * ro.telephony.call_ring.multiple is true or if it is absent. + * + * The rate of these events is controlled by ro.telephony.call_ring.delay + * and has a default value of 3000 (3 seconds) if absent. + * + * "data" is null for GSM + * "data" is const RIL_CDMA_SignalInfoRecord * if CDMA + */ +#define RIL_UNSOL_CALL_RING 1018 + +/** + * RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED + * + * Indicates that SIM state changes. + * + * Callee will invoke RIL_REQUEST_GET_SIM_STATUS on main thread + + * "data" is null + */ +#define RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED 1019 + +/** + * RIL_UNSOL_RESPONSE_CDMA_NEW_SMS + * + * Called when new CDMA SMS is received + * + * "data" is const RIL_CDMA_SMS_Message * + * + * Callee will subsequently confirm the receipt of the SMS with + * a RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE + * + * No new RIL_UNSOL_RESPONSE_CDMA_NEW_SMS should be sent until + * RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE has been received + * + */ +#define RIL_UNSOL_RESPONSE_CDMA_NEW_SMS 1020 + +/** + * RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS + * + * Called when new Broadcast SMS is received + * + * "data" can be one of the following: + * If received from GSM network, "data" is const char of 88 bytes + * which indicates each page of a CBS Message sent to the MS by the + * BTS as coded in 3GPP 23.041 Section 9.4.1.2. + * If received from UMTS network, "data" is const char of 90 up to 1252 + * bytes which contain between 1 and 15 CBS Message pages sent as one + * packet to the MS by the BTS as coded in 3GPP 23.041 Section 9.4.2.2. + * + */ +#define RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS 1021 + +/** + * RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL + * + * Indicates that SMS storage on the RUIM is full. Messages + * cannot be saved on the RUIM until space is freed. + * + * "data" is null + * + */ +#define RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL 1022 + +/** + * RIL_UNSOL_RESTRICTED_STATE_CHANGED + * + * Indicates a restricted state change (eg, for Domain Specific Access Control). + * + * Radio need send this msg after radio off/on cycle no matter it is changed or not. + * + * "data" is an int * + * ((int *)data)[0] contains a bitmask of RIL_RESTRICTED_STATE_* values. + */ +#define RIL_UNSOL_RESTRICTED_STATE_CHANGED 1023 + +/** + * RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE + * + * Indicates that the radio system selection module has + * autonomously entered emergency callback mode. + * + * "data" is null + * + */ +#define RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE 1024 + +/** + * RIL_UNSOL_CDMA_CALL_WAITING + * + * Called when CDMA radio receives a call waiting indication. + * + * "data" is const RIL_CDMA_CallWaiting * + * + */ +#define RIL_UNSOL_CDMA_CALL_WAITING 1025 + +/** + * RIL_UNSOL_CDMA_OTA_PROVISION_STATUS + * + * Called when CDMA radio receives an update of the progress of an + * OTASP/OTAPA call. + * + * "data" is const int * + * For CDMA this is an integer OTASP/OTAPA status listed in + * RIL_CDMA_OTA_ProvisionStatus. + * + */ +#define RIL_UNSOL_CDMA_OTA_PROVISION_STATUS 1026 + +/** + * RIL_UNSOL_CDMA_INFO_REC + * + * Called when CDMA radio receives one or more info recs. + * + * "data" is const RIL_CDMA_InformationRecords * + * + */ +#define RIL_UNSOL_CDMA_INFO_REC 1027 + +/** + * RIL_UNSOL_OEM_HOOK_RAW + * + * This is for OEM specific use. + * + * "data" is a byte[] + */ +#define RIL_UNSOL_OEM_HOOK_RAW 1028 + +/** + * RIL_UNSOL_RINGBACK_TONE + * + * Indicates that nework doesn't have in-band information, need to + * play out-band tone. + * + * "data" is an int * + * ((int *)data)[0] == 0 for stop play ringback tone. + * ((int *)data)[0] == 1 for start play ringback tone. + */ +#define RIL_UNSOL_RINGBACK_TONE 1029 + +/** + * RIL_UNSOL_RESEND_INCALL_MUTE + * + * Indicates that framework/application need reset the uplink mute state. + * + * There may be situations where the mute state becomes out of sync + * between the application and device in some GSM infrastructures. + * + * "data" is null + */ +#define RIL_UNSOL_RESEND_INCALL_MUTE 1030 + +/** + * RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED + * + * Called when CDMA subscription source changed. + * + * "data" is int * + * ((int *)data)[0] is == RIL_CdmaSubscriptionSource + */ +#define RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED 1031 + +/** + * RIL_UNSOL_CDMA_PRL_CHANGED + * + * Called when PRL (preferred roaming list) changes. + * + * "data" is int * + * ((int *)data)[0] is PRL_VERSION as would be returned by RIL_REQUEST_CDMA_SUBSCRIPTION + */ +#define RIL_UNSOL_CDMA_PRL_CHANGED 1032 + +/** + * RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE + * + * Called when Emergency Callback Mode Ends + * + * Indicates that the radio system selection module has + * proactively exited emergency callback mode. + * + * "data" is NULL + * + */ +#define RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE 1033 + +/** + * RIL_UNSOL_RIL_CONNECTED + * + * Called the ril connects and returns the version + * + * "data" is int * + * ((int *)data)[0] is RIL_VERSION + */ +#define RIL_UNSOL_RIL_CONNECTED 1034 + +/** + * RIL_UNSOL_VOICE_RADIO_TECH_CHANGED + * + * Indicates that voice technology has changed. Contains new radio technology + * as a data in the message. + * + * "data" is int * + * ((int *)data)[0] is of type const RIL_RadioTechnology + * + */ +#define RIL_UNSOL_VOICE_RADIO_TECH_CHANGED 1035 + +/** + * RIL_UNSOL_CELL_INFO_LIST + * + * Same information as returned by RIL_REQUEST_GET_CELL_INFO_LIST, but returned + * at the rate no greater than specified by RIL_REQUEST_SET_UNSOL_CELL_INFO_RATE. + * + * "data" is NULL + * + * "response" is an array of RIL_CellInfo_v12. + */ +#define RIL_UNSOL_CELL_INFO_LIST 1036 + +/** + * RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED + * + * This message is DEPRECATED and shall be removed in a future release (target: 2018); + * instead, provide IMS registration status via an IMS Service. + * + * Called when IMS registration state has changed + * + * To get IMS registration state and IMS SMS format, callee needs to invoke the + * following request on main thread: + * + * RIL_REQUEST_IMS_REGISTRATION_STATE + * + * "data" is NULL + * + */ +#define RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED 1037 + +/** + * RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED + * + * Indicated when there is a change in subscription status. + * This event will be sent in the following scenarios + * - subscription readiness at modem, which was selected by telephony layer + * - when subscription is deactivated by modem due to UICC card removal + * - When network invalidates the subscription i.e. attach reject due to authentication reject + * + * "data" is const int * + * ((const int *)data)[0] == 0 for Subscription Deactivated + * ((const int *)data)[0] == 1 for Subscription Activated + * + */ +#define RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED 1038 + +/** + * RIL_UNSOL_SRVCC_STATE_NOTIFY + * + * Called when Single Radio Voice Call Continuity(SRVCC) + * progress state has changed + * + * "data" is int * + * ((int *)data)[0] is of type const RIL_SrvccState + * + */ + +#define RIL_UNSOL_SRVCC_STATE_NOTIFY 1039 + +/** + * RIL_UNSOL_HARDWARE_CONFIG_CHANGED + * + * Called when the hardware configuration associated with the RILd changes + * + * "data" is an array of RIL_HardwareConfig + * + */ +#define RIL_UNSOL_HARDWARE_CONFIG_CHANGED 1040 + +/** + * RIL_UNSOL_DC_RT_INFO_CHANGED + * + * The message is DEPRECATED, use RIL_REQUEST_GET_ACTIVITY_INFO + * Sent when the DC_RT_STATE changes but the time + * between these messages must not be less than the + * value set by RIL_REQUEST_SET_DC_RT_RATE. + * + * "data" is the most recent RIL_DcRtInfo + * + */ +#define RIL_UNSOL_DC_RT_INFO_CHANGED 1041 + +/** + * RIL_UNSOL_RADIO_CAPABILITY + * + * Sent when RIL_REQUEST_SET_RADIO_CAPABILITY completes. + * Returns the phone radio capability exactly as + * RIL_REQUEST_GET_RADIO_CAPABILITY and should be the + * same set as sent by RIL_REQUEST_SET_RADIO_CAPABILITY. + * + * "data" is the RIL_RadioCapability structure + */ +#define RIL_UNSOL_RADIO_CAPABILITY 1042 + +/* + * RIL_UNSOL_ON_SS + * + * Called when SS response is received when DIAL/USSD/SS is changed to SS by + * call control. + * + * "data" is const RIL_StkCcUnsolSsResponse * + * + */ +#define RIL_UNSOL_ON_SS 1043 + +/** + * RIL_UNSOL_STK_CC_ALPHA_NOTIFY + * + * Called when there is an ALPHA from UICC during Call Control. + * + * "data" is const char * containing ALPHA string from UICC in UTF-8 format. + * + */ +#define RIL_UNSOL_STK_CC_ALPHA_NOTIFY 1044 + +/** + * RIL_UNSOL_LCEDATA_RECV + * + * Called when there is an incoming Link Capacity Estimate (LCE) info report. + * + * "data" is the RIL_LceDataInfo structure. + * + */ +#define RIL_UNSOL_LCEDATA_RECV 1045 + + /** + * RIL_UNSOL_PCO_DATA + * + * Called when there is new Carrier PCO data received for a data call. Ideally + * only new data will be forwarded, though this is not required. Multiple + * boxes of carrier PCO data for a given call should result in a series of + * RIL_UNSOL_PCO_DATA calls. + * + * "data" is the RIL_PCO_Data structure. + * + */ +#define RIL_UNSOL_PCO_DATA 1046 + + /** + * RIL_UNSOL_MODEM_RESTART + * + * Called when there is a modem reset. + * + * "reason" is "const char *" containing the reason for the reset. It + * could be a crash signature if the restart was due to a crash or some + * string such as "user-initiated restart" or "AT command initiated + * restart" that explains the cause of the modem restart. + * + * When modem restarts, one of the following radio state transitions will happen + * 1) RADIO_STATE_ON->RADIO_STATE_UNAVAILABLE->RADIO_STATE_ON or + * 2) RADIO_STATE_OFF->RADIO_STATE_UNAVAILABLE->RADIO_STATE_OFF + * This message can be sent either just before the RADIO_STATE changes to RADIO_STATE_UNAVAILABLE + * or just after but should never be sent after the RADIO_STATE changes from UNAVAILABLE to + * AVAILABLE(RADIO_STATE_ON/RADIO_STATE_OFF) again. + * + * It should NOT be sent after the RADIO_STATE changes to AVAILABLE after the + * modem restart as that could be interpreted as a second modem reset by the + * framework. + */ +#define RIL_UNSOL_MODEM_RESTART 1047 + +/** + * RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION + * + * Called when the modem needs Carrier specific information that will + * be used to encrypt IMSI and IMPI. + * + * "data" is NULL + * + */ +#define RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION 1048 + +/** + * RIL_UNSOL_NETWORK_SCAN_RESULT + * + * Returns incremental result for the network scan which is started by + * RIL_REQUEST_START_NETWORK_SCAN, sent to report results, status, or errors. + * + * "data" is NULL + * "response" is a const RIL_NetworkScanResult * + */ +#define RIL_UNSOL_NETWORK_SCAN_RESULT 1049 + +/** + * RIL_UNSOL_KEEPALIVE_STATUS + * + * "data" is NULL + * "response" is a const RIL_KeepaliveStatus * + */ +#define RIL_UNSOL_KEEPALIVE_STATUS 1050 + +/***********************************************************************/ + + +#if defined(ANDROID_MULTI_SIM) +/** + * RIL_Request Function pointer + * + * @param request is one of RIL_REQUEST_* + * @param data is pointer to data defined for that RIL_REQUEST_* + * data is owned by caller, and should not be modified or freed by callee + * structures passed as data may contain pointers to non-contiguous memory + * @param t should be used in subsequent call to RIL_onResponse + * @param datalen is the length of "data" which is defined as other argument. It may or may + * not be equal to sizeof(data). Refer to the documentation of individual structures + * to find if pointers listed in the structure are contiguous and counted in the datalen + * length or not. + * (Eg: RIL_IMS_SMS_Message where we don't have datalen equal to sizeof(data)) + * + */ +typedef void (*RIL_RequestFunc) (int request, void *data, + size_t datalen, RIL_Token t, RIL_SOCKET_ID socket_id); + +/** + * This function should return the current radio state synchronously + */ +typedef RIL_RadioState (*RIL_RadioStateRequest)(RIL_SOCKET_ID socket_id); + +#else +/* Backward compatible */ + +/** + * RIL_Request Function pointer + * + * @param request is one of RIL_REQUEST_* + * @param data is pointer to data defined for that RIL_REQUEST_* + * data is owned by caller, and should not be modified or freed by callee + * structures passed as data may contain pointers to non-contiguous memory + * @param t should be used in subsequent call to RIL_onResponse + * @param datalen is the length of "data" which is defined as other argument. It may or may + * not be equal to sizeof(data). Refer to the documentation of individual structures + * to find if pointers listed in the structure are contiguous and counted in the datalen + * length or not. + * (Eg: RIL_IMS_SMS_Message where we don't have datalen equal to sizeof(data)) + * + */ +typedef void (*RIL_RequestFunc) (int request, void *data, + size_t datalen, RIL_Token t); + +/** + * This function should return the current radio state synchronously + */ +typedef RIL_RadioState (*RIL_RadioStateRequest)(); + +#endif + + +/** + * This function returns "1" if the specified RIL_REQUEST code is + * supported and 0 if it is not + * + * @param requestCode is one of RIL_REQUEST codes + */ + +typedef int (*RIL_Supports)(int requestCode); + +/** + * This function is called from a separate thread--not the + * thread that calls RIL_RequestFunc--and indicates that a pending + * request should be cancelled. + * + * On cancel, the callee should do its best to abandon the request and + * call RIL_onRequestComplete with RIL_Errno CANCELLED at some later point. + * + * Subsequent calls to RIL_onRequestComplete for this request with + * other results will be tolerated but ignored. (That is, it is valid + * to ignore the cancellation request) + * + * RIL_Cancel calls should return immediately, and not wait for cancellation + * + * Please see ITU v.250 5.6.1 for how one might implement this on a TS 27.007 + * interface + * + * @param t token wants to be canceled + */ + +typedef void (*RIL_Cancel)(RIL_Token t); + +typedef void (*RIL_TimedCallback) (void *param); + +/** + * Return a version string for your RIL implementation + */ +typedef const char * (*RIL_GetVersion) (void); + +typedef struct { + int version; /* set to RIL_VERSION */ + RIL_RequestFunc onRequest; + RIL_RadioStateRequest onStateRequest; + RIL_Supports supports; + RIL_Cancel onCancel; + RIL_GetVersion getVersion; +} RIL_RadioFunctions; + +typedef struct { + char *apn; /* the APN to connect to */ + char *protocol; /* one of the PDP_type values in TS 27.007 section 10.1.1 used on + roaming network. For example, "IP", "IPV6", "IPV4V6", or "PPP".*/ + int authtype; /* authentication protocol used for this PDP context + (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) */ + char *username; /* the username for APN, or NULL */ + char *password; /* the password for APN, or NULL */ +} RIL_InitialAttachApn; + +typedef struct { + char *apn; /* the APN to connect to */ + char *protocol; /* one of the PDP_type values in TS 27.007 section 10.1.1 used on + home network. For example, "IP", "IPV6", "IPV4V6", or "PPP". */ + char *roamingProtocol; /* one of the PDP_type values in TS 27.007 section 10.1.1 used on + roaming network. For example, "IP", "IPV6", "IPV4V6", or "PPP".*/ + int authtype; /* authentication protocol used for this PDP context + (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3) */ + char *username; /* the username for APN, or NULL */ + char *password; /* the password for APN, or NULL */ + int supportedTypesBitmask; /* supported APN types bitmask. See RIL_ApnTypes for the value of + each bit. */ + int bearerBitmask; /* the bearer bitmask. See RIL_RadioAccessFamily for the value of + each bit. */ + int modemCognitive; /* indicating the APN setting was sent to the modem through + setDataProfile earlier. */ + int mtu; /* maximum transmission unit (MTU) size in bytes */ + char *mvnoType; /* the MVNO type: possible values are "imsi", "gid", "spn" */ + char *mvnoMatchData; /* MVNO match data. Can be anything defined by the carrier. + For example, + SPN like: "A MOBILE", "BEN NL", etc... + IMSI like: "302720x94", "2060188", etc... + GID like: "4E", "33", etc... */ +} RIL_InitialAttachApn_v15; + +typedef struct { + int authContext; /* P2 value of authentication command, see P2 parameter in + 3GPP TS 31.102 7.1.2 */ + char *authData; /* the challenge string in Base64 format, see 3GPP + TS 31.102 7.1.2 */ + char *aid; /* AID value, See ETSI 102.221 8.1 and 101.220 4, + NULL if no value. */ +} RIL_SimAuthentication; + +typedef struct { + int cid; /* Context ID, uniquely identifies this call */ + char *bearer_proto; /* One of the PDP_type values in TS 27.007 section 10.1.1. + For example, "IP", "IPV6", "IPV4V6". */ + int pco_id; /* The protocol ID for this box. Note that only IDs from + FF00H - FFFFH are accepted. If more than one is included + from the network, multiple calls should be made to send all + of them. */ + int contents_length; /* The number of octets in the contents. */ + char *contents; /* Carrier-defined content. It is binary, opaque and + loosely defined in LTE Layer 3 spec 24.008 */ +} RIL_PCO_Data; + +typedef enum { + NATT_IPV4 = 0, /* Keepalive specified by RFC 3948 Sec. 2.3 using IPv4 */ + NATT_IPV6 = 1 /* Keepalive specified by RFC 3948 Sec. 2.3 using IPv6 */ +} RIL_KeepaliveType; + +#define MAX_INADDR_LEN 16 +typedef struct { + RIL_KeepaliveType type; /* Type of keepalive packet */ + char sourceAddress[MAX_INADDR_LEN]; /* Source address in network-byte order */ + int sourcePort; /* Source port if applicable, or 0x7FFFFFFF; + the maximum value is 65535 */ + char destinationAddress[MAX_INADDR_LEN]; /* Destination address in network-byte order */ + int destinationPort; /* Destination port if applicable or 0x7FFFFFFF; + the maximum value is 65535 */ + int maxKeepaliveIntervalMillis; /* Maximum milliseconds between two packets */ + int cid; /* Context ID, uniquely identifies this call */ +} RIL_KeepaliveRequest; + +typedef enum { + KEEPALIVE_ACTIVE, /* Keepalive session is active */ + KEEPALIVE_INACTIVE, /* Keepalive session is inactive */ + KEEPALIVE_PENDING /* Keepalive session status not available */ +} RIL_KeepaliveStatusCode; + +typedef struct { + uint32_t sessionHandle; + RIL_KeepaliveStatusCode code; +} RIL_KeepaliveStatus; + +#ifdef RIL_SHLIB +struct RIL_Env { + /** + * "t" is parameter passed in on previous call to RIL_Notification + * routine. + * + * If "e" != SUCCESS, then response can be null/is ignored + * + * "response" is owned by caller, and should not be modified or + * freed by callee + * + * RIL_onRequestComplete will return as soon as possible + */ + void (*OnRequestComplete)(RIL_Token t, RIL_Errno e, + void *response, size_t responselen); + +#if defined(ANDROID_MULTI_SIM) + /** + * "unsolResponse" is one of RIL_UNSOL_RESPONSE_* + * "data" is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * + * "data" is owned by caller, and should not be modified or freed by callee + */ + void (*OnUnsolicitedResponse)(int unsolResponse, const void *data, size_t datalen, RIL_SOCKET_ID socket_id); +#else + /** + * "unsolResponse" is one of RIL_UNSOL_RESPONSE_* + * "data" is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * + * "data" is owned by caller, and should not be modified or freed by callee + */ + void (*OnUnsolicitedResponse)(int unsolResponse, const void *data, size_t datalen); +#endif + /** + * Call user-specifed "callback" function on on the same thread that + * RIL_RequestFunc is called. If "relativeTime" is specified, then it specifies + * a relative time value at which the callback is invoked. If relativeTime is + * NULL or points to a 0-filled structure, the callback will be invoked as + * soon as possible + */ + + void (*RequestTimedCallback) (RIL_TimedCallback callback, + void *param, const struct timeval *relativeTime); + /** + * "t" is parameter passed in on previous call RIL_Notification routine + * + * RIL_onRequestAck will be called by vendor when an Async RIL request was received + * by them and an ack needs to be sent back to java ril. + */ + void (*OnRequestAck) (RIL_Token t); +}; + + +/** + * RIL implementations must defined RIL_Init + * argc and argv will be command line arguments intended for the RIL implementation + * Return NULL on error + * + * @param env is environment point defined as RIL_Env + * @param argc number of arguments + * @param argv list fo arguments + * + */ +const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv); + +/** + * If BT SAP(SIM Access Profile) is supported, then RIL implementations must define RIL_SAP_Init + * for initializing RIL_RadioFunctions used for BT SAP communcations. It is called whenever RILD + * starts or modem restarts. Returns handlers for SAP related request that are made on SAP + * sepecific socket, analogous to the RIL_RadioFunctions returned by the call to RIL_Init + * and used on the general RIL socket. + * argc and argv will be command line arguments intended for the RIL implementation + * Return NULL on error. + * + * @param env is environment point defined as RIL_Env + * @param argc number of arguments + * @param argv list fo arguments + * + */ +const RIL_RadioFunctions *RIL_SAP_Init(const struct RIL_Env *env, int argc, char **argv); + +#else /* RIL_SHLIB */ + +/** + * Call this once at startup to register notification routine + * + * @param callbacks user-specifed callback function + */ +void RIL_register (const RIL_RadioFunctions *callbacks); + +void rilc_thread_pool(); + + +/** + * + * RIL_onRequestComplete will return as soon as possible + * + * @param t is parameter passed in on previous call to RIL_Notification + * routine. + * @param e error code + * if "e" != SUCCESS, then response can be null/is ignored + * @param response is owned by caller, and should not be modified or + * freed by callee + * @param responselen the length of response in byte + */ +void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, + void *response, size_t responselen); + +/** + * RIL_onRequestAck will be called by vendor when an Async RIL request was received by them and + * an ack needs to be sent back to java ril. This doesn't mark the end of the command or it's + * results, just that the command was received and will take a while. After sending this Ack + * its vendor's responsibility to make sure that AP is up whenever needed while command is + * being processed. + * + * @param t is parameter passed in on previous call to RIL_Notification + * routine. + */ +void RIL_onRequestAck(RIL_Token t); + +#if defined(ANDROID_MULTI_SIM) +/** + * @param unsolResponse is one of RIL_UNSOL_RESPONSE_* + * @param data is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * "data" is owned by caller, and should not be modified or freed by callee + * @param datalen the length of data in byte + */ + +void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen, RIL_SOCKET_ID socket_id); +#else +/** + * @param unsolResponse is one of RIL_UNSOL_RESPONSE_* + * @param data is pointer to data defined for that RIL_UNSOL_RESPONSE_* + * "data" is owned by caller, and should not be modified or freed by callee + * @param datalen the length of data in byte + */ + +void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen); +#endif + +/** + * Call user-specifed "callback" function on on the same thread that + * RIL_RequestFunc is called. If "relativeTime" is specified, then it specifies + * a relative time value at which the callback is invoked. If relativeTime is + * NULL or points to a 0-filled structure, the callback will be invoked as + * soon as possible + * + * @param callback user-specifed callback function + * @param param parameter list + * @param relativeTime a relative time value at which the callback is invoked + */ + +void RIL_requestTimedCallback (RIL_TimedCallback callback, + void *param, const struct timeval *relativeTime); + +#endif /* RIL_SHLIB */ + +#ifdef __cplusplus +} +#endif + +#endif /*ANDROID_RIL_H*/ diff --git a/ril/include/telephony/ril_cdma_sms.h b/ril/include/telephony/ril_cdma_sms.h new file mode 100644 index 0000000..bcf6b30 --- /dev/null +++ b/ril/include/telephony/ril_cdma_sms.h @@ -0,0 +1,806 @@ +/* + * Copyright (C) 2006 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. + */ + +/* + * ISSUES: + * + */ + +/** + * TODO + * + * + */ + + +#ifndef ANDROID_RIL_CDMA_SMS_H +#define ANDROID_RIL_CDMA_SMS_H 1 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Used by RIL_REQUEST_CDMA_SEND_SMS and RIL_UNSOL_RESPONSE_CDMA_NEW_SMS */ + +#define RIL_CDMA_SMS_ADDRESS_MAX 36 +#define RIL_CDMA_SMS_SUBADDRESS_MAX 36 +#define RIL_CDMA_SMS_BEARER_DATA_MAX 255 + +typedef enum { + RIL_CDMA_SMS_DIGIT_MODE_4_BIT = 0, /* DTMF digits */ + RIL_CDMA_SMS_DIGIT_MODE_8_BIT = 1, + RIL_CDMA_SMS_DIGIT_MODE_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_DigitMode; + +typedef enum { + RIL_CDMA_SMS_NUMBER_MODE_NOT_DATA_NETWORK = 0, + RIL_CDMA_SMS_NUMBER_MODE_DATA_NETWORK = 1, + RIL_CDMA_SMS_NUMBER_MODE_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_NumberMode; + +typedef enum { + RIL_CDMA_SMS_NUMBER_TYPE_UNKNOWN = 0, + RIL_CDMA_SMS_NUMBER_TYPE_INTERNATIONAL_OR_DATA_IP = 1, + /* INTERNATIONAL is used when number mode is not data network address. + * DATA_IP is used when the number mode is data network address + */ + RIL_CDMA_SMS_NUMBER_TYPE_NATIONAL_OR_INTERNET_MAIL = 2, + /* NATIONAL is used when the number mode is not data network address. + * INTERNET_MAIL is used when the number mode is data network address. + * For INTERNET_MAIL, in the address data "digits", each byte contains + * an ASCII character. Examples are "x@y.com,a@b.com - ref TIA/EIA-637A 3.4.3.3 + */ + RIL_CDMA_SMS_NUMBER_TYPE_NETWORK = 3, + RIL_CDMA_SMS_NUMBER_TYPE_SUBSCRIBER = 4, + RIL_CDMA_SMS_NUMBER_TYPE_ALPHANUMERIC = 5, + /* GSM SMS: address value is GSM 7-bit chars */ + RIL_CDMA_SMS_NUMBER_TYPE_ABBREVIATED = 6, + RIL_CDMA_SMS_NUMBER_TYPE_RESERVED_7 = 7, + RIL_CDMA_SMS_NUMBER_TYPE_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_NumberType; + +typedef enum { + RIL_CDMA_SMS_NUMBER_PLAN_UNKNOWN = 0, + RIL_CDMA_SMS_NUMBER_PLAN_TELEPHONY = 1, /* CCITT E.164 and E.163, including ISDN plan */ + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_2 = 2, + RIL_CDMA_SMS_NUMBER_PLAN_DATA = 3, /* CCITT X.121 */ + RIL_CDMA_SMS_NUMBER_PLAN_TELEX = 4, /* CCITT F.69 */ + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_5 = 5, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_6 = 6, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_7 = 7, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_8 = 8, + RIL_CDMA_SMS_NUMBER_PLAN_PRIVATE = 9, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_10 = 10, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_11 = 11, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_12 = 12, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_13 = 13, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_14 = 14, + RIL_CDMA_SMS_NUMBER_PLAN_RESERVED_15 = 15, + RIL_CDMA_SMS_NUMBER_PLAN_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_NumberPlan; + +typedef struct { + RIL_CDMA_SMS_DigitMode digit_mode; + /* Indicates 4-bit or 8-bit */ + RIL_CDMA_SMS_NumberMode number_mode; + /* Used only when digitMode is 8-bit */ + RIL_CDMA_SMS_NumberType number_type; + /* Used only when digitMode is 8-bit. + * To specify an international address, use the following: + * digitMode = RIL_CDMA_SMS_DIGIT_MODE_8_BIT + * numberMode = RIL_CDMA_SMS_NOT_DATA_NETWORK + * numberType = RIL_CDMA_SMS_NUMBER_TYPE_INTERNATIONAL_OR_DATA_IP + * numberPlan = RIL_CDMA_SMS_NUMBER_PLAN_TELEPHONY + * numberOfDigits = number of digits + * digits = ASCII digits, e.g. '1', '2', '3'3, '4', and '5' + */ + RIL_CDMA_SMS_NumberPlan number_plan; + /* Used only when digitMode is 8-bit */ + unsigned char number_of_digits; + unsigned char digits[ RIL_CDMA_SMS_ADDRESS_MAX ]; + /* Each byte in this array represnts a 40bit or 8-bit digit of address data */ +} RIL_CDMA_SMS_Address; + +typedef enum { + RIL_CDMA_SMS_SUBADDRESS_TYPE_NSAP = 0, /* CCITT X.213 or ISO 8348 AD2 */ + RIL_CDMA_SMS_SUBADDRESS_TYPE_USER_SPECIFIED = 1, /* e.g. X.25 */ + RIL_CDMA_SMS_SUBADDRESS_TYPE_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_SubaddressType; + +typedef struct { + RIL_CDMA_SMS_SubaddressType subaddressType; + /* 1 means the last byte's lower 4 bits should be ignored */ + unsigned char odd; + unsigned char number_of_digits; + /* Each byte respresents a 8-bit digit of subaddress data */ + unsigned char digits[ RIL_CDMA_SMS_SUBADDRESS_MAX ]; +} RIL_CDMA_SMS_Subaddress; + +typedef struct { + int uTeleserviceID; + unsigned char bIsServicePresent; + int uServicecategory; + RIL_CDMA_SMS_Address sAddress; + RIL_CDMA_SMS_Subaddress sSubAddress; + int uBearerDataLen; + unsigned char aBearerData[ RIL_CDMA_SMS_BEARER_DATA_MAX ]; +} RIL_CDMA_SMS_Message; + +/* Used by RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE */ + +typedef enum { + RIL_CDMA_SMS_NO_ERROR = 0, + RIL_CDMA_SMS_ERROR = 1, + RIL_CDMA_SMS_ERROR_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_ErrorClass; + +typedef struct { + RIL_CDMA_SMS_ErrorClass uErrorClass; + int uSMSCauseCode; /* As defined in N.S00005, 6.5.2.125. + Currently, only 35 (resource shortage) and + 39 (other terminal problem) are reported. */ +} RIL_CDMA_SMS_Ack; + +/* Used by RIL_REQUEST_CDMA_SMS_GET_BROADCAST_CONFIG and + RIL_REQUEST_CDMA_SMS_SET_BROADCAST_CONFIG */ + +typedef struct { + int service_category; + int language; + unsigned char selected; +} RIL_CDMA_BroadcastSmsConfigInfo; + +/* Used by RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM */ + +typedef struct { + int status; /* Status of message. See TS 27.005 3.1, "": */ + /* 0 = "REC UNREAD" */ + /* 1 = "REC READ" */ + /* 2 = "STO UNSENT" */ + /* 3 = "STO SENT" */ + + RIL_CDMA_SMS_Message message; +} RIL_CDMA_SMS_WriteArgs; + + +/* Used by RIL_REQUEST_ENCODE_CDMA_SMS and RIL_REQUEST_DECODE_CDMA_SMS*/ + +#define RIL_CDMA_SMS_UDH_MAX_SND_SIZE 128 +#define RIL_CDMA_SMS_UDH_EO_DATA_SEGMENT_MAX 131 /* 140 - 3 - 6 */ +#define RIL_CDMA_SMS_MAX_UD_HEADERS 7 +#define RIL_CDMA_SMS_USER_DATA_MAX 229 +#define RIL_CDMA_SMS_ADDRESS_MAX 36 +#define RIL_CDMA_SMS_UDH_LARGE_PIC_SIZE 128 +#define RIL_CDMA_SMS_UDH_SMALL_PIC_SIZE 32 +#define RIL_CDMA_SMS_UDH_VAR_PIC_SIZE 134 +#define RIL_CDMA_SMS_UDH_ANIM_NUM_BITMAPS 4 +#define RIL_CDMA_SMS_UDH_LARGE_BITMAP_SIZE 32 +#define RIL_CDMA_SMS_UDH_SMALL_BITMAP_SIZE 8 +#define RIL_CDMA_SMS_UDH_OTHER_SIZE 226 +#define RIL_CDMA_SMS_IP_ADDRESS_SIZE 4 + +/* ------------------- */ +/* ---- User Data ---- */ +/* ------------------- */ +typedef enum { + RIL_CDMA_SMS_UDH_CONCAT_8 = 0x00, + RIL_CDMA_SMS_UDH_SPECIAL_SM, + /* 02 - 03 Reserved */ + RIL_CDMA_SMS_UDH_PORT_8 = 0x04, + RIL_CDMA_SMS_UDH_PORT_16, + RIL_CDMA_SMS_UDH_SMSC_CONTROL, + RIL_CDMA_SMS_UDH_SOURCE, + RIL_CDMA_SMS_UDH_CONCAT_16, + RIL_CDMA_SMS_UDH_WCMP, + RIL_CDMA_SMS_UDH_TEXT_FORMATING, + RIL_CDMA_SMS_UDH_PRE_DEF_SOUND, + RIL_CDMA_SMS_UDH_USER_DEF_SOUND, + RIL_CDMA_SMS_UDH_PRE_DEF_ANIM, + RIL_CDMA_SMS_UDH_LARGE_ANIM, + RIL_CDMA_SMS_UDH_SMALL_ANIM, + RIL_CDMA_SMS_UDH_LARGE_PICTURE, + RIL_CDMA_SMS_UDH_SMALL_PICTURE, + RIL_CDMA_SMS_UDH_VAR_PICTURE, + + RIL_CDMA_SMS_UDH_USER_PROMPT = 0x13, + RIL_CDMA_SMS_UDH_EXTENDED_OBJECT = 0x14, + + /* 15 - 1F Reserved for future EMS */ + + RIL_CDMA_SMS_UDH_RFC822 = 0x20, + + /* 21 - 6F Reserved for future use */ + /* 70 - 7f Reserved for (U)SIM Toolkit Security Headers */ + /* 80 - 9F SME to SME specific use */ + /* A0 - BF Reserved for future use */ + /* C0 - DF SC specific use */ + /* E0 - FF Reserved for future use */ + + RIL_CDMA_SMS_UDH_OTHER = 0xFFFF, /* For unsupported or proprietary headers */ + RIL_CDMA_SMS_UDH_ID_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ + +} RIL_CDMA_SMS_UdhId; + +typedef struct { + /*indicates the reference number for a particular concatenated short message. */ + /*it is constant for every short message which makes up a particular concatenated short message*/ + unsigned char msg_ref; + + /*indicates the total number of short messages within the concatenated short message. + The value shall start at 1 and remain constant for every + short message which makes up the concatenated short message. + if it is 0 then the receiving entity shall ignore the whole Information Element*/ + unsigned char total_sm; + + /* + * it indicates the sequence number of a particular short message within the concatenated short + * message. The value shall start at 1 and increment by one for every short message sent + * within the concatenated short message. If the value is zero or the value is + * greater than the value in octet 2 then the receiving + * entity shall ignore the whole Information Element. + */ + unsigned char seq_num; +} RIL_CDMA_SMS_UdhConcat8; + +/* GW message waiting actions +*/ +typedef enum { + RIL_CDMA_SMS_GW_MSG_WAITING_NONE, + RIL_CDMA_SMS_GW_MSG_WAITING_DISCARD, + RIL_CDMA_SMS_GW_MSG_WAITING_STORE, + RIL_CDMA_SMS_GW_MSG_WAITING_NONE_1111, + RIL_CDMA_SMS_GW_MSG_WAITING_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_GWMsgWaiting; + +/* GW message waiting types +*/ +typedef enum { + RIL_CDMA_SMS_GW_MSG_WAITING_VOICEMAIL, + RIL_CDMA_SMS_GW_MSG_WAITING_FAX, + RIL_CDMA_SMS_GW_MSG_WAITING_EMAIL, + RIL_CDMA_SMS_GW_MSG_WAITING_OTHER, + RIL_CDMA_SMS_GW_MSG_WAITING_KIND_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_GWMsgWaitingKind; + +typedef struct { + RIL_CDMA_SMS_GWMsgWaiting msg_waiting; + RIL_CDMA_SMS_GWMsgWaitingKind msg_waiting_kind; + + /*it indicates the number of messages of the type specified in Octet 1 waiting.*/ + unsigned char message_count; +} RIL_CDMA_SMS_UdhSpecialSM; + +typedef struct { + unsigned char dest_port; + unsigned char orig_port; +} RIL_CDMA_SMS_UdhWap8; + +typedef struct { + unsigned short dest_port; + unsigned short orig_port; +} RIL_CDMA_SMS_UdhWap16; + +typedef struct { + unsigned short msg_ref; + unsigned char total_sm; + unsigned char seq_num; + +} RIL_CDMA_SMS_UdhConcat16; + +typedef enum { + RIL_CDMA_SMS_UDH_LEFT_ALIGNMENT = 0, + RIL_CDMA_SMS_UDH_CENTER_ALIGNMENT, + RIL_CDMA_SMS_UDH_RIGHT_ALIGNMENT, + RIL_CDMA_SMS_UDH_DEFAULT_ALIGNMENT, + RIL_CDMA_SMS_UDH_MAX_ALIGNMENT, + RIL_CDMA_SMS_UDH_ALIGNMENT_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_UdhAlignment; + +typedef enum { + RIL_CDMA_SMS_UDH_FONT_NORMAL = 0, + RIL_CDMA_SMS_UDH_FONT_LARGE, + RIL_CDMA_SMS_UDH_FONT_SMALL, + RIL_CDMA_SMS_UDH_FONT_RESERVED, + RIL_CDMA_SMS_UDH_FONT_MAX, + RIL_CDMA_SMS_UDH_FONT_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_UdhFontSize; + +typedef enum { + RIL_CDMA_SMS_UDH_TEXT_COLOR_BLACK = 0x0, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_GREY = 0x1, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_RED = 0x2, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_YELLOW = 0x3, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_GREEN = 0x4, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_CYAN = 0x5, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_BLUE = 0x6, + RIL_CDMA_SMS_UDH_TEXT_COLOR_DARK_MAGENTA = 0x7, + RIL_CDMA_SMS_UDH_TEXT_COLOR_GREY = 0x8, + RIL_CDMA_SMS_UDH_TEXT_COLOR_WHITE = 0x9, + RIL_CDMA_SMS_UDH_TEXT_COLOR_BRIGHT_RED = 0xA, + RIL_CDMA_SMS_UDH_TEXT_COLOR_BRIGHT_YELLOW = 0xB, + RIL_CDMA_SMS_UDH_TEXT_COLOR_BRIGHT_GREEN = 0xC, + RIL_CDMA_SMS_UDH_TEXT_COLOR_BRIGHT_CYAN = 0xD, + RIL_CDMA_SMS_UDH_TEXT_COLOR_BRIGHT_BLUE = 0xE, + RIL_CDMA_SMS_UDH_TEXT_COLOR_BRIGHT_MAGENTA = 0xF, + RIL_CDMA_SMS_UDH_TEXT_COLOR_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_UdhTextColor; + +typedef struct { + unsigned char start_position; + unsigned char text_formatting_length; + RIL_CDMA_SMS_UdhAlignment alignment_type ; /*bit 0 and bit 1*/ + RIL_CDMA_SMS_UdhFontSize font_size ; /*bit 3 and bit 2*/ + unsigned char style_bold; /*bit 4 */ + unsigned char style_italic; /*bit 5 */ + unsigned char style_underlined; /*bit 6 */ + unsigned char style_strikethrough; /*bit 7 */ + + /* if FALSE, ignore the following color information */ + unsigned char is_color_present; + RIL_CDMA_SMS_UdhTextColor text_color_foreground; + RIL_CDMA_SMS_UdhTextColor text_color_background; + +} RIL_CDMA_SMS_UdhTextFormating; + +/* Predefined sound +*/ +typedef struct { + unsigned char position; + unsigned char snd_number; +} RIL_CDMA_SMS_UdhPreDefSound; + +/* User Defined sound +*/ +typedef struct { + unsigned char data_length; + unsigned char position; + unsigned char user_def_sound[RIL_CDMA_SMS_UDH_MAX_SND_SIZE]; +} RIL_CDMA_SMS_UdhUserDefSound; + +/* Large picture +*/ +typedef struct { + unsigned char position; + unsigned char data[RIL_CDMA_SMS_UDH_LARGE_PIC_SIZE]; +} RIL_CDMA_SMS_UdhLargePictureData; + +/* Small picture +*/ +typedef struct { + unsigned char position; + unsigned char data[RIL_CDMA_SMS_UDH_SMALL_PIC_SIZE]; +} RIL_CDMA_SMS_UdhSmallPictureData; + +/* Variable length picture +*/ +typedef struct { + unsigned char position; + unsigned char width; /* Number of pixels - Should be a mutliple of 8 */ + unsigned char height; + unsigned char data[RIL_CDMA_SMS_UDH_VAR_PIC_SIZE]; +} RIL_CDMA_SMS_UdhVarPicture; + +/* Predefined animation +*/ +typedef struct { + unsigned char position; + unsigned char animation_number; +} RIL_CDMA_SMS_UdhPreDefAnim; + +/* Large animation +*/ +typedef struct { + unsigned char position; + unsigned char data[RIL_CDMA_SMS_UDH_ANIM_NUM_BITMAPS][RIL_CDMA_SMS_UDH_LARGE_BITMAP_SIZE]; +} RIL_CDMA_SMS_UdhLargeAnim; + +/* Small animation +*/ +typedef struct { + unsigned char position; + unsigned char data[RIL_CDMA_SMS_UDH_ANIM_NUM_BITMAPS][RIL_CDMA_SMS_UDH_SMALL_BITMAP_SIZE]; +} RIL_CDMA_SMS_UdhSmallAnim; + +/* User Prompt Indicator UDH +*/ +typedef struct { + unsigned char number_of_objects; + /* Number of objects of the same kind that follow this header which will + ** be stitched together by the applications. For example, 5 small pictures + ** are to be stitched together horizontally, or 6 iMelody tones are to be + ** connected together with intermediate iMelody header and footer ignored. + ** Allowed objects to be stitched: + ** - Images (small, large, variable) + ** - User defined sounds + */ +} RIL_CDMA_SMS_UdhUserPrompt; + +typedef struct { + unsigned char length; + + unsigned char data[RIL_CDMA_SMS_UDH_EO_DATA_SEGMENT_MAX]; + /* RIL_CDMA_SMS_UDH_EO_VCARD: See http://www.imc.org/pdi/vcard-21.doc for payload */ + /* RIL_CDMA_SMS_UDH_EO_VCALENDAR: See http://www.imc.org/pdi/vcal-10.doc */ + /* Or: Unsupported/proprietary extended objects */ + +} RIL_CDMA_SMS_UdhEoContent; + +/* Extended Object UDH +*/ +/* Extended Object IDs/types +*/ +typedef enum { + RIL_CDMA_SMS_UDH_EO_VCARD = 0x09, + RIL_CDMA_SMS_UDH_EO_VCALENDAR = 0x0A, + RIL_CDMA_SMS_UDH_EO_MAX32 = 0x10000000 /* Force constant ENUM size in structures */ +} RIL_CDMA_SMS_UdhEoId; + +typedef struct { + /* Extended objects are to be used together with 16-bit concatenation + ** UDH. The max number of segments supported for E.O. is 8 at least. + */ + RIL_CDMA_SMS_UdhEoContent content; + + unsigned char first_segment; + /* The following fields are only present in the first segment of a + ** concatenated SMS message. + */ + unsigned char reference; + /* Identify those extended object segments which should be linked together + */ + unsigned short length; + /* Length of the whole extended object data + */ + unsigned char control; + RIL_CDMA_SMS_UdhEoId type; + unsigned short position; + /* Absolute position of the E.O. in the whole text after concatenation, + ** starting from 1. + */ +} RIL_CDMA_SMS_UdhEo; + +typedef struct { + RIL_CDMA_SMS_UdhId header_id; + unsigned char header_length; + unsigned char data[RIL_CDMA_SMS_UDH_OTHER_SIZE]; +} RIL_CDMA_SMS_UdhOther; + +typedef struct { + unsigned char header_length; +} RIL_CDMA_SMS_UdhRfc822; + +typedef struct { + RIL_CDMA_SMS_UdhId header_id; + + union { + RIL_CDMA_SMS_UdhConcat8 concat_8; // 00 + + RIL_CDMA_SMS_UdhSpecialSM special_sm; // 01 + RIL_CDMA_SMS_UdhWap8 wap_8; // 04 + RIL_CDMA_SMS_UdhWap16 wap_16; // 05 + RIL_CDMA_SMS_UdhConcat16 concat_16; // 08 + RIL_CDMA_SMS_UdhTextFormating text_formating; // 0a + RIL_CDMA_SMS_UdhPreDefSound pre_def_sound; // 0b + RIL_CDMA_SMS_UdhUserDefSound user_def_sound; // 0c + RIL_CDMA_SMS_UdhPreDefAnim pre_def_anim; // 0d + RIL_CDMA_SMS_UdhLargeAnim large_anim; // 0e + RIL_CDMA_SMS_UdhSmallAnim small_anim; // 0f + RIL_CDMA_SMS_UdhLargePictureData large_picture; // 10 + RIL_CDMA_SMS_UdhSmallPictureData small_picture; // 11 + RIL_CDMA_SMS_UdhVarPicture var_picture; // 12 + + RIL_CDMA_SMS_UdhUserPrompt user_prompt; // 13 + RIL_CDMA_SMS_UdhEo eo; // 14 + + RIL_CDMA_SMS_UdhRfc822 rfc822; // 20 + RIL_CDMA_SMS_UdhOther other; + + }u; +} RIL_CDMA_SMS_Udh; + +/* ----------------------------- */ +/* -- User data encoding type -- */ +/* ----------------------------- */ +typedef enum { + RIL_CDMA_SMS_ENCODING_OCTET = 0, /* 8-bit */ + RIL_CDMA_SMS_ENCODING_IS91EP, /* varies */ + RIL_CDMA_SMS_ENCODING_ASCII, /* 7-bit */ + RIL_CDMA_SMS_ENCODING_IA5, /* 7-bit */ + RIL_CDMA_SMS_ENCODING_UNICODE, /* 16-bit */ + RIL_CDMA_SMS_ENCODING_SHIFT_JIS, /* 8 or 16-bit */ + RIL_CDMA_SMS_ENCODING_KOREAN, /* 8 or 16-bit */ + RIL_CDMA_SMS_ENCODING_LATIN_HEBREW, /* 8-bit */ + RIL_CDMA_SMS_ENCODING_LATIN, /* 8-bit */ + RIL_CDMA_SMS_ENCODING_GSM_7_BIT_DEFAULT, /* 7-bit */ + RIL_CDMA_SMS_ENCODING_MAX32 = 0x10000000 + +} RIL_CDMA_SMS_UserDataEncoding; + +/* ------------------------ */ +/* -- IS-91 EP data type -- */ +/* ------------------------ */ +typedef enum { + RIL_CDMA_SMS_IS91EP_VOICE_MAIL = 0x82, + RIL_CDMA_SMS_IS91EP_SHORT_MESSAGE_FULL = 0x83, + RIL_CDMA_SMS_IS91EP_CLI_ORDER = 0x84, + RIL_CDMA_SMS_IS91EP_SHORT_MESSAGE = 0x85, + RIL_CDMA_SMS_IS91EP_MAX32 = 0x10000000 + +} RIL_CDMA_SMS_IS91EPType; + +typedef struct { + /* NOTE: If message_id.udh_present == TRUE: + ** 'num_headers' is the number of User Data Headers (UDHs), + ** and 'headers' include all those headers. + */ + unsigned char num_headers; + RIL_CDMA_SMS_Udh headers[RIL_CDMA_SMS_MAX_UD_HEADERS]; + + RIL_CDMA_SMS_UserDataEncoding encoding; + RIL_CDMA_SMS_IS91EPType is91ep_type; + + /*---------------------------------------------------------------------- + 'data_len' indicates the valid number of bytes in the 'data' array. + + 'padding_bits' (0-7) indicates how many bits in the last byte of 'data' + are invalid bits. This parameter is only used for Mobile-Originated + messages. There is no way for the API to tell how many padding bits + exist in the received message. Instead, the application can find out how + many padding bits exist in the user data when decoding the user data. + + 'data' has the raw bits of the user data field of the SMS message. + The client software should decode the raw user data according to its + supported encoding types and languages. + + EXCEPTION 1: CMT-91 user data raw bits are first translated into BD fields + (e.g. num_messages, callback, etc.) The translated user data field in + VMN and Short Message is in the form of ASCII characters, each occupying + a byte in the resulted 'data'. + + EXCEPTION 2: GSM 7-bit Default characters are decoded so that each byte + has one 7-bit GSM character. + + 'number_of_digits' is the number of digits/characters (7, 8, 16, or + whatever bits) in the raw user data, which can be used by the client + when decoding the user data according to the encoding type and language. + -------------------------------------------------------------------------*/ + unsigned char data_len; + unsigned char padding_bits; + unsigned char data[ RIL_CDMA_SMS_USER_DATA_MAX ]; + unsigned char number_of_digits; + +} RIL_CDMA_SMS_CdmaUserData; + +/* -------------------- */ +/* ---- Message Id ---- */ +/* -------------------- */ +typedef enum { + RIL_CDMA_SMS_BD_TYPE_RESERVED_0 = 0, + RIL_CDMA_SMS_BD_TYPE_DELIVER, /* MT only */ + RIL_CDMA_SMS_BD_TYPE_SUBMIT, /* MO only */ + RIL_CDMA_SMS_BD_TYPE_CANCELLATION, /* MO only */ + RIL_CDMA_SMS_BD_TYPE_DELIVERY_ACK, /* MT only */ + RIL_CDMA_SMS_BD_TYPE_USER_ACK, /* MT & MO */ + RIL_CDMA_SMS_BD_TYPE_READ_ACK, /* MT & MO */ + RIL_CDMA_SMS_BD_TYPE_MAX32 = 0x10000000 + +} RIL_CDMA_SMS_BdMessageType; + +typedef unsigned int RIL_CDMA_SMS_MessageNumber; + +typedef struct { + RIL_CDMA_SMS_BdMessageType type; + RIL_CDMA_SMS_MessageNumber id_number; + unsigned char udh_present; + /* NOTE: if FEATURE_SMS_UDH is not defined, + ** udh_present should be ignored. + */ +} RIL_CDMA_SMS_MessageId; + +typedef unsigned char RIL_CDMA_SMS_UserResponse; + +/* ------------------- */ +/* ---- Timestamp ---- */ +/* ------------------- */ +typedef struct { + /* If 'year' is between 96 and 99, the actual year is 1900 + 'year'; + if 'year' is between 00 and 95, the actual year is 2000 + 'year'. + NOTE: Each field has two BCD digits and byte arrangement is + */ + unsigned char year; /* 0x00-0x99 */ + unsigned char month; /* 0x01-0x12 */ + unsigned char day; /* 0x01-0x31 */ + unsigned char hour; /* 0x00-0x23 */ + unsigned char minute; /* 0x00-0x59 */ + unsigned char second; /* 0x00-0x59 */ + signed char timezone; /* +/-, [-48,+48] number of 15 minutes - GW only */ +} RIL_CDMA_SMS_Timestamp; + +/* ------------------ */ +/* ---- Priority ---- */ +/* ------------------ */ +typedef enum { + RIL_CDMA_SMS_PRIORITY_NORMAL = 0, + RIL_CDMA_SMS_PRIORITY_INTERACTIVE, + RIL_CDMA_SMS_PRIORITY_URGENT, + RIL_CDMA_SMS_PRIORITY_EMERGENCY, + RIL_CDMA_SMS_PRIORITY_MAX32 = 0x10000000 + +} RIL_CDMA_SMS_Priority; + +/* ----------------- */ +/* ---- Privacy ---- */ +/* ----------------- */ +typedef enum { + RIL_CDMA_SMS_PRIVACY_NORMAL = 0, + RIL_CDMA_SMS_PRIVACY_RESTRICTED, + RIL_CDMA_SMS_PRIVACY_CONFIDENTIAL, + RIL_CDMA_SMS_PRIVACY_SECRET, + RIL_CDMA_SMS_PRIVACY_MAX32 = 0x10000000 + +} RIL_CDMA_SMS_Privacy; + +/* ---------------------- */ +/* ---- Reply option ---- */ +/* ---------------------- */ +typedef struct { + /* whether user ack is requested + */ + unsigned char user_ack_requested; + + /* whether delivery ack is requested. + Should be FALSE for incoming messages. + */ + unsigned char delivery_ack_requested; + + /* Message originator requests the receiving phone to send back a READ_ACK + ** message automatically when the user reads the received message. + */ + unsigned char read_ack_requested; + +} RIL_CDMA_SMS_ReplyOption; + +typedef enum { + RIL_CDMA_SMS_ALERT_MODE_DEFAULT = 0, + RIL_CDMA_SMS_ALERT_MODE_LOW_PRIORITY = 1, + RIL_CDMA_SMS_ALERT_MODE_MEDIUM_PRIORITY = 2, + RIL_CDMA_SMS_ALERT_MODE_HIGH_PRIORITY = 3, + + /* For pre-IS637A implementations, alert_mode only has values of True/False: + */ + RIL_CDMA_SMS_ALERT_MODE_OFF = 0, + RIL_CDMA_SMS_ALERT_MODE_ON = 1 + +} RIL_CDMA_SMS_AlertMode; + +/* ------------------ */ +/* ---- Language ---- */ +/* ------------------ */ +typedef enum { + RIL_CDMA_SMS_LANGUAGE_UNSPECIFIED = 0, + RIL_CDMA_SMS_LANGUAGE_ENGLISH, + RIL_CDMA_SMS_LANGUAGE_FRENCH, + RIL_CDMA_SMS_LANGUAGE_SPANISH, + RIL_CDMA_SMS_LANGUAGE_JAPANESE, + RIL_CDMA_SMS_LANGUAGE_KOREAN, + RIL_CDMA_SMS_LANGUAGE_CHINESE, + RIL_CDMA_SMS_LANGUAGE_HEBREW, + RIL_CDMA_SMS_LANGUAGE_MAX32 = 0x10000000 + +} RIL_CDMA_SMS_Language; + +/* ---------------------------------- */ +/* ---------- Display Mode ---------- */ +/* ---------------------------------- */ +typedef enum { + RIL_CDMA_SMS_DISPLAY_MODE_IMMEDIATE = 0, + RIL_CDMA_SMS_DISPLAY_MODE_DEFAULT = 1, + RIL_CDMA_SMS_DISPLAY_MODE_USER_INVOKE = 2, + RIL_CDMA_SMS_DISPLAY_MODE_RESERVED = 3 +} RIL_CDMA_SMS_DisplayMode; + +/* IS-637B parameters/fields +*/ + +/* ---------------------------------- */ +/* ---------- Delivery Status ------- */ +/* ---------------------------------- */ +typedef enum { + RIL_CDMA_SMS_DELIVERY_STATUS_ACCEPTED = 0, /* ERROR_CLASS_NONE */ + RIL_CDMA_SMS_DELIVERY_STATUS_DEPOSITED_TO_INTERNET = 1, /* ERROR_CLASS_NONE */ + RIL_CDMA_SMS_DELIVERY_STATUS_DELIVERED = 2, /* ERROR_CLASS_NONE */ + RIL_CDMA_SMS_DELIVERY_STATUS_CANCELLED = 3, /* ERROR_CLASS_NONE */ + + RIL_CDMA_SMS_DELIVERY_STATUS_NETWORK_CONGESTION = 4, /* ERROR_CLASS_TEMP & PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_NETWORK_ERROR = 5, /* ERROR_CLASS_TEMP & PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_CANCEL_FAILED = 6, /* ERROR_CLASS_PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_BLOCKED_DESTINATION = 7, /* ERROR_CLASS_PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_TEXT_TOO_LONG = 8, /* ERROR_CLASS_PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_DUPLICATE_MESSAGE = 9, /* ERROR_CLASS_PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_INVALID_DESTINATION = 10, /* ERROR_CLASS_PERM */ + RIL_CDMA_SMS_DELIVERY_STATUS_MESSAGE_EXPIRED = 13, /* ERROR_CLASS_PERM */ + + RIL_CDMA_SMS_DELIVERY_STATUS_UNKNOWN_ERROR = 0x1F /* ERROR_CLASS_PERM */ + + /* All the other values are reserved */ + +} RIL_CDMA_SMS_DeliveryStatusE; + +typedef struct { + RIL_CDMA_SMS_ErrorClass error_class; + RIL_CDMA_SMS_DeliveryStatusE status; +} RIL_CDMA_SMS_DeliveryStatus; + +typedef struct { + unsigned char address[RIL_CDMA_SMS_IP_ADDRESS_SIZE]; + unsigned char is_valid; +} RIL_CDMA_SMS_IpAddress; + +/* This special parameter captures any unrecognized/proprietary parameters +*/ +typedef struct { + unsigned char input_other_len; + unsigned char desired_other_len; /* used during decoding */ + unsigned char * other_data; +} RIL_CDMA_SMS_OtherParm; + +typedef struct { + /* the mask indicates which fields are present in this message */ + unsigned int mask; + + RIL_CDMA_SMS_MessageId message_id; + RIL_CDMA_SMS_CdmaUserData user_data; + RIL_CDMA_SMS_UserResponse user_response; + RIL_CDMA_SMS_Timestamp mc_time; + RIL_CDMA_SMS_Timestamp validity_absolute; + RIL_CDMA_SMS_Timestamp validity_relative; + RIL_CDMA_SMS_Timestamp deferred_absolute; + RIL_CDMA_SMS_Timestamp deferred_relative; + RIL_CDMA_SMS_Priority priority; + RIL_CDMA_SMS_Privacy privacy; + RIL_CDMA_SMS_ReplyOption reply_option; + unsigned char num_messages; /* the actual value; not BCDs */ + RIL_CDMA_SMS_AlertMode alert_mode; + /* For pre-IS-637A implementations, alert_mode is either Off or On. */ + RIL_CDMA_SMS_Language language; + RIL_CDMA_SMS_Address callback; + RIL_CDMA_SMS_DisplayMode display_mode; + + RIL_CDMA_SMS_DeliveryStatus delivery_status; + unsigned int deposit_index; + + RIL_CDMA_SMS_IpAddress ip_address; + unsigned char rsn_no_notify; + + /* See function comments of wms_ts_decode() and + ** wms_ts_decode_cdma_bd_with_other() for details regarding 'other' parameters + */ + RIL_CDMA_SMS_OtherParm other; + +} RIL_CDMA_SMS_ClientBd; + +typedef struct { + unsigned char length; /* length, in bytes, of the encoded SMS message */ + unsigned char * data; /* the encoded SMS message (max 255 bytes) */ +} RIL_CDMA_Encoded_SMS; + +#ifdef __cplusplus +} +#endif + +#endif /*ANDROID_RIL_CDMA_SMS_H*/ diff --git a/ril/libril/Android.mk b/ril/libril/Android.mk new file mode 100644 index 0000000..e23daae --- /dev/null +++ b/ril/libril/Android.mk @@ -0,0 +1,51 @@ +# Copyright 2006 The Android Open Source Project +# Copyright 2018 The LineageOS Project + +ifeq ($(BOARD_PROVIDES_LIBRIL),true) + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_VENDOR_MODULE := true + +LOCAL_SRC_FILES:= \ + ril.cpp \ + ril_event.cpp\ + RilSapSocket.cpp \ + ril_service.cpp \ + sap_service.cpp + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libutils \ + libcutils \ + libhardware_legacy \ + librilutils \ + android.hardware.radio@1.0 \ + android.hardware.radio@1.1 \ + android.hardware.radio.deprecated@1.0 \ + libhidlbase \ + libhidltransport \ + libhwbinder + +LOCAL_STATIC_LIBRARIES := \ + libprotobuf-c-nano-enable_malloc \ + +LOCAL_CFLAGS += -Wall -Wextra -Wno-unused-parameter -Werror + +ifeq ($(SIM_COUNT), 2) + LOCAL_CFLAGS += -DANDROID_MULTI_SIM -DDSDA_RILD1 + LOCAL_CFLAGS += -DANDROID_SIM_COUNT_2 +endif + +LOCAL_C_INCLUDES += external/nanopb-c +LOCAL_C_INCLUDES += $(LOCAL_PATH)/../include +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../include + +LOCAL_MODULE:= libril +LOCAL_CLANG := true +LOCAL_SANITIZE := integer + +include $(BUILD_SHARED_LIBRARY) + +endif # BOARD_PROVIDES_LIBRIL diff --git a/ril/libril/MODULE_LICENSE_APACHE2 b/ril/libril/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000..e69de29 diff --git a/ril/libril/NOTICE b/ril/libril/NOTICE new file mode 100644 index 0000000..c5b1efa --- /dev/null +++ b/ril/libril/NOTICE @@ -0,0 +1,190 @@ + + Copyright (c) 2005-2008, 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. + + 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. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ril/libril/RilSapSocket.cpp b/ril/libril/RilSapSocket.cpp new file mode 100644 index 0000000..cf99773 --- /dev/null +++ b/ril/libril/RilSapSocket.cpp @@ -0,0 +1,290 @@ +/* +* Copyright (C) 2014 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. +*/ + +#define __STDC_LIMIT_MACROS +#include +#define RIL_SHLIB +#include "telephony/ril.h" +#include "RilSapSocket.h" +#include "pb_decode.h" +#include "pb_encode.h" +#undef LOG_TAG +#define LOG_TAG "RIL_UIM_SOCKET" +#include +#include +#include +#include + +static RilSapSocket::RilSapSocketList *head = NULL; + +extern "C" void +RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, + const struct timeval *relativeTime); + +struct RIL_Env RilSapSocket::uimRilEnv = { + .OnRequestComplete = RilSapSocket::sOnRequestComplete, + .OnUnsolicitedResponse = RilSapSocket::sOnUnsolicitedResponse, + .RequestTimedCallback = RIL_requestTimedCallback +}; + +void RilSapSocket::sOnRequestComplete (RIL_Token t, + RIL_Errno e, + void *response, + size_t responselen) { + RilSapSocket *sap_socket; + SapSocketRequest *request = (SapSocketRequest*) t; + + RLOGD("Socket id:%d", request->socketId); + + sap_socket = getSocketById(request->socketId); + + if (sap_socket) { + sap_socket->onRequestComplete(t,e,response,responselen); + } else { + RLOGE("Invalid socket id"); + if (request->curr->payload) { + free(request->curr->payload); + } + free(request->curr); + free(request); + } +} + +#if defined(ANDROID_MULTI_SIM) +void RilSapSocket::sOnUnsolicitedResponse(int unsolResponse, + const void *data, + size_t datalen, + RIL_SOCKET_ID socketId) { + RilSapSocket *sap_socket = getSocketById(socketId); + if (sap_socket) { + sap_socket->onUnsolicitedResponse(unsolResponse, (void *)data, datalen); + } +} +#else +void RilSapSocket::sOnUnsolicitedResponse(int unsolResponse, + const void *data, + size_t datalen) { + RilSapSocket *sap_socket = getSocketById(RIL_SOCKET_1); + if(sap_socket){ + sap_socket->onUnsolicitedResponse(unsolResponse, (void *)data, datalen); + } +} +#endif + +void RilSapSocket::printList() { + RilSapSocketList *current = head; + RLOGD("Printing socket list"); + while(NULL != current) { + RLOGD("SocketName:%s",current->socket->name); + RLOGD("Socket id:%d",current->socket->id); + current = current->next; + } +} + +RilSapSocket *RilSapSocket::getSocketById(RIL_SOCKET_ID socketId) { + RilSapSocket *sap_socket; + RilSapSocketList *current = head; + + RLOGD("Entered getSocketById"); + printList(); + + while(NULL != current) { + if(socketId == current->socket->id) { + sap_socket = current->socket; + return sap_socket; + } + current = current->next; + } + return NULL; +} + +void RilSapSocket::initSapSocket(const char *socketName, + RIL_RadioFunctions *uimFuncs) { + + if (strcmp(socketName, RIL1_SERVICE_NAME) == 0) { + if(!SocketExists(socketName)) { + addSocketToList(socketName, RIL_SOCKET_1, uimFuncs); + } + } + +#if (SIM_COUNT >= 2) + if (strcmp(socketName, RIL2_SERVICE_NAME) == 0) { + if(!SocketExists(socketName)) { + addSocketToList(socketName, RIL_SOCKET_2, uimFuncs); + } + } +#endif + +#if (SIM_COUNT >= 3) + if (strcmp(socketName, RIL3_SERVICE_NAME) == 0) { + if(!SocketExists(socketName)) { + addSocketToList(socketName, RIL_SOCKET_3, uimFuncs); + } + } +#endif + +#if (SIM_COUNT >= 4) + if (strcmp(socketName, RIL4_SERVICE_NAME) == 0) { + if(!SocketExists(socketName)) { + addSocketToList(socketName, RIL_SOCKET_4, uimFuncs); + } + } +#endif +} + +void RilSapSocket::addSocketToList(const char *socketName, RIL_SOCKET_ID socketid, + RIL_RadioFunctions *uimFuncs) { + RilSapSocket* socket = NULL; + RilSapSocketList *current; + + if(!SocketExists(socketName)) { + socket = new RilSapSocket(socketName, socketid, uimFuncs); + RilSapSocketList* listItem = (RilSapSocketList*)malloc(sizeof(RilSapSocketList)); + if (!listItem) { + RLOGE("addSocketToList: OOM"); + delete socket; + return; + } + listItem->socket = socket; + listItem->next = NULL; + + RLOGD("Adding socket with id: %d", socket->id); + + if(NULL == head) { + head = listItem; + head->next = NULL; + } + else { + current = head; + while(NULL != current->next) { + current = current->next; + } + current->next = listItem; + } + } +} + +bool RilSapSocket::SocketExists(const char *socketName) { + RilSapSocketList* current = head; + + while(NULL != current) { + if(strcmp(current->socket->name, socketName) == 0) { + return true; + } + current = current->next; + } + return false; +} + +RilSapSocket::RilSapSocket(const char *socketName, + RIL_SOCKET_ID socketId, + RIL_RadioFunctions *inputUimFuncs): + RilSocket(socketName, socketId) { + if (inputUimFuncs) { + uimFuncs = inputUimFuncs; + } +} + +void RilSapSocket::dispatchRequest(MsgHeader *req) { + // SapSocketRequest will be deallocated in onRequestComplete() + SapSocketRequest* currRequest=(SapSocketRequest*)malloc(sizeof(SapSocketRequest)); + if (!currRequest) { + RLOGE("dispatchRequest: OOM"); + // Free MsgHeader allocated in pushRecord() + free(req); + return; + } + currRequest->token = req->token; + currRequest->curr = req; + currRequest->p_next = NULL; + currRequest->socketId = id; + + pendingResponseQueue.enqueue(currRequest); + + if (uimFuncs) { + RLOGI("RilSapSocket::dispatchRequest [%d] > SAP REQUEST type: %d. id: %d. error: %d, \ + token 0x%p", + req->token, + req->type, + req->id, + req->error, + currRequest ); + +#if defined(ANDROID_MULTI_SIM) + uimFuncs->onRequest(req->id, req->payload->bytes, req->payload->size, currRequest, id); +#else + uimFuncs->onRequest(req->id, req->payload->bytes, req->payload->size, currRequest); +#endif + } +} + +void RilSapSocket::onRequestComplete(RIL_Token t, RIL_Errno e, void *response, + size_t response_len) { + SapSocketRequest* request= (SapSocketRequest*)t; + MsgHeader *hdr = request->curr; + + MsgHeader rsp; + rsp.token = request->curr->token; + rsp.type = MsgType_RESPONSE; + rsp.id = request->curr->id; + rsp.error = (Error)e; + rsp.payload = (pb_bytes_array_t *)calloc(1, sizeof(pb_bytes_array_t) + response_len); + if (!rsp.payload) { + RLOGE("onRequestComplete: OOM"); + } else { + if (response && response_len > 0) { + memcpy(rsp.payload->bytes, response, response_len); + rsp.payload->size = response_len; + } else { + rsp.payload->size = 0; + } + + RLOGE("RilSapSocket::onRequestComplete: Token:%d, MessageId:%d ril token 0x%p", + hdr->token, hdr->id, t); + + sap::processResponse(&rsp, this); + free(rsp.payload); + } + + // Deallocate SapSocketRequest + if(!pendingResponseQueue.checkAndDequeue(hdr->id, hdr->token)) { + RLOGE("Token:%d, MessageId:%d", hdr->token, hdr->id); + RLOGE ("RilSapSocket::onRequestComplete: invalid Token or Message Id"); + } + + // Deallocate MsgHeader + free(hdr); +} + +void RilSapSocket::onUnsolicitedResponse(int unsolResponse, void *data, size_t datalen) { + if (data && datalen > 0) { + pb_bytes_array_t *payload = (pb_bytes_array_t *)calloc(1, + sizeof(pb_bytes_array_t) + datalen); + if (!payload) { + RLOGE("onUnsolicitedResponse: OOM"); + return; + } + memcpy(payload->bytes, data, datalen); + payload->size = datalen; + MsgHeader rsp; + rsp.payload = payload; + rsp.type = MsgType_UNSOL_RESPONSE; + rsp.id = (MsgId)unsolResponse; + rsp.error = Error_RIL_E_SUCCESS; + sap::processUnsolResponse(&rsp, this); + free(payload); + } +} \ No newline at end of file diff --git a/ril/libril/RilSapSocket.h b/ril/libril/RilSapSocket.h new file mode 100644 index 0000000..8c8c4bc --- /dev/null +++ b/ril/libril/RilSapSocket.h @@ -0,0 +1,200 @@ +/* +* Copyright (C) 2014 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. +*/ + +#ifndef RIL_UIM_SOCKET_H_INCLUDED +#define RIL_UIM_SOCKET_H_INCLUDED +#define RIL_SHLIB +#include "telephony/ril.h" +#include "RilSocket.h" +#include + +/** + * RilSapSocket is a derived class, derived from the RilSocket abstract + * class, representing sockets for communication between bluetooth SAP module and + * the ril daemon. + *

+ * This class performs the following functions : + *

    + *
  • Initialize the socket. + *
  • Process the requests coming on the socket. + *
  • Provide handlers for Unsolicited and request responses. + *
  • Request and pending response queue handling. + *
+ */ +class RilSapSocket : public RilSocket { + /** + * Place holder for the radio functions returned by the initialization + * function. Currenty only onRequest handler is being used. + */ + RIL_RadioFunctions* uimFuncs; + + /** + * Wrapper struct for handling the requests in the queue. + */ + typedef struct SapSocketRequest { + int token; + MsgHeader* curr; + struct SapSocketRequest* p_next; + RIL_SOCKET_ID socketId; + } SapSocketRequest; + + /** + * Queue for requests that are pending dispatch. + */ + Ril_queue dispatchQueue; + + /** + * Queue for requests that are dispatched but are pending response + */ + Ril_queue pendingResponseQueue; + + public: + /** + * Initialize the socket and add the socket to the list. + * + * @param Name of the socket. + * @param Radio functions to be used by the socket. + */ + static void initSapSocket(const char *socketName, + RIL_RadioFunctions *uimFuncs); + + /** + * Ril envoronment variable that holds the request and + * unsol response handlers. + */ + static struct RIL_Env uimRilEnv; + + /** + * Function to print the socket list. + */ + static void printList(); + + /** + * Dispatches the request to the lower layers. + * It calls the on request function. + * + * @param request The request message. + */ + void dispatchRequest(MsgHeader *request); + + /** + * Class method to get the socket from the socket list. + * + * @param socketId Socket id. + * @return the sap socket. + */ + static RilSapSocket* getSocketById(RIL_SOCKET_ID socketId); + + /** + * Datatype to handle the socket list. + */ + typedef struct RilSapSocketList { + RilSapSocket* socket; + RilSapSocketList *next; + } RilSapSocketList; + + protected: + /** + * Socket handler to be called when a request has + * been completed. + * + * @param Token associated with the request. + * @param Error, if any, while processing the request. + * @param The response payload. + * @param Response payload length. + */ + void onRequestComplete(RIL_Token t,RIL_Errno e, + void *response, size_t response_len); + + /** + * Socket handler to be called when there is an + * unsolicited response. + * + * @param Message id. + * @param Response data. + * @param Response data length. + */ + void onUnsolicitedResponse(int unsolResponse, + void *data, size_t datalen); + + /** + * Class method to add the sap socket to the list of sockets. + * Does nothing if the socket is already present in the list. + * Otherwise, calls the constructor of the parent class(To startlistening) + * and add socket to the socket list. + */ + static void addSocketToList(const char *socketName, RIL_SOCKET_ID socketid, + RIL_RadioFunctions *uimFuncs); + + /** + * Check if a socket of the given name exists in the socket list. + * + * @param Socket name. + * @return true if exists, false otherwise. + */ + static bool SocketExists(const char *socketName); + + private: + /** + * Constructor. + * + * @param Socket name. + * @param Socket id. + * @param Radio functions. + */ + RilSapSocket(const char *socketName, + RIL_SOCKET_ID socketId, + RIL_RadioFunctions *inputUimFuncs); + + /** + * Class method that selects the socket on which the onRequestComplete + * is called. + * + * @param Token associated with the request. + * @param Error, if any, while processing the request. + * @param The response payload. + * @param Response payload length. + */ + static void sOnRequestComplete(RIL_Token t, + RIL_Errno e, void *response, size_t responselen); + +#if defined(ANDROID_MULTI_SIM) + /** + * Class method that selects the socket on which the onUnsolicitedResponse + * is called. + * + * @param Message id. + * @param Response data. + * @param Response data length. + * @param Socket id. + */ + static void sOnUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen, RIL_SOCKET_ID socket_id); +#else + /** + * Class method that selects the socket on which the onUnsolicitedResponse + * is called. + * + * @param Message id. + * @param Response data. + * @param Response data length. + */ + static void sOnUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen); +#endif +}; + +#endif /*RIL_UIM_SOCKET_H_INCLUDED*/ diff --git a/ril/libril/RilSocket.h b/ril/libril/RilSocket.h new file mode 100644 index 0000000..53b00c9 --- /dev/null +++ b/ril/libril/RilSocket.h @@ -0,0 +1,70 @@ +/* +* Copyright (C) 2014 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. +*/ + +#ifndef RIL_SOCKET_H_INCLUDED +#define RIL_SOCKET_H_INCLUDED +#include +#include "rilSocketQueue.h" +#include + +/** + * Abstract socket class representing sockets in rild. + *

+ * This class performs the following functions : + *

    + *
  • Start socket listen. + *
  • Handle socket listen and command callbacks. + *
+ */ +class RilSocket { + protected: + + /** + * Socket name. + */ + const char* name; + + /** + * Socket id. + */ + RIL_SOCKET_ID id; + + public: + + /** + * Constructor. + * + * @param Socket name. + * @param Socket id. + */ + RilSocket(const char* socketName, RIL_SOCKET_ID socketId) { + name = socketName; + id = socketId; + } + + /** + * Get socket id. + * + * @return RIL_SOCKET_ID socket id. + */ + RIL_SOCKET_ID getSocketId(void) { + return id; + } + + virtual ~RilSocket(){} +}; + +#endif diff --git a/ril/libril/ril.cpp b/ril/libril/ril.cpp new file mode 100644 index 0000000..3abe559 --- /dev/null +++ b/ril/libril/ril.cpp @@ -0,0 +1,1233 @@ +/* //device/libs/telephony/ril.cpp +** +** Copyright 2006, The Android Open Source Project +** Copyright 2018, The LineageOS 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. +*/ + +#define LOG_TAG "RILC" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" void +RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen); + +extern "C" void +RIL_onRequestAck(RIL_Token t); +namespace android { + +#define PHONE_PROCESS "radio" +#define BLUETOOTH_PROCESS "bluetooth" + +#define ANDROID_WAKE_LOCK_NAME "radio-interface" + +#define ANDROID_WAKE_LOCK_SECS 0 +#define ANDROID_WAKE_LOCK_USECS 200000 + +#define PROPERTY_RIL_IMPL "gsm.version.ril-impl" + +// match with constant in RIL.java +#define MAX_COMMAND_BYTES (8 * 1024) + +// Basically: memset buffers that the client library +// shouldn't be using anymore in an attempt to find +// memory usage issues sooner. +#define MEMSET_FREED 1 + +#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0]) + +/* Negative values for private RIL errno's */ +#define RIL_ERRNO_INVALID_RESPONSE (-1) +#define RIL_ERRNO_NO_MEMORY (-12) + +// request, response, and unsolicited msg print macro +#define PRINTBUF_SIZE 8096 + +enum WakeType {DONT_WAKE, WAKE_PARTIAL}; + +typedef struct { + int requestNumber; + int (*responseFunction) (int slotId, int responseType, int token, + RIL_Errno e, void *response, size_t responselen); + WakeType wakeType; +} UnsolResponseInfo; + +typedef struct UserCallbackInfo { + RIL_TimedCallback p_callback; + void *userParam; + struct ril_event event; + struct UserCallbackInfo *p_next; +} UserCallbackInfo; + +extern "C" const char * failCauseToString(RIL_Errno); +extern "C" const char * callStateToString(RIL_CallState); +extern "C" const char * radioStateToString(RIL_RadioState); +extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id); + +extern "C" +char ril_service_name_base[MAX_SERVICE_NAME_LENGTH] = RIL_SERVICE_NAME_BASE; +extern "C" +char ril_service_name[MAX_SERVICE_NAME_LENGTH] = RIL1_SERVICE_NAME; +/*******************************************************************/ + +RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL}; +static int s_registerCalled = 0; + +static pthread_t s_tid_dispatch; +static int s_started = 0; + +static int s_fdWakeupRead; +static int s_fdWakeupWrite; + +int s_wakelock_count = 0; + +static struct ril_event s_wakeupfd_event; + +static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER; +static RequestInfo *s_pendingRequests = NULL; + +#if (SIM_COUNT >= 2) +static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER; +static RequestInfo *s_pendingRequests_socket2 = NULL; +#endif + +#if (SIM_COUNT >= 3) +static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER; +static RequestInfo *s_pendingRequests_socket3 = NULL; +#endif + +#if (SIM_COUNT >= 4) +static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER; +static RequestInfo *s_pendingRequests_socket4 = NULL; +#endif + +static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS}; + + +static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER; + +static UserCallbackInfo *s_last_wake_timeout_info = NULL; + +static void *s_lastNITZTimeData = NULL; +static size_t s_lastNITZTimeDataSize; + +#if RILC_LOG + static char printBuf[PRINTBUF_SIZE]; +#endif + +/*******************************************************************/ +static void grabPartialWakeLock(); +void releaseWakeLock(); +static void wakeTimeoutCallback(void *); + +#ifdef RIL_SHLIB +#if defined(ANDROID_MULTI_SIM) +extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen, RIL_SOCKET_ID socket_id); +#else +extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen); +#endif +#endif + +#if defined(ANDROID_MULTI_SIM) +#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d)) +#else +#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c)) +#endif + +static UserCallbackInfo * internalRequestTimedCallback + (RIL_TimedCallback callback, void *param, + const struct timeval *relativeTime); + +/** Index == requestNumber */ +static CommandInfo s_commands[] = { +#include "ril_commands.h" +}; + +static UnsolResponseInfo s_unsolResponses[] = { +#include "ril_unsol_commands.h" +}; + +char * RIL_getServiceName() { + return ril_service_name; +} + +extern "C" +void RIL_setServiceName(const char * s) { + strncpy(ril_service_name, s, MAX_SERVICE_NAME_LENGTH); +} + +RequestInfo * +addRequestToList(int serial, int slotId, int request) { + RequestInfo *pRI; + int ret; + RIL_SOCKET_ID socket_id = (RIL_SOCKET_ID) slotId; + /* Hook for current context */ + /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ + pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; + /* pendingRequestsHook refer to &s_pendingRequests */ + RequestInfo** pendingRequestsHook = &s_pendingRequests; + +#if (SIM_COUNT >= 2) + if (socket_id == RIL_SOCKET_2) { + pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; + pendingRequestsHook = &s_pendingRequests_socket2; + } +#if (SIM_COUNT >= 3) + else if (socket_id == RIL_SOCKET_3) { + pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3; + pendingRequestsHook = &s_pendingRequests_socket3; + } +#endif +#if (SIM_COUNT >= 4) + else if (socket_id == RIL_SOCKET_4) { + pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4; + pendingRequestsHook = &s_pendingRequests_socket4; + } +#endif +#endif + + pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo)); + if (pRI == NULL) { + RLOGE("Memory allocation failed for request %s", requestToString(request)); + return NULL; + } + + pRI->token = serial; + pRI->pCI = &(s_commands[request]); + pRI->socket_id = socket_id; + + ret = pthread_mutex_lock(pendingRequestsMutexHook); + assert (ret == 0); + + pRI->p_next = *pendingRequestsHook; + *pendingRequestsHook = pRI; + + ret = pthread_mutex_unlock(pendingRequestsMutexHook); + assert (ret == 0); + + return pRI; +} + +static void triggerEvLoop() { + int ret; + if (!pthread_equal(pthread_self(), s_tid_dispatch)) { + /* trigger event loop to wakeup. No reason to do this, + * if we're in the event loop thread */ + do { + ret = write (s_fdWakeupWrite, " ", 1); + } while (ret < 0 && errno == EINTR); + } +} + +static void rilEventAddWakeup(struct ril_event *ev) { + ril_event_add(ev); + triggerEvLoop(); +} + +/** + * A write on the wakeup fd is done just to pop us out of select() + * We empty the buffer here and then ril_event will reset the timers on the + * way back down + */ +static void processWakeupCallback(int fd, short flags, void *param) { + char buff[16]; + int ret; + + RLOGV("processWakeupCallback"); + + /* empty our wakeup socket out */ + do { + ret = read(s_fdWakeupRead, &buff, sizeof(buff)); + } while (ret > 0 || (ret < 0 && errno == EINTR)); +} + +static void resendLastNITZTimeData(RIL_SOCKET_ID socket_id) { + if (s_lastNITZTimeData != NULL) { + int responseType = (s_callbacks.version >= 13) + ? RESPONSE_UNSOLICITED_ACK_EXP + : RESPONSE_UNSOLICITED; + int ret = radio::nitzTimeReceivedInd( + (int)socket_id, responseType, 0, + RIL_E_SUCCESS, s_lastNITZTimeData, s_lastNITZTimeDataSize); + if (ret == 0) { + free(s_lastNITZTimeData); + s_lastNITZTimeData = NULL; + } + } +} + +void onNewCommandConnect(RIL_SOCKET_ID socket_id) { + // Inform we are connected and the ril version + int rilVer = s_callbacks.version; + RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED, + &rilVer, sizeof(rilVer), socket_id); + + // implicit radio state changed + RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, + NULL, 0, socket_id); + + // Send last NITZ time data, in case it was missed + if (s_lastNITZTimeData != NULL) { + resendLastNITZTimeData(socket_id); + } + + // Get version string + if (s_callbacks.getVersion != NULL) { + const char *version; + version = s_callbacks.getVersion(); + RLOGI("RIL Daemon version: %s\n", version); + + property_set(PROPERTY_RIL_IMPL, version); + } else { + RLOGI("RIL Daemon version: unavailable\n"); + property_set(PROPERTY_RIL_IMPL, "unavailable"); + } + +} + +static void userTimerCallback (int fd, short flags, void *param) { + UserCallbackInfo *p_info; + + p_info = (UserCallbackInfo *)param; + + p_info->p_callback(p_info->userParam); + + + // FIXME generalize this...there should be a cancel mechanism + if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) { + s_last_wake_timeout_info = NULL; + } + + free(p_info); +} + + +static void * +eventLoop(void *param) { + int ret; + int filedes[2]; + + ril_event_init(); + + pthread_mutex_lock(&s_startupMutex); + + s_started = 1; + pthread_cond_broadcast(&s_startupCond); + + pthread_mutex_unlock(&s_startupMutex); + + ret = pipe(filedes); + + if (ret < 0) { + RLOGE("Error in pipe() errno:%d", errno); + return NULL; + } + + s_fdWakeupRead = filedes[0]; + s_fdWakeupWrite = filedes[1]; + + fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK); + + ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true, + processWakeupCallback, NULL); + + rilEventAddWakeup (&s_wakeupfd_event); + + // Only returns on error + ril_event_loop(); + RLOGE ("error in event_loop_base errno:%d", errno); + // kill self to restart on error + kill(0, SIGKILL); + + return NULL; +} + +extern "C" void +RIL_startEventLoop(void) { + /* spin up eventLoop thread and wait for it to get started */ + s_started = 0; + pthread_mutex_lock(&s_startupMutex); + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL); + if (result != 0) { + RLOGE("Failed to create dispatch thread: %s", strerror(result)); + goto done; + } + + while (s_started == 0) { + pthread_cond_wait(&s_startupCond, &s_startupMutex); + } + +done: + pthread_mutex_unlock(&s_startupMutex); +} + +// Used for testing purpose only. +extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) { + memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions)); +} + +extern "C" void +RIL_register (const RIL_RadioFunctions *callbacks) { + RLOGI("SIM_COUNT: %d", SIM_COUNT); + + if (callbacks == NULL) { + RLOGE("RIL_register: RIL_RadioFunctions * null"); + return; + } + if (callbacks->version < RIL_VERSION_MIN) { + RLOGE("RIL_register: version %d is to old, min version is %d", + callbacks->version, RIL_VERSION_MIN); + return; + } + + RLOGE("RIL_register: RIL version %d", callbacks->version); + + if (s_registerCalled > 0) { + RLOGE("RIL_register has been called more than once. " + "Subsequent call ignored"); + return; + } + + memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions)); + + s_registerCalled = 1; + + RLOGI("s_registerCalled flag set, %d", s_started); + // Little self-check + + for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) { + assert(i == s_commands[i].requestNumber); + } + + for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) { + assert(i + RIL_UNSOL_RESPONSE_BASE + == s_unsolResponses[i].requestNumber); + } + + radio::registerService(&s_callbacks, s_commands); + RLOGI("RILHIDL called registerService"); + +} + +extern "C" void +RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **), + RIL_SOCKET_TYPE socketType, int argc, char **argv) { + + RIL_RadioFunctions* UimFuncs = NULL; + + if(Init) { + UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv); + + switch(socketType) { + case RIL_SAP_SOCKET: + RilSapSocket::initSapSocket(RIL1_SERVICE_NAME, UimFuncs); + +#if (SIM_COUNT >= 2) + RilSapSocket::initSapSocket(RIL2_SERVICE_NAME, UimFuncs); +#endif + +#if (SIM_COUNT >= 3) + RilSapSocket::initSapSocket(RIL3_SERVICE_NAME, UimFuncs); +#endif + +#if (SIM_COUNT >= 4) + RilSapSocket::initSapSocket(RIL4_SERVICE_NAME, UimFuncs); +#endif + break; + default:; + } + + RLOGI("RIL_register_socket: calling registerService"); + sap::registerService(UimFuncs); + } +} + +// Check and remove RequestInfo if its a response and not just ack sent back +static int +checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) { + int ret = 0; + /* Hook for current context + pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ + pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; + /* pendingRequestsHook refer to &s_pendingRequests */ + RequestInfo ** pendingRequestsHook = &s_pendingRequests; + + if (pRI == NULL) { + return 0; + } + +#if (SIM_COUNT >= 2) + if (pRI->socket_id == RIL_SOCKET_2) { + pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; + pendingRequestsHook = &s_pendingRequests_socket2; + } +#if (SIM_COUNT >= 3) + if (pRI->socket_id == RIL_SOCKET_3) { + pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3; + pendingRequestsHook = &s_pendingRequests_socket3; + } +#endif +#if (SIM_COUNT >= 4) + if (pRI->socket_id == RIL_SOCKET_4) { + pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4; + pendingRequestsHook = &s_pendingRequests_socket4; + } +#endif +#endif + pthread_mutex_lock(pendingRequestsMutexHook); + + for(RequestInfo **ppCur = pendingRequestsHook + ; *ppCur != NULL + ; ppCur = &((*ppCur)->p_next) + ) { + if (pRI == *ppCur) { + ret = 1; + if (isAck) { // Async ack + if (pRI->wasAckSent == 1) { + RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber)); + } else { + pRI->wasAckSent = 1; + } + } else { + *ppCur = (*ppCur)->p_next; + } + break; + } + } + + pthread_mutex_unlock(pendingRequestsMutexHook); + + return ret; +} + +extern "C" void +RIL_onRequestAck(RIL_Token t) { + RequestInfo *pRI; + + RIL_SOCKET_ID socket_id = RIL_SOCKET_1; + + pRI = (RequestInfo *)t; + + if (!checkAndDequeueRequestInfoIfAck(pRI, true)) { + RLOGE ("RIL_onRequestAck: invalid RIL_Token"); + return; + } + + socket_id = pRI->socket_id; + +#if VDBG + RLOGD("Request Ack, %s", rilSocketIdToString(socket_id)); +#endif + + appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber)); + + if (pRI->cancelled == 0) { + pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock( + (int) socket_id); + int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr); + assert(rwlockRet == 0); + + radio::acknowledgeRequest((int) socket_id, pRI->token); + + rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(rwlockRet == 0); + } +} +extern "C" void +RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) { + RequestInfo *pRI; + int ret; + RIL_SOCKET_ID socket_id = RIL_SOCKET_1; + + pRI = (RequestInfo *)t; + + if (!checkAndDequeueRequestInfoIfAck(pRI, false)) { + RLOGE ("RIL_onRequestComplete: invalid RIL_Token"); + return; + } + + socket_id = pRI->socket_id; +#if VDBG + RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id)); +#endif + + if (pRI->local > 0) { + // Locally issued command...void only! + // response does not go back up the command socket + RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber)); + + free(pRI); + return; + } + + appendPrintBuf("[%04d]< %s", + pRI->token, requestToString(pRI->pCI->requestNumber)); + + if (pRI->cancelled == 0) { + int responseType; + if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) { + // If ack was already sent, then this call is an asynchronous response. So we need to + // send id indicating that we expect an ack from RIL.java as we acquire wakelock here. + responseType = RESPONSE_SOLICITED_ACK_EXP; + grabPartialWakeLock(); + } else { + responseType = RESPONSE_SOLICITED; + } + + // there is a response payload, no matter success or not. +#if VDBG + RLOGE ("Calling responseFunction() for token %d", pRI->token); +#endif + + pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) socket_id); + int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr); + assert(rwlockRet == 0); + + ret = pRI->pCI->responseFunction((int) socket_id, + responseType, pRI->token, e, response, responselen); + + rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(rwlockRet == 0); + } + free(pRI); +} + +static void +grabPartialWakeLock() { + if (s_callbacks.version >= 13) { + int ret; + ret = pthread_mutex_lock(&s_wakeLockCountMutex); + assert(ret == 0); + acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME); + + UserCallbackInfo *p_info = + internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT); + if (p_info == NULL) { + release_wake_lock(ANDROID_WAKE_LOCK_NAME); + } else { + s_wakelock_count++; + if (s_last_wake_timeout_info != NULL) { + s_last_wake_timeout_info->userParam = (void *)1; + } + s_last_wake_timeout_info = p_info; + } + ret = pthread_mutex_unlock(&s_wakeLockCountMutex); + assert(ret == 0); + } else { + acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME); + } +} + +void +releaseWakeLock() { + if (s_callbacks.version >= 13) { + int ret; + ret = pthread_mutex_lock(&s_wakeLockCountMutex); + assert(ret == 0); + + if (s_wakelock_count > 1) { + s_wakelock_count--; + } else { + s_wakelock_count = 0; + release_wake_lock(ANDROID_WAKE_LOCK_NAME); + if (s_last_wake_timeout_info != NULL) { + s_last_wake_timeout_info->userParam = (void *)1; + } + } + + ret = pthread_mutex_unlock(&s_wakeLockCountMutex); + assert(ret == 0); + } else { + release_wake_lock(ANDROID_WAKE_LOCK_NAME); + } +} + +/** + * Timer callback to put us back to sleep before the default timeout + */ +static void +wakeTimeoutCallback (void *param) { + // We're using "param != NULL" as a cancellation mechanism + if (s_callbacks.version >= 13) { + if (param == NULL) { + int ret; + ret = pthread_mutex_lock(&s_wakeLockCountMutex); + assert(ret == 0); + s_wakelock_count = 0; + release_wake_lock(ANDROID_WAKE_LOCK_NAME); + ret = pthread_mutex_unlock(&s_wakeLockCountMutex); + assert(ret == 0); + } + } else { + if (param == NULL) { + releaseWakeLock(); + } + } +} + +#if defined(ANDROID_MULTI_SIM) +extern "C" +void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen, RIL_SOCKET_ID socket_id) +#else +extern "C" +void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, + size_t datalen) +#endif +{ + int unsolResponseIndex; + int ret; + bool shouldScheduleTimeout = false; + RIL_SOCKET_ID soc_id = RIL_SOCKET_1; + +#if defined(ANDROID_MULTI_SIM) + soc_id = socket_id; +#endif + + + if (s_registerCalled == 0) { + // Ignore RIL_onUnsolicitedResponse before RIL_register + RLOGW("RIL_onUnsolicitedResponse called before RIL_register"); + return; + } + + remapUnsol(&unsolResponse); + + unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE; + + if ((unsolResponseIndex < 0) + || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) { + RLOGE("unsupported unsolicited response code %d", unsolResponse); + return; + } + + // Grab a wake lock if needed for this reponse, + // as we exit we'll either release it immediately + // or set a timer to release it later. + switch (s_unsolResponses[unsolResponseIndex].wakeType) { + case WAKE_PARTIAL: + grabPartialWakeLock(); + shouldScheduleTimeout = true; + break; + + case DONT_WAKE: + default: + // No wake lock is grabed so don't set timeout + shouldScheduleTimeout = false; + break; + } + + appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse)); + + int responseType; + if (s_callbacks.version >= 13 + && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) { + responseType = RESPONSE_UNSOLICITED_ACK_EXP; + } else { + responseType = RESPONSE_UNSOLICITED; + } + + pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) soc_id); + int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr); + assert(rwlockRet == 0); + + if (s_unsolResponses[unsolResponseIndex].responseFunction) { + ret = s_unsolResponses[unsolResponseIndex].responseFunction( + (int) soc_id, responseType, 0, RIL_E_SUCCESS, const_cast(data), + datalen); + } + + rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(rwlockRet == 0); + + if (s_callbacks.version < 13) { + if (shouldScheduleTimeout) { + UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL, + &TIMEVAL_WAKE_TIMEOUT); + + if (p_info == NULL) { + goto error_exit; + } else { + // Cancel the previous request + if (s_last_wake_timeout_info != NULL) { + s_last_wake_timeout_info->userParam = (void *)1; + } + s_last_wake_timeout_info = p_info; + } + } + } + +#if VDBG + RLOGI("%s UNSOLICITED: %s length:%zu", rilSocketIdToString(soc_id), + requestToString(unsolResponse), datalen); +#endif + + if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) { + // Unfortunately, NITZ time is not poll/update like everything + // else in the system. So, if the upstream client isn't connected, + // keep a copy of the last NITZ response (with receive time noted + // above) around so we can deliver it when it is connected + + if (s_lastNITZTimeData != NULL) { + free(s_lastNITZTimeData); + s_lastNITZTimeData = NULL; + } + + s_lastNITZTimeData = calloc(datalen, 1); + if (s_lastNITZTimeData == NULL) { + RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse"); + goto error_exit; + } + s_lastNITZTimeDataSize = datalen; + memcpy(s_lastNITZTimeData, data, datalen); + } + + // Normal exit + return; + +error_exit: + if (shouldScheduleTimeout) { + releaseWakeLock(); + } +} + +/** FIXME generalize this if you track UserCAllbackInfo, clear it + when the callback occurs +*/ +static UserCallbackInfo * +internalRequestTimedCallback (RIL_TimedCallback callback, void *param, + const struct timeval *relativeTime) +{ + struct timeval myRelativeTime; + UserCallbackInfo *p_info; + + p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo)); + if (p_info == NULL) { + RLOGE("Memory allocation failed in internalRequestTimedCallback"); + return p_info; + + } + + p_info->p_callback = callback; + p_info->userParam = param; + + if (relativeTime == NULL) { + /* treat null parameter as a 0 relative time */ + memset (&myRelativeTime, 0, sizeof(myRelativeTime)); + } else { + /* FIXME I think event_add's tv param is really const anyway */ + memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime)); + } + + ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info); + + ril_timer_add(&(p_info->event), &myRelativeTime); + + triggerEvLoop(); + return p_info; +} + + +extern "C" void +RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, + const struct timeval *relativeTime) { + internalRequestTimedCallback (callback, param, relativeTime); +} + +const char * +failCauseToString(RIL_Errno e) { + switch(e) { + case RIL_E_SUCCESS: return "E_SUCCESS"; + case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE"; + case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE"; + case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT"; + case RIL_E_SIM_PIN2: return "E_SIM_PIN2"; + case RIL_E_SIM_PUK2: return "E_SIM_PUK2"; + case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED"; + case RIL_E_CANCELLED: return "E_CANCELLED"; + case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL"; + case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW"; + case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY"; + case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT"; + case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME"; +#ifdef FEATURE_MULTIMODE_ANDROID + case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE"; + case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED"; +#endif + case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE"; + case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE"; + case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT"; + case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD"; + case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS"; + case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL"; + case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL"; + case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS"; + case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD"; + case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL"; + case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD"; + case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED"; + case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS"; + case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED"; + case RIL_E_NO_MEMORY: return "E_NO_MEMORY"; + case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR"; + case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR"; + case RIL_E_MODEM_ERR: return "E_MODEM_ERR"; + case RIL_E_INVALID_STATE: return "E_INVALID_STATE"; + case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES"; + case RIL_E_SIM_ERR: return "E_SIM_ERR"; + case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS"; + case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE"; + case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE"; + case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID"; + case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK"; + case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR"; + case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED"; + case RIL_E_SIM_BUSY: return "E_SIM_BUSY"; + case RIL_E_SIM_FULL: return "E_SIM_FULL"; + case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT"; + case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED"; + case RIL_E_EMPTY_RECORD: return "E_EMPTY_RECORD"; + case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT"; + case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR"; + case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS"; + case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY"; + case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY"; + case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED"; + case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION"; + case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND"; + case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE"; + case RIL_E_ABORTED: return "E_ABORTED"; + case RIL_E_INVALID_RESPONSE: return "INVALID_RESPONSE"; + case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1"; + case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2"; + case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3"; + case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4"; + case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5"; + case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6"; + case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7"; + case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8"; + case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9"; + case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10"; + case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11"; + case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12"; + case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13"; + case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14"; + case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15"; + case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16"; + case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17"; + case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18"; + case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19"; + case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20"; + case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21"; + case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22"; + case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23"; + case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24"; + case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25"; + default: return ""; + } +} + +const char * +radioStateToString(RIL_RadioState s) { + switch(s) { + case RADIO_STATE_OFF: return "RADIO_OFF"; + case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE"; + case RADIO_STATE_ON:return"RADIO_ON"; + default: return ""; + } +} + +const char * +callStateToString(RIL_CallState s) { + switch(s) { + case RIL_CALL_ACTIVE : return "ACTIVE"; + case RIL_CALL_HOLDING: return "HOLDING"; + case RIL_CALL_DIALING: return "DIALING"; + case RIL_CALL_ALERTING: return "ALERTING"; + case RIL_CALL_INCOMING: return "INCOMING"; + case RIL_CALL_WAITING: return "WAITING"; + default: return ""; + } +} + +const char * +requestToString(int request) { +/* + cat libs/telephony/ril_commands.h \ + | egrep "^ *{RIL_" \ + | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/' + + + cat libs/telephony/ril_unsol_commands.h \ + | egrep "^ *{RIL_" \ + | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/' + +*/ + switch(request) { + case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS"; + case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN"; + case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK"; + case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2"; + case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2"; + case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN"; + case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2"; + case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION"; + case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS"; + case RIL_REQUEST_DIAL: return "DIAL"; + case RIL_REQUEST_GET_IMSI: return "GET_IMSI"; + case RIL_REQUEST_HANGUP: return "HANGUP"; + case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND"; + case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND"; + case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE"; + case RIL_REQUEST_CONFERENCE: return "CONFERENCE"; + case RIL_REQUEST_UDUB: return "UDUB"; + case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE"; + case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH"; + case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE"; + case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE"; + case RIL_REQUEST_OPERATOR: return "OPERATOR"; + case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER"; + case RIL_REQUEST_DTMF: return "DTMF"; + case RIL_REQUEST_SEND_SMS: return "SEND_SMS"; + case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE"; + case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL"; + case RIL_REQUEST_SIM_IO: return "SIM_IO"; + case RIL_REQUEST_SEND_USSD: return "SEND_USSD"; + case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD"; + case RIL_REQUEST_GET_CLIR: return "GET_CLIR"; + case RIL_REQUEST_SET_CLIR: return "SET_CLIR"; + case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS"; + case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD"; + case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING"; + case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING"; + case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE"; + case RIL_REQUEST_GET_IMEI: return "GET_IMEI"; + case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV"; + case RIL_REQUEST_ANSWER: return "ANSWER"; + case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL"; + case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK"; + case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK"; + case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD"; + case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE"; + case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC"; + case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL"; + case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS"; + case RIL_REQUEST_DTMF_START: return "DTMF_START"; + case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP"; + case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION"; + case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION"; + case RIL_REQUEST_SET_MUTE: return "SET_MUTE"; + case RIL_REQUEST_GET_MUTE: return "GET_MUTE"; + case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP"; + case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE"; + case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST"; + case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO"; + case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW"; + case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS"; + case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE"; + case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION"; + case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM"; + case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM"; + case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE"; + case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE"; + case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE"; + case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE"; + case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND"; + case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE"; + case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM"; + case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER"; + case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE"; + case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE"; + case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS"; + case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES"; + case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE"; + case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE"; + case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE"; + case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE"; + case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE"; + case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE"; + case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE"; + case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH"; + case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF"; + case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY"; + case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS"; + case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE"; + case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG"; + case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG"; + case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION"; + case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG"; + case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG"; + case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION"; + case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION"; + case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM"; + case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM"; + case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY"; + case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE"; + case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS"; + case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS"; + case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS"; + case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING"; + case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE"; + case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION"; + case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU"; + case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS"; + case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH"; + case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST"; + case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE"; + case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN"; + case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE"; + case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS"; + case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC"; + case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL"; + case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL"; + case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL"; + case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM"; + case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM"; + case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL"; + case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG"; + case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION"; + case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA"; + case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG"; + case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION"; + case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO"; + case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE"; + case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE"; + case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN"; + case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY"; + case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY"; + case RIL_REQUEST_START_LCE: return "START_LCE"; + case RIL_REQUEST_STOP_LCE: return "STOP_LCE"; + case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA"; + case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO"; + case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS"; + case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS"; + case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION: return "SET_CARRIER_INFO_IMSI_ENCRYPTION"; + case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT"; + case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED"; + case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED"; + case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED"; + case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS"; + case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT"; + case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM"; + case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD"; + case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST"; + case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED"; + case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH"; + case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED"; + case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION"; + case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END"; + case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND"; + case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY"; + case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP"; + case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL"; + case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH"; + case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING"; + case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED"; + case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS"; + case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS"; + case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL"; + case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED"; + case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE"; + case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING"; + case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS"; + case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC"; + case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW"; + case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE"; + case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE"; + case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED"; + case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED"; + case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE"; + case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED"; + case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED"; + case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST"; + case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED"; + case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED"; + case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY"; + case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED"; + case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED"; + case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY"; + case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART"; + case RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION: return "UNSOL_CARRIER_INFO_IMSI_ENCRYPTION"; + case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS"; + case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY"; + case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV"; + case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA"; + default: return ""; + } +} + +const char * +rilSocketIdToString(RIL_SOCKET_ID socket_id) +{ + switch(socket_id) { + case RIL_SOCKET_1: + return "RIL_SOCKET_1"; +#if (SIM_COUNT >= 2) + case RIL_SOCKET_2: + return "RIL_SOCKET_2"; +#endif +#if (SIM_COUNT >= 3) + case RIL_SOCKET_3: + return "RIL_SOCKET_3"; +#endif +#if (SIM_COUNT >= 4) + case RIL_SOCKET_4: + return "RIL_SOCKET_4"; +#endif + default: + return "not a valid RIL"; + } +} + +} /* namespace android */ diff --git a/ril/libril/rilSocketQueue.h b/ril/libril/rilSocketQueue.h new file mode 100644 index 0000000..eaa5155 --- /dev/null +++ b/ril/libril/rilSocketQueue.h @@ -0,0 +1,167 @@ +/* +* Copyright (C) 2014 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. +*/ + +#include "pb_decode.h" +#include +#include +#include + +using namespace std; + +/** + * Template queue class to handling requests for a rild socket. + *

+ * This class performs the following functions : + *

    + *
  • Enqueue. + *
  • Dequeue. + *
  • Check and dequeue. + *
+ */ + +template +class Ril_queue { + + /** + * Mutex attribute used in queue mutex initialization. + */ + pthread_mutexattr_t attr; + + /** + * Queue mutex variable for synchronized queue access. + */ + pthread_mutex_t mutex_instance; + + /** + * Condition to be waited on for dequeuing. + */ + pthread_cond_t cond; + + /** + * Front of the queue. + */ + T *front; + + public: + + /** + * Remove the first element of the queue. + * + * @return first element of the queue. + */ + T* dequeue(void); + + /** + * Add a request to the front of the queue. + * + * @param Request to be added. + */ + void enqueue(T* request); + + /** + * Check if the queue is empty. + */ + int empty(void); + + /** + * Check and remove an element with a particular message id and token. + * + * @param Request message id. + * @param Request token. + */ + int checkAndDequeue( MsgId id, int token); + + /** + * Queue constructor. + */ + Ril_queue(void); +}; + +template +Ril_queue::Ril_queue(void) { + pthread_mutexattr_init(&attr); + pthread_mutex_init(&mutex_instance, &attr); + cond = PTHREAD_COND_INITIALIZER; + front = NULL; +} + +template +T* Ril_queue::dequeue(void) { + T* temp = NULL; + + pthread_mutex_lock(&mutex_instance); + while(empty()) { + pthread_cond_wait(&cond, &mutex_instance); + } + temp = this->front; + if(NULL != this->front->p_next) { + this->front = this->front->p_next; + } else { + this->front = NULL; + } + pthread_mutex_unlock(&mutex_instance); + + return temp; +} + +template +void Ril_queue::enqueue(T* request) { + + pthread_mutex_lock(&mutex_instance); + + if(NULL == this->front) { + this->front = request; + request->p_next = NULL; + } else { + request->p_next = this->front; + this->front = request; + } + pthread_cond_broadcast(&cond); + pthread_mutex_unlock(&mutex_instance); +} + +template +int Ril_queue::checkAndDequeue(MsgId id, int token) { + int ret = 0; + T* temp; + + pthread_mutex_lock(&mutex_instance); + + for(T **ppCur = &(this->front); *ppCur != NULL; ppCur = &((*ppCur)->p_next)) { + if (token == (*ppCur)->token && id == (*ppCur)->curr->id) { + ret = 1; + temp = *ppCur; + *ppCur = (*ppCur)->p_next; + free(temp); + break; + } + } + + pthread_mutex_unlock(&mutex_instance); + + return ret; +} + + +template +int Ril_queue::empty(void) { + + if(this->front == NULL) { + return 1; + } else { + return 0; + } +} diff --git a/ril/libril/ril_commands.h b/ril/libril/ril_commands.h new file mode 100644 index 0000000..94c2a26 --- /dev/null +++ b/ril/libril/ril_commands.h @@ -0,0 +1,162 @@ +/* //device/libs/telephony/ril_commands.h +** +** Copyright 2006, 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. +*/ + {0, NULL}, //none + {RIL_REQUEST_GET_SIM_STATUS, radio::getIccCardStatusResponse}, + {RIL_REQUEST_ENTER_SIM_PIN, radio::supplyIccPinForAppResponse}, + {RIL_REQUEST_ENTER_SIM_PUK, radio::supplyIccPukForAppResponse}, + {RIL_REQUEST_ENTER_SIM_PIN2, radio::supplyIccPin2ForAppResponse}, + {RIL_REQUEST_ENTER_SIM_PUK2, radio::supplyIccPuk2ForAppResponse}, + {RIL_REQUEST_CHANGE_SIM_PIN, radio::changeIccPinForAppResponse}, + {RIL_REQUEST_CHANGE_SIM_PIN2, radio::changeIccPin2ForAppResponse}, + {RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, radio::supplyNetworkDepersonalizationResponse}, + {RIL_REQUEST_GET_CURRENT_CALLS, radio::getCurrentCallsResponse}, + {RIL_REQUEST_DIAL, radio::dialResponse}, + {RIL_REQUEST_GET_IMSI, radio::getIMSIForAppResponse}, + {RIL_REQUEST_HANGUP, radio::hangupConnectionResponse}, + {RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, radio::hangupWaitingOrBackgroundResponse}, + {RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, radio::hangupForegroundResumeBackgroundResponse}, + {RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, radio::switchWaitingOrHoldingAndActiveResponse}, + {RIL_REQUEST_CONFERENCE, radio::conferenceResponse}, + {RIL_REQUEST_UDUB, radio::rejectCallResponse}, + {RIL_REQUEST_LAST_CALL_FAIL_CAUSE, radio::getLastCallFailCauseResponse}, + {RIL_REQUEST_SIGNAL_STRENGTH, radio::getSignalStrengthResponse}, + {RIL_REQUEST_VOICE_REGISTRATION_STATE, radio::getVoiceRegistrationStateResponse}, + {RIL_REQUEST_DATA_REGISTRATION_STATE, radio::getDataRegistrationStateResponse}, + {RIL_REQUEST_OPERATOR, radio::getOperatorResponse}, + {RIL_REQUEST_RADIO_POWER, radio::setRadioPowerResponse}, + {RIL_REQUEST_DTMF, radio::sendDtmfResponse}, + {RIL_REQUEST_SEND_SMS, radio::sendSmsResponse}, + {RIL_REQUEST_SEND_SMS_EXPECT_MORE, radio::sendSMSExpectMoreResponse}, + {RIL_REQUEST_SETUP_DATA_CALL, radio::setupDataCallResponse}, + {RIL_REQUEST_SIM_IO, radio::iccIOForAppResponse}, + {RIL_REQUEST_SEND_USSD, radio::sendUssdResponse}, + {RIL_REQUEST_CANCEL_USSD, radio::cancelPendingUssdResponse}, + {RIL_REQUEST_GET_CLIR, radio::getClirResponse}, + {RIL_REQUEST_SET_CLIR, radio::setClirResponse}, + {RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, radio::getCallForwardStatusResponse}, + {RIL_REQUEST_SET_CALL_FORWARD, radio::setCallForwardResponse}, + {RIL_REQUEST_QUERY_CALL_WAITING, radio::getCallWaitingResponse}, + {RIL_REQUEST_SET_CALL_WAITING, radio::setCallWaitingResponse}, + {RIL_REQUEST_SMS_ACKNOWLEDGE, radio::acknowledgeLastIncomingGsmSmsResponse}, + {RIL_REQUEST_GET_IMEI, NULL}, + {RIL_REQUEST_GET_IMEISV, NULL}, + {RIL_REQUEST_ANSWER, radio::acceptCallResponse}, + {RIL_REQUEST_DEACTIVATE_DATA_CALL, radio::deactivateDataCallResponse}, + {RIL_REQUEST_QUERY_FACILITY_LOCK, radio::getFacilityLockForAppResponse}, + {RIL_REQUEST_SET_FACILITY_LOCK, radio::setFacilityLockForAppResponse}, + {RIL_REQUEST_CHANGE_BARRING_PASSWORD, radio::setBarringPasswordResponse}, + {RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, radio::getNetworkSelectionModeResponse}, + {RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, radio::setNetworkSelectionModeAutomaticResponse}, + {RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, radio::setNetworkSelectionModeManualResponse}, + {RIL_REQUEST_QUERY_AVAILABLE_NETWORKS , radio::getAvailableNetworksResponse}, + {RIL_REQUEST_DTMF_START, radio::startDtmfResponse}, + {RIL_REQUEST_DTMF_STOP, radio::stopDtmfResponse}, + {RIL_REQUEST_BASEBAND_VERSION, radio::getBasebandVersionResponse}, + {RIL_REQUEST_SEPARATE_CONNECTION, radio::separateConnectionResponse}, + {RIL_REQUEST_SET_MUTE, radio::setMuteResponse}, + {RIL_REQUEST_GET_MUTE, radio::getMuteResponse}, + {RIL_REQUEST_QUERY_CLIP, radio::getClipResponse}, + {RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE, NULL}, + {RIL_REQUEST_DATA_CALL_LIST, radio::getDataCallListResponse}, + {RIL_REQUEST_RESET_RADIO, NULL}, + {RIL_REQUEST_OEM_HOOK_RAW, radio::sendRequestRawResponse}, + {RIL_REQUEST_OEM_HOOK_STRINGS, radio::sendRequestStringsResponse}, + {RIL_REQUEST_SCREEN_STATE, radio::sendDeviceStateResponse}, // Note the response function is different. + {RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, radio::setSuppServiceNotificationsResponse}, + {RIL_REQUEST_WRITE_SMS_TO_SIM, radio::writeSmsToSimResponse}, + {RIL_REQUEST_DELETE_SMS_ON_SIM, radio::deleteSmsOnSimResponse}, + {RIL_REQUEST_SET_BAND_MODE, radio::setBandModeResponse}, + {RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, radio::getAvailableBandModesResponse}, + {RIL_REQUEST_STK_GET_PROFILE, NULL}, + {RIL_REQUEST_STK_SET_PROFILE, NULL}, + {RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, radio::sendEnvelopeResponse}, + {RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, radio::sendTerminalResponseToSimResponse}, + {RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM, radio::handleStkCallSetupRequestFromSimResponse}, + {RIL_REQUEST_EXPLICIT_CALL_TRANSFER, radio::explicitCallTransferResponse}, + {RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, radio::setPreferredNetworkTypeResponse}, + {RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, radio::getPreferredNetworkTypeResponse}, + {RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, radio::getNeighboringCidsResponse}, + {RIL_REQUEST_SET_LOCATION_UPDATES, radio::setLocationUpdatesResponse}, + {RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, radio::setCdmaSubscriptionSourceResponse}, + {RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, radio::setCdmaRoamingPreferenceResponse}, + {RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, radio::getCdmaRoamingPreferenceResponse}, + {RIL_REQUEST_SET_TTY_MODE, radio::setTTYModeResponse}, + {RIL_REQUEST_QUERY_TTY_MODE, radio::getTTYModeResponse}, + {RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE, radio::setPreferredVoicePrivacyResponse}, + {RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE, radio::getPreferredVoicePrivacyResponse}, + {RIL_REQUEST_CDMA_FLASH, radio::sendCDMAFeatureCodeResponse}, + {RIL_REQUEST_CDMA_BURST_DTMF, radio::sendBurstDtmfResponse}, + {RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY, NULL}, + {RIL_REQUEST_CDMA_SEND_SMS, radio::sendCdmaSmsResponse}, + {RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, radio::acknowledgeLastIncomingCdmaSmsResponse}, + {RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG, radio::getGsmBroadcastConfigResponse}, + {RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG, radio::setGsmBroadcastConfigResponse}, + {RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION, radio::setGsmBroadcastActivationResponse}, + {RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG, radio::getCdmaBroadcastConfigResponse}, + {RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG, radio::setCdmaBroadcastConfigResponse}, + {RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION, radio::setCdmaBroadcastActivationResponse}, + {RIL_REQUEST_CDMA_SUBSCRIPTION, radio::getCDMASubscriptionResponse}, + {RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM, radio::writeSmsToRuimResponse}, + {RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, radio::deleteSmsOnRuimResponse}, + {RIL_REQUEST_DEVICE_IDENTITY, radio::getDeviceIdentityResponse}, + {RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, radio::exitEmergencyCallbackModeResponse}, + {RIL_REQUEST_GET_SMSC_ADDRESS, radio::getSmscAddressResponse}, + {RIL_REQUEST_SET_SMSC_ADDRESS, radio::setSmscAddressResponse}, + {RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, radio::reportSmsMemoryStatusResponse}, + {RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, radio::reportStkServiceIsRunningResponse}, + {RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, radio::getCdmaSubscriptionSourceResponse}, + {RIL_REQUEST_ISIM_AUTHENTICATION, radio::requestIsimAuthenticationResponse}, + {RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, radio::acknowledgeIncomingGsmSmsWithPduResponse}, + {RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, radio::sendEnvelopeWithStatusResponse}, + {RIL_REQUEST_VOICE_RADIO_TECH, radio::getVoiceRadioTechnologyResponse}, + {RIL_REQUEST_GET_CELL_INFO_LIST, radio::getCellInfoListResponse}, + {RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, radio::setCellInfoListRateResponse}, + {RIL_REQUEST_SET_INITIAL_ATTACH_APN, radio::setInitialAttachApnResponse}, + {RIL_REQUEST_IMS_REGISTRATION_STATE, radio::getImsRegistrationStateResponse}, + {RIL_REQUEST_IMS_SEND_SMS, radio::sendImsSmsResponse}, + {RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, radio::iccTransmitApduBasicChannelResponse}, + {RIL_REQUEST_SIM_OPEN_CHANNEL, radio::iccOpenLogicalChannelResponse}, + {RIL_REQUEST_SIM_CLOSE_CHANNEL, radio::iccCloseLogicalChannelResponse}, + {RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, radio::iccTransmitApduLogicalChannelResponse}, + {RIL_REQUEST_NV_READ_ITEM, radio::nvReadItemResponse}, + {RIL_REQUEST_NV_WRITE_ITEM, radio::nvWriteItemResponse}, + {RIL_REQUEST_NV_WRITE_CDMA_PRL, radio::nvWriteCdmaPrlResponse}, + {RIL_REQUEST_NV_RESET_CONFIG, radio::nvResetConfigResponse}, + {RIL_REQUEST_SET_UICC_SUBSCRIPTION, radio::setUiccSubscriptionResponse}, + {RIL_REQUEST_ALLOW_DATA, radio::setDataAllowedResponse}, + {RIL_REQUEST_GET_HARDWARE_CONFIG, radio::getHardwareConfigResponse}, + {RIL_REQUEST_SIM_AUTHENTICATION, radio::requestIccSimAuthenticationResponse}, + {RIL_REQUEST_GET_DC_RT_INFO, NULL}, + {RIL_REQUEST_SET_DC_RT_INFO_RATE, NULL}, + {RIL_REQUEST_SET_DATA_PROFILE, radio::setDataProfileResponse}, + {RIL_REQUEST_SHUTDOWN, radio::requestShutdownResponse}, + {RIL_REQUEST_GET_RADIO_CAPABILITY, radio::getRadioCapabilityResponse}, + {RIL_REQUEST_SET_RADIO_CAPABILITY, radio::setRadioCapabilityResponse}, + {RIL_REQUEST_START_LCE, radio::startLceServiceResponse}, + {RIL_REQUEST_STOP_LCE, radio::stopLceServiceResponse}, + {RIL_REQUEST_PULL_LCEDATA, radio::pullLceDataResponse}, + {RIL_REQUEST_GET_ACTIVITY_INFO, radio::getModemActivityInfoResponse}, + {RIL_REQUEST_SET_CARRIER_RESTRICTIONS, radio::setAllowedCarriersResponse}, + {RIL_REQUEST_GET_CARRIER_RESTRICTIONS, radio::getAllowedCarriersResponse}, + {RIL_REQUEST_SEND_DEVICE_STATE, radio::sendDeviceStateResponse}, + {RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, radio::setIndicationFilterResponse}, + {RIL_REQUEST_SET_SIM_CARD_POWER, radio::setSimCardPowerResponse}, + {RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, radio::setCarrierInfoForImsiEncryptionResponse}, + {RIL_REQUEST_START_NETWORK_SCAN, radio::startNetworkScanResponse}, + {RIL_REQUEST_STOP_NETWORK_SCAN, radio::stopNetworkScanResponse}, + {RIL_REQUEST_START_KEEPALIVE, radio::startKeepaliveResponse}, + {RIL_REQUEST_STOP_KEEPALIVE, radio::stopKeepaliveResponse}, diff --git a/ril/libril/ril_event.cpp b/ril/libril/ril_event.cpp new file mode 100644 index 0000000..84b8b72 --- /dev/null +++ b/ril/libril/ril_event.cpp @@ -0,0 +1,384 @@ +/* //device/libs/telephony/ril_event.cpp +** +** Copyright 2008, 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. +*/ + +#define LOG_TAG "RILC" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +static pthread_mutex_t listMutex; +#define MUTEX_ACQUIRE() pthread_mutex_lock(&listMutex) +#define MUTEX_RELEASE() pthread_mutex_unlock(&listMutex) +#define MUTEX_INIT() pthread_mutex_init(&listMutex, NULL) +#define MUTEX_DESTROY() pthread_mutex_destroy(&listMutex) + +#ifndef timeradd +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#endif + +#ifndef timercmp +#define timercmp(a, b, op) \ + ((a)->tv_sec == (b)->tv_sec \ + ? (a)->tv_usec op (b)->tv_usec \ + : (a)->tv_sec op (b)->tv_sec) +#endif + +#ifndef timersub +#define timersub(a, b, res) \ + do { \ + (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((res)->tv_usec < 0) { \ + (res)->tv_usec += 1000000; \ + (res)->tv_sec -= 1; \ + } \ + } while(0); +#endif + +static fd_set readFds; +static int nfds = 0; + +static struct ril_event * watch_table[MAX_FD_EVENTS]; +static struct ril_event timer_list; +static struct ril_event pending_list; + +#define DEBUG 0 + +#if DEBUG +#define dlog(x...) RLOGD( x ) +static void dump_event(struct ril_event * ev) +{ + dlog("~~~~ Event %x ~~~~", (unsigned int)ev); + dlog(" next = %x", (unsigned int)ev->next); + dlog(" prev = %x", (unsigned int)ev->prev); + dlog(" fd = %d", ev->fd); + dlog(" pers = %d", ev->persist); + dlog(" timeout = %ds + %dus", (int)ev->timeout.tv_sec, (int)ev->timeout.tv_usec); + dlog(" func = %x", (unsigned int)ev->func); + dlog(" param = %x", (unsigned int)ev->param); + dlog("~~~~~~~~~~~~~~~~~~"); +} +#else +#define dlog(x...) do {} while(0) +#define dump_event(x) do {} while(0) +#endif + +static void getNow(struct timeval * tv) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec/1000; +} + +static void init_list(struct ril_event * list) +{ + memset(list, 0, sizeof(struct ril_event)); + list->next = list; + list->prev = list; + list->fd = -1; +} + +static void addToList(struct ril_event * ev, struct ril_event * list) +{ + ev->next = list; + ev->prev = list->prev; + ev->prev->next = ev; + list->prev = ev; + dump_event(ev); +} + +static void removeFromList(struct ril_event * ev) +{ + dlog("~~~~ +removeFromList ~~~~"); + dump_event(ev); + + ev->next->prev = ev->prev; + ev->prev->next = ev->next; + ev->next = NULL; + ev->prev = NULL; + dlog("~~~~ -removeFromList ~~~~"); +} + + +static void removeWatch(struct ril_event * ev, int index) +{ + dlog("~~~~ +removeWatch ~~~~"); + watch_table[index] = NULL; + ev->index = -1; + + FD_CLR(ev->fd, &readFds); + + if (ev->fd+1 == nfds) { + int n = 0; + + for (int i = 0; i < MAX_FD_EVENTS; i++) { + struct ril_event * rev = watch_table[i]; + + if ((rev != NULL) && (rev->fd > n)) { + n = rev->fd; + } + } + nfds = n + 1; + dlog("~~~~ nfds = %d ~~~~", nfds); + } + dlog("~~~~ -removeWatch ~~~~"); +} + +static void processTimeouts() +{ + dlog("~~~~ +processTimeouts ~~~~"); + MUTEX_ACQUIRE(); + struct timeval now; + struct ril_event * tev = timer_list.next; + struct ril_event * next; + + getNow(&now); + // walk list, see if now >= ev->timeout for any events + + dlog("~~~~ Looking for timers <= %ds + %dus ~~~~", (int)now.tv_sec, (int)now.tv_usec); + while ((tev != &timer_list) && (timercmp(&now, &tev->timeout, >))) { + // Timer expired + dlog("~~~~ firing timer ~~~~"); + next = tev->next; + removeFromList(tev); + addToList(tev, &pending_list); + tev = next; + } + MUTEX_RELEASE(); + dlog("~~~~ -processTimeouts ~~~~"); +} + +static void processReadReadies(fd_set * rfds, int n) +{ + dlog("~~~~ +processReadReadies (%d) ~~~~", n); + MUTEX_ACQUIRE(); + + for (int i = 0; (i < MAX_FD_EVENTS) && (n > 0); i++) { + struct ril_event * rev = watch_table[i]; + if (rev != NULL && FD_ISSET(rev->fd, rfds)) { + addToList(rev, &pending_list); + if (rev->persist == false) { + removeWatch(rev, i); + } + n--; + } + } + + MUTEX_RELEASE(); + dlog("~~~~ -processReadReadies (%d) ~~~~", n); +} + +static void firePending() +{ + dlog("~~~~ +firePending ~~~~"); + struct ril_event * ev = pending_list.next; + while (ev != &pending_list) { + struct ril_event * next = ev->next; + removeFromList(ev); + ev->func(ev->fd, 0, ev->param); + ev = next; + } + dlog("~~~~ -firePending ~~~~"); +} + +static int calcNextTimeout(struct timeval * tv) +{ + struct ril_event * tev = timer_list.next; + struct timeval now; + + getNow(&now); + + // Sorted list, so calc based on first node + if (tev == &timer_list) { + // no pending timers + return -1; + } + + dlog("~~~~ now = %ds + %dus ~~~~", (int)now.tv_sec, (int)now.tv_usec); + dlog("~~~~ next = %ds + %dus ~~~~", + (int)tev->timeout.tv_sec, (int)tev->timeout.tv_usec); + if (timercmp(&tev->timeout, &now, >)) { + timersub(&tev->timeout, &now, tv); + } else { + // timer already expired. + tv->tv_sec = tv->tv_usec = 0; + } + return 0; +} + +// Initialize internal data structs +void ril_event_init() +{ + MUTEX_INIT(); + + FD_ZERO(&readFds); + init_list(&timer_list); + init_list(&pending_list); + memset(watch_table, 0, sizeof(watch_table)); +} + +// Initialize an event +void ril_event_set(struct ril_event * ev, int fd, bool persist, ril_event_cb func, void * param) +{ + dlog("~~~~ ril_event_set %x ~~~~", (unsigned int)ev); + memset(ev, 0, sizeof(struct ril_event)); + ev->fd = fd; + ev->index = -1; + ev->persist = persist; + ev->func = func; + ev->param = param; + fcntl(fd, F_SETFL, O_NONBLOCK); +} + +// Add event to watch list +void ril_event_add(struct ril_event * ev) +{ + dlog("~~~~ +ril_event_add ~~~~"); + MUTEX_ACQUIRE(); + for (int i = 0; i < MAX_FD_EVENTS; i++) { + if (watch_table[i] == NULL) { + watch_table[i] = ev; + ev->index = i; + dlog("~~~~ added at %d ~~~~", i); + dump_event(ev); + FD_SET(ev->fd, &readFds); + if (ev->fd >= nfds) nfds = ev->fd+1; + dlog("~~~~ nfds = %d ~~~~", nfds); + break; + } + } + MUTEX_RELEASE(); + dlog("~~~~ -ril_event_add ~~~~"); +} + +// Add timer event +void ril_timer_add(struct ril_event * ev, struct timeval * tv) +{ + dlog("~~~~ +ril_timer_add ~~~~"); + MUTEX_ACQUIRE(); + + struct ril_event * list; + if (tv != NULL) { + // add to timer list + list = timer_list.next; + ev->fd = -1; // make sure fd is invalid + + struct timeval now; + getNow(&now); + timeradd(&now, tv, &ev->timeout); + + // keep list sorted + while (timercmp(&list->timeout, &ev->timeout, < ) + && (list != &timer_list)) { + list = list->next; + } + // list now points to the first event older than ev + addToList(ev, list); + } + + MUTEX_RELEASE(); + dlog("~~~~ -ril_timer_add ~~~~"); +} + +// Remove event from watch or timer list +void ril_event_del(struct ril_event * ev) +{ + dlog("~~~~ +ril_event_del ~~~~"); + MUTEX_ACQUIRE(); + + if (ev->index < 0 || ev->index >= MAX_FD_EVENTS) { + MUTEX_RELEASE(); + return; + } + + removeWatch(ev, ev->index); + + MUTEX_RELEASE(); + dlog("~~~~ -ril_event_del ~~~~"); +} + +#if DEBUG +static void printReadies(fd_set * rfds) +{ + for (int i = 0; (i < MAX_FD_EVENTS); i++) { + struct ril_event * rev = watch_table[i]; + if (rev != NULL && FD_ISSET(rev->fd, rfds)) { + dlog("DON: fd=%d is ready", rev->fd); + } + } +} +#else +#define printReadies(rfds) do {} while(0) +#endif + +void ril_event_loop() +{ + int n; + fd_set rfds; + struct timeval tv; + struct timeval * ptv; + + + for (;;) { + + // make local copy of read fd_set + memcpy(&rfds, &readFds, sizeof(fd_set)); + if (-1 == calcNextTimeout(&tv)) { + // no pending timers; block indefinitely + dlog("~~~~ no timers; blocking indefinitely ~~~~"); + ptv = NULL; + } else { + dlog("~~~~ blocking for %ds + %dus ~~~~", (int)tv.tv_sec, (int)tv.tv_usec); + ptv = &tv; + } + printReadies(&rfds); + n = select(nfds, &rfds, NULL, NULL, ptv); + printReadies(&rfds); + dlog("~~~~ %d events fired ~~~~", n); + if (n < 0) { + if (errno == EINTR) continue; + + RLOGE("ril_event: select error (%d)", errno); + // bail? + return; + } + + // Check for timeouts + processTimeouts(); + // Check for read-ready + processReadReadies(&rfds, n); + // Fire away + firePending(); + } +} diff --git a/ril/libril/ril_event.h b/ril/libril/ril_event.h new file mode 100644 index 0000000..7ba231b --- /dev/null +++ b/ril/libril/ril_event.h @@ -0,0 +1,52 @@ +/* //device/libs/telephony/ril_event.h +** +** Copyright 2008, 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. +*/ + +// Max number of fd's we watch at any one time. Increase if necessary. +#define MAX_FD_EVENTS 8 + +typedef void (*ril_event_cb)(int fd, short events, void *userdata); + +struct ril_event { + struct ril_event *next; + struct ril_event *prev; + + int fd; + int index; + bool persist; + struct timeval timeout; + ril_event_cb func; + void *param; +}; + +// Initialize internal data structs +void ril_event_init(); + +// Initialize an event +void ril_event_set(struct ril_event * ev, int fd, bool persist, ril_event_cb func, void * param); + +// Add event to watch list +void ril_event_add(struct ril_event * ev); + +// Add timer event +void ril_timer_add(struct ril_event * ev, struct timeval * tv); + +// Remove event from watch list +void ril_event_del(struct ril_event * ev); + +// Event loop +void ril_event_loop(); + diff --git a/ril/libril/ril_internal.h b/ril/libril/ril_internal.h new file mode 100644 index 0000000..350791b --- /dev/null +++ b/ril/libril/ril_internal.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2016 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. + */ + +#ifndef ANDROID_RIL_INTERNAL_H +#define ANDROID_RIL_INTERNAL_H + +namespace android { + +#define RIL_SERVICE_NAME_BASE "slot" +#define RIL1_SERVICE_NAME "slot1" +#define RIL2_SERVICE_NAME "slot2" +#define RIL3_SERVICE_NAME "slot3" +#define RIL4_SERVICE_NAME "slot4" + +/* Constants for response types */ +#define RESPONSE_SOLICITED 0 +#define RESPONSE_UNSOLICITED 1 +#define RESPONSE_SOLICITED_ACK 2 +#define RESPONSE_SOLICITED_ACK_EXP 3 +#define RESPONSE_UNSOLICITED_ACK_EXP 4 + +// Enable verbose logging +#define VDBG 0 + +#define MIN(a,b) ((a)<(b) ? (a) : (b)) + +// Enable RILC log +#define RILC_LOG 0 + +#if RILC_LOG + #define startRequest sprintf(printBuf, "(") + #define closeRequest sprintf(printBuf, "%s)", printBuf) + #define printRequest(token, req) \ + RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf) + + #define startResponse sprintf(printBuf, "%s {", printBuf) + #define closeResponse sprintf(printBuf, "%s}", printBuf) + #define printResponse RLOGD("%s", printBuf) + + #define clearPrintBuf printBuf[0] = 0 + #define removeLastChar printBuf[strlen(printBuf)-1] = 0 + #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x) +#else + #define startRequest + #define closeRequest + #define printRequest(token, req) + #define startResponse + #define closeResponse + #define printResponse + #define clearPrintBuf + #define removeLastChar + #define appendPrintBuf(x...) +#endif + +typedef struct CommandInfo CommandInfo; + +extern "C" const char * requestToString(int request); + +typedef struct RequestInfo { + int32_t token; //this is not RIL_Token + CommandInfo *pCI; + struct RequestInfo *p_next; + char cancelled; + char local; // responses to local commands do not go back to command process + RIL_SOCKET_ID socket_id; + int wasAckSent; // Indicates whether an ack was sent earlier +} RequestInfo; + +typedef struct CommandInfo { + int requestNumber; + int(*responseFunction) (int slotId, int responseType, int token, + RIL_Errno e, void *response, size_t responselen); +} CommandInfo; + +RequestInfo * addRequestToList(int serial, int slotId, int request); + +char * RIL_getServiceName(); + +void releaseWakeLock(); + +void onNewCommandConnect(RIL_SOCKET_ID socket_id); + +} // namespace android + +#endif //ANDROID_RIL_INTERNAL_H diff --git a/ril/libril/ril_service.cpp b/ril/libril/ril_service.cpp new file mode 100644 index 0000000..e5acc60 --- /dev/null +++ b/ril/libril/ril_service.cpp @@ -0,0 +1,8690 @@ +/* + * Copyright (c) 2016 The Android Open Source Project + * Copyright (c) 2018 The LineageOS 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. + */ + +#define LOG_TAG "RILC" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define ANDROID_ATOMIC_INLINE +extern "C" { +#include +} + +#define INVALID_HEX_CHAR 16 + +using namespace android::hardware::radio; +using namespace android::hardware::radio::V1_0; +using namespace android::hardware::radio::deprecated::V1_0; +using ::android::hardware::configureRpcThreadpool; +using ::android::hardware::joinRpcThreadpool; +using ::android::hardware::Return; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_array; +using ::android::hardware::Void; +using android::CommandInfo; +using android::RequestInfo; +using android::requestToString; +using android::sp; + +#define BOOL_TO_INT(x) (x ? 1 : 0) +#define ATOI_NULL_HANDLED(x) (x ? atoi(x) : -1) +#define ATOI_NULL_HANDLED_DEF(x, defaultVal) (x ? atoi(x) : defaultVal) + +#if defined(ANDROID_MULTI_SIM) +#define CALL_ONREQUEST(a, b, c, d, e) \ + s_vendorFunctions->onRequest((a), (b), (c), (d), ((RIL_SOCKET_ID)(e))) +#define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest((RIL_SOCKET_ID)(a)) +#else +#define CALL_ONREQUEST(a, b, c, d, e) s_vendorFunctions->onRequest((a), (b), (c), (d)) +#define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest() +#endif + +RIL_RadioFunctions *s_vendorFunctions = NULL; +static CommandInfo *s_commands; + +struct RadioImpl; +struct OemHookImpl; + +#if (SIM_COUNT >= 2) +sp radioService[SIM_COUNT]; +sp oemHookService[SIM_COUNT]; +// counter used for synchronization. It is incremented every time response callbacks are updated. +volatile int32_t mCounterRadio[SIM_COUNT]; +volatile int32_t mCounterOemHook[SIM_COUNT]; +#else +sp radioService[1]; +sp oemHookService[1]; +// counter used for synchronization. It is incremented every time response callbacks are updated. +volatile int32_t mCounterRadio[1]; +volatile int32_t mCounterOemHook[1]; +#endif + +static pthread_rwlock_t radioServiceRwlock = PTHREAD_RWLOCK_INITIALIZER; + +#if (SIM_COUNT >= 2) +static pthread_rwlock_t radioServiceRwlock2 = PTHREAD_RWLOCK_INITIALIZER; +#if (SIM_COUNT >= 3) +static pthread_rwlock_t radioServiceRwlock3 = PTHREAD_RWLOCK_INITIALIZER; +#if (SIM_COUNT >= 4) +static pthread_rwlock_t radioServiceRwlock4 = PTHREAD_RWLOCK_INITIALIZER; +#endif +#endif +#endif + +void convertRilHardwareConfigListToHal(void *response, size_t responseLen, + hidl_vec& records); + +void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc); + +void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce); + +void convertRilSignalStrengthToHal(void *response, size_t responseLen, + SignalStrength& signalStrength); + +void convertRilDataCallToHal(RIL_Data_Call_Response_v6 *dcResponse, + SetupDataCallResult& dcResult); + +void convertRilDataCallToHal(RIL_Data_Call_Response_v9 *dcResponse, + SetupDataCallResult& dcResult); + +void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse, + SetupDataCallResult& dcResult); + +void convertRilDataCallListToHal(void *response, size_t responseLen, + hidl_vec& dcResultList); + +void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec& records); + +struct RadioImpl : public V1_1::IRadio { + int32_t mSlotId; + sp mRadioResponse; + sp mRadioIndication; + sp mRadioResponseV1_1; + sp mRadioIndicationV1_1; + + Return setResponseFunctions( + const ::android::sp& radioResponse, + const ::android::sp& radioIndication); + + Return getIccCardStatus(int32_t serial); + + Return supplyIccPinForApp(int32_t serial, const hidl_string& pin, + const hidl_string& aid); + + Return supplyIccPukForApp(int32_t serial, const hidl_string& puk, + const hidl_string& pin, const hidl_string& aid); + + Return supplyIccPin2ForApp(int32_t serial, + const hidl_string& pin2, + const hidl_string& aid); + + Return supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2, + const hidl_string& pin2, const hidl_string& aid); + + Return changeIccPinForApp(int32_t serial, const hidl_string& oldPin, + const hidl_string& newPin, const hidl_string& aid); + + Return changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2, + const hidl_string& newPin2, const hidl_string& aid); + + Return supplyNetworkDepersonalization(int32_t serial, const hidl_string& netPin); + + Return getCurrentCalls(int32_t serial); + + Return dial(int32_t serial, const Dial& dialInfo); + + Return getImsiForApp(int32_t serial, + const ::android::hardware::hidl_string& aid); + + Return hangup(int32_t serial, int32_t gsmIndex); + + Return hangupWaitingOrBackground(int32_t serial); + + Return hangupForegroundResumeBackground(int32_t serial); + + Return switchWaitingOrHoldingAndActive(int32_t serial); + + Return conference(int32_t serial); + + Return rejectCall(int32_t serial); + + Return getLastCallFailCause(int32_t serial); + + Return getSignalStrength(int32_t serial); + + Return getVoiceRegistrationState(int32_t serial); + + Return getDataRegistrationState(int32_t serial); + + Return getOperator(int32_t serial); + + Return setRadioPower(int32_t serial, bool on); + + Return sendDtmf(int32_t serial, + const ::android::hardware::hidl_string& s); + + Return sendSms(int32_t serial, const GsmSmsMessage& message); + + Return sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message); + + Return setupDataCall(int32_t serial, + RadioTechnology radioTechnology, + const DataProfileInfo& profileInfo, + bool modemCognitive, + bool roamingAllowed, + bool isRoaming); + + Return iccIOForApp(int32_t serial, + const IccIo& iccIo); + + Return sendUssd(int32_t serial, + const ::android::hardware::hidl_string& ussd); + + Return cancelPendingUssd(int32_t serial); + + Return getClir(int32_t serial); + + Return setClir(int32_t serial, int32_t status); + + Return getCallForwardStatus(int32_t serial, + const CallForwardInfo& callInfo); + + Return setCallForward(int32_t serial, + const CallForwardInfo& callInfo); + + Return getCallWaiting(int32_t serial, int32_t serviceClass); + + Return setCallWaiting(int32_t serial, bool enable, int32_t serviceClass); + + Return acknowledgeLastIncomingGsmSms(int32_t serial, + bool success, SmsAcknowledgeFailCause cause); + + Return acceptCall(int32_t serial); + + Return deactivateDataCall(int32_t serial, + int32_t cid, bool reasonRadioShutDown); + + Return getFacilityLockForApp(int32_t serial, + const ::android::hardware::hidl_string& facility, + const ::android::hardware::hidl_string& password, + int32_t serviceClass, + const ::android::hardware::hidl_string& appId); + + Return setFacilityLockForApp(int32_t serial, + const ::android::hardware::hidl_string& facility, + bool lockState, + const ::android::hardware::hidl_string& password, + int32_t serviceClass, + const ::android::hardware::hidl_string& appId); + + Return setBarringPassword(int32_t serial, + const ::android::hardware::hidl_string& facility, + const ::android::hardware::hidl_string& oldPassword, + const ::android::hardware::hidl_string& newPassword); + + Return getNetworkSelectionMode(int32_t serial); + + Return setNetworkSelectionModeAutomatic(int32_t serial); + + Return setNetworkSelectionModeManual(int32_t serial, + const ::android::hardware::hidl_string& operatorNumeric); + + Return getAvailableNetworks(int32_t serial); + + Return startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request); + + Return stopNetworkScan(int32_t serial); + + Return startDtmf(int32_t serial, + const ::android::hardware::hidl_string& s); + + Return stopDtmf(int32_t serial); + + Return getBasebandVersion(int32_t serial); + + Return separateConnection(int32_t serial, int32_t gsmIndex); + + Return setMute(int32_t serial, bool enable); + + Return getMute(int32_t serial); + + Return getClip(int32_t serial); + + Return getDataCallList(int32_t serial); + + Return setSuppServiceNotifications(int32_t serial, bool enable); + + Return writeSmsToSim(int32_t serial, + const SmsWriteArgs& smsWriteArgs); + + Return deleteSmsOnSim(int32_t serial, int32_t index); + + Return setBandMode(int32_t serial, RadioBandMode mode); + + Return getAvailableBandModes(int32_t serial); + + Return sendEnvelope(int32_t serial, + const ::android::hardware::hidl_string& command); + + Return sendTerminalResponseToSim(int32_t serial, + const ::android::hardware::hidl_string& commandResponse); + + Return handleStkCallSetupRequestFromSim(int32_t serial, bool accept); + + Return explicitCallTransfer(int32_t serial); + + Return setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType); + + Return getPreferredNetworkType(int32_t serial); + + Return getNeighboringCids(int32_t serial); + + Return setLocationUpdates(int32_t serial, bool enable); + + Return setCdmaSubscriptionSource(int32_t serial, + CdmaSubscriptionSource cdmaSub); + + Return setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type); + + Return getCdmaRoamingPreference(int32_t serial); + + Return setTTYMode(int32_t serial, TtyMode mode); + + Return getTTYMode(int32_t serial); + + Return setPreferredVoicePrivacy(int32_t serial, bool enable); + + Return getPreferredVoicePrivacy(int32_t serial); + + Return sendCDMAFeatureCode(int32_t serial, + const ::android::hardware::hidl_string& featureCode); + + Return sendBurstDtmf(int32_t serial, + const ::android::hardware::hidl_string& dtmf, + int32_t on, + int32_t off); + + Return sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms); + + Return acknowledgeLastIncomingCdmaSms(int32_t serial, + const CdmaSmsAck& smsAck); + + Return getGsmBroadcastConfig(int32_t serial); + + Return setGsmBroadcastConfig(int32_t serial, + const hidl_vec& configInfo); + + Return setGsmBroadcastActivation(int32_t serial, bool activate); + + Return getCdmaBroadcastConfig(int32_t serial); + + Return setCdmaBroadcastConfig(int32_t serial, + const hidl_vec& configInfo); + + Return setCdmaBroadcastActivation(int32_t serial, bool activate); + + Return getCDMASubscription(int32_t serial); + + Return writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms); + + Return deleteSmsOnRuim(int32_t serial, int32_t index); + + Return getDeviceIdentity(int32_t serial); + + Return exitEmergencyCallbackMode(int32_t serial); + + Return getSmscAddress(int32_t serial); + + Return setSmscAddress(int32_t serial, + const ::android::hardware::hidl_string& smsc); + + Return reportSmsMemoryStatus(int32_t serial, bool available); + + Return reportStkServiceIsRunning(int32_t serial); + + Return getCdmaSubscriptionSource(int32_t serial); + + Return requestIsimAuthentication(int32_t serial, + const ::android::hardware::hidl_string& challenge); + + Return acknowledgeIncomingGsmSmsWithPdu(int32_t serial, + bool success, + const ::android::hardware::hidl_string& ackPdu); + + Return sendEnvelopeWithStatus(int32_t serial, + const ::android::hardware::hidl_string& contents); + + Return getVoiceRadioTechnology(int32_t serial); + + Return getCellInfoList(int32_t serial); + + Return setCellInfoListRate(int32_t serial, int32_t rate); + + Return setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo, + bool modemCognitive, bool isRoaming); + + Return getImsRegistrationState(int32_t serial); + + Return sendImsSms(int32_t serial, const ImsSmsMessage& message); + + Return iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message); + + Return iccOpenLogicalChannel(int32_t serial, + const ::android::hardware::hidl_string& aid, int32_t p2); + + Return iccCloseLogicalChannel(int32_t serial, int32_t channelId); + + Return iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message); + + Return nvReadItem(int32_t serial, NvItem itemId); + + Return nvWriteItem(int32_t serial, const NvWriteItem& item); + + Return nvWriteCdmaPrl(int32_t serial, + const ::android::hardware::hidl_vec& prl); + + Return nvResetConfig(int32_t serial, ResetNvType resetType); + + Return setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub); + + Return setDataAllowed(int32_t serial, bool allow); + + Return getHardwareConfig(int32_t serial); + + Return requestIccSimAuthentication(int32_t serial, + int32_t authContext, + const ::android::hardware::hidl_string& authData, + const ::android::hardware::hidl_string& aid); + + Return setDataProfile(int32_t serial, + const ::android::hardware::hidl_vec& profiles, bool isRoaming); + + Return requestShutdown(int32_t serial); + + Return getRadioCapability(int32_t serial); + + Return setRadioCapability(int32_t serial, const RadioCapability& rc); + + Return startLceService(int32_t serial, int32_t reportInterval, bool pullMode); + + Return stopLceService(int32_t serial); + + Return pullLceData(int32_t serial); + + Return getModemActivityInfo(int32_t serial); + + Return setAllowedCarriers(int32_t serial, + bool allAllowed, + const CarrierRestrictions& carriers); + + Return getAllowedCarriers(int32_t serial); + + Return sendDeviceState(int32_t serial, DeviceStateType deviceStateType, bool state); + + Return setIndicationFilter(int32_t serial, int32_t indicationFilter); + + Return startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive); + + Return stopKeepalive(int32_t serial, int32_t sessionHandle); + + Return setSimCardPower(int32_t serial, bool powerUp); + Return setSimCardPower_1_1(int32_t serial, + const V1_1::CardPowerState state); + + Return responseAcknowledgement(); + + Return setCarrierInfoForImsiEncryption(int32_t serial, + const V1_1::ImsiEncryptionInfo& message); + + void checkReturnStatus(Return& ret); +}; + +struct OemHookImpl : public IOemHook { + int32_t mSlotId; + sp mOemHookResponse; + sp mOemHookIndication; + + Return setResponseFunctions( + const ::android::sp& oemHookResponse, + const ::android::sp& oemHookIndication); + + Return sendRequestRaw(int32_t serial, + const ::android::hardware::hidl_vec& data); + + Return sendRequestStrings(int32_t serial, + const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& data); +}; + +void memsetAndFreeStrings(int numPointers, ...) { + va_list ap; + va_start(ap, numPointers); + for (int i = 0; i < numPointers; i++) { + char *ptr = va_arg(ap, char *); + if (ptr) { +#ifdef MEMSET_FREED +#define MAX_STRING_LENGTH 4096 + memset(ptr, 0, strnlen(ptr, MAX_STRING_LENGTH)); +#endif + free(ptr); + } + } + va_end(ap); +} + +void sendErrorResponse(RequestInfo *pRI, RIL_Errno err) { + pRI->pCI->responseFunction((int) pRI->socket_id, + (int) RadioResponseType::SOLICITED, pRI->token, err, NULL, 0); +} + +/** + * Copies over src to dest. If memory allocation fails, responseFunction() is called for the + * request with error RIL_E_NO_MEMORY. + * Returns true on success, and false on failure. + */ +bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI, bool allowEmpty) { + size_t len = src.size(); + if (len == 0 && !allowEmpty) { + *dest = NULL; + return true; + } + *dest = (char *) calloc(len + 1, sizeof(char)); + if (*dest == NULL) { + RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return false; + } + strncpy(*dest, src.c_str(), len + 1); + return true; +} + +bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) { + return copyHidlStringToRil(dest, src, pRI, false); +} + +hidl_string convertCharPtrToHidlString(const char *ptr) { + hidl_string ret; + if (ptr != NULL) { + // TODO: replace this with strnlen + ret.setToExternal(ptr, strlen(ptr)); + } + return ret; +} + +bool dispatchVoid(int serial, int slotId, int request) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + CALL_ONREQUEST(request, NULL, 0, pRI, slotId); + return true; +} + +bool dispatchString(int serial, int slotId, int request, const char * str) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + char *pString; + if (!copyHidlStringToRil(&pString, str, pRI)) { + return false; + } + + CALL_ONREQUEST(request, pString, sizeof(char *), pRI, slotId); + + memsetAndFreeStrings(1, pString); + return true; +} + +bool dispatchStrings(int serial, int slotId, int request, bool allowEmpty, int countStrings, ...) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + char **pStrings; + pStrings = (char **)calloc(countStrings, sizeof(char *)); + if (pStrings == NULL) { + RLOGE("Memory allocation failed for request %s", requestToString(request)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return false; + } + va_list ap; + va_start(ap, countStrings); + for (int i = 0; i < countStrings; i++) { + const char* str = va_arg(ap, const char *); + if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI, allowEmpty)) { + va_end(ap); + for (int j = 0; j < i; j++) { + memsetAndFreeStrings(1, pStrings[j]); + } + free(pStrings); + return false; + } + } + va_end(ap); + + CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId); + + if (pStrings != NULL) { + for (int i = 0 ; i < countStrings ; i++) { + memsetAndFreeStrings(1, pStrings[i]); + } + +#ifdef MEMSET_FREED + memset(pStrings, 0, countStrings * sizeof(char *)); +#endif + free(pStrings); + } + return true; +} + +bool dispatchStrings(int serial, int slotId, int request, const hidl_vec& data) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + int countStrings = data.size(); + char **pStrings; + pStrings = (char **)calloc(countStrings, sizeof(char *)); + if (pStrings == NULL) { + RLOGE("Memory allocation failed for request %s", requestToString(request)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return false; + } + + for (int i = 0; i < countStrings; i++) { + if (!copyHidlStringToRil(&pStrings[i], data[i], pRI)) { + for (int j = 0; j < i; j++) { + memsetAndFreeStrings(1, pStrings[j]); + } + free(pStrings); + return false; + } + } + + CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId); + + if (pStrings != NULL) { + for (int i = 0 ; i < countStrings ; i++) { + memsetAndFreeStrings(1, pStrings[i]); + } + +#ifdef MEMSET_FREED + memset(pStrings, 0, countStrings * sizeof(char *)); +#endif + free(pStrings); + } + return true; +} + +bool dispatchInts(int serial, int slotId, int request, int countInts, ...) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + int *pInts = (int *)calloc(countInts, sizeof(int)); + + if (pInts == NULL) { + RLOGE("Memory allocation failed for request %s", requestToString(request)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return false; + } + va_list ap; + va_start(ap, countInts); + for (int i = 0; i < countInts; i++) { + pInts[i] = va_arg(ap, int); + } + va_end(ap); + + CALL_ONREQUEST(request, pInts, countInts * sizeof(int), pRI, slotId); + + if (pInts != NULL) { +#ifdef MEMSET_FREED + memset(pInts, 0, countInts * sizeof(int)); +#endif + free(pInts); + } + return true; +} + +bool dispatchCallForwardStatus(int serial, int slotId, int request, + const CallForwardInfo& callInfo) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + RIL_CallForwardInfo cf; + cf.status = (int) callInfo.status; + cf.reason = callInfo.reason; + cf.serviceClass = callInfo.serviceClass; + cf.toa = callInfo.toa; + cf.timeSeconds = callInfo.timeSeconds; + + if (!copyHidlStringToRil(&cf.number, callInfo.number, pRI)) { + return false; + } + + CALL_ONREQUEST(request, &cf, sizeof(cf), pRI, slotId); + + memsetAndFreeStrings(1, cf.number); + + return true; +} + +bool dispatchRaw(int serial, int slotId, int request, const hidl_vec& rawBytes) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + const uint8_t *uData = rawBytes.data(); + + CALL_ONREQUEST(request, (void *) uData, rawBytes.size(), pRI, slotId); + + return true; +} + +bool dispatchIccApdu(int serial, int slotId, int request, const SimApdu& message) { + RequestInfo *pRI = android::addRequestToList(serial, slotId, request); + if (pRI == NULL) { + return false; + } + + RIL_SIM_APDU apdu = {}; + + apdu.sessionid = message.sessionId; + apdu.cla = message.cla; + apdu.instruction = message.instruction; + apdu.p1 = message.p1; + apdu.p2 = message.p2; + apdu.p3 = message.p3; + + if (!copyHidlStringToRil(&apdu.data, message.data, pRI)) { + return false; + } + + CALL_ONREQUEST(request, &apdu, sizeof(apdu), pRI, slotId); + + memsetAndFreeStrings(1, apdu.data); + + return true; +} + +void checkReturnStatus(int32_t slotId, Return& ret, bool isRadioService) { + if (ret.isOk() == false) { + RLOGE("checkReturnStatus: unable to call response/indication callback"); + // Remote process hosting the callbacks must be dead. Reset the callback objects; + // there's no other recovery to be done here. When the client process is back up, it will + // call setResponseFunctions() + + // Caller should already hold rdlock, release that first + // note the current counter to avoid overwriting updates made by another thread before + // write lock is acquired. + int counter = isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId]; + pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(slotId); + int ret = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(ret == 0); + + // acquire wrlock + ret = pthread_rwlock_wrlock(radioServiceRwlockPtr); + assert(ret == 0); + + // make sure the counter value has not changed + if (counter == (isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId])) { + if (isRadioService) { + radioService[slotId]->mRadioResponse = NULL; + radioService[slotId]->mRadioIndication = NULL; + radioService[slotId]->mRadioResponseV1_1 = NULL; + radioService[slotId]->mRadioIndicationV1_1 = NULL; + } else { + oemHookService[slotId]->mOemHookResponse = NULL; + oemHookService[slotId]->mOemHookIndication = NULL; + } + isRadioService ? mCounterRadio[slotId]++ : mCounterOemHook[slotId]++; + } else { + RLOGE("checkReturnStatus: not resetting responseFunctions as they likely " + "got updated on another thread"); + } + + // release wrlock + ret = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(ret == 0); + + // Reacquire rdlock + ret = pthread_rwlock_rdlock(radioServiceRwlockPtr); + assert(ret == 0); + } +} + +void RadioImpl::checkReturnStatus(Return& ret) { + ::checkReturnStatus(mSlotId, ret, true); +} + +Return RadioImpl::setResponseFunctions( + const ::android::sp& radioResponseParam, + const ::android::sp& radioIndicationParam) { + RLOGD("setResponseFunctions"); + + pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(mSlotId); + int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr); + assert(ret == 0); + + mRadioResponse = radioResponseParam; + mRadioIndication = radioIndicationParam; + mRadioResponseV1_1 = V1_1::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr); + mRadioIndicationV1_1 = V1_1::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr); + if (mRadioResponseV1_1 == nullptr || mRadioIndicationV1_1 == nullptr) { + mRadioResponseV1_1 = nullptr; + mRadioIndicationV1_1 = nullptr; + } + + mCounterRadio[mSlotId]++; + + ret = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(ret == 0); + + // client is connected. Send initial indications. + android::onNewCommandConnect((RIL_SOCKET_ID) mSlotId); + + return Void(); +} + +Return RadioImpl::getIccCardStatus(int32_t serial) { +#if VDBG + RLOGD("getIccCardStatus: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_STATUS); + return Void(); +} + +Return RadioImpl::supplyIccPinForApp(int32_t serial, const hidl_string& pin, + const hidl_string& aid) { +#if VDBG + RLOGD("supplyIccPinForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN, true, + 2, pin.c_str(), aid.c_str()); + return Void(); +} + +Return RadioImpl::supplyIccPukForApp(int32_t serial, const hidl_string& puk, + const hidl_string& pin, const hidl_string& aid) { +#if VDBG + RLOGD("supplyIccPukForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK, true, + 3, puk.c_str(), pin.c_str(), aid.c_str()); + return Void(); +} + +Return RadioImpl::supplyIccPin2ForApp(int32_t serial, const hidl_string& pin2, + const hidl_string& aid) { +#if VDBG + RLOGD("supplyIccPin2ForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN2, true, + 2, pin2.c_str(), aid.c_str()); + return Void(); +} + +Return RadioImpl::supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2, + const hidl_string& pin2, const hidl_string& aid) { +#if VDBG + RLOGD("supplyIccPuk2ForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK2, true, + 3, puk2.c_str(), pin2.c_str(), aid.c_str()); + return Void(); +} + +Return RadioImpl::changeIccPinForApp(int32_t serial, const hidl_string& oldPin, + const hidl_string& newPin, const hidl_string& aid) { +#if VDBG + RLOGD("changeIccPinForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN, true, + 3, oldPin.c_str(), newPin.c_str(), aid.c_str()); + return Void(); +} + +Return RadioImpl::changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2, + const hidl_string& newPin2, const hidl_string& aid) { +#if VDBG + RLOGD("changeIccPin2ForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN2, true, + 3, oldPin2.c_str(), newPin2.c_str(), aid.c_str()); + return Void(); +} + +Return RadioImpl::supplyNetworkDepersonalization(int32_t serial, + const hidl_string& netPin) { +#if VDBG + RLOGD("supplyNetworkDepersonalization: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, true, + 1, netPin.c_str()); + return Void(); +} + +Return RadioImpl::getCurrentCalls(int32_t serial) { +#if VDBG + RLOGD("getCurrentCalls: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CURRENT_CALLS); + return Void(); +} + +Return RadioImpl::dial(int32_t serial, const Dial& dialInfo) { +#if VDBG + RLOGD("dial: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_DIAL); + if (pRI == NULL) { + return Void(); + } + RIL_Dial dial = {}; + RIL_UUS_Info uusInfo = {}; + int32_t sizeOfDial = sizeof(dial); + + if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) { + return Void(); + } + dial.clir = (int) dialInfo.clir; + + if (dialInfo.uusInfo.size() != 0) { + uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType; + uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs; + + if (dialInfo.uusInfo[0].uusData.size() == 0) { + uusInfo.uusData = NULL; + uusInfo.uusLength = 0; + } else { + if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) { + memsetAndFreeStrings(1, dial.address); + return Void(); + } + uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size(); + } + + dial.uusInfo = &uusInfo; + } + + CALL_ONREQUEST(RIL_REQUEST_DIAL, &dial, sizeOfDial, pRI, mSlotId); + + memsetAndFreeStrings(2, dial.address, uusInfo.uusData); + + return Void(); +} + +Return RadioImpl::getImsiForApp(int32_t serial, const hidl_string& aid) { +#if VDBG + RLOGD("getImsiForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_GET_IMSI, false, + 1, aid.c_str()); + return Void(); +} + +Return RadioImpl::hangup(int32_t serial, int32_t gsmIndex) { +#if VDBG + RLOGD("hangup: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_HANGUP, 1, gsmIndex); + return Void(); +} + +Return RadioImpl::hangupWaitingOrBackground(int32_t serial) { +#if VDBG + RLOGD("hangupWaitingOrBackground: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND); + return Void(); +} + +Return RadioImpl::hangupForegroundResumeBackground(int32_t serial) { +#if VDBG + RLOGD("hangupForegroundResumeBackground: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND); + return Void(); +} + +Return RadioImpl::switchWaitingOrHoldingAndActive(int32_t serial) { +#if VDBG + RLOGD("switchWaitingOrHoldingAndActive: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE); + return Void(); +} + +Return RadioImpl::conference(int32_t serial) { +#if VDBG + RLOGD("conference: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFERENCE); + return Void(); +} + +Return RadioImpl::rejectCall(int32_t serial) { +#if VDBG + RLOGD("rejectCall: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_UDUB); + return Void(); +} + +Return RadioImpl::getLastCallFailCause(int32_t serial) { +#if VDBG + RLOGD("getLastCallFailCause: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_LAST_CALL_FAIL_CAUSE); + return Void(); +} + +Return RadioImpl::getSignalStrength(int32_t serial) { +#if VDBG + RLOGD("getSignalStrength: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH); + return Void(); +} + +Return RadioImpl::getVoiceRegistrationState(int32_t serial) { +#if VDBG + RLOGD("getVoiceRegistrationState: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE); + return Void(); +} + +Return RadioImpl::getDataRegistrationState(int32_t serial) { +#if VDBG + RLOGD("getDataRegistrationState: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE); + return Void(); +} + +Return RadioImpl::getOperator(int32_t serial) { +#if VDBG + RLOGD("getOperator: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_OPERATOR); + return Void(); +} + +Return RadioImpl::setRadioPower(int32_t serial, bool on) { + RLOGD("setRadioPower: serial %d on %d", serial, on); + dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(on)); + return Void(); +} + +Return RadioImpl::sendDtmf(int32_t serial, const hidl_string& s) { +#if VDBG + RLOGD("sendDtmf: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_DTMF, s.c_str()); + return Void(); +} + +Return RadioImpl::sendSms(int32_t serial, const GsmSmsMessage& message) { +#if VDBG + RLOGD("sendSms: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false, + 2, message.smscPdu.c_str(), message.pdu.c_str()); + return Void(); +} + +Return RadioImpl::sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message) { +#if VDBG + RLOGD("sendSMSExpectMore: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false, + 2, message.smscPdu.c_str(), message.pdu.c_str()); + return Void(); +} + +static bool convertMvnoTypeToString(MvnoType type, char *&str) { + switch (type) { + case MvnoType::IMSI: + str = (char *)"imsi"; + return true; + case MvnoType::GID: + str = (char *)"gid"; + return true; + case MvnoType::SPN: + str = (char *)"spn"; + return true; + case MvnoType::NONE: + str = (char *)""; + return true; + } + return false; +} + +Return RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechnology, + const DataProfileInfo& dataProfileInfo, bool modemCognitive, + bool roamingAllowed, bool isRoaming) { + +#if VDBG + RLOGD("setupDataCall: serial %d", serial); +#endif + + if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) { + const hidl_string &protocol = + (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol); + dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7, + std::to_string((int) radioTechnology + 2).c_str(), + std::to_string((int) dataProfileInfo.profileId).c_str(), + dataProfileInfo.apn.c_str(), + dataProfileInfo.user.c_str(), + dataProfileInfo.password.c_str(), + std::to_string((int) dataProfileInfo.authType).c_str(), + protocol.c_str()); + } else if (s_vendorFunctions->version >= 15) { + char *mvnoTypeStr = NULL; + if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) { + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SETUP_DATA_CALL); + if (pRI != NULL) { + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + } + return Void(); + } + dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15, + std::to_string((int) radioTechnology + 2).c_str(), + std::to_string((int) dataProfileInfo.profileId).c_str(), + dataProfileInfo.apn.c_str(), + dataProfileInfo.user.c_str(), + dataProfileInfo.password.c_str(), + std::to_string((int) dataProfileInfo.authType).c_str(), + dataProfileInfo.protocol.c_str(), + dataProfileInfo.roamingProtocol.c_str(), + std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(), + std::to_string(dataProfileInfo.bearerBitmap).c_str(), + modemCognitive ? "1" : "0", + std::to_string(dataProfileInfo.mtu).c_str(), + mvnoTypeStr, + dataProfileInfo.mvnoMatchData.c_str(), + roamingAllowed ? "1" : "0"); + } else { + RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version); + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SETUP_DATA_CALL); + if (pRI != NULL) { + sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED); + } + } + return Void(); +} + +Return RadioImpl::iccIOForApp(int32_t serial, const IccIo& iccIo) { +#if VDBG + RLOGD("iccIOForApp: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_IO); + if (pRI == NULL) { + return Void(); + } + + RIL_SIM_IO_v6 rilIccIo = {}; + rilIccIo.command = iccIo.command; + rilIccIo.fileid = iccIo.fileId; + if (!copyHidlStringToRil(&rilIccIo.path, iccIo.path, pRI)) { + return Void(); + } + + rilIccIo.p1 = iccIo.p1; + rilIccIo.p2 = iccIo.p2; + rilIccIo.p3 = iccIo.p3; + + if (!copyHidlStringToRil(&rilIccIo.data, iccIo.data, pRI)) { + memsetAndFreeStrings(1, rilIccIo.path); + return Void(); + } + + if (!copyHidlStringToRil(&rilIccIo.pin2, iccIo.pin2, pRI)) { + memsetAndFreeStrings(2, rilIccIo.path, rilIccIo.data); + return Void(); + } + + if (!copyHidlStringToRil(&rilIccIo.aidPtr, iccIo.aid, pRI)) { + memsetAndFreeStrings(3, rilIccIo.path, rilIccIo.data, rilIccIo.pin2); + return Void(); + } + + CALL_ONREQUEST(RIL_REQUEST_SIM_IO, &rilIccIo, sizeof(rilIccIo), pRI, mSlotId); + + memsetAndFreeStrings(4, rilIccIo.path, rilIccIo.data, rilIccIo.pin2, rilIccIo.aidPtr); + + return Void(); +} + +Return RadioImpl::sendUssd(int32_t serial, const hidl_string& ussd) { +#if VDBG + RLOGD("sendUssd: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_SEND_USSD, ussd.c_str()); + return Void(); +} + +Return RadioImpl::cancelPendingUssd(int32_t serial) { +#if VDBG + RLOGD("cancelPendingUssd: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CANCEL_USSD); + return Void(); +} + +Return RadioImpl::getClir(int32_t serial) { +#if VDBG + RLOGD("getClir: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CLIR); + return Void(); +} + +Return RadioImpl::setClir(int32_t serial, int32_t status) { +#if VDBG + RLOGD("setClir: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CLIR, 1, status); + return Void(); +} + +Return RadioImpl::getCallForwardStatus(int32_t serial, const CallForwardInfo& callInfo) { +#if VDBG + RLOGD("getCallForwardStatus: serial %d", serial); +#endif + dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, + callInfo); + return Void(); +} + +Return RadioImpl::setCallForward(int32_t serial, const CallForwardInfo& callInfo) { +#if VDBG + RLOGD("setCallForward: serial %d", serial); +#endif + dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_SET_CALL_FORWARD, + callInfo); + return Void(); +} + +Return RadioImpl::getCallWaiting(int32_t serial, int32_t serviceClass) { +#if VDBG + RLOGD("getCallWaiting: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_QUERY_CALL_WAITING, 1, serviceClass); + return Void(); +} + +Return RadioImpl::setCallWaiting(int32_t serial, bool enable, int32_t serviceClass) { +#if VDBG + RLOGD("setCallWaiting: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CALL_WAITING, 2, BOOL_TO_INT(enable), + serviceClass); + return Void(); +} + +Return RadioImpl::acknowledgeLastIncomingGsmSms(int32_t serial, + bool success, SmsAcknowledgeFailCause cause) { +#if VDBG + RLOGD("acknowledgeLastIncomingGsmSms: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SMS_ACKNOWLEDGE, 2, BOOL_TO_INT(success), + cause); + return Void(); +} + +Return RadioImpl::acceptCall(int32_t serial) { +#if VDBG + RLOGD("acceptCall: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_ANSWER); + return Void(); +} + +Return RadioImpl::deactivateDataCall(int32_t serial, + int32_t cid, bool reasonRadioShutDown) { +#if VDBG + RLOGD("deactivateDataCall: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false, + 2, (std::to_string(cid)).c_str(), reasonRadioShutDown ? "1" : "0"); + return Void(); +} + +Return RadioImpl::getFacilityLockForApp(int32_t serial, const hidl_string& facility, + const hidl_string& password, int32_t serviceClass, + const hidl_string& appId) { +#if VDBG + RLOGD("getFacilityLockForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_QUERY_FACILITY_LOCK, true, + 4, facility.c_str(), password.c_str(), + (std::to_string(serviceClass)).c_str(), appId.c_str()); + return Void(); +} + +Return RadioImpl::setFacilityLockForApp(int32_t serial, const hidl_string& facility, + bool lockState, const hidl_string& password, + int32_t serviceClass, const hidl_string& appId) { +#if VDBG + RLOGD("setFacilityLockForApp: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_SET_FACILITY_LOCK, true, + 5, facility.c_str(), lockState ? "1" : "0", password.c_str(), + (std::to_string(serviceClass)).c_str(), appId.c_str() ); + return Void(); +} + +Return RadioImpl::setBarringPassword(int32_t serial, const hidl_string& facility, + const hidl_string& oldPassword, + const hidl_string& newPassword) { +#if VDBG + RLOGD("setBarringPassword: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_BARRING_PASSWORD, true, + 3, facility.c_str(), oldPassword.c_str(), newPassword.c_str()); + return Void(); +} + +Return RadioImpl::getNetworkSelectionMode(int32_t serial) { +#if VDBG + RLOGD("getNetworkSelectionMode: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE); + return Void(); +} + +Return RadioImpl::setNetworkSelectionModeAutomatic(int32_t serial) { +#if VDBG + RLOGD("setNetworkSelectionModeAutomatic: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC); + return Void(); +} + +Return RadioImpl::setNetworkSelectionModeManual(int32_t serial, + const hidl_string& operatorNumeric) { +#if VDBG + RLOGD("setNetworkSelectionModeManual: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, + operatorNumeric.c_str()); + return Void(); +} + +Return RadioImpl::getAvailableNetworks(int32_t serial) { +#if VDBG + RLOGD("getAvailableNetworks: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_NETWORKS); + return Void(); +} + +Return RadioImpl::startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request) { +#if VDBG + RLOGD("startNetworkScan: serial %d", serial); +#endif + + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN); + if (pRI == NULL) { + return Void(); + } + + if (request.specifiers.size() > MAX_RADIO_ACCESS_NETWORKS) { + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return Void(); + } + + RIL_NetworkScanRequest scan_request = {}; + + scan_request.type = (RIL_ScanType) request.type; + scan_request.interval = request.interval; + scan_request.specifiers_length = request.specifiers.size(); + for (size_t i = 0; i < request.specifiers.size(); ++i) { + if (request.specifiers[i].geranBands.size() > MAX_BANDS || + request.specifiers[i].utranBands.size() > MAX_BANDS || + request.specifiers[i].eutranBands.size() > MAX_BANDS || + request.specifiers[i].channels.size() > MAX_CHANNELS) { + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return Void(); + } + const V1_1::RadioAccessSpecifier& ras_from = + request.specifiers[i]; + RIL_RadioAccessSpecifier& ras_to = scan_request.specifiers[i]; + + ras_to.radio_access_network = (RIL_RadioAccessNetworks) ras_from.radioAccessNetwork; + ras_to.channels_length = ras_from.channels.size(); + + std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels); + const std::vector * bands = nullptr; + switch (request.specifiers[i].radioAccessNetwork) { + case V1_1::RadioAccessNetworks::GERAN: + ras_to.bands_length = ras_from.geranBands.size(); + bands = (std::vector *) &ras_from.geranBands; + break; + case V1_1::RadioAccessNetworks::UTRAN: + ras_to.bands_length = ras_from.utranBands.size(); + bands = (std::vector *) &ras_from.utranBands; + break; + case V1_1::RadioAccessNetworks::EUTRAN: + ras_to.bands_length = ras_from.eutranBands.size(); + bands = (std::vector *) &ras_from.eutranBands; + break; + default: + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return Void(); + } + // safe to copy to geran_bands because it's a union member + for (size_t idx = 0; idx < ras_to.bands_length; ++idx) { + ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx]; + } + } + + CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI, + mSlotId); + + return Void(); +} + +Return RadioImpl::stopNetworkScan(int32_t serial) { +#if VDBG + RLOGD("stopNetworkScan: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_NETWORK_SCAN); + return Void(); +} + +Return RadioImpl::startDtmf(int32_t serial, const hidl_string& s) { +#if VDBG + RLOGD("startDtmf: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_DTMF_START, + s.c_str()); + return Void(); +} + +Return RadioImpl::stopDtmf(int32_t serial) { +#if VDBG + RLOGD("stopDtmf: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_DTMF_STOP); + return Void(); +} + +Return RadioImpl::getBasebandVersion(int32_t serial) { +#if VDBG + RLOGD("getBasebandVersion: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_BASEBAND_VERSION); + return Void(); +} + +Return RadioImpl::separateConnection(int32_t serial, int32_t gsmIndex) { +#if VDBG + RLOGD("separateConnection: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SEPARATE_CONNECTION, 1, gsmIndex); + return Void(); +} + +Return RadioImpl::setMute(int32_t serial, bool enable) { +#if VDBG + RLOGD("setMute: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_MUTE, 1, BOOL_TO_INT(enable)); + return Void(); +} + +Return RadioImpl::getMute(int32_t serial) { +#if VDBG + RLOGD("getMute: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_MUTE); + return Void(); +} + +Return RadioImpl::getClip(int32_t serial) { +#if VDBG + RLOGD("getClip: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_CLIP); + return Void(); +} + +Return RadioImpl::getDataCallList(int32_t serial) { +#if VDBG + RLOGD("getDataCallList: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_CALL_LIST); + return Void(); +} + +Return RadioImpl::setSuppServiceNotifications(int32_t serial, bool enable) { +#if VDBG + RLOGD("setSuppServiceNotifications: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, 1, + BOOL_TO_INT(enable)); + return Void(); +} + +Return RadioImpl::writeSmsToSim(int32_t serial, const SmsWriteArgs& smsWriteArgs) { +#if VDBG + RLOGD("writeSmsToSim: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_WRITE_SMS_TO_SIM); + if (pRI == NULL) { + return Void(); + } + + RIL_SMS_WriteArgs args; + args.status = (int) smsWriteArgs.status; + + if (!copyHidlStringToRil(&args.pdu, smsWriteArgs.pdu, pRI)) { + return Void(); + } + + if (!copyHidlStringToRil(&args.smsc, smsWriteArgs.smsc, pRI)) { + memsetAndFreeStrings(1, args.pdu); + return Void(); + } + + CALL_ONREQUEST(RIL_REQUEST_WRITE_SMS_TO_SIM, &args, sizeof(args), pRI, mSlotId); + + memsetAndFreeStrings(2, args.smsc, args.pdu); + + return Void(); +} + +Return RadioImpl::deleteSmsOnSim(int32_t serial, int32_t index) { +#if VDBG + RLOGD("deleteSmsOnSim: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_DELETE_SMS_ON_SIM, 1, index); + return Void(); +} + +Return RadioImpl::setBandMode(int32_t serial, RadioBandMode mode) { +#if VDBG + RLOGD("setBandMode: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_BAND_MODE, 1, mode); + return Void(); +} + +Return RadioImpl::getAvailableBandModes(int32_t serial) { +#if VDBG + RLOGD("getAvailableBandModes: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE); + return Void(); +} + +Return RadioImpl::sendEnvelope(int32_t serial, const hidl_string& command) { +#if VDBG + RLOGD("sendEnvelope: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, + command.c_str()); + return Void(); +} + +Return RadioImpl::sendTerminalResponseToSim(int32_t serial, + const hidl_string& commandResponse) { +#if VDBG + RLOGD("sendTerminalResponseToSim: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, + commandResponse.c_str()); + return Void(); +} + +Return RadioImpl::handleStkCallSetupRequestFromSim(int32_t serial, bool accept) { +#if VDBG + RLOGD("handleStkCallSetupRequestFromSim: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM, + 1, BOOL_TO_INT(accept)); + return Void(); +} + +Return RadioImpl::explicitCallTransfer(int32_t serial) { +#if VDBG + RLOGD("explicitCallTransfer: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_EXPLICIT_CALL_TRANSFER); + return Void(); +} + +Return RadioImpl::setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType) { +#if VDBG + RLOGD("setPreferredNetworkType: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, 1, nwType); + return Void(); +} + +Return RadioImpl::getPreferredNetworkType(int32_t serial) { +#if VDBG + RLOGD("getPreferredNetworkType: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE); + return Void(); +} + +Return RadioImpl::getNeighboringCids(int32_t serial) { +#if VDBG + RLOGD("getNeighboringCids: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_NEIGHBORING_CELL_IDS); + return Void(); +} + +Return RadioImpl::setLocationUpdates(int32_t serial, bool enable) { +#if VDBG + RLOGD("setLocationUpdates: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_LOCATION_UPDATES, 1, BOOL_TO_INT(enable)); + return Void(); +} + +Return RadioImpl::setCdmaSubscriptionSource(int32_t serial, CdmaSubscriptionSource cdmaSub) { +#if VDBG + RLOGD("setCdmaSubscriptionSource: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, 1, cdmaSub); + return Void(); +} + +Return RadioImpl::setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type) { +#if VDBG + RLOGD("setCdmaRoamingPreference: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, 1, type); + return Void(); +} + +Return RadioImpl::getCdmaRoamingPreference(int32_t serial) { +#if VDBG + RLOGD("getCdmaRoamingPreference: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE); + return Void(); +} + +Return RadioImpl::setTTYMode(int32_t serial, TtyMode mode) { +#if VDBG + RLOGD("setTTYMode: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_TTY_MODE, 1, mode); + return Void(); +} + +Return RadioImpl::getTTYMode(int32_t serial) { +#if VDBG + RLOGD("getTTYMode: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_TTY_MODE); + return Void(); +} + +Return RadioImpl::setPreferredVoicePrivacy(int32_t serial, bool enable) { +#if VDBG + RLOGD("setPreferredVoicePrivacy: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE, + 1, BOOL_TO_INT(enable)); + return Void(); +} + +Return RadioImpl::getPreferredVoicePrivacy(int32_t serial) { +#if VDBG + RLOGD("getPreferredVoicePrivacy: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE); + return Void(); +} + +Return RadioImpl::sendCDMAFeatureCode(int32_t serial, const hidl_string& featureCode) { +#if VDBG + RLOGD("sendCDMAFeatureCode: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_CDMA_FLASH, + featureCode.c_str()); + return Void(); +} + +Return RadioImpl::sendBurstDtmf(int32_t serial, const hidl_string& dtmf, int32_t on, + int32_t off) { +#if VDBG + RLOGD("sendBurstDtmf: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_CDMA_BURST_DTMF, false, + 3, dtmf.c_str(), (std::to_string(on)).c_str(), + (std::to_string(off)).c_str()); + return Void(); +} + +void constructCdmaSms(RIL_CDMA_SMS_Message &rcsm, const CdmaSmsMessage& sms) { + rcsm.uTeleserviceID = sms.teleserviceId; + rcsm.bIsServicePresent = BOOL_TO_INT(sms.isServicePresent); + rcsm.uServicecategory = sms.serviceCategory; + rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) sms.address.digitMode; + rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) sms.address.numberMode; + rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) sms.address.numberType; + rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) sms.address.numberPlan; + + rcsm.sAddress.number_of_digits = sms.address.digits.size(); + int digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX); + for (int i = 0; i < digitLimit; i++) { + rcsm.sAddress.digits[i] = sms.address.digits[i]; + } + + rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) sms.subAddress.subaddressType; + rcsm.sSubAddress.odd = BOOL_TO_INT(sms.subAddress.odd); + + rcsm.sSubAddress.number_of_digits = sms.subAddress.digits.size(); + digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX); + for (int i = 0; i < digitLimit; i++) { + rcsm.sSubAddress.digits[i] = sms.subAddress.digits[i]; + } + + rcsm.uBearerDataLen = sms.bearerData.size(); + digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX); + for (int i = 0; i < digitLimit; i++) { + rcsm.aBearerData[i] = sms.bearerData[i]; + } +} + +Return RadioImpl::sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms) { +#if VDBG + RLOGD("sendCdmaSms: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SEND_SMS); + if (pRI == NULL) { + return Void(); + } + + RIL_CDMA_SMS_Message rcsm = {}; + constructCdmaSms(rcsm, sms); + + CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::acknowledgeLastIncomingCdmaSms(int32_t serial, const CdmaSmsAck& smsAck) { +#if VDBG + RLOGD("acknowledgeLastIncomingCdmaSms: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE); + if (pRI == NULL) { + return Void(); + } + + RIL_CDMA_SMS_Ack rcsa = {}; + + rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) smsAck.errorClass; + rcsa.uSMSCauseCode = smsAck.smsCauseCode; + + CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::getGsmBroadcastConfig(int32_t serial) { +#if VDBG + RLOGD("getGsmBroadcastConfig: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG); + return Void(); +} + +Return RadioImpl::setGsmBroadcastConfig(int32_t serial, + const hidl_vec& + configInfo) { +#if VDBG + RLOGD("setGsmBroadcastConfig: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG); + if (pRI == NULL) { + return Void(); + } + + int num = configInfo.size(); + RIL_GSM_BroadcastSmsConfigInfo gsmBci[num]; + RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num]; + + for (int i = 0 ; i < num ; i++ ) { + gsmBciPtrs[i] = &gsmBci[i]; + gsmBci[i].fromServiceId = configInfo[i].fromServiceId; + gsmBci[i].toServiceId = configInfo[i].toServiceId; + gsmBci[i].fromCodeScheme = configInfo[i].fromCodeScheme; + gsmBci[i].toCodeScheme = configInfo[i].toCodeScheme; + gsmBci[i].selected = BOOL_TO_INT(configInfo[i].selected); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, gsmBciPtrs, + num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::setGsmBroadcastActivation(int32_t serial, bool activate) { +#if VDBG + RLOGD("setGsmBroadcastActivation: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION, + 1, BOOL_TO_INT(!activate)); + return Void(); +} + +Return RadioImpl::getCdmaBroadcastConfig(int32_t serial) { +#if VDBG + RLOGD("getCdmaBroadcastConfig: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG); + return Void(); +} + +Return RadioImpl::setCdmaBroadcastConfig(int32_t serial, + const hidl_vec& + configInfo) { +#if VDBG + RLOGD("setCdmaBroadcastConfig: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG); + if (pRI == NULL) { + return Void(); + } + + int num = configInfo.size(); + RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num]; + RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num]; + + for (int i = 0 ; i < num ; i++ ) { + cdmaBciPtrs[i] = &cdmaBci[i]; + cdmaBci[i].service_category = configInfo[i].serviceCategory; + cdmaBci[i].language = configInfo[i].language; + cdmaBci[i].selected = BOOL_TO_INT(configInfo[i].selected); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, cdmaBciPtrs, + num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::setCdmaBroadcastActivation(int32_t serial, bool activate) { +#if VDBG + RLOGD("setCdmaBroadcastActivation: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION, + 1, BOOL_TO_INT(!activate)); + return Void(); +} + +Return RadioImpl::getCDMASubscription(int32_t serial) { +#if VDBG + RLOGD("getCDMASubscription: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_SUBSCRIPTION); + return Void(); +} + +Return RadioImpl::writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms) { +#if VDBG + RLOGD("writeSmsToRuim: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM); + if (pRI == NULL) { + return Void(); + } + + RIL_CDMA_SMS_WriteArgs rcsw = {}; + rcsw.status = (int) cdmaSms.status; + constructCdmaSms(rcsw.message, cdmaSms.message); + + CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::deleteSmsOnRuim(int32_t serial, int32_t index) { +#if VDBG + RLOGD("deleteSmsOnRuim: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, 1, index); + return Void(); +} + +Return RadioImpl::getDeviceIdentity(int32_t serial) { +#if VDBG + RLOGD("getDeviceIdentity: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_DEVICE_IDENTITY); + return Void(); +} + +Return RadioImpl::exitEmergencyCallbackMode(int32_t serial) { +#if VDBG + RLOGD("exitEmergencyCallbackMode: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE); + return Void(); +} + +Return RadioImpl::getSmscAddress(int32_t serial) { +#if VDBG + RLOGD("getSmscAddress: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SMSC_ADDRESS); + return Void(); +} + +Return RadioImpl::setSmscAddress(int32_t serial, const hidl_string& smsc) { +#if VDBG + RLOGD("setSmscAddress: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_SET_SMSC_ADDRESS, + smsc.c_str()); + return Void(); +} + +Return RadioImpl::reportSmsMemoryStatus(int32_t serial, bool available) { +#if VDBG + RLOGD("reportSmsMemoryStatus: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, 1, + BOOL_TO_INT(available)); + return Void(); +} + +Return RadioImpl::reportStkServiceIsRunning(int32_t serial) { +#if VDBG + RLOGD("reportStkServiceIsRunning: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING); + return Void(); +} + +Return RadioImpl::getCdmaSubscriptionSource(int32_t serial) { +#if VDBG + RLOGD("getCdmaSubscriptionSource: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE); + return Void(); +} + +Return RadioImpl::requestIsimAuthentication(int32_t serial, const hidl_string& challenge) { +#if VDBG + RLOGD("requestIsimAuthentication: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_ISIM_AUTHENTICATION, + challenge.c_str()); + return Void(); +} + +Return RadioImpl::acknowledgeIncomingGsmSmsWithPdu(int32_t serial, bool success, + const hidl_string& ackPdu) { +#if VDBG + RLOGD("acknowledgeIncomingGsmSmsWithPdu: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, false, + 2, success ? "1" : "0", ackPdu.c_str()); + return Void(); +} + +Return RadioImpl::sendEnvelopeWithStatus(int32_t serial, const hidl_string& contents) { +#if VDBG + RLOGD("sendEnvelopeWithStatus: serial %d", serial); +#endif + dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, + contents.c_str()); + return Void(); +} + +Return RadioImpl::getVoiceRadioTechnology(int32_t serial) { +#if VDBG + RLOGD("getVoiceRadioTechnology: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_RADIO_TECH); + return Void(); +} + +Return RadioImpl::getCellInfoList(int32_t serial) { +#if VDBG + RLOGD("getCellInfoList: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CELL_INFO_LIST); + return Void(); +} + +Return RadioImpl::setCellInfoListRate(int32_t serial, int32_t rate) { +#if VDBG + RLOGD("setCellInfoListRate: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, 1, rate); + return Void(); +} + +Return RadioImpl::setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo, + bool modemCognitive, bool isRoaming) { +#if VDBG + RLOGD("setInitialAttachApn: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SET_INITIAL_ATTACH_APN); + if (pRI == NULL) { + return Void(); + } + + if (s_vendorFunctions->version <= 14) { + RIL_InitialAttachApn iaa = {}; + + if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) { + return Void(); + } + + const hidl_string &protocol = + (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol); + + if (!copyHidlStringToRil(&iaa.protocol, protocol, pRI)) { + memsetAndFreeStrings(1, iaa.apn); + return Void(); + } + iaa.authtype = (int) dataProfileInfo.authType; + if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) { + memsetAndFreeStrings(2, iaa.apn, iaa.protocol); + return Void(); + } + if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) { + memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.username); + return Void(); + } + + CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId); + + memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.username, iaa.password); + } else { + RIL_InitialAttachApn_v15 iaa = {}; + + if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) { + return Void(); + } + + if (!copyHidlStringToRil(&iaa.protocol, dataProfileInfo.protocol, pRI)) { + memsetAndFreeStrings(1, iaa.apn); + return Void(); + } + if (!copyHidlStringToRil(&iaa.roamingProtocol, dataProfileInfo.roamingProtocol, pRI)) { + memsetAndFreeStrings(2, iaa.apn, iaa.protocol); + return Void(); + } + iaa.authtype = (int) dataProfileInfo.authType; + if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) { + memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.roamingProtocol); + return Void(); + } + if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) { + memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username); + return Void(); + } + iaa.supportedTypesBitmask = dataProfileInfo.supportedApnTypesBitmap; + iaa.bearerBitmask = dataProfileInfo.bearerBitmap; + iaa.modemCognitive = BOOL_TO_INT(modemCognitive); + iaa.mtu = dataProfileInfo.mtu; + + if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, iaa.mvnoType)) { + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username, + iaa.password); + return Void(); + } + + if (!copyHidlStringToRil(&iaa.mvnoMatchData, dataProfileInfo.mvnoMatchData, pRI)) { + memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username, + iaa.password); + return Void(); + } + + CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId); + + memsetAndFreeStrings(6, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username, + iaa.password, iaa.mvnoMatchData); + } + + return Void(); +} + +Return RadioImpl::getImsRegistrationState(int32_t serial) { +#if VDBG + RLOGD("getImsRegistrationState: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_IMS_REGISTRATION_STATE); + return Void(); +} + +bool dispatchImsGsmSms(const ImsSmsMessage& message, RequestInfo *pRI) { + RIL_IMS_SMS_Message rism = {}; + char **pStrings; + int countStrings = 2; + int dataLen = sizeof(char *) * countStrings; + + rism.tech = RADIO_TECH_3GPP; + rism.retry = BOOL_TO_INT(message.retry); + rism.messageRef = message.messageRef; + + if (message.gsmMessage.size() != 1) { + RLOGE("dispatchImsGsmSms: Invalid len %s", requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return false; + } + + pStrings = (char **)calloc(countStrings, sizeof(char *)); + if (pStrings == NULL) { + RLOGE("dispatchImsGsmSms: Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return false; + } + + if (!copyHidlStringToRil(&pStrings[0], message.gsmMessage[0].smscPdu, pRI)) { +#ifdef MEMSET_FREED + memset(pStrings, 0, dataLen); +#endif + free(pStrings); + return false; + } + + if (!copyHidlStringToRil(&pStrings[1], message.gsmMessage[0].pdu, pRI)) { + memsetAndFreeStrings(1, pStrings[0]); +#ifdef MEMSET_FREED + memset(pStrings, 0, dataLen); +#endif + free(pStrings); + return false; + } + + rism.message.gsmMessage = pStrings; + CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, sizeof(RIL_RadioTechnologyFamily) + + sizeof(uint8_t) + sizeof(int32_t) + dataLen, pRI, pRI->socket_id); + + for (int i = 0 ; i < countStrings ; i++) { + memsetAndFreeStrings(1, pStrings[i]); + } + +#ifdef MEMSET_FREED + memset(pStrings, 0, dataLen); +#endif + free(pStrings); + + return true; +} + +struct ImsCdmaSms { + RIL_IMS_SMS_Message imsSms; + RIL_CDMA_SMS_Message cdmaSms; +}; + +bool dispatchImsCdmaSms(const ImsSmsMessage& message, RequestInfo *pRI) { + ImsCdmaSms temp = {}; + + if (message.cdmaMessage.size() != 1) { + RLOGE("dispatchImsCdmaSms: Invalid len %s", requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return false; + } + + temp.imsSms.tech = RADIO_TECH_3GPP2; + temp.imsSms.retry = BOOL_TO_INT(message.retry); + temp.imsSms.messageRef = message.messageRef; + temp.imsSms.message.cdmaMessage = &temp.cdmaSms; + + constructCdmaSms(temp.cdmaSms, message.cdmaMessage[0]); + + // Vendor code expects payload length to include actual msg payload + // (sizeof(RIL_CDMA_SMS_Message)) instead of (RIL_CDMA_SMS_Message *) + size of other fields in + // RIL_IMS_SMS_Message + int payloadLen = sizeof(RIL_RadioTechnologyFamily) + sizeof(uint8_t) + sizeof(int32_t) + + sizeof(RIL_CDMA_SMS_Message); + + CALL_ONREQUEST(pRI->pCI->requestNumber, &temp.imsSms, payloadLen, pRI, pRI->socket_id); + + return true; +} + +Return RadioImpl::sendImsSms(int32_t serial, const ImsSmsMessage& message) { +#if VDBG + RLOGD("sendImsSms: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_IMS_SEND_SMS); + if (pRI == NULL) { + return Void(); + } + + RIL_RadioTechnologyFamily format = (RIL_RadioTechnologyFamily) message.tech; + + if (RADIO_TECH_3GPP == format) { + dispatchImsGsmSms(message, pRI); + } else if (RADIO_TECH_3GPP2 == format) { + dispatchImsCdmaSms(message, pRI); + } else { + RLOGE("sendImsSms: Invalid radio tech %s", + requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + } + return Void(); +} + +Return RadioImpl::iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message) { +#if VDBG + RLOGD("iccTransmitApduBasicChannel: serial %d", serial); +#endif + dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, message); + return Void(); +} + +Return RadioImpl::iccOpenLogicalChannel(int32_t serial, const hidl_string& aid, int32_t p2) { +#if VDBG + RLOGD("iccOpenLogicalChannel: serial %d", serial); +#endif + if (s_vendorFunctions->version < 15) { + dispatchString(serial, mSlotId, RIL_REQUEST_SIM_OPEN_CHANNEL, aid.c_str()); + } else { + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_OPEN_CHANNEL); + if (pRI == NULL) { + return Void(); + } + + RIL_OpenChannelParams params = {}; + + params.p2 = p2; + + if (!copyHidlStringToRil(¶ms.aidPtr, aid, pRI)) { + return Void(); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, ¶ms, sizeof(params), pRI, mSlotId); + + memsetAndFreeStrings(1, params.aidPtr); + } + return Void(); +} + +Return RadioImpl::iccCloseLogicalChannel(int32_t serial, int32_t channelId) { +#if VDBG + RLOGD("iccCloseLogicalChannel: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SIM_CLOSE_CHANNEL, 1, channelId); + return Void(); +} + +Return RadioImpl::iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message) { +#if VDBG + RLOGD("iccTransmitApduLogicalChannel: serial %d", serial); +#endif + dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, message); + return Void(); +} + +Return RadioImpl::nvReadItem(int32_t serial, NvItem itemId) { +#if VDBG + RLOGD("nvReadItem: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_READ_ITEM); + if (pRI == NULL) { + return Void(); + } + + RIL_NV_ReadItem nvri = {}; + nvri.itemID = (RIL_NV_Item) itemId; + + CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::nvWriteItem(int32_t serial, const NvWriteItem& item) { +#if VDBG + RLOGD("nvWriteItem: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_WRITE_ITEM); + if (pRI == NULL) { + return Void(); + } + + RIL_NV_WriteItem nvwi = {}; + + nvwi.itemID = (RIL_NV_Item) item.itemId; + + if (!copyHidlStringToRil(&nvwi.value, item.value, pRI)) { + return Void(); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, mSlotId); + + memsetAndFreeStrings(1, nvwi.value); + return Void(); +} + +Return RadioImpl::nvWriteCdmaPrl(int32_t serial, const hidl_vec& prl) { +#if VDBG + RLOGD("nvWriteCdmaPrl: serial %d", serial); +#endif + dispatchRaw(serial, mSlotId, RIL_REQUEST_NV_WRITE_CDMA_PRL, prl); + return Void(); +} + +Return RadioImpl::nvResetConfig(int32_t serial, ResetNvType resetType) { + int rilResetType = -1; +#if VDBG + RLOGD("nvResetConfig: serial %d", serial); +#endif + /* Convert ResetNvType to RIL.h values + * RIL_REQUEST_NV_RESET_CONFIG + * 1 - reload all NV items + * 2 - erase NV reset (SCRTN) + * 3 - factory reset (RTN) + */ + switch(resetType) { + case ResetNvType::RELOAD: + rilResetType = 1; + break; + case ResetNvType::ERASE: + rilResetType = 2; + break; + case ResetNvType::FACTORY_RESET: + rilResetType = 3; + break; + } + dispatchInts(serial, mSlotId, RIL_REQUEST_NV_RESET_CONFIG, 1, rilResetType); + return Void(); +} + +Return RadioImpl::setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub) { +#if VDBG + RLOGD("setUiccSubscription: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SET_UICC_SUBSCRIPTION); + if (pRI == NULL) { + return Void(); + } + + RIL_SelectUiccSub rilUiccSub = {}; + + rilUiccSub.slot = uiccSub.slot; + rilUiccSub.app_index = uiccSub.appIndex; + rilUiccSub.sub_type = (RIL_SubscriptionType) uiccSub.subType; + rilUiccSub.act_status = (RIL_UiccSubActStatus) uiccSub.actStatus; + + CALL_ONREQUEST(pRI->pCI->requestNumber, &rilUiccSub, sizeof(rilUiccSub), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::setDataAllowed(int32_t serial, bool allow) { +#if VDBG + RLOGD("setDataAllowed: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_ALLOW_DATA, 1, BOOL_TO_INT(allow)); + return Void(); +} + +Return RadioImpl::getHardwareConfig(int32_t serial) { +#if VDBG + RLOGD("getHardwareConfig: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_HARDWARE_CONFIG); + return Void(); +} + +Return RadioImpl::requestIccSimAuthentication(int32_t serial, int32_t authContext, + const hidl_string& authData, const hidl_string& aid) { +#if VDBG + RLOGD("requestIccSimAuthentication: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_AUTHENTICATION); + if (pRI == NULL) { + return Void(); + } + + RIL_SimAuthentication pf = {}; + + pf.authContext = authContext; + + if (!copyHidlStringToRil(&pf.authData, authData, pRI)) { + return Void(); + } + + if (!copyHidlStringToRil(&pf.aid, aid, pRI)) { + memsetAndFreeStrings(1, pf.authData); + return Void(); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, mSlotId); + + memsetAndFreeStrings(2, pf.authData, pf.aid); + return Void(); +} + +/** + * @param numProfiles number of data profile + * @param dataProfiles the pointer to the actual data profiles. The acceptable type is + RIL_DataProfileInfo or RIL_DataProfileInfo_v15. + * @param dataProfilePtrs the pointer to the pointers that point to each data profile structure + * @param numfields number of string-type member in the data profile structure + * @param ... the variadic parameters are pointers to each string-type member + **/ +template +void freeSetDataProfileData(int numProfiles, T *dataProfiles, T **dataProfilePtrs, + int numfields, ...) { + va_list args; + va_start(args, numfields); + + // Iterate through each string-type field that need to be free. + for (int i = 0; i < numfields; i++) { + // Iterate through each data profile and free that specific string-type field. + // The type 'char *T::*' is a type of pointer to a 'char *' member inside T structure. + char *T::*ptr = va_arg(args, char *T::*); + for (int j = 0; j < numProfiles; j++) { + memsetAndFreeStrings(1, dataProfiles[j].*ptr); + } + } + + va_end(args); + +#ifdef MEMSET_FREED + memset(dataProfiles, 0, numProfiles * sizeof(T)); + memset(dataProfilePtrs, 0, numProfiles * sizeof(T *)); +#endif + free(dataProfiles); + free(dataProfilePtrs); +} + +Return RadioImpl::setDataProfile(int32_t serial, const hidl_vec& profiles, + bool isRoaming) { +#if VDBG + RLOGD("setDataProfile: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_DATA_PROFILE); + if (pRI == NULL) { + return Void(); + } + + size_t num = profiles.size(); + bool success = false; + + if (s_vendorFunctions->version <= 14) { + + RIL_DataProfileInfo *dataProfiles = + (RIL_DataProfileInfo *) calloc(num, sizeof(RIL_DataProfileInfo)); + + if (dataProfiles == NULL) { + RLOGE("Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return Void(); + } + + RIL_DataProfileInfo **dataProfilePtrs = + (RIL_DataProfileInfo **) calloc(num, sizeof(RIL_DataProfileInfo *)); + if (dataProfilePtrs == NULL) { + RLOGE("Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + free(dataProfiles); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return Void(); + } + + for (size_t i = 0; i < num; i++) { + dataProfilePtrs[i] = &dataProfiles[i]; + + success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true); + + const hidl_string &protocol = + (isRoaming ? profiles[i].roamingProtocol : profiles[i].protocol); + + if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, protocol, pRI, true)) { + success = false; + } + + if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI, + true)) { + success = false; + } + if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password, + pRI, true)) { + success = false; + } + + if (!success) { + freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4, + &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol, + &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password); + return Void(); + } + + dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId; + dataProfiles[i].authType = (int) profiles[i].authType; + dataProfiles[i].type = (int) profiles[i].type; + dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime; + dataProfiles[i].maxConns = profiles[i].maxConns; + dataProfiles[i].waitTime = profiles[i].waitTime; + dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled); + } + + CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs, + num * sizeof(RIL_DataProfileInfo *), pRI, mSlotId); + + freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4, + &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol, + &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password); + } else { + RIL_DataProfileInfo_v15 *dataProfiles = + (RIL_DataProfileInfo_v15 *) calloc(num, sizeof(RIL_DataProfileInfo_v15)); + + if (dataProfiles == NULL) { + RLOGE("Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return Void(); + } + + RIL_DataProfileInfo_v15 **dataProfilePtrs = + (RIL_DataProfileInfo_v15 **) calloc(num, sizeof(RIL_DataProfileInfo_v15 *)); + if (dataProfilePtrs == NULL) { + RLOGE("Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + free(dataProfiles); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return Void(); + } + + for (size_t i = 0; i < num; i++) { + dataProfilePtrs[i] = &dataProfiles[i]; + + success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true); + if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, profiles[i].protocol, + pRI)) { + success = false; + } + if (success && !copyHidlStringToRil(&dataProfiles[i].roamingProtocol, + profiles[i].roamingProtocol, pRI, true)) { + success = false; + } + if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI, + true)) { + success = false; + } + if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password, + pRI, true)) { + success = false; + } + if (success && !copyHidlStringToRil(&dataProfiles[i].mvnoMatchData, + profiles[i].mvnoMatchData, pRI, true)) { + success = false; + } + + if (success && !convertMvnoTypeToString(profiles[i].mvnoType, + dataProfiles[i].mvnoType)) { + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + success = false; + } + + if (!success) { + freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6, + &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol, + &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user, + &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData); + return Void(); + } + + dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId; + dataProfiles[i].authType = (int) profiles[i].authType; + dataProfiles[i].type = (int) profiles[i].type; + dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime; + dataProfiles[i].maxConns = profiles[i].maxConns; + dataProfiles[i].waitTime = profiles[i].waitTime; + dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled); + dataProfiles[i].supportedTypesBitmask = profiles[i].supportedApnTypesBitmap; + dataProfiles[i].bearerBitmask = profiles[i].bearerBitmap; + dataProfiles[i].mtu = profiles[i].mtu; + } + + CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs, + num * sizeof(RIL_DataProfileInfo_v15 *), pRI, mSlotId); + + freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6, + &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol, + &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user, + &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData); + } + + return Void(); +} + +Return RadioImpl::requestShutdown(int32_t serial) { +#if VDBG + RLOGD("requestShutdown: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_SHUTDOWN); + return Void(); +} + +Return RadioImpl::getRadioCapability(int32_t serial) { +#if VDBG + RLOGD("getRadioCapability: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_RADIO_CAPABILITY); + return Void(); +} + +Return RadioImpl::setRadioCapability(int32_t serial, const RadioCapability& rc) { +#if VDBG + RLOGD("setRadioCapability: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_RADIO_CAPABILITY); + if (pRI == NULL) { + return Void(); + } + + RIL_RadioCapability rilRc = {}; + + // TODO : set rilRc.version using HIDL version ? + rilRc.session = rc.session; + rilRc.phase = (int) rc.phase; + rilRc.rat = (int) rc.raf; + rilRc.status = (int) rc.status; + strncpy(rilRc.logicalModemUuid, rc.logicalModemUuid.c_str(), MAX_UUID_LENGTH); + + CALL_ONREQUEST(pRI->pCI->requestNumber, &rilRc, sizeof(rilRc), pRI, mSlotId); + + return Void(); +} + +Return RadioImpl::startLceService(int32_t serial, int32_t reportInterval, bool pullMode) { +#if VDBG + RLOGD("startLceService: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_START_LCE, 2, reportInterval, + BOOL_TO_INT(pullMode)); + return Void(); +} + +Return RadioImpl::stopLceService(int32_t serial) { +#if VDBG + RLOGD("stopLceService: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_LCE); + return Void(); +} + +Return RadioImpl::pullLceData(int32_t serial) { +#if VDBG + RLOGD("pullLceData: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_PULL_LCEDATA); + return Void(); +} + +Return RadioImpl::getModemActivityInfo(int32_t serial) { +#if VDBG + RLOGD("getModemActivityInfo: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_ACTIVITY_INFO); + return Void(); +} + +Return RadioImpl::setAllowedCarriers(int32_t serial, bool allAllowed, + const CarrierRestrictions& carriers) { +#if VDBG + RLOGD("setAllowedCarriers: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SET_CARRIER_RESTRICTIONS); + if (pRI == NULL) { + return Void(); + } + + RIL_CarrierRestrictions cr = {}; + RIL_Carrier *allowedCarriers = NULL; + RIL_Carrier *excludedCarriers = NULL; + + cr.len_allowed_carriers = carriers.allowedCarriers.size(); + allowedCarriers = (RIL_Carrier *)calloc(cr.len_allowed_carriers, sizeof(RIL_Carrier)); + if (allowedCarriers == NULL) { + RLOGE("setAllowedCarriers: Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); + return Void(); + } + cr.allowed_carriers = allowedCarriers; + + cr.len_excluded_carriers = carriers.excludedCarriers.size(); + excludedCarriers = (RIL_Carrier *)calloc(cr.len_excluded_carriers, sizeof(RIL_Carrier)); + if (excludedCarriers == NULL) { + RLOGE("setAllowedCarriers: Memory allocation failed for request %s", + requestToString(pRI->pCI->requestNumber)); + sendErrorResponse(pRI, RIL_E_NO_MEMORY); +#ifdef MEMSET_FREED + memset(allowedCarriers, 0, cr.len_allowed_carriers * sizeof(RIL_Carrier)); +#endif + free(allowedCarriers); + return Void(); + } + cr.excluded_carriers = excludedCarriers; + + for (int i = 0; i < cr.len_allowed_carriers; i++) { + allowedCarriers[i].mcc = carriers.allowedCarriers[i].mcc.c_str(); + allowedCarriers[i].mnc = carriers.allowedCarriers[i].mnc.c_str(); + allowedCarriers[i].match_type = (RIL_CarrierMatchType) carriers.allowedCarriers[i].matchType; + allowedCarriers[i].match_data = carriers.allowedCarriers[i].matchData.c_str(); + } + + for (int i = 0; i < cr.len_excluded_carriers; i++) { + excludedCarriers[i].mcc = carriers.excludedCarriers[i].mcc.c_str(); + excludedCarriers[i].mnc = carriers.excludedCarriers[i].mnc.c_str(); + excludedCarriers[i].match_type = + (RIL_CarrierMatchType) carriers.excludedCarriers[i].matchType; + excludedCarriers[i].match_data = carriers.excludedCarriers[i].matchData.c_str(); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, &cr, sizeof(RIL_CarrierRestrictions), pRI, mSlotId); + +#ifdef MEMSET_FREED + memset(allowedCarriers, 0, cr.len_allowed_carriers * sizeof(RIL_Carrier)); + memset(excludedCarriers, 0, cr.len_excluded_carriers * sizeof(RIL_Carrier)); +#endif + free(allowedCarriers); + free(excludedCarriers); + return Void(); +} + +Return RadioImpl::getAllowedCarriers(int32_t serial) { +#if VDBG + RLOGD("getAllowedCarriers: serial %d", serial); +#endif + dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CARRIER_RESTRICTIONS); + return Void(); +} + +Return RadioImpl::sendDeviceState(int32_t serial, DeviceStateType deviceStateType, + bool state) { +#if VDBG + RLOGD("sendDeviceState: serial %d", serial); +#endif + if (s_vendorFunctions->version < 15) { + if (deviceStateType == DeviceStateType::LOW_DATA_EXPECTED) { + RLOGD("sendDeviceState: calling screen state %d", BOOL_TO_INT(!state)); + dispatchInts(serial, mSlotId, RIL_REQUEST_SCREEN_STATE, 1, BOOL_TO_INT(!state)); + } else { + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SEND_DEVICE_STATE); + sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED); + } + return Void(); + } + dispatchInts(serial, mSlotId, RIL_REQUEST_SEND_DEVICE_STATE, 2, (int) deviceStateType, + BOOL_TO_INT(state)); + return Void(); +} + +Return RadioImpl::setIndicationFilter(int32_t serial, int32_t indicationFilter) { +#if VDBG + RLOGD("setIndicationFilter: serial %d", serial); +#endif + if (s_vendorFunctions->version < 15) { + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, + RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER); + sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED); + return Void(); + } + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, 1, indicationFilter); + return Void(); +} + +Return RadioImpl::setSimCardPower(int32_t serial, bool powerUp) { +#if VDBG + RLOGD("setSimCardPower: serial %d", serial); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, BOOL_TO_INT(powerUp)); + return Void(); +} + +Return RadioImpl::setSimCardPower_1_1(int32_t serial, const V1_1::CardPowerState state) { +#if VDBG + RLOGD("setSimCardPower_1_1: serial %d state %d", serial, state); +#endif + dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, state); + return Void(); +} + +Return RadioImpl::setCarrierInfoForImsiEncryption(int32_t serial, + const V1_1::ImsiEncryptionInfo& data) { +#if VDBG + RLOGD("setCarrierInfoForImsiEncryption: serial %d", serial); +#endif + RequestInfo *pRI = android::addRequestToList( + serial, mSlotId, RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION); + if (pRI == NULL) { + return Void(); + } + + RIL_CarrierInfoForImsiEncryption imsiEncryption = {}; + + if (!copyHidlStringToRil(&imsiEncryption.mnc, data.mnc, pRI)) { + return Void(); + } + if (!copyHidlStringToRil(&imsiEncryption.mcc, data.mcc, pRI)) { + memsetAndFreeStrings(1, imsiEncryption.mnc); + return Void(); + } + if (!copyHidlStringToRil(&imsiEncryption.keyIdentifier, data.keyIdentifier, pRI)) { + memsetAndFreeStrings(2, imsiEncryption.mnc, imsiEncryption.mcc); + return Void(); + } + int32_t lSize = data.carrierKey.size(); + imsiEncryption.carrierKey = new uint8_t[lSize]; + memcpy(imsiEncryption.carrierKey, data.carrierKey.data(), lSize); + imsiEncryption.expirationTime = data.expirationTime; + CALL_ONREQUEST(pRI->pCI->requestNumber, &imsiEncryption, + sizeof(RIL_CarrierInfoForImsiEncryption), pRI, mSlotId); + delete(imsiEncryption.carrierKey); + return Void(); +} + +Return RadioImpl::startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive) { +#if VDBG + RLOGD("%s(): %d", __FUNCTION__, serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_KEEPALIVE); + if (pRI == NULL) { + return Void(); + } + + RIL_KeepaliveRequest kaReq = {}; + + kaReq.type = static_cast(keepalive.type); + switch(kaReq.type) { + case NATT_IPV4: + if (keepalive.sourceAddress.size() != 4 || + keepalive.destinationAddress.size() != 4) { + RLOGE("Invalid address for keepalive!"); + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return Void(); + } + break; + case NATT_IPV6: + if (keepalive.sourceAddress.size() != 16 || + keepalive.destinationAddress.size() != 16) { + RLOGE("Invalid address for keepalive!"); + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return Void(); + } + break; + default: + RLOGE("Unknown packet keepalive type!"); + sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); + return Void(); + } + + ::memcpy(kaReq.sourceAddress, keepalive.sourceAddress.data(), keepalive.sourceAddress.size()); + kaReq.sourcePort = keepalive.sourcePort; + + ::memcpy(kaReq.destinationAddress, + keepalive.destinationAddress.data(), keepalive.destinationAddress.size()); + kaReq.destinationPort = keepalive.destinationPort; + + kaReq.maxKeepaliveIntervalMillis = keepalive.maxKeepaliveIntervalMillis; + kaReq.cid = keepalive.cid; // This is the context ID of the data call + + CALL_ONREQUEST(pRI->pCI->requestNumber, &kaReq, sizeof(RIL_KeepaliveRequest), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::stopKeepalive(int32_t serial, int32_t sessionHandle) { +#if VDBG + RLOGD("%s(): %d", __FUNCTION__, serial); +#endif + RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_STOP_KEEPALIVE); + if (pRI == NULL) { + return Void(); + } + + CALL_ONREQUEST(pRI->pCI->requestNumber, &sessionHandle, sizeof(uint32_t), pRI, mSlotId); + return Void(); +} + +Return RadioImpl::responseAcknowledgement() { + android::releaseWakeLock(); + return Void(); +} + +Return OemHookImpl::setResponseFunctions( + const ::android::sp& oemHookResponseParam, + const ::android::sp& oemHookIndicationParam) { +#if VDBG + RLOGD("OemHookImpl::setResponseFunctions"); +#endif + + pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(mSlotId); + int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr); + assert(ret == 0); + + mOemHookResponse = oemHookResponseParam; + mOemHookIndication = oemHookIndicationParam; + mCounterOemHook[mSlotId]++; + + ret = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(ret == 0); + + return Void(); +} + +Return OemHookImpl::sendRequestRaw(int32_t serial, const hidl_vec& data) { +#if VDBG + RLOGD("OemHookImpl::sendRequestRaw: serial %d", serial); +#endif + dispatchRaw(serial, mSlotId, RIL_REQUEST_OEM_HOOK_RAW, data); + return Void(); +} + +Return OemHookImpl::sendRequestStrings(int32_t serial, + const hidl_vec& data) { +#if VDBG + RLOGD("OemHookImpl::sendRequestStrings: serial %d", serial); +#endif + dispatchStrings(serial, mSlotId, RIL_REQUEST_OEM_HOOK_STRINGS, data); + return Void(); +} + +/*************************************************************************************************** + * RESPONSE FUNCTIONS + * Functions above are used for requests going from framework to vendor code. The ones below are + * responses for those requests coming back from the vendor code. + **************************************************************************************************/ + +void radio::acknowledgeRequest(int slotId, int serial) { + if (radioService[slotId]->mRadioResponse != NULL) { + Return retStatus = radioService[slotId]->mRadioResponse->acknowledgeRequest(serial); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("acknowledgeRequest: radioService[%d]->mRadioResponse == NULL", slotId); + } +} + +void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType, + RIL_Errno e) { + responseInfo.serial = serial; + switch (responseType) { + case RESPONSE_SOLICITED: + responseInfo.type = RadioResponseType::SOLICITED; + break; + case RESPONSE_SOLICITED_ACK_EXP: + responseInfo.type = RadioResponseType::SOLICITED_ACK_EXP; + break; + } + responseInfo.error = (RadioError) e; +} + +int responseIntOrEmpty(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e, + void *response, size_t responseLen) { + populateResponseInfo(responseInfo, serial, responseType, e); + int ret = -1; + + if (response == NULL && responseLen == 0) { + // Earlier RILs did not send a response for some cases although the interface + // expected an integer as response. Do not return error if response is empty. Instead + // Return -1 in those cases to maintain backward compatibility. + } else if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("responseIntOrEmpty: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *p_int = (int *) response; + ret = p_int[0]; + } + return ret; +} + +int responseInt(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e, + void *response, size_t responseLen) { + populateResponseInfo(responseInfo, serial, responseType, e); + int ret = -1; + + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("responseInt: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *p_int = (int *) response; + ret = p_int[0]; + } + return ret; +} + +int radio::getIccCardStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + CardStatus cardStatus = {}; + RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response); + if (response == NULL || responseLen != sizeof(RIL_CardStatus_v6) + || p_cur->gsm_umts_subscription_app_index >= p_cur->num_applications + || p_cur->cdma_subscription_app_index >= p_cur->num_applications + || p_cur->ims_subscription_app_index >= p_cur->num_applications) { + RLOGE("getIccCardStatusResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + cardStatus.cardState = (CardState) p_cur->card_state; + cardStatus.universalPinState = (PinState) p_cur->universal_pin_state; + cardStatus.gsmUmtsSubscriptionAppIndex = p_cur->gsm_umts_subscription_app_index; + cardStatus.cdmaSubscriptionAppIndex = p_cur->cdma_subscription_app_index; + cardStatus.imsSubscriptionAppIndex = p_cur->ims_subscription_app_index; + + RIL_AppStatus *rilAppStatus = p_cur->applications; + cardStatus.applications.resize(p_cur->num_applications); + AppStatus *appStatus = cardStatus.applications.data(); +#if VDBG + RLOGD("getIccCardStatusResponse: num_applications %d", p_cur->num_applications); +#endif + for (int i = 0; i < p_cur->num_applications; i++) { + appStatus[i].appType = (AppType) rilAppStatus[i].app_type; + appStatus[i].appState = (AppState) rilAppStatus[i].app_state; + appStatus[i].persoSubstate = (PersoSubstate) rilAppStatus[i].perso_substate; + appStatus[i].aidPtr = convertCharPtrToHidlString(rilAppStatus[i].aid_ptr); + appStatus[i].appLabelPtr = convertCharPtrToHidlString( + rilAppStatus[i].app_label_ptr); + appStatus[i].pin1Replaced = rilAppStatus[i].pin1_replaced; + appStatus[i].pin1 = (PinState) rilAppStatus[i].pin1; + appStatus[i].pin2 = (PinState) rilAppStatus[i].pin2; + } + } + + Return retStatus = radioService[slotId]->mRadioResponse-> + getIccCardStatusResponse(responseInfo, cardStatus); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getIccCardStatusResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::supplyIccPinForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("supplyIccPinForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + supplyIccPinForAppResponse(responseInfo, ret); + RLOGE("supplyIccPinForAppResponse: amit ret %d", ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("supplyIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::supplyIccPukForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("supplyIccPukForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse->supplyIccPukForAppResponse( + responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("supplyIccPukForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::supplyIccPin2ForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("supplyIccPin2ForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + supplyIccPin2ForAppResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("supplyIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::supplyIccPuk2ForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("supplyIccPuk2ForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + supplyIccPuk2ForAppResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("supplyIccPuk2ForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::changeIccPinForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("changeIccPinForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + changeIccPinForAppResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("changeIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::changeIccPin2ForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("changeIccPin2ForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + changeIccPin2ForAppResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("changeIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::supplyNetworkDepersonalizationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("supplyNetworkDepersonalizationResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + supplyNetworkDepersonalizationResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("supplyNetworkDepersonalizationResponse: radioService[%d]->mRadioResponse == " + "NULL", slotId); + } + + return 0; +} + +int radio::getCurrentCallsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getCurrentCallsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + hidl_vec calls; + if ((response == NULL && responseLen != 0) + || (responseLen % sizeof(RIL_Call *)) != 0) { + RLOGE("getCurrentCallsResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int num = responseLen / sizeof(RIL_Call *); + calls.resize(num); + + for (int i = 0 ; i < num ; i++) { + RIL_Call *p_cur = ((RIL_Call **) response)[i]; + /* each call info */ + calls[i].state = (CallState) p_cur->state; + calls[i].index = p_cur->index; + calls[i].toa = p_cur->toa; + calls[i].isMpty = p_cur->isMpty; + calls[i].isMT = p_cur->isMT; + calls[i].als = p_cur->als; + calls[i].isVoice = p_cur->isVoice; + calls[i].isVoicePrivacy = p_cur->isVoicePrivacy; + calls[i].number = convertCharPtrToHidlString(p_cur->number); + calls[i].numberPresentation = (CallPresentation) p_cur->numberPresentation; + calls[i].name = convertCharPtrToHidlString(p_cur->name); + calls[i].namePresentation = (CallPresentation) p_cur->namePresentation; + if (p_cur->uusInfo != NULL && p_cur->uusInfo->uusData != NULL) { + RIL_UUS_Info *uusInfo = p_cur->uusInfo; + calls[i].uusInfo.resize(1); + calls[i].uusInfo[0].uusType = (UusType) uusInfo->uusType; + calls[i].uusInfo[0].uusDcs = (UusDcs) uusInfo->uusDcs; + // convert uusInfo->uusData to a null-terminated string + char *nullTermStr = strndup(uusInfo->uusData, uusInfo->uusLength); + calls[i].uusInfo[0].uusData = nullTermStr; + free(nullTermStr); + } + } + } + + Return retStatus = radioService[slotId]->mRadioResponse-> + getCurrentCallsResponse(responseInfo, calls); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCurrentCallsResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::dialResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("dialResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->dialResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("dialResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getIMSIForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getIMSIForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->getIMSIForAppResponse( + responseInfo, convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getIMSIForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::hangupConnectionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("hangupConnectionResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->hangupConnectionResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("hangupConnectionResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::hangupWaitingOrBackgroundResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = + radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::hangupForegroundResumeBackgroundResponse(int slotId, int responseType, int serial, + RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = + radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::switchWaitingOrHoldingAndActiveResponse(int slotId, int responseType, int serial, + RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("switchWaitingOrHoldingAndActiveResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = + radioService[slotId]->mRadioResponse->switchWaitingOrHoldingAndActiveResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("switchWaitingOrHoldingAndActiveResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::conferenceResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responseLen) { +#if VDBG + RLOGD("conferenceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->conferenceResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("conferenceResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::rejectCallResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responseLen) { +#if VDBG + RLOGD("rejectCallResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->rejectCallResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("rejectCallResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getLastCallFailCauseResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getLastCallFailCauseResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + LastCallFailCauseInfo info = {}; + info.vendorCause = hidl_string(); + if (response == NULL) { + RLOGE("getCurrentCallsResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else if (responseLen == sizeof(RIL_LastCallFailCauseInfo)) { + RIL_LastCallFailCauseInfo *pFailCauseInfo = (RIL_LastCallFailCauseInfo *) response; + info.causeCode = (LastCallFailCause) pFailCauseInfo->cause_code; + info.vendorCause = convertCharPtrToHidlString(pFailCauseInfo->vendor_cause); + } else if (responseLen % sizeof(int) != 0) { + int *pInt = (int *) response; + info.causeCode = (LastCallFailCause) pInt[0]; + } else { + RLOGE("getCurrentCallsResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } + + Return retStatus = radioService[slotId]->mRadioResponse->getLastCallFailCauseResponse( + responseInfo, info); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getLastCallFailCauseResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getSignalStrengthResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getSignalStrengthResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + SignalStrength signalStrength = {}; + if (response == NULL || (responseLen != sizeof(RIL_SignalStrength_v10) + && responseLen != sizeof(RIL_SignalStrength_v8))) { + RLOGE("getSignalStrengthResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + convertRilSignalStrengthToHal(response, responseLen, signalStrength); + } + + Return retStatus = radioService[slotId]->mRadioResponse->getSignalStrengthResponse( + responseInfo, signalStrength); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getSignalStrengthResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +RIL_CellInfoType getCellInfoTypeRadioTechnology(char *rat) { + if (rat == NULL) { + return RIL_CELL_INFO_TYPE_NONE; + } + + int radioTech = atoi(rat); + + switch(radioTech) { + + case RADIO_TECH_GPRS: + case RADIO_TECH_EDGE: + case RADIO_TECH_GSM: { + return RIL_CELL_INFO_TYPE_GSM; + } + + case RADIO_TECH_UMTS: + case RADIO_TECH_HSDPA: + case RADIO_TECH_HSUPA: + case RADIO_TECH_HSPA: + case RADIO_TECH_HSPAP: { + return RIL_CELL_INFO_TYPE_WCDMA; + } + + case RADIO_TECH_IS95A: + case RADIO_TECH_IS95B: + case RADIO_TECH_1xRTT: + case RADIO_TECH_EVDO_0: + case RADIO_TECH_EVDO_A: + case RADIO_TECH_EVDO_B: + case RADIO_TECH_EHRPD: { + return RIL_CELL_INFO_TYPE_CDMA; + } + + case RADIO_TECH_LTE: + case RADIO_TECH_LTE_CA: { + return RIL_CELL_INFO_TYPE_LTE; + } + + case RADIO_TECH_TD_SCDMA: { + return RIL_CELL_INFO_TYPE_TD_SCDMA; + } + + default: { + break; + } + } + + return RIL_CELL_INFO_TYPE_NONE; + +} + +void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &rilCellIdentity) { + + cellIdentity.cellIdentityGsm.resize(0); + cellIdentity.cellIdentityWcdma.resize(0); + cellIdentity.cellIdentityCdma.resize(0); + cellIdentity.cellIdentityTdscdma.resize(0); + cellIdentity.cellIdentityLte.resize(0); + cellIdentity.cellInfoType = (CellInfoType)rilCellIdentity.cellInfoType; + switch(rilCellIdentity.cellInfoType) { + + case RIL_CELL_INFO_TYPE_GSM: { + cellIdentity.cellIdentityGsm.resize(1); + cellIdentity.cellIdentityGsm[0].mcc = + std::to_string(rilCellIdentity.cellIdentityGsm.mcc); + cellIdentity.cellIdentityGsm[0].mnc = + std::to_string(rilCellIdentity.cellIdentityGsm.mnc); + cellIdentity.cellIdentityGsm[0].lac = rilCellIdentity.cellIdentityGsm.lac; + cellIdentity.cellIdentityGsm[0].cid = rilCellIdentity.cellIdentityGsm.cid; + cellIdentity.cellIdentityGsm[0].arfcn = rilCellIdentity.cellIdentityGsm.arfcn; + cellIdentity.cellIdentityGsm[0].bsic = rilCellIdentity.cellIdentityGsm.bsic; + break; + } + + case RIL_CELL_INFO_TYPE_WCDMA: { + cellIdentity.cellIdentityWcdma.resize(1); + cellIdentity.cellIdentityWcdma[0].mcc = + std::to_string(rilCellIdentity.cellIdentityWcdma.mcc); + cellIdentity.cellIdentityWcdma[0].mnc = + std::to_string(rilCellIdentity.cellIdentityWcdma.mnc); + cellIdentity.cellIdentityWcdma[0].lac = rilCellIdentity.cellIdentityWcdma.lac; + cellIdentity.cellIdentityWcdma[0].cid = rilCellIdentity.cellIdentityWcdma.cid; + cellIdentity.cellIdentityWcdma[0].psc = rilCellIdentity.cellIdentityWcdma.psc; + cellIdentity.cellIdentityWcdma[0].uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn; + break; + } + + case RIL_CELL_INFO_TYPE_CDMA: { + cellIdentity.cellIdentityCdma.resize(1); + cellIdentity.cellIdentityCdma[0].networkId = rilCellIdentity.cellIdentityCdma.networkId; + cellIdentity.cellIdentityCdma[0].systemId = rilCellIdentity.cellIdentityCdma.systemId; + cellIdentity.cellIdentityCdma[0].baseStationId = + rilCellIdentity.cellIdentityCdma.basestationId; + cellIdentity.cellIdentityCdma[0].longitude = rilCellIdentity.cellIdentityCdma.longitude; + cellIdentity.cellIdentityCdma[0].latitude = rilCellIdentity.cellIdentityCdma.latitude; + break; + } + + case RIL_CELL_INFO_TYPE_LTE: { + cellIdentity.cellIdentityLte.resize(1); + cellIdentity.cellIdentityLte[0].mcc = + std::to_string(rilCellIdentity.cellIdentityLte.mcc); + cellIdentity.cellIdentityLte[0].mnc = + std::to_string(rilCellIdentity.cellIdentityLte.mnc); + cellIdentity.cellIdentityLte[0].ci = rilCellIdentity.cellIdentityLte.ci; + cellIdentity.cellIdentityLte[0].pci = rilCellIdentity.cellIdentityLte.pci; + cellIdentity.cellIdentityLte[0].tac = rilCellIdentity.cellIdentityLte.tac; + cellIdentity.cellIdentityLte[0].earfcn = rilCellIdentity.cellIdentityLte.earfcn; + break; + } + + case RIL_CELL_INFO_TYPE_TD_SCDMA: { + cellIdentity.cellIdentityTdscdma.resize(1); + cellIdentity.cellIdentityTdscdma[0].mcc = + std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc); + cellIdentity.cellIdentityTdscdma[0].mnc = + std::to_string(rilCellIdentity.cellIdentityTdscdma.mnc); + cellIdentity.cellIdentityTdscdma[0].lac = rilCellIdentity.cellIdentityTdscdma.lac; + cellIdentity.cellIdentityTdscdma[0].cid = rilCellIdentity.cellIdentityTdscdma.cid; + cellIdentity.cellIdentityTdscdma[0].cpid = rilCellIdentity.cellIdentityTdscdma.cpid; + break; + } + + default: { + break; + } + } +} + +int convertResponseStringEntryToInt(char **response, int index, int numStrings) { + if ((response != NULL) && (numStrings > index) && (response[index] != NULL)) { + return atoi(response[index]); + } + + return -1; +} + +int convertResponseHexStringEntryToInt(char **response, int index, int numStrings) { + const int hexBase = 16; + if ((response != NULL) && (numStrings > index) && (response[index] != NULL)) { + return strtol(response[index], NULL, hexBase); + } + + return -1; +} + +/* Fill Cell Identity info from Voice Registration State Response. + * This fucntion is applicable only for RIL Version < 15. + * Response is a "char **". + * First and Second entries are in hex string format + * and rest are integers represented in ascii format. */ +void fillCellIdentityFromVoiceRegStateResponseString(CellIdentity &cellIdentity, + int numStrings, char** response) { + + RIL_CellIdentity_v16 rilCellIdentity; + memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16)); + + rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]); + switch(rilCellIdentity.cellInfoType) { + + case RIL_CELL_INFO_TYPE_GSM: { + /* valid LAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityGsm.lac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityGsm.cid = + convertResponseHexStringEntryToInt(response, 2, numStrings); + break; + } + + case RIL_CELL_INFO_TYPE_WCDMA: { + /* valid LAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityWcdma.lac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityWcdma.cid = + convertResponseHexStringEntryToInt(response, 2, numStrings); + rilCellIdentity.cellIdentityWcdma.psc = + convertResponseStringEntryToInt(response, 14, numStrings); + break; + } + + case RIL_CELL_INFO_TYPE_TD_SCDMA:{ + /* valid LAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityTdscdma.lac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityTdscdma.cid = + convertResponseHexStringEntryToInt(response, 2, numStrings); + break; + } + + case RIL_CELL_INFO_TYPE_CDMA:{ + rilCellIdentity.cellIdentityCdma.basestationId = + convertResponseStringEntryToInt(response, 4, numStrings); + /* Order of Lat. and Long. swapped between RIL and HIDL interface versions. */ + rilCellIdentity.cellIdentityCdma.latitude = + convertResponseStringEntryToInt(response, 5, numStrings); + rilCellIdentity.cellIdentityCdma.longitude = + convertResponseStringEntryToInt(response, 6, numStrings); + rilCellIdentity.cellIdentityCdma.systemId = + convertResponseStringEntryToInt(response, 8, numStrings); + rilCellIdentity.cellIdentityCdma.networkId = + convertResponseStringEntryToInt(response, 9, numStrings); + break; + } + + case RIL_CELL_INFO_TYPE_LTE:{ + /* valid TAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityLte.tac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityLte.ci = + convertResponseHexStringEntryToInt(response, 2, numStrings); + break; + } + + default: { + break; + } + } + + fillCellIdentityResponse(cellIdentity, rilCellIdentity); +} + +/* Fill Cell Identity info from Data Registration State Response. + * This fucntion is applicable only for RIL Version < 15. + * Response is a "char **". + * First and Second entries are in hex string format + * and rest are integers represented in ascii format. */ +void fillCellIdentityFromDataRegStateResponseString(CellIdentity &cellIdentity, + int numStrings, char** response) { + + RIL_CellIdentity_v16 rilCellIdentity; + memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16)); + + rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]); + switch(rilCellIdentity.cellInfoType) { + case RIL_CELL_INFO_TYPE_GSM: { + /* valid LAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityGsm.lac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityGsm.cid = + convertResponseHexStringEntryToInt(response, 2, numStrings); + break; + } + case RIL_CELL_INFO_TYPE_WCDMA: { + /* valid LAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityWcdma.lac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityWcdma.cid = + convertResponseHexStringEntryToInt(response, 2, numStrings); + break; + } + case RIL_CELL_INFO_TYPE_TD_SCDMA:{ + /* valid LAC are hexstrings in the range 0x0000 - 0xffff */ + rilCellIdentity.cellIdentityTdscdma.lac = + convertResponseHexStringEntryToInt(response, 1, numStrings); + + /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */ + rilCellIdentity.cellIdentityTdscdma.cid = + convertResponseHexStringEntryToInt(response, 2, numStrings); + break; + } + case RIL_CELL_INFO_TYPE_LTE: { + rilCellIdentity.cellIdentityLte.tac = + convertResponseStringEntryToInt(response, 6, numStrings); + rilCellIdentity.cellIdentityLte.pci = + convertResponseStringEntryToInt(response, 7, numStrings); + rilCellIdentity.cellIdentityLte.ci = + convertResponseStringEntryToInt(response, 8, numStrings); + break; + } + default: { + break; + } + } + + fillCellIdentityResponse(cellIdentity, rilCellIdentity); +} + +int radio::getVoiceRegistrationStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getVoiceRegistrationStateResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + VoiceRegStateResult voiceRegResponse = {}; + int numStrings = responseLen / sizeof(char *); + if (response == NULL) { + RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else if (s_vendorFunctions->version <= 14) { + if (numStrings < 15) { + RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + char **resp = (char **) response; + voiceRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4); + voiceRegResponse.rat = ATOI_NULL_HANDLED(resp[3]); + voiceRegResponse.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0); + voiceRegResponse.roamingIndicator = ATOI_NULL_HANDLED(resp[10]); + voiceRegResponse.systemIsInPrl = ATOI_NULL_HANDLED_DEF(resp[11], 0); + voiceRegResponse.defaultRoamingIndicator = ATOI_NULL_HANDLED_DEF(resp[12], 0); + voiceRegResponse.reasonForDenial = ATOI_NULL_HANDLED_DEF(resp[13], 0); + fillCellIdentityFromVoiceRegStateResponseString(voiceRegResponse.cellIdentity, + 15, resp); + } + } else { + RIL_VoiceRegistrationStateResponse *voiceRegState = + (RIL_VoiceRegistrationStateResponse *)response; + + if (responseLen != sizeof(RIL_VoiceRegistrationStateResponse)) { + RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + voiceRegResponse.regState = (RegState) voiceRegState->regState; + voiceRegResponse.rat = voiceRegState->rat;; + voiceRegResponse.cssSupported = voiceRegState->cssSupported; + voiceRegResponse.roamingIndicator = voiceRegState->roamingIndicator; + voiceRegResponse.systemIsInPrl = voiceRegState->systemIsInPrl; + voiceRegResponse.defaultRoamingIndicator = voiceRegState->defaultRoamingIndicator; + voiceRegResponse.reasonForDenial = voiceRegState->reasonForDenial; + fillCellIdentityResponse(voiceRegResponse.cellIdentity, + voiceRegState->cellIdentity); + } + } + + Return retStatus = + radioService[slotId]->mRadioResponse->getVoiceRegistrationStateResponse( + responseInfo, voiceRegResponse); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getVoiceRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getDataRegistrationStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getDataRegistrationStateResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + DataRegStateResult dataRegResponse = {}; + if (response == NULL) { + RLOGE("getDataRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else if (s_vendorFunctions->version <= 14) { + int numStrings = responseLen / sizeof(char *); + if (numStrings < 6) { + RLOGE("getDataRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + char **resp = (char **) response; + dataRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4); + dataRegResponse.rat = ATOI_NULL_HANDLED_DEF(resp[3], 0); + dataRegResponse.reasonDataDenied = ATOI_NULL_HANDLED(resp[4]); + dataRegResponse.maxDataCalls = ATOI_NULL_HANDLED_DEF(resp[5], 1); + fillCellIdentityFromDataRegStateResponseString(dataRegResponse.cellIdentity, + numStrings < 11 ? 6 : 11, resp); + } + } else { + RIL_DataRegistrationStateResponse *dataRegState = + (RIL_DataRegistrationStateResponse *)response; + + if (responseLen != sizeof(RIL_DataRegistrationStateResponse)) { + RLOGE("getDataRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + dataRegResponse.regState = (RegState) dataRegState->regState; + dataRegResponse.rat = dataRegState->rat;; + dataRegResponse.reasonDataDenied = dataRegState->reasonDataDenied; + dataRegResponse.maxDataCalls = dataRegState->maxDataCalls; + fillCellIdentityResponse(dataRegResponse.cellIdentity, dataRegState->cellIdentity); + } + } + + Return retStatus = + radioService[slotId]->mRadioResponse->getDataRegistrationStateResponse(responseInfo, + dataRegResponse); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getDataRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getOperatorResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getOperatorResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_string longName; + hidl_string shortName; + hidl_string numeric; + int numStrings = responseLen / sizeof(char *); + if (response == NULL || numStrings < 3) { + RLOGE("getOperatorResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + + } else { + char **resp = (char **) response; + longName = convertCharPtrToHidlString(resp[0]); + shortName = convertCharPtrToHidlString(resp[1]); + numeric = convertCharPtrToHidlString(resp[2]); + } + Return retStatus = radioService[slotId]->mRadioResponse->getOperatorResponse( + responseInfo, longName, shortName, numeric); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getOperatorResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setRadioPowerResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { + RLOGD("setRadioPowerResponse: serial %d", serial); + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->setRadioPowerResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setRadioPowerResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendDtmfResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->sendDtmfResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendDtmfResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +SendSmsResult makeSendSmsResult(RadioResponseInfo& responseInfo, int serial, int responseType, + RIL_Errno e, void *response, size_t responseLen) { + populateResponseInfo(responseInfo, serial, responseType, e); + SendSmsResult result = {}; + + if (response != NULL && responseLen == sizeof(RIL_SMS_Response)) { + RIL_SMS_Response *resp = (RIL_SMS_Response *) response; + result.messageRef = resp->messageRef; + result.ackPDU = convertCharPtrToHidlString(resp->ackPDU); + result.errorCode = resp->errorCode; + } else if (response != NULL && responseLen == sizeof(RIL_SMS_Response_Ext)) { + RIL_SMS_Response *resp = &(((RIL_SMS_Response_Ext *) response)->response); + result.messageRef = resp->messageRef; + result.ackPDU = convertCharPtrToHidlString(resp->ackPDU); + result.errorCode = resp->errorCode; + } else { + RLOGE("Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + result.ackPDU = hidl_string(); + } + return result; +} + +int radio::sendSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendSmsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus = radioService[slotId]->mRadioResponse->sendSmsResponse(responseInfo, + result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::sendSMSExpectMoreResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendSMSExpectMoreResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus = radioService[slotId]->mRadioResponse->sendSMSExpectMoreResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendSMSExpectMoreResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setupDataCallResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("setupDataCallResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + SetupDataCallResult result = {}; + + if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11) != 0 + && responseLen % sizeof(RIL_Data_Call_Response_v9) != 0 + && responseLen % sizeof(RIL_Data_Call_Response_v6) != 0)) { + if (response != NULL) { + RLOGE("setupDataCallResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } + result.status = DataCallFailCause::ERROR_UNSPECIFIED; + result.type = hidl_string(); + result.ifname = hidl_string(); + result.addresses = hidl_string(); + result.dnses = hidl_string(); + result.gateways = hidl_string(); + result.pcscf = hidl_string(); + } else if ((responseLen % sizeof(RIL_Data_Call_Response_v11)) == 0) { + convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result); + } else if ((responseLen % sizeof(RIL_Data_Call_Response_v9)) == 0) { + convertRilDataCallToHal((RIL_Data_Call_Response_v9 *) response, result); + } else if ((responseLen % sizeof(RIL_Data_Call_Response_v6)) == 0) { + convertRilDataCallToHal((RIL_Data_Call_Response_v6 *) response, result); + } + + Return retStatus = radioService[slotId]->mRadioResponse->setupDataCallResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setupDataCallResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +IccIoResult responseIccIo(RadioResponseInfo& responseInfo, int serial, int responseType, + RIL_Errno e, void *response, size_t responseLen) { + populateResponseInfo(responseInfo, serial, responseType, e); + IccIoResult result = {}; + + if (response == NULL || responseLen != sizeof(RIL_SIM_IO_Response)) { + RLOGE("Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + result.simResponse = hidl_string(); + } else { + RIL_SIM_IO_Response *resp = (RIL_SIM_IO_Response *) response; + result.sw1 = resp->sw1; + result.sw2 = resp->sw2; + result.simResponse = convertCharPtrToHidlString(resp->simResponse); + } + return result; +} + +int radio::iccIOForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("iccIOForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus = radioService[slotId]->mRadioResponse->iccIOForAppResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("iccIOForAppResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::sendUssdResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendUssdResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->sendUssdResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendUssdResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::cancelPendingUssdResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("cancelPendingUssdResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->cancelPendingUssdResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cancelPendingUssdResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getClirResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getClirResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + int n = -1, m = -1; + int numInts = responseLen / sizeof(int); + if (response == NULL || numInts < 2) { + RLOGE("getClirResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + n = pInt[0]; + m = pInt[1]; + } + Return retStatus = radioService[slotId]->mRadioResponse->getClirResponse(responseInfo, + n, m); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getClirResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setClirResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("setClirResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->setClirResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setClirResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getCallForwardStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getCallForwardStatusResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec callForwardInfos; + + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_CallForwardInfo *) != 0) { + RLOGE("getCallForwardStatusResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int num = responseLen / sizeof(RIL_CallForwardInfo *); + callForwardInfos.resize(num); + for (int i = 0 ; i < num; i++) { + RIL_CallForwardInfo *resp = ((RIL_CallForwardInfo **) response)[i]; + callForwardInfos[i].status = (CallForwardInfoStatus) resp->status; + callForwardInfos[i].reason = resp->reason; + callForwardInfos[i].serviceClass = resp->serviceClass; + callForwardInfos[i].toa = resp->toa; + callForwardInfos[i].number = convertCharPtrToHidlString(resp->number); + callForwardInfos[i].timeSeconds = resp->timeSeconds; + } + } + + Return retStatus = radioService[slotId]->mRadioResponse->getCallForwardStatusResponse( + responseInfo, callForwardInfos); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCallForwardStatusResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setCallForwardResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("setCallForwardResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->setCallForwardResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCallForwardResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getCallWaitingResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getCallWaitingResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + bool enable = false; + int serviceClass = -1; + int numInts = responseLen / sizeof(int); + if (response == NULL || numInts < 2) { + RLOGE("getCallWaitingResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + enable = pInt[0] == 1 ? true : false; + serviceClass = pInt[1]; + } + Return retStatus = radioService[slotId]->mRadioResponse->getCallWaitingResponse( + responseInfo, enable, serviceClass); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setCallWaitingResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("setCallWaitingResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->setCallWaitingResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::acknowledgeLastIncomingGsmSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("acknowledgeLastIncomingGsmSmsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = + radioService[slotId]->mRadioResponse->acknowledgeLastIncomingGsmSmsResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("acknowledgeLastIncomingGsmSmsResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::acceptCallResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("acceptCallResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->acceptCallResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("acceptCallResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::deactivateDataCallResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("deactivateDataCallResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->deactivateDataCallResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("deactivateDataCallResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getFacilityLockForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getFacilityLockForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse-> + getFacilityLockForAppResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setFacilityLockForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setFacilityLockForAppResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->setFacilityLockForAppResponse(responseInfo, + ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setBarringPasswordResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("acceptCallResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setBarringPasswordResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setBarringPasswordResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getNetworkSelectionModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getNetworkSelectionModeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + bool manual = false; + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("getNetworkSelectionModeResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + manual = pInt[0] == 1 ? true : false; + } + Return retStatus + = radioService[slotId]->mRadioResponse->getNetworkSelectionModeResponse( + responseInfo, + manual); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getNetworkSelectionModeResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setNetworkSelectionModeAutomaticResponse(int slotId, int responseType, int serial, + RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("setNetworkSelectionModeAutomaticResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setNetworkSelectionModeAutomaticResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setNetworkSelectionModeAutomaticResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::setNetworkSelectionModeManualResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setNetworkSelectionModeManualResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setNetworkSelectionModeManualResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("acceptCallResponse: radioService[%d]->setNetworkSelectionModeManualResponse " + "== NULL", slotId); + } + + return 0; +} + +int convertOperatorStatusToInt(const char *str) { + if (strncmp("unknown", str, 9) == 0) { + return (int) OperatorStatus::UNKNOWN; + } else if (strncmp("available", str, 9) == 0) { + return (int) OperatorStatus::AVAILABLE; + } else if (strncmp("current", str, 9) == 0) { + return (int) OperatorStatus::CURRENT; + } else if (strncmp("forbidden", str, 9) == 0) { + return (int) OperatorStatus::FORBIDDEN; + } else { + return -1; + } +} + +int radio::getAvailableNetworksResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getAvailableNetworksResponse: serial %d", serial); +#endif + int qanRespStrings = property_get_int32("ro.ril.telephony.qan_resp_strings", 4); + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec networks; + if ((response == NULL && responseLen != 0) + || responseLen % (qanRespStrings * sizeof(char *)) != 0) { + RLOGE("getAvailableNetworksResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + char **resp = (char **) response; + int numStrings = responseLen / sizeof(char *); + networks.resize(numStrings/qanRespStrings); + for (int i = 0, j = 0; i < numStrings; i = i + qanRespStrings, j++) { + networks[j].alphaLong = convertCharPtrToHidlString(resp[i]); + networks[j].alphaShort = convertCharPtrToHidlString(resp[i + 1]); + networks[j].operatorNumeric = convertCharPtrToHidlString(resp[i + 2]); + int status = convertOperatorStatusToInt(resp[i + 3]); + if (status == -1) { + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + networks[j].status = (OperatorStatus) status; + } + } + } + Return retStatus + = radioService[slotId]->mRadioResponse->getAvailableNetworksResponse(responseInfo, + networks); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getAvailableNetworksResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::startDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("startDtmfResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->startDtmfResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("startDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::stopDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("stopDtmfResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->stopDtmfResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stopDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getBasebandVersionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getBasebandVersionResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->getBasebandVersionResponse(responseInfo, + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getBasebandVersionResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::separateConnectionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("separateConnectionResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->separateConnectionResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("separateConnectionResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setMuteResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setMuteResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setMuteResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getMuteResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getMuteResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + bool enable = false; + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("getMuteResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + enable = pInt[0] == 1 ? true : false; + } + Return retStatus = radioService[slotId]->mRadioResponse->getMuteResponse(responseInfo, + enable); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getClipResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getClipResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus = radioService[slotId]->mRadioResponse->getClipResponse(responseInfo, + (ClipStatus) ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getClipResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getDataCallListResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getDataCallListResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + hidl_vec ret; + if ((response == NULL && responseLen != 0) + || (responseLen % sizeof(RIL_Data_Call_Response_v11) != 0 + && responseLen % sizeof(RIL_Data_Call_Response_v9) != 0 + && responseLen % sizeof(RIL_Data_Call_Response_v6) != 0)) { + RLOGE("getDataCallListResponse: invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + convertRilDataCallListToHal(response, responseLen, ret); + } + + Return retStatus = radioService[slotId]->mRadioResponse->getDataCallListResponse( + responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getDataCallListResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setSuppServiceNotificationsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setSuppServiceNotificationsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setSuppServiceNotificationsResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setSuppServiceNotificationsResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::deleteSmsOnSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("deleteSmsOnSimResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->deleteSmsOnSimResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("deleteSmsOnSimResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setBandModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setBandModeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setBandModeResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setBandModeResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::writeSmsToSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("writeSmsToSimResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->writeSmsToSimResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("writeSmsToSimResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getAvailableBandModesResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getAvailableBandModesResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec modes; + if ((response == NULL && responseLen != 0)|| responseLen % sizeof(int) != 0) { + RLOGE("getAvailableBandModesResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + int numInts = responseLen / sizeof(int); + modes.resize(numInts); + for (int i = 0; i < numInts; i++) { + modes[i] = (RadioBandMode) pInt[i]; + } + } + Return retStatus + = radioService[slotId]->mRadioResponse->getAvailableBandModesResponse(responseInfo, + modes); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getAvailableBandModesResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendEnvelopeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("sendEnvelopeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->sendEnvelopeResponse(responseInfo, + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendEnvelopeResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::sendTerminalResponseToSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("sendTerminalResponseToSimResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->sendTerminalResponseToSimResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendTerminalResponseToSimResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::handleStkCallSetupRequestFromSimResponse(int slotId, + int responseType, int serial, + RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("handleStkCallSetupRequestFromSimResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->handleStkCallSetupRequestFromSimResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("handleStkCallSetupRequestFromSimResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::explicitCallTransferResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("explicitCallTransferResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->explicitCallTransferResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("explicitCallTransferResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setPreferredNetworkTypeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setPreferredNetworkTypeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setPreferredNetworkTypeResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + + +int radio::getPreferredNetworkTypeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getPreferredNetworkTypeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->getPreferredNetworkTypeResponse( + responseInfo, (PreferredNetworkType) ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getNeighboringCidsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getNeighboringCidsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec cells; + + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_NeighboringCell *) != 0) { + RLOGE("getNeighboringCidsResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int num = responseLen / sizeof(RIL_NeighboringCell *); + cells.resize(num); + for (int i = 0 ; i < num; i++) { + RIL_NeighboringCell *resp = ((RIL_NeighboringCell **) response)[i]; + cells[i].cid = convertCharPtrToHidlString(resp->cid); + cells[i].rssi = resp->rssi; + } + } + + Return retStatus + = radioService[slotId]->mRadioResponse->getNeighboringCidsResponse(responseInfo, + cells); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getNeighboringCidsResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setLocationUpdatesResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setLocationUpdatesResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setLocationUpdatesResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setLocationUpdatesResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setCdmaSubscriptionSourceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setCdmaSubscriptionSourceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setCdmaSubscriptionSourceResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setCdmaRoamingPreferenceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setCdmaRoamingPreferenceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setCdmaRoamingPreferenceResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getCdmaRoamingPreferenceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getCdmaRoamingPreferenceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->getCdmaRoamingPreferenceResponse( + responseInfo, (CdmaRoamingType) ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setTTYModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setTTYModeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setTTYModeResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getTTYModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getTTYModeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->getTTYModeResponse(responseInfo, + (TtyMode) ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setPreferredVoicePrivacyResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setPreferredVoicePrivacyResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setPreferredVoicePrivacyResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getPreferredVoicePrivacyResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getPreferredVoicePrivacyResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + bool enable = false; + int numInts = responseLen / sizeof(int); + if (response == NULL || numInts < 1) { + RLOGE("getPreferredVoicePrivacyResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + enable = pInt[0] == 1 ? true : false; + } + Return retStatus + = radioService[slotId]->mRadioResponse->getPreferredVoicePrivacyResponse( + responseInfo, enable); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendCDMAFeatureCodeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("sendCDMAFeatureCodeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->sendCDMAFeatureCodeResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendCDMAFeatureCodeResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendBurstDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("sendBurstDtmfResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->sendBurstDtmfResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendBurstDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::sendCdmaSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendCdmaSmsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->sendCdmaSmsResponse(responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendCdmaSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::acknowledgeLastIncomingCdmaSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("acknowledgeLastIncomingCdmaSmsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->acknowledgeLastIncomingCdmaSmsResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("acknowledgeLastIncomingCdmaSmsResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::getGsmBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getGsmBroadcastConfigResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec configs; + + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_GSM_BroadcastSmsConfigInfo *) != 0) { + RLOGE("getGsmBroadcastConfigResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int num = responseLen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *); + configs.resize(num); + for (int i = 0 ; i < num; i++) { + RIL_GSM_BroadcastSmsConfigInfo *resp = + ((RIL_GSM_BroadcastSmsConfigInfo **) response)[i]; + configs[i].fromServiceId = resp->fromServiceId; + configs[i].toServiceId = resp->toServiceId; + configs[i].fromCodeScheme = resp->fromCodeScheme; + configs[i].toCodeScheme = resp->toCodeScheme; + configs[i].selected = resp->selected == 1 ? true : false; + } + } + + Return retStatus + = radioService[slotId]->mRadioResponse->getGsmBroadcastConfigResponse(responseInfo, + configs); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setGsmBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setGsmBroadcastConfigResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setGsmBroadcastConfigResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setGsmBroadcastActivationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setGsmBroadcastActivationResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setGsmBroadcastActivationResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setGsmBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getCdmaBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getCdmaBroadcastConfigResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec configs; + + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_CDMA_BroadcastSmsConfigInfo *) != 0) { + RLOGE("getCdmaBroadcastConfigResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int num = responseLen / sizeof(RIL_CDMA_BroadcastSmsConfigInfo *); + configs.resize(num); + for (int i = 0 ; i < num; i++) { + RIL_CDMA_BroadcastSmsConfigInfo *resp = + ((RIL_CDMA_BroadcastSmsConfigInfo **) response)[i]; + configs[i].serviceCategory = resp->service_category; + configs[i].language = resp->language; + configs[i].selected = resp->selected == 1 ? true : false; + } + } + + Return retStatus + = radioService[slotId]->mRadioResponse->getCdmaBroadcastConfigResponse(responseInfo, + configs); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setCdmaBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setCdmaBroadcastConfigResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setCdmaBroadcastConfigResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setCdmaBroadcastActivationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setCdmaBroadcastActivationResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setCdmaBroadcastActivationResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCdmaBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getCDMASubscriptionResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getCDMASubscriptionResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + int numStrings = responseLen / sizeof(char *); + hidl_string emptyString; + if (response == NULL || numStrings < 5) { + RLOGE("getOperatorResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + Return retStatus + = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse( + responseInfo, emptyString, emptyString, emptyString, emptyString, emptyString); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + char **resp = (char **) response; + Return retStatus + = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse( + responseInfo, + convertCharPtrToHidlString(resp[0]), + convertCharPtrToHidlString(resp[1]), + convertCharPtrToHidlString(resp[2]), + convertCharPtrToHidlString(resp[3]), + convertCharPtrToHidlString(resp[4])); + radioService[slotId]->checkReturnStatus(retStatus); + } + } else { + RLOGE("getCDMASubscriptionResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::writeSmsToRuimResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("writeSmsToRuimResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->writeSmsToRuimResponse(responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("writeSmsToRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::deleteSmsOnRuimResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("deleteSmsOnRuimResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->deleteSmsOnRuimResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("deleteSmsOnRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getDeviceIdentityResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getDeviceIdentityResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + int numStrings = responseLen / sizeof(char *); + hidl_string emptyString; + if (response == NULL || numStrings < 4) { + RLOGE("getDeviceIdentityResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + Return retStatus + = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo, + emptyString, emptyString, emptyString, emptyString); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + char **resp = (char **) response; + Return retStatus + = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo, + convertCharPtrToHidlString(resp[0]), + convertCharPtrToHidlString(resp[1]), + convertCharPtrToHidlString(resp[2]), + convertCharPtrToHidlString(resp[3])); + radioService[slotId]->checkReturnStatus(retStatus); + } + } else { + RLOGE("getDeviceIdentityResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::exitEmergencyCallbackModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("exitEmergencyCallbackModeResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->exitEmergencyCallbackModeResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("exitEmergencyCallbackModeResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getSmscAddressResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getSmscAddressResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->getSmscAddressResponse(responseInfo, + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setSmscAddressResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setSmscAddressResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setSmscAddressResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::reportSmsMemoryStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("reportSmsMemoryStatusResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->reportSmsMemoryStatusResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("reportSmsMemoryStatusResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::reportStkServiceIsRunningResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("reportStkServiceIsRunningResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse-> + reportStkServiceIsRunningResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("reportStkServiceIsRunningResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getCdmaSubscriptionSourceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getCdmaSubscriptionSourceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->getCdmaSubscriptionSourceResponse( + responseInfo, (CdmaSubscriptionSource) ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::requestIsimAuthenticationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("requestIsimAuthenticationResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->requestIsimAuthenticationResponse( + responseInfo, + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("requestIsimAuthenticationResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::acknowledgeIncomingGsmSmsWithPduResponse(int slotId, + int responseType, + int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("acknowledgeIncomingGsmSmsWithPduResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->acknowledgeIncomingGsmSmsWithPduResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("acknowledgeIncomingGsmSmsWithPduResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::sendEnvelopeWithStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendEnvelopeWithStatusResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, + response, responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->sendEnvelopeWithStatusResponse(responseInfo, + result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendEnvelopeWithStatusResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getVoiceRadioTechnologyResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getVoiceRadioTechnologyResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->getVoiceRadioTechnologyResponse( + responseInfo, (RadioTechnology) ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getVoiceRadioTechnologyResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getCellInfoListResponse(int slotId, + int responseType, + int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("getCellInfoListResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + hidl_vec ret; + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_CellInfo_v12) != 0) { + RLOGE("getCellInfoListResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + convertRilCellInfoListToHal(response, responseLen, ret); + } + + Return retStatus = radioService[slotId]->mRadioResponse->getCellInfoListResponse( + responseInfo, ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getCellInfoListResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setCellInfoListRateResponse(int slotId, + int responseType, + int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("setCellInfoListRateResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setCellInfoListRateResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCellInfoListRateResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setInitialAttachApnResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setInitialAttachApnResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getImsRegistrationStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getImsRegistrationStateResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + bool isRegistered = false; + int ratFamily = 0; + int numInts = responseLen / sizeof(int); + if (response == NULL || numInts < 2) { + RLOGE("getImsRegistrationStateResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + int *pInt = (int *) response; + isRegistered = pInt[0] == 1 ? true : false; + ratFamily = pInt[1]; + } + Return retStatus + = radioService[slotId]->mRadioResponse->getImsRegistrationStateResponse( + responseInfo, isRegistered, (RadioTechnologyFamily) ratFamily); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getImsRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendImsSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("sendImsSmsResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->sendImsSmsResponse(responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::iccTransmitApduBasicChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("iccTransmitApduBasicChannelResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->iccTransmitApduBasicChannelResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("iccTransmitApduBasicChannelResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::iccOpenLogicalChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("iccOpenLogicalChannelResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + int channelId = -1; + hidl_vec selectResponse; + int numInts = responseLen / sizeof(int); + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("iccOpenLogicalChannelResponse Invalid response: NULL"); + if (response != NULL) { + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } + } else { + int *pInt = (int *) response; + channelId = pInt[0]; + selectResponse.resize(numInts - 1); + for (int i = 1; i < numInts; i++) { + selectResponse[i - 1] = (int8_t) pInt[i]; + } + } + Return retStatus + = radioService[slotId]->mRadioResponse->iccOpenLogicalChannelResponse(responseInfo, + channelId, selectResponse); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("iccOpenLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::iccCloseLogicalChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("iccCloseLogicalChannelResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->iccCloseLogicalChannelResponse( + responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("iccCloseLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::iccTransmitApduLogicalChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("iccTransmitApduLogicalChannelResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->iccTransmitApduLogicalChannelResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("iccTransmitApduLogicalChannelResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::nvReadItemResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("nvReadItemResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponse->nvReadItemResponse( + responseInfo, + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("nvReadItemResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::nvWriteItemResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("nvWriteItemResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->nvWriteItemResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("nvWriteItemResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::nvWriteCdmaPrlResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("nvWriteCdmaPrlResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->nvWriteCdmaPrlResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("nvWriteCdmaPrlResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::nvResetConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("nvResetConfigResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->nvResetConfigResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("nvResetConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setUiccSubscriptionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setUiccSubscriptionResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setUiccSubscriptionResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setUiccSubscriptionResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setDataAllowedResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setDataAllowedResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setDataAllowedResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setDataAllowedResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getHardwareConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getHardwareConfigResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + hidl_vec result; + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_HardwareConfig) != 0) { + RLOGE("hardwareConfigChangedInd: invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + convertRilHardwareConfigListToHal(response, responseLen, result); + } + + Return retStatus = radioService[slotId]->mRadioResponse->getHardwareConfigResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getHardwareConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::requestIccSimAuthenticationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("requestIccSimAuthenticationResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response, + responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->requestIccSimAuthenticationResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("requestIccSimAuthenticationResponse: radioService[%d]->mRadioResponse " + "== NULL", slotId); + } + + return 0; +} + +int radio::setDataProfileResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setDataProfileResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setDataProfileResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::requestShutdownResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("requestShutdownResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->requestShutdownResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("requestShutdownResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +void responseRadioCapability(RadioResponseInfo& responseInfo, int serial, + int responseType, RIL_Errno e, void *response, size_t responseLen, RadioCapability& rc) { + populateResponseInfo(responseInfo, serial, responseType, e); + + if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) { + RLOGE("responseRadioCapability: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + rc.logicalModemUuid = hidl_string(); + } else { + convertRilRadioCapabilityToHal(response, responseLen, rc); + } +} + +int radio::getRadioCapabilityResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getRadioCapabilityResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + RadioCapability result = {}; + responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen, + result); + Return retStatus = radioService[slotId]->mRadioResponse->getRadioCapabilityResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setRadioCapabilityResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setRadioCapabilityResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + RadioCapability result = {}; + responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen, + result); + Return retStatus = radioService[slotId]->mRadioResponse->setRadioCapabilityResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +LceStatusInfo responseLceStatusInfo(RadioResponseInfo& responseInfo, int serial, int responseType, + RIL_Errno e, void *response, size_t responseLen) { + populateResponseInfo(responseInfo, serial, responseType, e); + LceStatusInfo result = {}; + + if (response == NULL || responseLen != sizeof(RIL_LceStatusInfo)) { + RLOGE("Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + RIL_LceStatusInfo *resp = (RIL_LceStatusInfo *) response; + result.lceStatus = (LceStatus) resp->lce_status; + result.actualIntervalMs = (uint8_t) resp->actual_interval_ms; + } + return result; +} + +int radio::startLceServiceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("startLceServiceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e, + response, responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->startLceServiceResponse(responseInfo, + result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("startLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::stopLceServiceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("stopLceServiceResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e, + response, responseLen); + + Return retStatus + = radioService[slotId]->mRadioResponse->stopLceServiceResponse(responseInfo, + result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stopLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::pullLceDataResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("pullLceDataResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + LceDataInfo result = {}; + if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) { + RLOGE("pullLceDataResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + convertRilLceDataInfoToHal(response, responseLen, result); + } + + Return retStatus = radioService[slotId]->mRadioResponse->pullLceDataResponse( + responseInfo, result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("pullLceDataResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::getModemActivityInfoResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getModemActivityInfoResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + ActivityStatsInfo info; + if (response == NULL || responseLen != sizeof(RIL_ActivityStatsInfo)) { + RLOGE("getModemActivityInfoResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + RIL_ActivityStatsInfo *resp = (RIL_ActivityStatsInfo *)response; + info.sleepModeTimeMs = resp->sleep_mode_time_ms; + info.idleModeTimeMs = resp->idle_mode_time_ms; + for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) { + info.txmModetimeMs[i] = resp->tx_mode_time_ms[i]; + } + info.rxModeTimeMs = resp->rx_mode_time_ms; + } + + Return retStatus + = radioService[slotId]->mRadioResponse->getModemActivityInfoResponse(responseInfo, + info); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getModemActivityInfoResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setAllowedCarriersResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setAllowedCarriersResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen); + Return retStatus + = radioService[slotId]->mRadioResponse->setAllowedCarriersResponse(responseInfo, + ret); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::getAllowedCarriersResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("getAllowedCarriersResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + CarrierRestrictions carrierInfo = {}; + bool allAllowed = true; + if (response == NULL) { +#if VDBG + RLOGD("getAllowedCarriersResponse response is NULL: all allowed"); +#endif + carrierInfo.allowedCarriers.resize(0); + carrierInfo.excludedCarriers.resize(0); + } else if (responseLen != sizeof(RIL_CarrierRestrictions)) { + RLOGE("getAllowedCarriersResponse Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + RIL_CarrierRestrictions *pCr = (RIL_CarrierRestrictions *)response; + if (pCr->len_allowed_carriers > 0 || pCr->len_excluded_carriers > 0) { + allAllowed = false; + } + + carrierInfo.allowedCarriers.resize(pCr->len_allowed_carriers); + for(int i = 0; i < pCr->len_allowed_carriers; i++) { + RIL_Carrier *carrier = pCr->allowed_carriers + i; + carrierInfo.allowedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc); + carrierInfo.allowedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc); + carrierInfo.allowedCarriers[i].matchType = (CarrierMatchType) carrier->match_type; + carrierInfo.allowedCarriers[i].matchData = + convertCharPtrToHidlString(carrier->match_data); + } + + carrierInfo.excludedCarriers.resize(pCr->len_excluded_carriers); + for(int i = 0; i < pCr->len_excluded_carriers; i++) { + RIL_Carrier *carrier = pCr->excluded_carriers + i; + carrierInfo.excludedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc); + carrierInfo.excludedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc); + carrierInfo.excludedCarriers[i].matchType = (CarrierMatchType) carrier->match_type; + carrierInfo.excludedCarriers[i].matchData = + convertCharPtrToHidlString(carrier->match_data); + } + } + + Return retStatus + = radioService[slotId]->mRadioResponse->getAllowedCarriersResponse(responseInfo, + allAllowed, carrierInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("getAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendDeviceStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen) { +#if VDBG + RLOGD("sendDeviceStateResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->sendDeviceStateResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("sendDeviceStateResponse: radioService[%d]->mRadioResponse == NULL", slotId); + } + + return 0; +} + +int radio::setCarrierInfoForImsiEncryptionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { + RLOGD("setCarrierInfoForImsiEncryptionResponse: serial %d", serial); + if (radioService[slotId]->mRadioResponseV1_1 != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus = radioService[slotId]->mRadioResponseV1_1-> + setCarrierInfoForImsiEncryptionResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setCarrierInfoForImsiEncryptionResponse: radioService[%d]->mRadioResponseV1_1 == " + "NULL", slotId); + } + return 0; +} + +int radio::setIndicationFilterResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen) { +#if VDBG + RLOGD("setIndicationFilterResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponse->setIndicationFilterResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("setIndicationFilterResponse: radioService[%d]->mRadioResponse == NULL", + slotId); + } + + return 0; +} + +int radio::setSimCardPowerResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("setSimCardPowerResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponse != NULL + || radioService[slotId]->mRadioResponseV1_1 != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + if (radioService[slotId]->mRadioResponseV1_1 != NULL) { + Return retStatus = radioService[slotId]->mRadioResponseV1_1-> + setSimCardPowerResponse_1_1(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGD("setSimCardPowerResponse: radioService[%d]->mRadioResponseV1_1 == NULL", + slotId); + Return retStatus + = radioService[slotId]->mRadioResponse->setSimCardPowerResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } + } else { + RLOGE("setSimCardPowerResponse: radioService[%d]->mRadioResponse == NULL && " + "radioService[%d]->mRadioResponseV1_1 == NULL", slotId, slotId); + } + return 0; +} + +int radio::startNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("startNetworkScanResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponseV1_1 != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponseV1_1->startNetworkScanResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("startNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL", slotId); + } + + return 0; +} + +int radio::stopNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("stopNetworkScanResponse: serial %d", serial); +#endif + + if (radioService[slotId]->mRadioResponseV1_1 != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + Return retStatus + = radioService[slotId]->mRadioResponseV1_1->stopNetworkScanResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stopNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL", slotId); + } + + return 0; +} + +void convertRilKeepaliveStatusToHal(const RIL_KeepaliveStatus *rilStatus, + V1_1::KeepaliveStatus& halStatus) { + halStatus.sessionHandle = rilStatus->sessionHandle; + halStatus.code = static_cast(rilStatus->code); +} + +int radio::startKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("%s(): %d", __FUNCTION__, serial); +#endif + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + // If we don't have a radio service, there's nothing we can do + if (radioService[slotId]->mRadioResponseV1_1 == NULL) { + RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId); + return 0; + } + + V1_1::KeepaliveStatus ks = {}; + if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) { + RLOGE("%s: invalid response - %d", __FUNCTION__, static_cast(e)); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + convertRilKeepaliveStatusToHal(static_cast(response), ks); + } + + Return retStatus = + radioService[slotId]->mRadioResponseV1_1->startKeepaliveResponse(responseInfo, ks); + radioService[slotId]->checkReturnStatus(retStatus); + return 0; +} + +int radio::stopKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("%s(): %d", __FUNCTION__, serial); +#endif + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + + // If we don't have a radio service, there's nothing we can do + if (radioService[slotId]->mRadioResponseV1_1 == NULL) { + RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId); + return 0; + } + + Return retStatus = + radioService[slotId]->mRadioResponseV1_1->stopKeepaliveResponse(responseInfo); + radioService[slotId]->checkReturnStatus(retStatus); + return 0; +} + +int radio::sendRequestRawResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("sendRequestRawResponse: serial %d", serial); +#endif + + if (oemHookService[slotId]->mOemHookResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec data; + + if (response == NULL) { + RLOGE("sendRequestRawResponse: Invalid response"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + data.setToExternal((uint8_t *) response, responseLen); + } + Return retStatus = oemHookService[slotId]->mOemHookResponse-> + sendRequestRawResponse(responseInfo, data); + checkReturnStatus(slotId, retStatus, false); + } else { + RLOGE("sendRequestRawResponse: oemHookService[%d]->mOemHookResponse == NULL", + slotId); + } + + return 0; +} + +int radio::sendRequestStringsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen) { +#if VDBG + RLOGD("sendRequestStringsResponse: serial %d", serial); +#endif + + if (oemHookService[slotId]->mOemHookResponse != NULL) { + RadioResponseInfo responseInfo = {}; + populateResponseInfo(responseInfo, serial, responseType, e); + hidl_vec data; + + if ((response == NULL && responseLen != 0) || responseLen % sizeof(char *) != 0) { + RLOGE("sendRequestStringsResponse Invalid response: NULL"); + if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE; + } else { + char **resp = (char **) response; + int numStrings = responseLen / sizeof(char *); + data.resize(numStrings); + for (int i = 0; i < numStrings; i++) { + data[i] = convertCharPtrToHidlString(resp[i]); + } + } + Return retStatus + = oemHookService[slotId]->mOemHookResponse->sendRequestStringsResponse( + responseInfo, data); + checkReturnStatus(slotId, retStatus, false); + } else { + RLOGE("sendRequestStringsResponse: oemHookService[%d]->mOemHookResponse == " + "NULL", slotId); + } + + return 0; +} + +/*************************************************************************************************** + * INDICATION FUNCTIONS + * The below function handle unsolicited messages coming from the Radio + * (messages for which there is no pending request) + **************************************************************************************************/ + +RadioIndicationType convertIntToRadioIndicationType(int indicationType) { + return indicationType == RESPONSE_UNSOLICITED ? (RadioIndicationType::UNSOLICITED) : + (RadioIndicationType::UNSOLICITED_ACK_EXP); +} + +int radio::radioStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + RadioState radioState = + (RadioState) CALL_ONSTATEREQUEST(slotId); + RLOGD("radioStateChangedInd: radioState %d", radioState); + Return retStatus = radioService[slotId]->mRadioIndication->radioStateChanged( + convertIntToRadioIndicationType(indicationType), radioState); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("radioStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::callStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("callStateChangedInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->callStateChanged( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("callStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::networkStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("networkStateChangedInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->networkStateChanged( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("networkStateChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +uint8_t hexCharToInt(uint8_t c) { + if (c >= '0' && c <= '9') return (c - '0'); + if (c >= 'A' && c <= 'F') return (c - 'A' + 10); + if (c >= 'a' && c <= 'f') return (c - 'a' + 10); + + return INVALID_HEX_CHAR; +} + +uint8_t * convertHexStringToBytes(void *response, size_t responseLen) { + if (responseLen % 2 != 0) { + return NULL; + } + + uint8_t *bytes = (uint8_t *)calloc(responseLen/2, sizeof(uint8_t)); + if (bytes == NULL) { + RLOGE("convertHexStringToBytes: cannot allocate memory for bytes string"); + return NULL; + } + uint8_t *hexString = (uint8_t *)response; + + for (size_t i = 0; i < responseLen; i += 2) { + uint8_t hexChar1 = hexCharToInt(hexString[i]); + uint8_t hexChar2 = hexCharToInt(hexString[i + 1]); + + if (hexChar1 == INVALID_HEX_CHAR || hexChar2 == INVALID_HEX_CHAR) { + RLOGE("convertHexStringToBytes: invalid hex char %d %d", + hexString[i], hexString[i + 1]); + free(bytes); + return NULL; + } + bytes[i/2] = ((hexChar1 << 4) | hexChar2); + } + + return bytes; +} + +int radio::newSmsInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("newSmsInd: invalid response"); + return 0; + } + + uint8_t *bytes = convertHexStringToBytes(response, responseLen); + if (bytes == NULL) { + RLOGE("newSmsInd: convertHexStringToBytes failed"); + return 0; + } + + hidl_vec pdu; + pdu.setToExternal(bytes, responseLen/2); +#if VDBG + RLOGD("newSmsInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->newSms( + convertIntToRadioIndicationType(indicationType), pdu); + radioService[slotId]->checkReturnStatus(retStatus); + free(bytes); + } else { + RLOGE("newSmsInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::newSmsStatusReportInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("newSmsStatusReportInd: invalid response"); + return 0; + } + + uint8_t *bytes = convertHexStringToBytes(response, responseLen); + if (bytes == NULL) { + RLOGE("newSmsStatusReportInd: convertHexStringToBytes failed"); + return 0; + } + + hidl_vec pdu; + pdu.setToExternal(bytes, responseLen/2); +#if VDBG + RLOGD("newSmsStatusReportInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->newSmsStatusReport( + convertIntToRadioIndicationType(indicationType), pdu); + radioService[slotId]->checkReturnStatus(retStatus); + free(bytes); + } else { + RLOGE("newSmsStatusReportInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::newSmsOnSimInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("newSmsOnSimInd: invalid response"); + return 0; + } + int32_t recordNumber = ((int32_t *) response)[0]; +#if VDBG + RLOGD("newSmsOnSimInd: slotIndex %d", recordNumber); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->newSmsOnSim( + convertIntToRadioIndicationType(indicationType), recordNumber); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("newSmsOnSimInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::onUssdInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen < 2 * sizeof(char *)) { + RLOGE("onUssdInd: invalid response"); + return 0; + } + char **strings = (char **) response; + char *mode = strings[0]; + hidl_string msg = convertCharPtrToHidlString(strings[1]); + UssdModeType modeType = (UssdModeType) atoi(mode); +#if VDBG + RLOGD("onUssdInd: mode %s", mode); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->onUssd( + convertIntToRadioIndicationType(indicationType), modeType, msg); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("onUssdInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::nitzTimeReceivedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("nitzTimeReceivedInd: invalid response"); + return 0; + } + hidl_string nitzTime; + int64_t timeReceived = android::elapsedRealtime(); + char *resp = strndup((char *) response, responseLen); + char *tmp = resp; + + /* Find the 3rd comma */ + for (int i = 0; i < 3; i++) { + if (tmp != NULL) { + tmp = strchr(tmp + 1, ','); + } + } + + /* Make the 3rd comma the end of the string */ + if (tmp != NULL) { + *tmp = '\0'; + } + + nitzTime = convertCharPtrToHidlString(resp); + memsetAndFreeStrings(1, resp); +#if VDBG + RLOGD("nitzTimeReceivedInd: nitzTime %s receivedTime %" PRId64, nitzTime.c_str(), + timeReceived); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->nitzTimeReceived( + convertIntToRadioIndicationType(indicationType), nitzTime, timeReceived); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("nitzTimeReceivedInd: radioService[%d]->mRadioIndication == NULL", slotId); + return -1; + } + + return 0; +} + +void convertRilSignalStrengthToHalV8(void *response, size_t responseLen, + SignalStrength& signalStrength) { + RIL_SignalStrength_v8 *rilSignalStrength = (RIL_SignalStrength_v8 *) response; + + // Fixup LTE for backwards compatibility + // signalStrength: -1 -> 99 + if (rilSignalStrength->LTE_SignalStrength.signalStrength == -1) { + rilSignalStrength->LTE_SignalStrength.signalStrength = 99; + } + // rsrp: -1 -> INT_MAX all other negative value to positive. + // So remap here + if (rilSignalStrength->LTE_SignalStrength.rsrp == -1) { + rilSignalStrength->LTE_SignalStrength.rsrp = INT_MAX; + } else if (rilSignalStrength->LTE_SignalStrength.rsrp < -1) { + rilSignalStrength->LTE_SignalStrength.rsrp = -rilSignalStrength->LTE_SignalStrength.rsrp; + } + // rsrq: -1 -> INT_MAX + if (rilSignalStrength->LTE_SignalStrength.rsrq == -1) { + rilSignalStrength->LTE_SignalStrength.rsrq = INT_MAX; + } + // Not remapping rssnr is already using INT_MAX + // cqi: -1 -> INT_MAX + if (rilSignalStrength->LTE_SignalStrength.cqi == -1) { + rilSignalStrength->LTE_SignalStrength.cqi = INT_MAX; + } + + signalStrength.gw.signalStrength = rilSignalStrength->GW_SignalStrength.signalStrength; + signalStrength.gw.bitErrorRate = rilSignalStrength->GW_SignalStrength.bitErrorRate; + signalStrength.cdma.dbm = rilSignalStrength->CDMA_SignalStrength.dbm; + signalStrength.cdma.ecio = rilSignalStrength->CDMA_SignalStrength.ecio; + signalStrength.evdo.dbm = rilSignalStrength->EVDO_SignalStrength.dbm; + signalStrength.evdo.ecio = rilSignalStrength->EVDO_SignalStrength.ecio; + signalStrength.evdo.signalNoiseRatio = + rilSignalStrength->EVDO_SignalStrength.signalNoiseRatio; + signalStrength.lte.signalStrength = rilSignalStrength->LTE_SignalStrength.signalStrength; + signalStrength.lte.rsrp = rilSignalStrength->LTE_SignalStrength.rsrp; + signalStrength.lte.rsrq = rilSignalStrength->LTE_SignalStrength.rsrq; + signalStrength.lte.rssnr = rilSignalStrength->LTE_SignalStrength.rssnr; + signalStrength.lte.cqi = rilSignalStrength->LTE_SignalStrength.cqi; + signalStrength.lte.timingAdvance = rilSignalStrength->LTE_SignalStrength.timingAdvance; + signalStrength.tdScdma.rscp = INT_MAX; +} + +void convertRilSignalStrengthToHalV10(void *response, size_t responseLen, + SignalStrength& signalStrength) { + RIL_SignalStrength_v10 *rilSignalStrength = (RIL_SignalStrength_v10 *) response; + + // Fixup LTE for backwards compatibility + // signalStrength: -1 -> 99 + if (rilSignalStrength->LTE_SignalStrength.signalStrength == -1) { + rilSignalStrength->LTE_SignalStrength.signalStrength = 99; + } + // rsrp: -1 -> INT_MAX all other negative value to positive. + // So remap here + if (rilSignalStrength->LTE_SignalStrength.rsrp == -1) { + rilSignalStrength->LTE_SignalStrength.rsrp = INT_MAX; + } else if (rilSignalStrength->LTE_SignalStrength.rsrp < -1) { + rilSignalStrength->LTE_SignalStrength.rsrp = -rilSignalStrength->LTE_SignalStrength.rsrp; + } + // rsrq: -1 -> INT_MAX + if (rilSignalStrength->LTE_SignalStrength.rsrq == -1) { + rilSignalStrength->LTE_SignalStrength.rsrq = INT_MAX; + } + // Not remapping rssnr is already using INT_MAX + // cqi: -1 -> INT_MAX + if (rilSignalStrength->LTE_SignalStrength.cqi == -1) { + rilSignalStrength->LTE_SignalStrength.cqi = INT_MAX; + } + + signalStrength.gw.signalStrength = rilSignalStrength->GW_SignalStrength.signalStrength; + signalStrength.gw.bitErrorRate = rilSignalStrength->GW_SignalStrength.bitErrorRate; + signalStrength.cdma.dbm = rilSignalStrength->CDMA_SignalStrength.dbm; + signalStrength.cdma.ecio = rilSignalStrength->CDMA_SignalStrength.ecio; + signalStrength.evdo.dbm = rilSignalStrength->EVDO_SignalStrength.dbm; + signalStrength.evdo.ecio = rilSignalStrength->EVDO_SignalStrength.ecio; + signalStrength.evdo.signalNoiseRatio = + rilSignalStrength->EVDO_SignalStrength.signalNoiseRatio; + signalStrength.lte.signalStrength = rilSignalStrength->LTE_SignalStrength.signalStrength; + signalStrength.lte.rsrp = rilSignalStrength->LTE_SignalStrength.rsrp; + signalStrength.lte.rsrq = rilSignalStrength->LTE_SignalStrength.rsrq; + signalStrength.lte.rssnr = rilSignalStrength->LTE_SignalStrength.rssnr; + signalStrength.lte.cqi = rilSignalStrength->LTE_SignalStrength.cqi; + signalStrength.lte.timingAdvance = rilSignalStrength->LTE_SignalStrength.timingAdvance; + signalStrength.tdScdma.rscp = rilSignalStrength->TD_SCDMA_SignalStrength.rscp; +} + +void convertRilSignalStrengthToHal(void *response, size_t responseLen, + SignalStrength& signalStrength) { + if (responseLen == sizeof(RIL_SignalStrength_v8)) { + convertRilSignalStrengthToHalV8(response, responseLen, signalStrength); + } else { + convertRilSignalStrengthToHalV10(response, responseLen, signalStrength); + } +} + +int radio::currentSignalStrengthInd(int slotId, + int indicationType, int token, RIL_Errno e, + void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || (responseLen != sizeof(RIL_SignalStrength_v10) + && responseLen != sizeof(RIL_SignalStrength_v8))) { + RLOGE("currentSignalStrengthInd: invalid response"); + return 0; + } + + SignalStrength signalStrength = {}; + convertRilSignalStrengthToHal(response, responseLen, signalStrength); + +#if VDBG + RLOGD("currentSignalStrengthInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->currentSignalStrength( + convertIntToRadioIndicationType(indicationType), signalStrength); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("currentSignalStrengthInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +void convertRilDataCallToHal(RIL_Data_Call_Response_v6 *dcResponse, + SetupDataCallResult& dcResult) { + dcResult.status = (DataCallFailCause) dcResponse->status; + dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime; + dcResult.cid = dcResponse->cid; + dcResult.active = dcResponse->active; + dcResult.type = convertCharPtrToHidlString(dcResponse->type); + dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname); + dcResult.addresses = convertCharPtrToHidlString(dcResponse->addresses); + dcResult.dnses = convertCharPtrToHidlString(dcResponse->dnses); + dcResult.gateways = convertCharPtrToHidlString(dcResponse->gateways); + dcResult.pcscf = hidl_string(); + dcResult.mtu = 0; +} + +void convertRilDataCallToHal(RIL_Data_Call_Response_v9 *dcResponse, + SetupDataCallResult& dcResult) { + dcResult.status = (DataCallFailCause) dcResponse->status; + dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime; + dcResult.cid = dcResponse->cid; + dcResult.active = dcResponse->active; + dcResult.type = convertCharPtrToHidlString(dcResponse->type); + dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname); + dcResult.addresses = convertCharPtrToHidlString(dcResponse->addresses); + dcResult.dnses = convertCharPtrToHidlString(dcResponse->dnses); + dcResult.gateways = convertCharPtrToHidlString(dcResponse->gateways); + dcResult.pcscf = convertCharPtrToHidlString(dcResponse->pcscf); + dcResult.mtu = 0; +} + +void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse, + SetupDataCallResult& dcResult) { + dcResult.status = (DataCallFailCause) dcResponse->status; + dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime; + dcResult.cid = dcResponse->cid; + dcResult.active = dcResponse->active; + dcResult.type = convertCharPtrToHidlString(dcResponse->type); + dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname); + dcResult.addresses = convertCharPtrToHidlString(dcResponse->addresses); + dcResult.dnses = convertCharPtrToHidlString(dcResponse->dnses); + dcResult.gateways = convertCharPtrToHidlString(dcResponse->gateways); + dcResult.pcscf = convertCharPtrToHidlString(dcResponse->pcscf); + dcResult.mtu = dcResponse->mtu; +} + +void convertRilDataCallListToHal(void *response, size_t responseLen, + hidl_vec& dcResultList) { + int num; + + if ((responseLen % sizeof(RIL_Data_Call_Response_v11)) == 0) { + num = responseLen / sizeof(RIL_Data_Call_Response_v11); + RIL_Data_Call_Response_v11 *dcResponse = (RIL_Data_Call_Response_v11 *) response; + dcResultList.resize(num); + for (int i = 0; i < num; i++) { + convertRilDataCallToHal(&dcResponse[i], dcResultList[i]); + } + } else if ((responseLen % sizeof(RIL_Data_Call_Response_v9)) == 0) { + num = responseLen / sizeof(RIL_Data_Call_Response_v9); + RIL_Data_Call_Response_v9 *dcResponse = (RIL_Data_Call_Response_v9 *) response; + dcResultList.resize(num); + for (int i = 0; i < num; i++) { + convertRilDataCallToHal(&dcResponse[i], dcResultList[i]); + } + } else if ((responseLen % sizeof(RIL_Data_Call_Response_v6)) == 0) { + num = responseLen / sizeof(RIL_Data_Call_Response_v6); + RIL_Data_Call_Response_v6 *dcResponse = (RIL_Data_Call_Response_v6 *) response; + dcResultList.resize(num); + for (int i = 0; i < num; i++) { + convertRilDataCallToHal(&dcResponse[i], dcResultList[i]); + } + } +} + +int radio::dataCallListChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if ((response == NULL && responseLen != 0) + || (responseLen % sizeof(RIL_Data_Call_Response_v11) != 0 + && responseLen % sizeof(RIL_Data_Call_Response_v9) != 0 + && responseLen % sizeof(RIL_Data_Call_Response_v6) != 0)) { + RLOGE("dataCallListChangedInd: invalid response"); + return 0; + } + hidl_vec dcList; + convertRilDataCallListToHal(response, responseLen, dcList); +#if VDBG + RLOGD("dataCallListChangedInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->dataCallListChanged( + convertIntToRadioIndicationType(indicationType), dcList); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("dataCallListChangedInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::suppSvcNotifyInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_SuppSvcNotification)) { + RLOGE("suppSvcNotifyInd: invalid response"); + return 0; + } + + SuppSvcNotification suppSvc = {}; + RIL_SuppSvcNotification *ssn = (RIL_SuppSvcNotification *) response; + suppSvc.isMT = ssn->notificationType; + suppSvc.code = ssn->code; + suppSvc.index = ssn->index; + suppSvc.type = ssn->type; + suppSvc.number = convertCharPtrToHidlString(ssn->number); + +#if VDBG + RLOGD("suppSvcNotifyInd: isMT %d code %d index %d type %d", + suppSvc.isMT, suppSvc.code, suppSvc.index, suppSvc.type); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->suppSvcNotify( + convertIntToRadioIndicationType(indicationType), suppSvc); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("suppSvcNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::stkSessionEndInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("stkSessionEndInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->stkSessionEnd( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stkSessionEndInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::stkProactiveCommandInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("stkProactiveCommandInd: invalid response"); + return 0; + } +#if VDBG + RLOGD("stkProactiveCommandInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->stkProactiveCommand( + convertIntToRadioIndicationType(indicationType), + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stkProactiveCommandInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::stkEventNotifyInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("stkEventNotifyInd: invalid response"); + return 0; + } +#if VDBG + RLOGD("stkEventNotifyInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->stkEventNotify( + convertIntToRadioIndicationType(indicationType), + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stkEventNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::stkCallSetupInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("stkCallSetupInd: invalid response"); + return 0; + } + int32_t timeout = ((int32_t *) response)[0]; +#if VDBG + RLOGD("stkCallSetupInd: timeout %d", timeout); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->stkCallSetup( + convertIntToRadioIndicationType(indicationType), timeout); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stkCallSetupInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::simSmsStorageFullInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("simSmsStorageFullInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->simSmsStorageFull( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("simSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::simRefreshInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_SimRefreshResponse_v7)) { + RLOGE("simRefreshInd: invalid response"); + return 0; + } + + SimRefreshResult refreshResult = {}; + RIL_SimRefreshResponse_v7 *simRefreshResponse = ((RIL_SimRefreshResponse_v7 *) response); + refreshResult.type = + (V1_0::SimRefreshType) simRefreshResponse->result; + refreshResult.efId = simRefreshResponse->ef_id; + refreshResult.aid = convertCharPtrToHidlString(simRefreshResponse->aid); + +#if VDBG + RLOGD("simRefreshInd: type %d efId %d", refreshResult.type, refreshResult.efId); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->simRefresh( + convertIntToRadioIndicationType(indicationType), refreshResult); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("simRefreshInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +void convertRilCdmaSignalInfoRecordToHal(RIL_CDMA_SignalInfoRecord *signalInfoRecord, + CdmaSignalInfoRecord& record) { + record.isPresent = signalInfoRecord->isPresent; + record.signalType = signalInfoRecord->signalType; + record.alertPitch = signalInfoRecord->alertPitch; + record.signal = signalInfoRecord->signal; +} + +int radio::callRingInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + bool isGsm; + CdmaSignalInfoRecord record = {}; + if (response == NULL || responseLen == 0) { + isGsm = true; + } else { + isGsm = false; + if (responseLen != sizeof (RIL_CDMA_SignalInfoRecord)) { + RLOGE("callRingInd: invalid response"); + return 0; + } + convertRilCdmaSignalInfoRecordToHal((RIL_CDMA_SignalInfoRecord *) response, record); + } + +#if VDBG + RLOGD("callRingInd: isGsm %d", isGsm); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->callRing( + convertIntToRadioIndicationType(indicationType), isGsm, record); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("callRingInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::simStatusChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("simStatusChangedInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->simStatusChanged( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("simStatusChangedInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::cdmaNewSmsInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_CDMA_SMS_Message)) { + RLOGE("cdmaNewSmsInd: invalid response"); + return 0; + } + + CdmaSmsMessage msg = {}; + RIL_CDMA_SMS_Message *rilMsg = (RIL_CDMA_SMS_Message *) response; + msg.teleserviceId = rilMsg->uTeleserviceID; + msg.isServicePresent = rilMsg->bIsServicePresent; + msg.serviceCategory = rilMsg->uServicecategory; + msg.address.digitMode = + (V1_0::CdmaSmsDigitMode) rilMsg->sAddress.digit_mode; + msg.address.numberMode = + (V1_0::CdmaSmsNumberMode) rilMsg->sAddress.number_mode; + msg.address.numberType = + (V1_0::CdmaSmsNumberType) rilMsg->sAddress.number_type; + msg.address.numberPlan = + (V1_0::CdmaSmsNumberPlan) rilMsg->sAddress.number_plan; + + int digitLimit = MIN((rilMsg->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX); + msg.address.digits.setToExternal(rilMsg->sAddress.digits, digitLimit); + + msg.subAddress.subaddressType = (V1_0::CdmaSmsSubaddressType) + rilMsg->sSubAddress.subaddressType; + msg.subAddress.odd = rilMsg->sSubAddress.odd; + + digitLimit= MIN((rilMsg->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX); + msg.subAddress.digits.setToExternal(rilMsg->sSubAddress.digits, digitLimit); + + digitLimit = MIN((rilMsg->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX); + msg.bearerData.setToExternal(rilMsg->aBearerData, digitLimit); + +#if VDBG + RLOGD("cdmaNewSmsInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cdmaNewSms( + convertIntToRadioIndicationType(indicationType), msg); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaNewSmsInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::newBroadcastSmsInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("newBroadcastSmsInd: invalid response"); + return 0; + } + + hidl_vec data; + data.setToExternal((uint8_t *) response, responseLen); +#if VDBG + RLOGD("newBroadcastSmsInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->newBroadcastSms( + convertIntToRadioIndicationType(indicationType), data); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("newBroadcastSmsInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::cdmaRuimSmsStorageFullInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("cdmaRuimSmsStorageFullInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cdmaRuimSmsStorageFull( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaRuimSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::restrictedStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("restrictedStateChangedInd: invalid response"); + return 0; + } + int32_t state = ((int32_t *) response)[0]; +#if VDBG + RLOGD("restrictedStateChangedInd: state %d", state); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->restrictedStateChanged( + convertIntToRadioIndicationType(indicationType), (PhoneRestrictedState) state); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("restrictedStateChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::enterEmergencyCallbackModeInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("enterEmergencyCallbackModeInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->enterEmergencyCallbackMode( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("enterEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::cdmaCallWaitingInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_CDMA_CallWaiting_v6)) { + RLOGE("cdmaCallWaitingInd: invalid response"); + return 0; + } + + CdmaCallWaiting callWaitingRecord = {}; + RIL_CDMA_CallWaiting_v6 *callWaitingRil = ((RIL_CDMA_CallWaiting_v6 *) response); + callWaitingRecord.number = convertCharPtrToHidlString(callWaitingRil->number); + callWaitingRecord.numberPresentation = + (CdmaCallWaitingNumberPresentation) callWaitingRil->numberPresentation; + callWaitingRecord.name = convertCharPtrToHidlString(callWaitingRil->name); + convertRilCdmaSignalInfoRecordToHal(&callWaitingRil->signalInfoRecord, + callWaitingRecord.signalInfoRecord); + callWaitingRecord.numberType = (CdmaCallWaitingNumberType) callWaitingRil->number_type; + callWaitingRecord.numberPlan = (CdmaCallWaitingNumberPlan) callWaitingRil->number_plan; + +#if VDBG + RLOGD("cdmaCallWaitingInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cdmaCallWaiting( + convertIntToRadioIndicationType(indicationType), callWaitingRecord); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaCallWaitingInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::cdmaOtaProvisionStatusInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("cdmaOtaProvisionStatusInd: invalid response"); + return 0; + } + int32_t status = ((int32_t *) response)[0]; +#if VDBG + RLOGD("cdmaOtaProvisionStatusInd: status %d", status); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cdmaOtaProvisionStatus( + convertIntToRadioIndicationType(indicationType), (CdmaOtaProvisionStatus) status); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaOtaProvisionStatusInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::cdmaInfoRecInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_CDMA_InformationRecords)) { + RLOGE("cdmaInfoRecInd: invalid response"); + return 0; + } + + CdmaInformationRecords records = {}; + RIL_CDMA_InformationRecords *recordsRil = (RIL_CDMA_InformationRecords *) response; + + char* string8 = NULL; + int num = MIN(recordsRil->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS); + if (recordsRil->numberOfInfoRecs > RIL_CDMA_MAX_NUMBER_OF_INFO_RECS) { + RLOGE("cdmaInfoRecInd: received %d recs which is more than %d, dropping " + "additional ones", recordsRil->numberOfInfoRecs, + RIL_CDMA_MAX_NUMBER_OF_INFO_RECS); + } + records.infoRec.resize(num); + for (int i = 0 ; i < num ; i++) { + CdmaInformationRecord *record = &records.infoRec[i]; + RIL_CDMA_InformationRecord *infoRec = &recordsRil->infoRec[i]; + record->name = (CdmaInfoRecName) infoRec->name; + // All vectors should be size 0 except one which will be size 1. Set everything to + // size 0 initially. + record->display.resize(0); + record->number.resize(0); + record->signal.resize(0); + record->redir.resize(0); + record->lineCtrl.resize(0); + record->clir.resize(0); + record->audioCtrl.resize(0); + switch (infoRec->name) { + case RIL_CDMA_DISPLAY_INFO_REC: + case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC: { + if (infoRec->rec.display.alpha_len > CDMA_ALPHA_INFO_BUFFER_LENGTH) { + RLOGE("cdmaInfoRecInd: invalid display info response length %d " + "expected not more than %d", (int) infoRec->rec.display.alpha_len, + CDMA_ALPHA_INFO_BUFFER_LENGTH); + return 0; + } + string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1) * sizeof(char)); + if (string8 == NULL) { + RLOGE("cdmaInfoRecInd: Memory allocation failed for " + "responseCdmaInformationRecords"); + return 0; + } + memcpy(string8, infoRec->rec.display.alpha_buf, infoRec->rec.display.alpha_len); + string8[(int)infoRec->rec.display.alpha_len] = '\0'; + + record->display.resize(1); + record->display[0].alphaBuf = string8; + free(string8); + string8 = NULL; + break; + } + + case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC: + case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC: + case RIL_CDMA_CONNECTED_NUMBER_INFO_REC: { + if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) { + RLOGE("cdmaInfoRecInd: invalid display info response length %d " + "expected not more than %d", (int) infoRec->rec.number.len, + CDMA_NUMBER_INFO_BUFFER_LENGTH); + return 0; + } + string8 = (char*) malloc((infoRec->rec.number.len + 1) * sizeof(char)); + if (string8 == NULL) { + RLOGE("cdmaInfoRecInd: Memory allocation failed for " + "responseCdmaInformationRecords"); + return 0; + } + memcpy(string8, infoRec->rec.number.buf, infoRec->rec.number.len); + string8[(int)infoRec->rec.number.len] = '\0'; + + record->number.resize(1); + record->number[0].number = string8; + free(string8); + string8 = NULL; + record->number[0].numberType = infoRec->rec.number.number_type; + record->number[0].numberPlan = infoRec->rec.number.number_plan; + record->number[0].pi = infoRec->rec.number.pi; + record->number[0].si = infoRec->rec.number.si; + break; + } + + case RIL_CDMA_SIGNAL_INFO_REC: { + record->signal.resize(1); + record->signal[0].isPresent = infoRec->rec.signal.isPresent; + record->signal[0].signalType = infoRec->rec.signal.signalType; + record->signal[0].alertPitch = infoRec->rec.signal.alertPitch; + record->signal[0].signal = infoRec->rec.signal.signal; + + /* Drop the response to workaround the "ring of death" bug */ + if (infoRec->rec.signal.isPresent + /* IS95_CONST_IR_SIGNAL_IS54B */ + && infoRec->rec.signal.signalType == 2 + /* IS95_CONST_IR_ALERT_MED */ + && infoRec->rec.signal.alertPitch == 0 + /* IS95_CONST_IR_SIG_IS54B_L */ + && infoRec->rec.signal.signal == 1) { + return 0; + } + + break; + } + + case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC: { + if (infoRec->rec.redir.redirectingNumber.len > + CDMA_NUMBER_INFO_BUFFER_LENGTH) { + RLOGE("cdmaInfoRecInd: invalid display info response length %d " + "expected not more than %d\n", + (int)infoRec->rec.redir.redirectingNumber.len, + CDMA_NUMBER_INFO_BUFFER_LENGTH); + return 0; + } + string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber.len + 1) * + sizeof(char)); + if (string8 == NULL) { + RLOGE("cdmaInfoRecInd: Memory allocation failed for " + "responseCdmaInformationRecords"); + return 0; + } + memcpy(string8, infoRec->rec.redir.redirectingNumber.buf, + infoRec->rec.redir.redirectingNumber.len); + string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0'; + + record->redir.resize(1); + record->redir[0].redirectingNumber.number = string8; + free(string8); + string8 = NULL; + record->redir[0].redirectingNumber.numberType = + infoRec->rec.redir.redirectingNumber.number_type; + record->redir[0].redirectingNumber.numberPlan = + infoRec->rec.redir.redirectingNumber.number_plan; + record->redir[0].redirectingNumber.pi = infoRec->rec.redir.redirectingNumber.pi; + record->redir[0].redirectingNumber.si = infoRec->rec.redir.redirectingNumber.si; + record->redir[0].redirectingReason = + (CdmaRedirectingReason) infoRec->rec.redir.redirectingReason; + break; + } + + case RIL_CDMA_LINE_CONTROL_INFO_REC: { + record->lineCtrl.resize(1); + record->lineCtrl[0].lineCtrlPolarityIncluded = + infoRec->rec.lineCtrl.lineCtrlPolarityIncluded; + record->lineCtrl[0].lineCtrlToggle = infoRec->rec.lineCtrl.lineCtrlToggle; + record->lineCtrl[0].lineCtrlReverse = infoRec->rec.lineCtrl.lineCtrlReverse; + record->lineCtrl[0].lineCtrlPowerDenial = + infoRec->rec.lineCtrl.lineCtrlPowerDenial; + break; + } + + case RIL_CDMA_T53_CLIR_INFO_REC: { + record->clir.resize(1); + record->clir[0].cause = infoRec->rec.clir.cause; + break; + } + + case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC: { + record->audioCtrl.resize(1); + record->audioCtrl[0].upLink = infoRec->rec.audioCtrl.upLink; + record->audioCtrl[0].downLink = infoRec->rec.audioCtrl.downLink; + break; + } + + case RIL_CDMA_T53_RELEASE_INFO_REC: + RLOGE("cdmaInfoRecInd: RIL_CDMA_T53_RELEASE_INFO_REC: INVALID"); + return 0; + + default: + RLOGE("cdmaInfoRecInd: Incorrect name value"); + return 0; + } + } + +#if VDBG + RLOGD("cdmaInfoRecInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cdmaInfoRec( + convertIntToRadioIndicationType(indicationType), records); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaInfoRecInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::indicateRingbackToneInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("indicateRingbackToneInd: invalid response"); + return 0; + } + bool start = ((int32_t *) response)[0]; +#if VDBG + RLOGD("indicateRingbackToneInd: start %d", start); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->indicateRingbackTone( + convertIntToRadioIndicationType(indicationType), start); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("indicateRingbackToneInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::resendIncallMuteInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("resendIncallMuteInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->resendIncallMute( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("resendIncallMuteInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::cdmaSubscriptionSourceChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, + void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("cdmaSubscriptionSourceChangedInd: invalid response"); + return 0; + } + int32_t cdmaSource = ((int32_t *) response)[0]; +#if VDBG + RLOGD("cdmaSubscriptionSourceChangedInd: cdmaSource %d", cdmaSource); +#endif + Return retStatus = radioService[slotId]->mRadioIndication-> + cdmaSubscriptionSourceChanged(convertIntToRadioIndicationType(indicationType), + (CdmaSubscriptionSource) cdmaSource); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaSubscriptionSourceChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::cdmaPrlChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("cdmaPrlChangedInd: invalid response"); + return 0; + } + int32_t version = ((int32_t *) response)[0]; +#if VDBG + RLOGD("cdmaPrlChangedInd: version %d", version); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cdmaPrlChanged( + convertIntToRadioIndicationType(indicationType), version); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cdmaPrlChangedInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::exitEmergencyCallbackModeInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("exitEmergencyCallbackModeInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->exitEmergencyCallbackMode( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("exitEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::rilConnectedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + RLOGD("rilConnectedInd"); + Return retStatus = radioService[slotId]->mRadioIndication->rilConnected( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("rilConnectedInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::voiceRadioTechChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("voiceRadioTechChangedInd: invalid response"); + return 0; + } + int32_t rat = ((int32_t *) response)[0]; +#if VDBG + RLOGD("voiceRadioTechChangedInd: rat %d", rat); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->voiceRadioTechChanged( + convertIntToRadioIndicationType(indicationType), (RadioTechnology) rat); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("voiceRadioTechChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec& records) { + int num = responseLen / sizeof(RIL_CellInfo_v12); + records.resize(num); + + RIL_CellInfo_v12 *rillCellInfo = (RIL_CellInfo_v12 *) response; + for (int i = 0; i < num; i++) { + records[i].cellInfoType = (CellInfoType) rillCellInfo->cellInfoType; + records[i].registered = rillCellInfo->registered; + records[i].timeStampType = (TimeStampType) rillCellInfo->timeStampType; + records[i].timeStamp = rillCellInfo->timeStamp; + // All vectors should be size 0 except one which will be size 1. Set everything to + // size 0 initially. + records[i].gsm.resize(0); + records[i].wcdma.resize(0); + records[i].cdma.resize(0); + records[i].lte.resize(0); + records[i].tdscdma.resize(0); + switch(rillCellInfo->cellInfoType) { + case RIL_CELL_INFO_TYPE_GSM: { + records[i].gsm.resize(1); + CellInfoGsm *cellInfoGsm = &records[i].gsm[0]; + cellInfoGsm->cellIdentityGsm.mcc = + std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc); + cellInfoGsm->cellIdentityGsm.mnc = + std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc); + cellInfoGsm->cellIdentityGsm.lac = + rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac; + cellInfoGsm->cellIdentityGsm.cid = + rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid; + cellInfoGsm->cellIdentityGsm.arfcn = + rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn; + cellInfoGsm->cellIdentityGsm.bsic = + rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic; + cellInfoGsm->signalStrengthGsm.signalStrength = + rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength; + cellInfoGsm->signalStrengthGsm.bitErrorRate = + rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate; + cellInfoGsm->signalStrengthGsm.timingAdvance = + rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance; + break; + } + + case RIL_CELL_INFO_TYPE_WCDMA: { + records[i].wcdma.resize(1); + CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0]; + cellInfoWcdma->cellIdentityWcdma.mcc = + std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc); + cellInfoWcdma->cellIdentityWcdma.mnc = + std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc); + cellInfoWcdma->cellIdentityWcdma.lac = + rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac; + cellInfoWcdma->cellIdentityWcdma.cid = + rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid; + cellInfoWcdma->cellIdentityWcdma.psc = + rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc; + cellInfoWcdma->cellIdentityWcdma.uarfcn = + rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn; + cellInfoWcdma->signalStrengthWcdma.signalStrength = + rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength; + cellInfoWcdma->signalStrengthWcdma.bitErrorRate = + rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate; + break; + } + + case RIL_CELL_INFO_TYPE_CDMA: { + records[i].cdma.resize(1); + CellInfoCdma *cellInfoCdma = &records[i].cdma[0]; + cellInfoCdma->cellIdentityCdma.networkId = + rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId; + cellInfoCdma->cellIdentityCdma.systemId = + rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId; + cellInfoCdma->cellIdentityCdma.baseStationId = + rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId; + cellInfoCdma->cellIdentityCdma.longitude = + rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude; + cellInfoCdma->cellIdentityCdma.latitude = + rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude; + cellInfoCdma->signalStrengthCdma.dbm = + rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm; + cellInfoCdma->signalStrengthCdma.ecio = + rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio; + cellInfoCdma->signalStrengthEvdo.dbm = + rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm; + cellInfoCdma->signalStrengthEvdo.ecio = + rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio; + cellInfoCdma->signalStrengthEvdo.signalNoiseRatio = + rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio; + break; + } + + case RIL_CELL_INFO_TYPE_LTE: { + records[i].lte.resize(1); + CellInfoLte *cellInfoLte = &records[i].lte[0]; + cellInfoLte->cellIdentityLte.mcc = + std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc); + cellInfoLte->cellIdentityLte.mnc = + std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc); + cellInfoLte->cellIdentityLte.ci = + rillCellInfo->CellInfo.lte.cellIdentityLte.ci; + cellInfoLte->cellIdentityLte.pci = + rillCellInfo->CellInfo.lte.cellIdentityLte.pci; + cellInfoLte->cellIdentityLte.tac = + rillCellInfo->CellInfo.lte.cellIdentityLte.tac; + cellInfoLte->cellIdentityLte.earfcn = + rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn; + cellInfoLte->signalStrengthLte.signalStrength = + rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength; + cellInfoLte->signalStrengthLte.rsrp = + rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp; + cellInfoLte->signalStrengthLte.rsrq = + rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq; + cellInfoLte->signalStrengthLte.rssnr = + rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr; + cellInfoLte->signalStrengthLte.cqi = + rillCellInfo->CellInfo.lte.signalStrengthLte.cqi; + cellInfoLte->signalStrengthLte.timingAdvance = + rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance; + break; + } + + case RIL_CELL_INFO_TYPE_TD_SCDMA: { + records[i].tdscdma.resize(1); + CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0]; + cellInfoTdscdma->cellIdentityTdscdma.mcc = + std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc); + cellInfoTdscdma->cellIdentityTdscdma.mnc = + std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc); + cellInfoTdscdma->cellIdentityTdscdma.lac = + rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac; + cellInfoTdscdma->cellIdentityTdscdma.cid = + rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid; + cellInfoTdscdma->cellIdentityTdscdma.cpid = + rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid; + cellInfoTdscdma->signalStrengthTdscdma.rscp = + rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp; + break; + } + default: { + break; + } + } + rillCellInfo += 1; + } +} + +int radio::cellInfoListInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if ((response == NULL && responseLen != 0) || responseLen % sizeof(RIL_CellInfo_v12) != 0) { + RLOGE("cellInfoListInd: invalid response"); + return 0; + } + + hidl_vec records; + convertRilCellInfoListToHal(response, responseLen, records); + +#if VDBG + RLOGD("cellInfoListInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->cellInfoList( + convertIntToRadioIndicationType(indicationType), records); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("cellInfoListInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::imsNetworkStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { +#if VDBG + RLOGD("imsNetworkStateChangedInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->imsNetworkStateChanged( + convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("imsNetworkStateChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::subscriptionStatusChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("subscriptionStatusChangedInd: invalid response"); + return 0; + } + bool activate = ((int32_t *) response)[0]; +#if VDBG + RLOGD("subscriptionStatusChangedInd: activate %d", activate); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->subscriptionStatusChanged( + convertIntToRadioIndicationType(indicationType), activate); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("subscriptionStatusChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +int radio::srvccStateNotifyInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen % sizeof(int) != 0) { + RLOGE("srvccStateNotifyInd: invalid response"); + return 0; + } + int32_t state = ((int32_t *) response)[0]; +#if VDBG + RLOGD("srvccStateNotifyInd: rat %d", state); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->srvccStateNotify( + convertIntToRadioIndicationType(indicationType), (SrvccState) state); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("srvccStateNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +void convertRilHardwareConfigListToHal(void *response, size_t responseLen, + hidl_vec& records) { + int num = responseLen / sizeof(RIL_HardwareConfig); + records.resize(num); + + RIL_HardwareConfig *rilHardwareConfig = (RIL_HardwareConfig *) response; + for (int i = 0; i < num; i++) { + records[i].type = (HardwareConfigType) rilHardwareConfig[i].type; + records[i].uuid = convertCharPtrToHidlString(rilHardwareConfig[i].uuid); + records[i].state = (HardwareConfigState) rilHardwareConfig[i].state; + switch (rilHardwareConfig[i].type) { + case RIL_HARDWARE_CONFIG_MODEM: { + records[i].modem.resize(1); + records[i].sim.resize(0); + HardwareConfigModem *hwConfigModem = &records[i].modem[0]; + hwConfigModem->rat = rilHardwareConfig[i].cfg.modem.rat; + hwConfigModem->maxVoice = rilHardwareConfig[i].cfg.modem.maxVoice; + hwConfigModem->maxData = rilHardwareConfig[i].cfg.modem.maxData; + hwConfigModem->maxStandby = rilHardwareConfig[i].cfg.modem.maxStandby; + break; + } + + case RIL_HARDWARE_CONFIG_SIM: { + records[i].sim.resize(1); + records[i].modem.resize(0); + records[i].sim[0].modemUuid = + convertCharPtrToHidlString(rilHardwareConfig[i].cfg.sim.modemUuid); + break; + } + } + } +} + +int radio::hardwareConfigChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if ((response == NULL && responseLen != 0) + || responseLen % sizeof(RIL_HardwareConfig) != 0) { + RLOGE("hardwareConfigChangedInd: invalid response"); + return 0; + } + + hidl_vec configs; + convertRilHardwareConfigListToHal(response, responseLen, configs); + +#if VDBG + RLOGD("hardwareConfigChangedInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->hardwareConfigChanged( + convertIntToRadioIndicationType(indicationType), configs); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("hardwareConfigChangedInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc) { + RIL_RadioCapability *rilRadioCapability = (RIL_RadioCapability *) response; + rc.session = rilRadioCapability->session; + rc.phase = (V1_0::RadioCapabilityPhase) rilRadioCapability->phase; + rc.raf = rilRadioCapability->rat; + rc.logicalModemUuid = convertCharPtrToHidlString(rilRadioCapability->logicalModemUuid); + rc.status = (V1_0::RadioCapabilityStatus) rilRadioCapability->status; +} + +int radio::radioCapabilityIndicationInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) { + RLOGE("radioCapabilityIndicationInd: invalid response"); + return 0; + } + + RadioCapability rc = {}; + convertRilRadioCapabilityToHal(response, responseLen, rc); + +#if VDBG + RLOGD("radioCapabilityIndicationInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->radioCapabilityIndication( + convertIntToRadioIndicationType(indicationType), rc); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("radioCapabilityIndicationInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) { + if ((reqType == SS_INTERROGATION) && + (serType == SS_CFU || + serType == SS_CF_BUSY || + serType == SS_CF_NO_REPLY || + serType == SS_CF_NOT_REACHABLE || + serType == SS_CF_ALL || + serType == SS_CF_ALL_CONDITIONAL)) { + return true; + } + return false; +} + +int radio::onSupplementaryServiceIndicationInd(int slotId, + int indicationType, int token, RIL_Errno e, + void *response, size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_StkCcUnsolSsResponse)) { + RLOGE("onSupplementaryServiceIndicationInd: invalid response"); + return 0; + } + + RIL_StkCcUnsolSsResponse *rilSsResponse = (RIL_StkCcUnsolSsResponse *) response; + StkCcUnsolSsResult ss = {}; + ss.serviceType = (SsServiceType) rilSsResponse->serviceType; + ss.requestType = (SsRequestType) rilSsResponse->requestType; + ss.teleserviceType = (SsTeleserviceType) rilSsResponse->teleserviceType; + ss.serviceClass = rilSsResponse->serviceClass; + ss.result = (RadioError) rilSsResponse->result; + + if (isServiceTypeCfQuery(rilSsResponse->serviceType, rilSsResponse->requestType)) { +#if VDBG + RLOGD("onSupplementaryServiceIndicationInd CF type, num of Cf elements %d", + rilSsResponse->cfData.numValidIndexes); +#endif + if (rilSsResponse->cfData.numValidIndexes > NUM_SERVICE_CLASSES) { + RLOGE("onSupplementaryServiceIndicationInd numValidIndexes is greater than " + "max value %d, truncating it to max value", NUM_SERVICE_CLASSES); + rilSsResponse->cfData.numValidIndexes = NUM_SERVICE_CLASSES; + } + + ss.cfData.resize(1); + ss.ssInfo.resize(0); + + /* number of call info's */ + ss.cfData[0].cfInfo.resize(rilSsResponse->cfData.numValidIndexes); + + for (int i = 0; i < rilSsResponse->cfData.numValidIndexes; i++) { + RIL_CallForwardInfo cf = rilSsResponse->cfData.cfInfo[i]; + CallForwardInfo *cfInfo = &ss.cfData[0].cfInfo[i]; + + cfInfo->status = (CallForwardInfoStatus) cf.status; + cfInfo->reason = cf.reason; + cfInfo->serviceClass = cf.serviceClass; + cfInfo->toa = cf.toa; + cfInfo->number = convertCharPtrToHidlString(cf.number); + cfInfo->timeSeconds = cf.timeSeconds; +#if VDBG + RLOGD("onSupplementaryServiceIndicationInd: " + "Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status, + cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds); +#endif + } + } else { + ss.ssInfo.resize(1); + ss.cfData.resize(0); + + /* each int */ + ss.ssInfo[0].ssInfo.resize(SS_INFO_MAX); + for (int i = 0; i < SS_INFO_MAX; i++) { +#if VDBG + RLOGD("onSupplementaryServiceIndicationInd: Data: %d", + rilSsResponse->ssInfo[i]); +#endif + ss.ssInfo[0].ssInfo[i] = rilSsResponse->ssInfo[i]; + } + } + +#if VDBG + RLOGD("onSupplementaryServiceIndicationInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication-> + onSupplementaryServiceIndication(convertIntToRadioIndicationType(indicationType), + ss); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("onSupplementaryServiceIndicationInd: " + "radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::stkCallControlAlphaNotifyInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("stkCallControlAlphaNotifyInd: invalid response"); + return 0; + } +#if VDBG + RLOGD("stkCallControlAlphaNotifyInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->stkCallControlAlphaNotify( + convertIntToRadioIndicationType(indicationType), + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("stkCallControlAlphaNotifyInd: radioService[%d]->mRadioIndication == NULL", + slotId); + } + + return 0; +} + +void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce) { + RIL_LceDataInfo *rilLceDataInfo = (RIL_LceDataInfo *)response; + lce.lastHopCapacityKbps = rilLceDataInfo->last_hop_capacity_kbps; + lce.confidenceLevel = rilLceDataInfo->confidence_level; + lce.lceSuspended = rilLceDataInfo->lce_suspended; +} + +int radio::lceDataInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) { + RLOGE("lceDataInd: invalid response"); + return 0; + } + + LceDataInfo lce = {}; + convertRilLceDataInfoToHal(response, responseLen, lce); +#if VDBG + RLOGD("lceDataInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->lceData( + convertIntToRadioIndicationType(indicationType), lce); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("lceDataInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::pcoDataInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen != sizeof(RIL_PCO_Data)) { + RLOGE("pcoDataInd: invalid response"); + return 0; + } + + PcoDataInfo pco = {}; + RIL_PCO_Data *rilPcoData = (RIL_PCO_Data *)response; + pco.cid = rilPcoData->cid; + pco.bearerProto = convertCharPtrToHidlString(rilPcoData->bearer_proto); + pco.pcoId = rilPcoData->pco_id; + pco.contents.setToExternal((uint8_t *) rilPcoData->contents, rilPcoData->contents_length); + +#if VDBG + RLOGD("pcoDataInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->pcoData( + convertIntToRadioIndicationType(indicationType), pco); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("pcoDataInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::modemResetInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("modemResetInd: invalid response"); + return 0; + } +#if VDBG + RLOGD("modemResetInd"); +#endif + Return retStatus = radioService[slotId]->mRadioIndication->modemReset( + convertIntToRadioIndicationType(indicationType), + convertCharPtrToHidlString((char *) response)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("modemResetInd: radioService[%d]->mRadioIndication == NULL", slotId); + } + + return 0; +} + +int radio::networkScanResultInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("networkScanResultInd"); +#endif + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndicationV1_1 != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("networkScanResultInd: invalid response"); + return 0; + } + RLOGD("networkScanResultInd"); + +#if VDBG + RLOGD("networkScanResultInd"); +#endif + + RIL_NetworkScanResult *networkScanResult = (RIL_NetworkScanResult *) response; + + V1_1::NetworkScanResult result; + result.status = (V1_1::ScanStatus) networkScanResult->status; + result.error = (RadioError) e; + convertRilCellInfoListToHal( + networkScanResult->network_infos, + networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v12), + result.networkInfos); + + Return retStatus = radioService[slotId]->mRadioIndicationV1_1->networkScanResult( + convertIntToRadioIndicationType(indicationType), result); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("networkScanResultInd: radioService[%d]->mRadioIndicationV1_1 == NULL", slotId); + } + return 0; +} + +int radio::carrierInfoForImsiEncryption(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndicationV1_1 != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("carrierInfoForImsiEncryption: invalid response"); + return 0; + } + RLOGD("carrierInfoForImsiEncryption"); + Return retStatus = radioService[slotId]->mRadioIndicationV1_1-> + carrierInfoForImsiEncryption(convertIntToRadioIndicationType(indicationType)); + radioService[slotId]->checkReturnStatus(retStatus); + } else { + RLOGE("carrierInfoForImsiEncryption: radioService[%d]->mRadioIndicationV1_1 == NULL", + slotId); + } + + return 0; +} + +int radio::keepaliveStatusInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { +#if VDBG + RLOGD("%s(): token=%d", __FUNCTION__, token); +#endif + if (radioService[slotId] == NULL || radioService[slotId]->mRadioIndication == NULL) { + RLOGE("%s: radioService[%d]->mRadioIndication == NULL", __FUNCTION__, slotId); + return 0; + } + + auto ret = V1_1::IRadioIndication::castFrom( + radioService[slotId]->mRadioIndication); + if (!ret.isOk()) { + RLOGE("%s: ret.isOk() == false for radioService[%d]", __FUNCTION__, slotId); + return 0; + } + sp radioIndicationV1_1 = ret; + + if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) { + RLOGE("%s: invalid response", __FUNCTION__); + return 0; + } + + V1_1::KeepaliveStatus ks; + convertRilKeepaliveStatusToHal(static_cast(response), ks); + + Return retStatus = radioIndicationV1_1->keepaliveStatus( + convertIntToRadioIndicationType(indicationType), ks); + radioService[slotId]->checkReturnStatus(retStatus); + return 0; +} + +int radio::oemHookRawInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen) { + if (oemHookService[slotId] != NULL && oemHookService[slotId]->mOemHookIndication != NULL) { + if (response == NULL || responseLen == 0) { + RLOGE("oemHookRawInd: invalid response"); + return 0; + } + + hidl_vec data; + data.setToExternal((uint8_t *) response, responseLen); +#if VDBG + RLOGD("oemHookRawInd"); +#endif + Return retStatus = oemHookService[slotId]->mOemHookIndication->oemHookRaw( + convertIntToRadioIndicationType(indicationType), data); + checkReturnStatus(slotId, retStatus, false); + } else { + RLOGE("oemHookRawInd: oemHookService[%d]->mOemHookIndication == NULL", slotId); + } + + return 0; +} + +void radio::registerService(RIL_RadioFunctions *callbacks, CommandInfo *commands) { + using namespace android::hardware; + int simCount = 1; + const char *serviceNames[] = { + android::RIL_getServiceName() + #if (SIM_COUNT >= 2) + , RIL2_SERVICE_NAME + #if (SIM_COUNT >= 3) + , RIL3_SERVICE_NAME + #if (SIM_COUNT >= 4) + , RIL4_SERVICE_NAME + #endif + #endif + #endif + }; + + #if (SIM_COUNT >= 2) + simCount = SIM_COUNT; + #endif + + configureRpcThreadpool(1, true /* callerWillJoin */); + for (int i = 0; i < simCount; i++) { + pthread_rwlock_t *radioServiceRwlockPtr = getRadioServiceRwlock(i); + int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr); + assert(ret == 0); + + radioService[i] = new RadioImpl; + radioService[i]->mSlotId = i; + oemHookService[i] = new OemHookImpl; + oemHookService[i]->mSlotId = i; + RLOGD("registerService: starting android::hardware::radio::V1_1::IRadio %s", + serviceNames[i]); + android::status_t status = radioService[i]->registerAsService(serviceNames[i]); + status = oemHookService[i]->registerAsService(serviceNames[i]); + + ret = pthread_rwlock_unlock(radioServiceRwlockPtr); + assert(ret == 0); + } + + s_vendorFunctions = callbacks; + s_commands = commands; +} + +void rilc_thread_pool() { + joinRpcThreadpool(); +} + +pthread_rwlock_t * radio::getRadioServiceRwlock(int slotId) { + pthread_rwlock_t *radioServiceRwlockPtr = &radioServiceRwlock; + + #if (SIM_COUNT >= 2) + if (slotId == 2) radioServiceRwlockPtr = &radioServiceRwlock2; + #if (SIM_COUNT >= 3) + if (slotId == 3) radioServiceRwlockPtr = &radioServiceRwlock3; + #if (SIM_COUNT >= 4) + if (slotId == 4) radioServiceRwlockPtr = &radioServiceRwlock4; + #endif + #endif + #endif + + return radioServiceRwlockPtr; +} diff --git a/ril/libril/ril_service.h b/ril/libril/ril_service.h new file mode 100644 index 0000000..2240e2a --- /dev/null +++ b/ril/libril/ril_service.h @@ -0,0 +1,748 @@ +/* + * Copyright (c) 2016 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. + */ + +#ifndef RIL_SERVICE_H +#define RIL_SERVICE_H + +#include +#include + +namespace radio { +void registerService(RIL_RadioFunctions *callbacks, android::CommandInfo *commands); + +int getIccCardStatusResponse(int slotId, int responseType, + int token, RIL_Errno e, void *response, size_t responselen); + +int supplyIccPinForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int supplyIccPukForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int supplyIccPin2ForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int supplyIccPuk2ForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int changeIccPinForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int changeIccPin2ForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int supplyNetworkDepersonalizationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getCurrentCallsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int dialResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, size_t responselen); + +int getIMSIForAppResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responselen); + +int hangupConnectionResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responselen); + +int hangupWaitingOrBackgroundResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int hangupForegroundResumeBackgroundResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int switchWaitingOrHoldingAndActiveResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int conferenceResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responselen); + +int rejectCallResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responselen); + +int getLastCallFailCauseResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getSignalStrengthResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int getVoiceRegistrationStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getDataRegistrationStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getOperatorResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setRadioPowerResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendSMSExpectMoreResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setupDataCallResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responseLen); + +int iccIOForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendUssdResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int cancelPendingUssdResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getClirResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, size_t responselen); + +int setClirResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, size_t responselen); + +int getCallForwardStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCallForwardResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getCallWaitingResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCallWaitingResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int acknowledgeLastIncomingGsmSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int acceptCallResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int deactivateDataCallResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getFacilityLockForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setFacilityLockForAppResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setBarringPasswordResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getNetworkSelectionModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setNetworkSelectionModeAutomaticResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setNetworkSelectionModeManualResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getAvailableNetworksResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int startNetworkScanResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int stopNetworkScanResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int startDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int stopDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getBasebandVersionResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int separateConnectionResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setMuteResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getMuteResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getClipResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getDataCallListResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int setSuppServiceNotificationsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int writeSmsToSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int deleteSmsOnSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setBandModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getAvailableBandModesResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendEnvelopeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendTerminalResponseToSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int handleStkCallSetupRequestFromSimResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int explicitCallTransferResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setPreferredNetworkTypeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getPreferredNetworkTypeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getNeighboringCidsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setLocationUpdatesResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCdmaSubscriptionSourceResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCdmaRoamingPreferenceResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getCdmaRoamingPreferenceResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setTTYModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getTTYModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setPreferredVoicePrivacyResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getPreferredVoicePrivacyResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendCDMAFeatureCodeResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int sendBurstDtmfResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int sendCdmaSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int acknowledgeLastIncomingCdmaSmsResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getGsmBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setGsmBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setGsmBroadcastActivationResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getCdmaBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCdmaBroadcastConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCdmaBroadcastActivationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getCDMASubscriptionResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int writeSmsToRuimResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int deleteSmsOnRuimResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getDeviceIdentityResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int exitEmergencyCallbackModeResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getSmscAddressResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int setCdmaBroadcastActivationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setSmscAddressResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int reportSmsMemoryStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int reportStkServiceIsRunningResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int getCdmaSubscriptionSourceResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int requestIsimAuthenticationResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int acknowledgeIncomingGsmSmsWithPduResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int sendEnvelopeWithStatusResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + +int getVoiceRadioTechnologyResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getCellInfoListResponse(int slotId, + int responseType, + int serial, RIL_Errno e, void *response, + size_t responseLen); + +int setCellInfoListRateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setInitialAttachApnResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getImsRegistrationStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int sendImsSmsResponse(int slotId, int responseType, + int serial, RIL_Errno e, void *response, size_t responselen); + +int iccTransmitApduBasicChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int iccOpenLogicalChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, void *response, + size_t responselen); + + +int iccCloseLogicalChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int iccTransmitApduLogicalChannelResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int nvReadItemResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + + +int nvWriteItemResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int nvWriteCdmaPrlResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int nvResetConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setUiccSubscriptionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setDataAllowedResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getHardwareConfigResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int requestIccSimAuthenticationResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setDataProfileResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int requestShutdownResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getRadioCapabilityResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int setRadioCapabilityResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int startLceServiceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int stopLceServiceResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int pullLceDataResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int getModemActivityInfoResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setAllowedCarriersResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int getAllowedCarriersResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int sendDeviceStateResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setIndicationFilterResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int setSimCardPowerResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int startKeepaliveResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +int stopKeepaliveResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responselen); + +void acknowledgeRequest(int slotId, int serial); + +int radioStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responseLen); + +int callStateChangedInd(int slotId, int indType, int token, + RIL_Errno e, void *response, size_t responselen); + +int networkStateChangedInd(int slotId, int indType, + int token, RIL_Errno e, void *response, size_t responselen); + +int newSmsInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int newSmsStatusReportInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int newSmsOnSimInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int onUssdInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int nitzTimeReceivedInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int currentSignalStrengthInd(int slotId, + int indicationType, int token, RIL_Errno e, + void *response, size_t responselen); + +int dataCallListChangedInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int suppSvcNotifyInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int stkSessionEndInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int stkProactiveCommandInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int stkEventNotifyInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int stkCallSetupInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int simSmsStorageFullInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int simRefreshInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int callRingInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int simStatusChangedInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int cdmaNewSmsInd(int slotId, int indicationType, + int token, RIL_Errno e, void *response, size_t responselen); + +int newBroadcastSmsInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int cdmaRuimSmsStorageFullInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int restrictedStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int enterEmergencyCallbackModeInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int cdmaCallWaitingInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int cdmaOtaProvisionStatusInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int cdmaInfoRecInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int oemHookRawInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int indicateRingbackToneInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int resendIncallMuteInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int cdmaSubscriptionSourceChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, + void *response, size_t responselen); + +int cdmaPrlChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int exitEmergencyCallbackModeInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int rilConnectedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int voiceRadioTechChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int cellInfoListInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int imsNetworkStateChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int subscriptionStatusChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int srvccStateNotifyInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int hardwareConfigChangedInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int radioCapabilityIndicationInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int onSupplementaryServiceIndicationInd(int slotId, + int indicationType, int token, RIL_Errno e, + void *response, size_t responselen); + +int stkCallControlAlphaNotifyInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int lceDataInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int pcoDataInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int modemResetInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int networkScanResultInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int keepaliveStatusInd(int slotId, + int indicationType, int token, RIL_Errno e, void *response, + size_t responselen); + +int sendRequestRawResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int sendRequestStringsResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int setCarrierInfoForImsiEncryptionResponse(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +int carrierInfoForImsiEncryption(int slotId, + int responseType, int serial, RIL_Errno e, + void *response, size_t responseLen); + +pthread_rwlock_t * getRadioServiceRwlock(int slotId); + +} // namespace radio + +#endif // RIL_SERVICE_H diff --git a/ril/libril/ril_unsol_commands.h b/ril/libril/ril_unsol_commands.h new file mode 100644 index 0000000..bd2cf70 --- /dev/null +++ b/ril/libril/ril_unsol_commands.h @@ -0,0 +1,66 @@ +/* //device/libs/telephony/ril_unsol_commands.h +** +** Copyright 2006, 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. +*/ + {RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, radio::radioStateChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, radio::callStateChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, radio::networkStateChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_NEW_SMS, radio::newSmsInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT, radio::newSmsStatusReportInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM, radio::newSmsOnSimInd, WAKE_PARTIAL}, + {RIL_UNSOL_ON_USSD, radio::onUssdInd, WAKE_PARTIAL}, + {RIL_UNSOL_ON_USSD_REQUEST, radio::onUssdInd, DONT_WAKE}, + {RIL_UNSOL_NITZ_TIME_RECEIVED, radio::nitzTimeReceivedInd, WAKE_PARTIAL}, + {RIL_UNSOL_SIGNAL_STRENGTH, radio::currentSignalStrengthInd, DONT_WAKE}, + {RIL_UNSOL_DATA_CALL_LIST_CHANGED, radio::dataCallListChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_SUPP_SVC_NOTIFICATION, radio::suppSvcNotifyInd, WAKE_PARTIAL}, + {RIL_UNSOL_STK_SESSION_END, radio::stkSessionEndInd, WAKE_PARTIAL}, + {RIL_UNSOL_STK_PROACTIVE_COMMAND, radio::stkProactiveCommandInd, WAKE_PARTIAL}, + {RIL_UNSOL_STK_EVENT_NOTIFY, radio::stkEventNotifyInd, WAKE_PARTIAL}, + {RIL_UNSOL_STK_CALL_SETUP, radio::stkCallSetupInd, WAKE_PARTIAL}, + {RIL_UNSOL_SIM_SMS_STORAGE_FULL, radio::simSmsStorageFullInd, WAKE_PARTIAL}, + {RIL_UNSOL_SIM_REFRESH, radio::simRefreshInd, WAKE_PARTIAL}, + {RIL_UNSOL_CALL_RING, radio::callRingInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, radio::simStatusChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_CDMA_NEW_SMS, radio::cdmaNewSmsInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS, radio::newBroadcastSmsInd, WAKE_PARTIAL}, + {RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL, radio::cdmaRuimSmsStorageFullInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESTRICTED_STATE_CHANGED, radio::restrictedStateChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE, radio::enterEmergencyCallbackModeInd, WAKE_PARTIAL}, + {RIL_UNSOL_CDMA_CALL_WAITING, radio::cdmaCallWaitingInd, WAKE_PARTIAL}, + {RIL_UNSOL_CDMA_OTA_PROVISION_STATUS, radio::cdmaOtaProvisionStatusInd, WAKE_PARTIAL}, + {RIL_UNSOL_CDMA_INFO_REC, radio::cdmaInfoRecInd, WAKE_PARTIAL}, + {RIL_UNSOL_OEM_HOOK_RAW, radio::oemHookRawInd, WAKE_PARTIAL}, + {RIL_UNSOL_RINGBACK_TONE, radio::indicateRingbackToneInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESEND_INCALL_MUTE, radio::resendIncallMuteInd, WAKE_PARTIAL}, + {RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED, radio::cdmaSubscriptionSourceChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_CDMA_PRL_CHANGED, radio::cdmaPrlChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE, radio::exitEmergencyCallbackModeInd, WAKE_PARTIAL}, + {RIL_UNSOL_RIL_CONNECTED, radio::rilConnectedInd, WAKE_PARTIAL}, + {RIL_UNSOL_VOICE_RADIO_TECH_CHANGED, radio::voiceRadioTechChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_CELL_INFO_LIST, radio::cellInfoListInd, WAKE_PARTIAL}, + {RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED, radio::imsNetworkStateChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED, radio::subscriptionStatusChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_SRVCC_STATE_NOTIFY, radio::srvccStateNotifyInd, WAKE_PARTIAL}, + {RIL_UNSOL_HARDWARE_CONFIG_CHANGED, radio::hardwareConfigChangedInd, WAKE_PARTIAL}, + {RIL_UNSOL_DC_RT_INFO_CHANGED, NULL, WAKE_PARTIAL}, + {RIL_UNSOL_RADIO_CAPABILITY, radio::radioCapabilityIndicationInd, WAKE_PARTIAL}, + {RIL_UNSOL_ON_SS, radio::onSupplementaryServiceIndicationInd, WAKE_PARTIAL}, + {RIL_UNSOL_STK_CC_ALPHA_NOTIFY, radio::stkCallControlAlphaNotifyInd, WAKE_PARTIAL}, + {RIL_UNSOL_LCEDATA_RECV, radio::lceDataInd, WAKE_PARTIAL}, + {RIL_UNSOL_PCO_DATA, radio::pcoDataInd, WAKE_PARTIAL}, + {RIL_UNSOL_MODEM_RESTART, radio::modemResetInd, WAKE_PARTIAL}, + {RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION, radio::carrierInfoForImsiEncryption, WAKE_PARTIAL}, + {RIL_UNSOL_NETWORK_SCAN_RESULT, radio::networkScanResultInd, WAKE_PARTIAL}, diff --git a/ril/libril/sap_service.cpp b/ril/libril/sap_service.cpp new file mode 100644 index 0000000..52ebd6c --- /dev/null +++ b/ril/libril/sap_service.cpp @@ -0,0 +1,965 @@ +/* + * Copyright (c) 2016 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. + */ + +#define LOG_TAG "RIL_SAP" + +#include + +#include +#include +#include +#include "pb_decode.h" +#include "pb_encode.h" + +using namespace android::hardware::radio::V1_0; +using ::android::hardware::Return; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_array; +using ::android::hardware::Void; +using android::CommandInfo; +using android::RequestInfo; +using android::requestToString; +using android::sp; + +struct SapImpl; + +#if (SIM_COUNT >= 2) +sp sapService[SIM_COUNT]; +#else +sp sapService[1]; +#endif + +struct SapImpl : public android::hardware::radio::V1_1::ISap { + int32_t slotId; + sp sapCallback; + RIL_SOCKET_ID rilSocketId; + + Return setCallback(const ::android::sp& sapCallbackParam); + + Return connectReq(int32_t token, int32_t maxMsgSize); + + Return disconnectReq(int32_t token); + + Return apduReq(int32_t token, SapApduType type, const hidl_vec& command); + + Return transferAtrReq(int32_t token); + + Return powerReq(int32_t token, bool state); + + Return resetSimReq(int32_t token); + + Return transferCardReaderStatusReq(int32_t token); + + Return setTransferProtocolReq(int32_t token, SapTransferProtocol transferProtocol); + + MsgHeader* createMsgHeader(MsgId msgId, int32_t token); + + Return addPayloadAndDispatchRequest(MsgHeader *msg, uint16_t reqLen, uint8_t *reqPtr); + + void sendFailedResponse(MsgId msgId, int32_t token, int numPointers, ...); + + void checkReturnStatus(Return& ret); +}; + +void SapImpl::checkReturnStatus(Return& ret) { + if (ret.isOk() == false) { + RLOGE("checkReturnStatus: unable to call response/indication callback: %s", + ret.description().c_str()); + // Remote process (SapRilReceiver.java) hosting the callback must be dead. Reset the + // callback object; there's no other recovery to be done here. When the client process is + // back up, it will call setCallback() + sapCallback = NULL; + } +} + +Return SapImpl::setCallback(const ::android::sp& sapCallbackParam) { + RLOGD("SapImpl::setCallback for slotId %d", slotId); + sapCallback = sapCallbackParam; + return Void(); +} + +MsgHeader* SapImpl::createMsgHeader(MsgId msgId, int32_t token) { + // Memory for msg will be freed by RilSapSocket::onRequestComplete() + MsgHeader *msg = (MsgHeader *)calloc(1, sizeof(MsgHeader)); + if (msg == NULL) { + return NULL; + } + msg->token = token; + msg->type = MsgType_REQUEST; + msg->id = msgId; + msg->error = Error_RIL_E_SUCCESS; + return msg; +} + +Return SapImpl::addPayloadAndDispatchRequest(MsgHeader *msg, uint16_t reqLen, + uint8_t *reqPtr) { + pb_bytes_array_t *payload = (pb_bytes_array_t *) malloc(sizeof(pb_bytes_array_t) - 1 + reqLen); + msg->payload = payload; + if (msg->payload == NULL) { + sendFailedResponse(msg->id, msg->token, 2, reqPtr, msg); + return Void(); + } + msg->payload->size = reqLen; + memcpy(msg->payload->bytes, reqPtr, reqLen); + + RilSapSocket *sapSocket = RilSapSocket::getSocketById(rilSocketId); + if (sapSocket) { + RLOGD("SapImpl::addPayloadAndDispatchRequest: calling dispatchRequest"); + sapSocket->dispatchRequest(msg); + } else { + RLOGE("SapImpl::addPayloadAndDispatchRequest: sapSocket is null"); + sendFailedResponse(msg->id, msg->token, 3, msg->payload, reqPtr, msg); + return Void(); + } + free(payload); + free(reqPtr); + return Void(); +} + +void SapImpl::sendFailedResponse(MsgId msgId, int32_t token, int numPointers, ...) { + va_list ap; + va_start(ap, numPointers); + for (int i = 0; i < numPointers; i++) { + void *ptr = va_arg(ap, void *); + if (ptr) free(ptr); + } + va_end(ap); + Return retStatus; + switch(msgId) { + case MsgId_RIL_SIM_SAP_CONNECT: + retStatus = sapCallback->connectResponse(token, SapConnectRsp::CONNECT_FAILURE, 0); + break; + + case MsgId_RIL_SIM_SAP_DISCONNECT: + retStatus = sapCallback->disconnectResponse(token); + break; + + case MsgId_RIL_SIM_SAP_APDU: { + hidl_vec apduRsp; + retStatus = sapCallback->apduResponse(token, SapResultCode::GENERIC_FAILURE, apduRsp); + break; + } + + case MsgId_RIL_SIM_SAP_TRANSFER_ATR: { + hidl_vec atr; + retStatus = sapCallback->transferAtrResponse(token, SapResultCode::GENERIC_FAILURE, + atr); + break; + } + + case MsgId_RIL_SIM_SAP_POWER: + retStatus = sapCallback->powerResponse(token, SapResultCode::GENERIC_FAILURE); + break; + + case MsgId_RIL_SIM_SAP_RESET_SIM: + retStatus = sapCallback->resetSimResponse(token, SapResultCode::GENERIC_FAILURE); + break; + + case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: + retStatus = sapCallback->transferCardReaderStatusResponse(token, + SapResultCode::GENERIC_FAILURE, 0); + break; + + case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: + retStatus = sapCallback->transferProtocolResponse(token, SapResultCode::NOT_SUPPORTED); + break; + + default: + return; + } + sapService[slotId]->checkReturnStatus(retStatus); +} + +Return SapImpl::connectReq(int32_t token, int32_t maxMsgSize) { + RLOGD("SapImpl::connectReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_CONNECT, token); + if (msg == NULL) { + RLOGE("SapImpl::connectReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_CONNECT_REQ *****/ + RIL_SIM_SAP_CONNECT_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_CONNECT_REQ)); + req.max_message_size = maxMsgSize; + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_CONNECT_REQ_fields, &req)) { + RLOGE("SapImpl::connectReq: Error getting encoded size for RIL_SIM_SAP_CONNECT_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::connectReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 1, msg); + return Void(); + } + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::connectReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_CONNECT_REQ_fields, &req)) { + RLOGE("SapImpl::connectReq: Error encoding RIL_SIM_SAP_CONNECT_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_CONNECT_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::disconnectReq(int32_t token) { + RLOGD("SapImpl::disconnectReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_DISCONNECT, token); + if (msg == NULL) { + RLOGE("SapImpl::disconnectReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_DISCONNECT_REQ *****/ + RIL_SIM_SAP_DISCONNECT_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_DISCONNECT_REQ)); + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_DISCONNECT_REQ_fields, &req)) { + RLOGE("SapImpl::disconnectReq: Error getting encoded size for RIL_SIM_SAP_DISCONNECT_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::disconnectReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 1, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::disconnectReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_DISCONNECT_REQ_fields, &req)) { + RLOGE("SapImpl::disconnectReq: Error encoding RIL_SIM_SAP_DISCONNECT_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_DISCONNECT_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::apduReq(int32_t token, SapApduType type, const hidl_vec& command) { + RLOGD("SapImpl::apduReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_APDU, token); + if (msg == NULL) { + RLOGE("SapImpl::apduReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_APDU_REQ *****/ + RIL_SIM_SAP_APDU_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_APDU_REQ)); + req.type = (RIL_SIM_SAP_APDU_REQ_Type)type; + + if (command.size() > 0) { + req.command = (pb_bytes_array_t *)malloc(sizeof(pb_bytes_array_t) - 1 + command.size()); + if (req.command == NULL) { + RLOGE("SapImpl::apduReq: Error allocating memory for req.command"); + sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 1, msg); + return Void(); + } + req.command->size = command.size(); + memcpy(req.command->bytes, command.data(), command.size()); + } + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_APDU_REQ_fields, &req)) { + RLOGE("SapImpl::apduReq: Error getting encoded size for RIL_SIM_SAP_APDU_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 2, req.command, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::apduReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 2, req.command, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::apduReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_APDU_REQ_fields, &req)) { + RLOGE("SapImpl::apduReq: Error encoding RIL_SIM_SAP_APDU_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 3, req.command, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_APDU_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::transferAtrReq(int32_t token) { + RLOGD("SapImpl::transferAtrReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token); + if (msg == NULL) { + RLOGE("SapImpl::transferAtrReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_TRANSFER_ATR_REQ *****/ + RIL_SIM_SAP_TRANSFER_ATR_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_TRANSFER_ATR_REQ)); + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_TRANSFER_ATR_REQ_fields, &req)) { + RLOGE("SapImpl::transferAtrReq: Error getting encoded size for " + "RIL_SIM_SAP_TRANSFER_ATR_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::transferAtrReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 1, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::transferAtrReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_TRANSFER_ATR_REQ_fields, &req)) { + RLOGE("SapImpl::transferAtrReq: Error encoding RIL_SIM_SAP_TRANSFER_ATR_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_TRANSFER_ATR_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::powerReq(int32_t token, bool state) { + RLOGD("SapImpl::powerReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_POWER, token); + if (msg == NULL) { + RLOGE("SapImpl::powerReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_POWER_REQ *****/ + RIL_SIM_SAP_POWER_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_POWER_REQ)); + req.state = state; + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_POWER_REQ_fields, &req)) { + RLOGE("SapImpl::powerReq: Error getting encoded size for RIL_SIM_SAP_POWER_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::powerReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 1, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::powerReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_POWER_REQ_fields, &req)) { + RLOGE("SapImpl::powerReq: Error encoding RIL_SIM_SAP_POWER_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_POWER_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::resetSimReq(int32_t token) { + RLOGD("SapImpl::resetSimReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_RESET_SIM, token); + if (msg == NULL) { + RLOGE("SapImpl::resetSimReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_RESET_SIM_REQ *****/ + RIL_SIM_SAP_RESET_SIM_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_RESET_SIM_REQ)); + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_RESET_SIM_REQ_fields, &req)) { + RLOGE("SapImpl::resetSimReq: Error getting encoded size for RIL_SIM_SAP_RESET_SIM_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::resetSimReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 1, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::resetSimReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_RESET_SIM_REQ_fields, &req)) { + RLOGE("SapImpl::resetSimReq: Error encoding RIL_SIM_SAP_RESET_SIM_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_RESET_SIM_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::transferCardReaderStatusReq(int32_t token) { + RLOGD("SapImpl::transferCardReaderStatusReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token); + if (msg == NULL) { + RLOGE("SapImpl::transferCardReaderStatusReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ *****/ + RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ)); + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ_fields, + &req)) { + RLOGE("SapImpl::transferCardReaderStatusReq: Error getting encoded size for " + "RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::transferCardReaderStatusReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 1, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::transferCardReaderStatusReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ_fields, &req)) { + RLOGE("SapImpl::transferCardReaderStatusReq: Error encoding " + "RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +Return SapImpl::setTransferProtocolReq(int32_t token, SapTransferProtocol transferProtocol) { + RLOGD("SapImpl::setTransferProtocolReq"); + MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token); + if (msg == NULL) { + RLOGE("SapImpl::setTransferProtocolReq: Error allocating memory for msg"); + sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 0); + return Void(); + } + + /***** Encode RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ *****/ + RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ req; + memset(&req, 0, sizeof(RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ)); + req.protocol = (RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_Protocol)transferProtocol; + + size_t encodedSize = 0; + if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_fields, &req)) { + RLOGE("SapImpl::setTransferProtocolReq: Error getting encoded size for " + "RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 1, msg); + return Void(); + } + + uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); + if (buffer == NULL) { + RLOGE("SapImpl::setTransferProtocolReq: Error allocating memory for buffer"); + sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 1, msg); + return Void(); + } + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); + + RLOGD("SapImpl::setTransferProtocolReq calling pb_encode"); + if (!pb_encode(&stream, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_fields, &req)) { + RLOGE("SapImpl::setTransferProtocolReq: Error encoding " + "RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ"); + sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 2, buffer, msg); + return Void(); + } + /***** Encode RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ done *****/ + + /* encoded req is payload */ + return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); +} + +void *sapDecodeMessage(MsgId msgId, MsgType msgType, uint8_t *payloadPtr, size_t payloadLen) { + void *responsePtr = NULL; + pb_istream_t stream; + + /* Create the stream */ + stream = pb_istream_from_buffer((uint8_t *)payloadPtr, payloadLen); + + /* Decode based on the message id */ + switch (msgId) + { + case MsgId_RIL_SIM_SAP_CONNECT: + responsePtr = malloc(sizeof(RIL_SIM_SAP_CONNECT_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_CONNECT_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_CONNECT_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_DISCONNECT: + if (msgType == MsgType_RESPONSE) { + responsePtr = malloc(sizeof(RIL_SIM_SAP_DISCONNECT_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_DISCONNECT_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_DISCONNECT_RSP"); + return NULL; + } + } + } else { + responsePtr = malloc(sizeof(RIL_SIM_SAP_DISCONNECT_IND)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_DISCONNECT_IND_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_DISCONNECT_IND"); + return NULL; + } + } + } + break; + + case MsgId_RIL_SIM_SAP_APDU: + responsePtr = malloc(sizeof(RIL_SIM_SAP_APDU_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_APDU_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_APDU_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_TRANSFER_ATR: + responsePtr = malloc(sizeof(RIL_SIM_SAP_TRANSFER_ATR_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_TRANSFER_ATR_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_TRANSFER_ATR_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_POWER: + responsePtr = malloc(sizeof(RIL_SIM_SAP_POWER_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_POWER_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_POWER_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_RESET_SIM: + responsePtr = malloc(sizeof(RIL_SIM_SAP_RESET_SIM_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_RESET_SIM_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_RESET_SIM_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_STATUS: + responsePtr = malloc(sizeof(RIL_SIM_SAP_STATUS_IND)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_STATUS_IND_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_STATUS_IND"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: + responsePtr = malloc(sizeof(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_fields, + responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_ERROR_RESP: + responsePtr = malloc(sizeof(RIL_SIM_SAP_ERROR_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_ERROR_RSP_fields, responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_ERROR_RSP"); + return NULL; + } + } + break; + + case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: + responsePtr = malloc(sizeof(RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP)); + if (responsePtr) { + if (!pb_decode(&stream, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP_fields, + responsePtr)) { + RLOGE("Error decoding RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP"); + return NULL; + } + } + break; + + default: + break; + } + return responsePtr; +} /* sapDecodeMessage */ + +sp getSapImpl(RilSapSocket *sapSocket) { + switch (sapSocket->getSocketId()) { + case RIL_SOCKET_1: + RLOGD("getSapImpl: returning sapService[0]"); + return sapService[0]; + #if (SIM_COUNT >= 2) + case RIL_SOCKET_2: + return sapService[1]; + #if (SIM_COUNT >= 3) + case RIL_SOCKET_3: + return sapService[2]; + #if (SIM_COUNT >= 4) + case RIL_SOCKET_4: + return sapService[3]; + #endif + #endif + #endif + default: + return NULL; + } +} + +SapResultCode convertApduResponseProtoToHal(RIL_SIM_SAP_APDU_RSP_Response responseProto) { + switch(responseProto) { + case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SUCCESS: + return SapResultCode::SUCCESS; + case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_GENERIC_FAILURE: + return SapResultCode::GENERIC_FAILURE; + case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_NOT_READY: + return SapResultCode::CARD_NOT_ACCESSSIBLE; + case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: + return SapResultCode::CARD_ALREADY_POWERED_OFF; + case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_ABSENT: + return SapResultCode::CARD_REMOVED; + default: + return SapResultCode::GENERIC_FAILURE; + } +} + +SapResultCode convertTransferAtrResponseProtoToHal( + RIL_SIM_SAP_TRANSFER_ATR_RSP_Response responseProto) { + switch(responseProto) { + case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SUCCESS: + return SapResultCode::SUCCESS; + case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_GENERIC_FAILURE: + return SapResultCode::GENERIC_FAILURE; + case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: + return SapResultCode::CARD_ALREADY_POWERED_OFF; + case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_ABSENT: + return SapResultCode::CARD_REMOVED; + case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_DATA_NOT_AVAILABLE: + return SapResultCode::DATA_NOT_AVAILABLE; + default: + return SapResultCode::GENERIC_FAILURE; + } +} + +SapResultCode convertPowerResponseProtoToHal(RIL_SIM_SAP_POWER_RSP_Response responseProto) { + switch(responseProto) { + case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SUCCESS: + return SapResultCode::SUCCESS; + case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_GENERIC_FAILURE: + return SapResultCode::GENERIC_FAILURE; + case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ABSENT: + return SapResultCode::CARD_REMOVED; + case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: + return SapResultCode::CARD_ALREADY_POWERED_OFF; + case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ALREADY_POWERED_ON: + return SapResultCode::CARD_ALREADY_POWERED_ON; + default: + return SapResultCode::GENERIC_FAILURE; + } +} + +SapResultCode convertResetSimResponseProtoToHal(RIL_SIM_SAP_RESET_SIM_RSP_Response responseProto) { + switch(responseProto) { + case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SUCCESS: + return SapResultCode::SUCCESS; + case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_GENERIC_FAILURE: + return SapResultCode::GENERIC_FAILURE; + case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_ABSENT: + return SapResultCode::CARD_REMOVED; + case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_NOT_READY: + return SapResultCode::CARD_NOT_ACCESSSIBLE; + case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: + return SapResultCode::CARD_ALREADY_POWERED_OFF; + } + return SapResultCode::GENERIC_FAILURE; +} + +SapResultCode convertTransferCardReaderStatusResponseProtoToHal( + RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response responseProto) { + switch(responseProto) { + case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_SUCCESS: + return SapResultCode::SUCCESS; + case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_GENERIC_FAILURE: + return SapResultCode::GENERIC_FAILURE; + case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_SIM_DATA_NOT_AVAILABLE: + return SapResultCode::DATA_NOT_AVAILABLE; + } + return SapResultCode::GENERIC_FAILURE; +} + +void processResponse(MsgHeader *rsp, RilSapSocket *sapSocket, MsgType msgType) { + MsgId msgId = rsp->id; + uint8_t *data = rsp->payload->bytes; + size_t dataLen = rsp->payload->size; + + void *messagePtr = sapDecodeMessage(msgId, msgType, data, dataLen); + + sp sapImpl = getSapImpl(sapSocket); + if (sapImpl->sapCallback == NULL) { + RLOGE("processResponse: sapCallback == NULL; msgId = %d; msgType = %d", + msgId, msgType); + return; + } + + if (messagePtr == NULL) { + RLOGE("processResponse: *messagePtr == NULL; msgId = %d; msgType = %d", + msgId, msgType); + sapImpl->sendFailedResponse(msgId, rsp->token, 0); + return; + } + + RLOGD("processResponse: sapCallback != NULL; msgId = %d; msgType = %d", + msgId, msgType); + + Return retStatus; + switch (msgId) { + case MsgId_RIL_SIM_SAP_CONNECT: { + RIL_SIM_SAP_CONNECT_RSP *connectRsp = (RIL_SIM_SAP_CONNECT_RSP *)messagePtr; + RLOGD("processResponse: calling sapCallback->connectResponse %d %d %d", + rsp->token, + connectRsp->response, + connectRsp->max_message_size); + retStatus = sapImpl->sapCallback->connectResponse(rsp->token, + (SapConnectRsp)connectRsp->response, + connectRsp->max_message_size); + break; + } + + case MsgId_RIL_SIM_SAP_DISCONNECT: + if (msgType == MsgType_RESPONSE) { + RLOGD("processResponse: calling sapCallback->disconnectResponse %d", rsp->token); + retStatus = sapImpl->sapCallback->disconnectResponse(rsp->token); + } else { + RIL_SIM_SAP_DISCONNECT_IND *disconnectInd = + (RIL_SIM_SAP_DISCONNECT_IND *)messagePtr; + RLOGD("processResponse: calling sapCallback->disconnectIndication %d %d", + rsp->token, disconnectInd->disconnectType); + retStatus = sapImpl->sapCallback->disconnectIndication(rsp->token, + (SapDisconnectType)disconnectInd->disconnectType); + } + break; + + case MsgId_RIL_SIM_SAP_APDU: { + RIL_SIM_SAP_APDU_RSP *apduRsp = (RIL_SIM_SAP_APDU_RSP *)messagePtr; + SapResultCode apduResponse = convertApduResponseProtoToHal(apduRsp->response); + RLOGD("processResponse: calling sapCallback->apduResponse %d %d", + rsp->token, apduResponse); + hidl_vec apduRspVec; + if (apduRsp->apduResponse != NULL && apduRsp->apduResponse->size > 0) { + apduRspVec.setToExternal(apduRsp->apduResponse->bytes, apduRsp->apduResponse->size); + } + retStatus = sapImpl->sapCallback->apduResponse(rsp->token, apduResponse, apduRspVec); + break; + } + + case MsgId_RIL_SIM_SAP_TRANSFER_ATR: { + RIL_SIM_SAP_TRANSFER_ATR_RSP *transferAtrRsp = + (RIL_SIM_SAP_TRANSFER_ATR_RSP *)messagePtr; + SapResultCode transferAtrResponse = + convertTransferAtrResponseProtoToHal(transferAtrRsp->response); + RLOGD("processResponse: calling sapCallback->transferAtrResponse %d %d", + rsp->token, transferAtrResponse); + hidl_vec transferAtrRspVec; + if (transferAtrRsp->atr != NULL && transferAtrRsp->atr->size > 0) { + transferAtrRspVec.setToExternal(transferAtrRsp->atr->bytes, + transferAtrRsp->atr->size); + } + retStatus = sapImpl->sapCallback->transferAtrResponse(rsp->token, transferAtrResponse, + transferAtrRspVec); + break; + } + + case MsgId_RIL_SIM_SAP_POWER: { + SapResultCode powerResponse = convertPowerResponseProtoToHal( + ((RIL_SIM_SAP_POWER_RSP *)messagePtr)->response); + RLOGD("processResponse: calling sapCallback->powerResponse %d %d", + rsp->token, powerResponse); + retStatus = sapImpl->sapCallback->powerResponse(rsp->token, powerResponse); + break; + } + + case MsgId_RIL_SIM_SAP_RESET_SIM: { + SapResultCode resetSimResponse = convertResetSimResponseProtoToHal( + ((RIL_SIM_SAP_RESET_SIM_RSP *)messagePtr)->response); + RLOGD("processResponse: calling sapCallback->resetSimResponse %d %d", + rsp->token, resetSimResponse); + retStatus = sapImpl->sapCallback->resetSimResponse(rsp->token, resetSimResponse); + break; + } + + case MsgId_RIL_SIM_SAP_STATUS: { + RIL_SIM_SAP_STATUS_IND *statusInd = (RIL_SIM_SAP_STATUS_IND *)messagePtr; + RLOGD("processResponse: calling sapCallback->statusIndication %d %d", + rsp->token, statusInd->statusChange); + retStatus = sapImpl->sapCallback->statusIndication(rsp->token, + (SapStatus)statusInd->statusChange); + break; + } + + case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: { + RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP *transferStatusRsp = + (RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP *)messagePtr; + SapResultCode transferCardReaderStatusResponse = + convertTransferCardReaderStatusResponseProtoToHal( + transferStatusRsp->response); + RLOGD("processResponse: calling sapCallback->transferCardReaderStatusResponse %d %d %d", + rsp->token, + transferCardReaderStatusResponse, + transferStatusRsp->CardReaderStatus); + retStatus = sapImpl->sapCallback->transferCardReaderStatusResponse(rsp->token, + transferCardReaderStatusResponse, + transferStatusRsp->CardReaderStatus); + break; + } + + case MsgId_RIL_SIM_SAP_ERROR_RESP: { + RLOGD("processResponse: calling sapCallback->errorResponse %d", rsp->token); + retStatus = sapImpl->sapCallback->errorResponse(rsp->token); + break; + } + + case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: { + SapResultCode setTransferProtocolResponse; + if (((RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP *)messagePtr)->response == + RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP_Response_RIL_E_SUCCESS) { + setTransferProtocolResponse = SapResultCode::SUCCESS; + } else { + setTransferProtocolResponse = SapResultCode::NOT_SUPPORTED; + } + RLOGD("processResponse: calling sapCallback->transferProtocolResponse %d %d", + rsp->token, setTransferProtocolResponse); + retStatus = sapImpl->sapCallback->transferProtocolResponse(rsp->token, + setTransferProtocolResponse); + break; + } + + default: + return; + } + sapImpl->checkReturnStatus(retStatus); +} + +void sap::processResponse(MsgHeader *rsp, RilSapSocket *sapSocket) { + processResponse(rsp, sapSocket, MsgType_RESPONSE); +} + +void sap::processUnsolResponse(MsgHeader *rsp, RilSapSocket *sapSocket) { + processResponse(rsp, sapSocket, MsgType_UNSOL_RESPONSE); +} + +void sap::registerService(RIL_RadioFunctions *callbacks) { + using namespace android::hardware; + int simCount = 1; + const char *serviceNames[] = { + android::RIL_getServiceName() + #if (SIM_COUNT >= 2) + , RIL2_SERVICE_NAME + #if (SIM_COUNT >= 3) + , RIL3_SERVICE_NAME + #if (SIM_COUNT >= 4) + , RIL4_SERVICE_NAME + #endif + #endif + #endif + }; + + RIL_SOCKET_ID socketIds[] = { + RIL_SOCKET_1 + #if (SIM_COUNT >= 2) + , RIL_SOCKET_2 + #if (SIM_COUNT >= 3) + , RIL_SOCKET_3 + #if (SIM_COUNT >= 4) + , RIL_SOCKET_4 + #endif + #endif + #endif + }; + #if (SIM_COUNT >= 2) + simCount = SIM_COUNT; + #endif + + for (int i = 0; i < simCount; i++) { + sapService[i] = new SapImpl; + sapService[i]->slotId = i; + sapService[i]->rilSocketId = socketIds[i]; + RLOGD("registerService: starting ISap %s for slotId %d", serviceNames[i], i); + android::status_t status = sapService[i]->registerAsService(serviceNames[i]); + RLOGD("registerService: started ISap %s status %d", serviceNames[i], status); + } +} diff --git a/ril/libril/sap_service.h b/ril/libril/sap_service.h new file mode 100644 index 0000000..afed612 --- /dev/null +++ b/ril/libril/sap_service.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 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. + */ + +#ifndef SAP_SERVICE_H +#define SAP_SERVICE_H + +#include +#include +#include +#include + +namespace sap { + +void registerService(RIL_RadioFunctions *callbacks); +void processResponse(MsgHeader *rsp, RilSapSocket *sapSocket); +void processUnsolResponse(MsgHeader *rsp, RilSapSocket *sapSocket); + +} // namespace android + +#endif // RIL_SERVICE_H \ No newline at end of file diff --git a/rootdir/Android.mk b/rootdir/Android.mk new file mode 100644 index 0000000..c687a5f --- /dev/null +++ b/rootdir/Android.mk @@ -0,0 +1,71 @@ +LOCAL_PATH:= $(call my-dir) + +# Configuration scripts + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.bt.sh +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.qcom.bt.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.ril.sh +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.ril.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.firmware.sh +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.firmware.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +# Init scripts + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.rc +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := init.qcom.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.power.rc +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := init.qcom.power.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.usb.rc +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := init.qcom.usb.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +# Copy the power config for recovery too +include $(CLEAR_VARS) +LOCAL_MODULE := init.recovery.qcom.rc +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := init.qcom.power.rc +LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := ueventd.qcom.rc +LOCAL_MODULE_STEM := ueventd.rc +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := ueventd.qcom.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR) +include $(BUILD_PREBUILT) diff --git a/rootdir/etc/init.firmware.sh b/rootdir/etc/init.firmware.sh new file mode 100644 index 0000000..0f59856 --- /dev/null +++ b/rootdir/etc/init.firmware.sh @@ -0,0 +1,40 @@ +#!/vendor/bin/sh + +LOG_TAG="fwscript" + +function print_log() +{ + echo "<$1>$2: $3" >> /dev/kmsg +} + +# Remount /system to read and write state +mount -o remount,rw /system +if [ $? -ne 0 ] +then + print_log 3 $LOG_TAG "Remount /system to rw state failed!" + exit 1 +fi + +# Detect on first start if we need firmware fix or not +if [ -f "/system/etc/firmware/a300_pm4.fw" ] +then + print_log 5 $LOG_TAG "Symlink already created, skip..." +else + ln -sf /vendor/etc/firmware /system/etc/firmware + if [ $? -ne 0 ] + then + print_log 3 $LOG_TAG "Failed to create symlink to /system/etc!" + fi +fi + +# Remount /system to read only state +mount -o remount,ro /system + +if [ $? -ne 0 ] +then + print_log 3 $LOG_TAG "Remount /system to ro state failed!" + exit 1 +else + print_log 5 $LOG_TAG "Script successfully done." + exit 0 +fi diff --git a/rootdir/etc/init.qcom.bt.sh b/rootdir/etc/init.qcom.bt.sh new file mode 100644 index 0000000..5f62860 --- /dev/null +++ b/rootdir/etc/init.qcom.bt.sh @@ -0,0 +1,68 @@ +#!/system/bin/sh + +LOG_TAG="qcom-bluetooth" +LOG_NAME="${0}:" + +loge () +{ + /vendor/bin/log -t $LOG_TAG -p e "$LOG_NAME $@" +} + +logi () +{ + /vendor/bin/log -t $LOG_TAG -p i "$LOG_NAME $@" +} + +failed () +{ + loge "$1: exit code $2" + exit $2 +} + +setprop ro.qualcomm.bt.hci_transport smd + +# Note that "hci_qcomm_init -e" prints expressions to set the shell variables +# BTS_DEVICE, BTS_TYPE, BTS_BAUD, and BTS_ADDRESS. + +# BR/EDR & LE power class configurations +POWER_CLASS=`getprop qcom.bt.dev_power_class` +LE_POWER_CLASS=`getprop qcom.bt.le_dev_pwr_class` + +setprop bluetooth.status off + +case $POWER_CLASS in + 1) PWR_CLASS="-p 0" ; + logi "Power Class: 1";; + 2) PWR_CLASS="-p 1" ; + logi "Power Class: 2";; + 3) PWR_CLASS="-p 2" ; + logi "Power Class: CUSTOM";; + *) PWR_CLASS=""; + logi "Power Class: Ignored. Default(1) used (1-CLASS1/2-CLASS2/3-CUSTOM)"; + logi "Power Class: To override, Before turning BT ON; setprop qcom.bt.dev_power_class <1 or 2 or 3>";; +esac + +case $LE_POWER_CLASS in + 1) LE_PWR_CLASS="-P 0" ; + logi "LE Power Class: 1";; + 2) LE_PWR_CLASS="-P 1" ; + logi "LE Power Class: 2";; + 3) LE_PWR_CLASS="-P 2" ; + logi "LE Power Class: CUSTOM";; + *) LE_PWR_CLASS="-P 1"; + logi "LE Power Class: Ignored. Default(2) used (1-CLASS1/2-CLASS2/3-CUSTOM)"; + logi "LE Power Class: To override, Before turning BT ON; setprop qcom.bt.le_dev_pwr_class <1 or 2 or 3>";; +esac + +eval $(/vendor/bin/hci_qcomm_init -e $PWR_CLASS $LE_PWR_CLASS && echo "exit_code_hci_qcomm_init=0" || echo "exit_code_hci_qcomm_init=1") + +case $exit_code_hci_qcomm_init in + 0) logi "Bluetooth QSoC firmware download succeeded, $BTS_DEVICE $BTS_TYPE $BTS_BAUD $BTS_ADDRESS";; + *) failed "Bluetooth QSoC firmware download failed" $exit_code_hci_qcomm_init; + setprop bluetooth.status off + exit $exit_code_hci_qcomm_init;; +esac + +setprop bluetooth.status on + +exit 0 diff --git a/rootdir/etc/init.ril.sh b/rootdir/etc/init.ril.sh new file mode 100644 index 0000000..ddbcd44 --- /dev/null +++ b/rootdir/etc/init.ril.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -rf /data/user_de/0/com.android.providers.telephony/databases/telephony.db* +rm -rf /data/user_de/0/com.android.providers.telephony/shared_prefs diff --git a/rootdir/init.qcom.power.rc b/rootdir/init.qcom.power.rc new file mode 100644 index 0000000..eaef84b --- /dev/null +++ b/rootdir/init.qcom.power.rc @@ -0,0 +1,73 @@ +on init + + # HMP scheduler settings + write /proc/sys/kernel/sched_ravg_hist_size 3 + write /proc/sys/kernel/sched_window_stats_policy 3 + + # HMP Task packing settings for 8226 + write /proc/sys/kernel/sched_small_task 50 + + # disable thermal core_control to update interactive governor settings + write /sys/module/msm_thermal/core_control/enabled 0 + + # Switch to interactive and let PowerHAL configure it + write /sys/devices/system/cpu/cpu0/online 1 + write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "interactive" + chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse + chmod 0644 /sys/devices/system/cpu/cpufreq/interactive/boostpulse + chown system system /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + chown system system /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + chown system system /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + chmod 0644 /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + chown system system /sys/devices/system/cpu/cpufreq/interactive/timer_rate + chmod 0644 /sys/devices/system/cpu/cpufreq/interactive/timer_rate + chown system system /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + chmod 0644 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + chown system system /sys/devices/system/cpu/cpufreq/interactive/target_loads + chmod 0644 /sys/devices/system/cpu/cpufreq/interactive/target_loads + chown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # enable thermal core_control now + write /sys/module/msm_thermal/core_control/enabled 1 + + # bring all CPUs online + write /sys/devices/system/cpu/cpu1/online 1 + write /sys/devices/system/cpu/cpu2/online 1 + write /sys/devices/system/cpu/cpu3/online 1 + + # Enable low power modes + write /sys/module/lpm_levels/parameters/sleep_disabled 0 + + # Set RPS mask + write /sys/class/net/rmnet0/queues/rx-0/rps_cpus 2 + + # add a cpuset for the camera daemon + # we want all the cores for camera + mkdir /dev/cpuset/camera-daemon + chown system system /dev/cpuset/camera-daemon + chown system system /dev/cpuset/camera-daemon/tasks + chmod 0664 /dev/cpuset/camera-daemon/tasks + + # Update foreground and background cpusets + # Reserve CPU 3 for the top app + write /dev/cpuset/foreground/cpus 0-2 + write /dev/cpuset/background/cpus 0-2 + write /dev/cpuset/system-background/cpus 0-1 + write /dev/cpuset/top-app/cpus 0-3 + write /dev/cpuset/camera-daemon/cpus 0-3 + +on charger + write /sys/module/lpm_levels/parameters/sleep_disabled 0 + write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "powersave" + +on class_start:late_start + trigger enable-low-power + +on property:init.svc.recovery=running + trigger enable-low-power + +on property:dev.bootcomplete=1 + setprop sys.io.scheduler "bfq" diff --git a/rootdir/init.qcom.rc b/rootdir/init.qcom.rc new file mode 100644 index 0000000..82e6b85 --- /dev/null +++ b/rootdir/init.qcom.rc @@ -0,0 +1,743 @@ +# Copyright (c) 2009-2012, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +import /vendor/etc/init/hw/init.qcom.power.rc +import /vendor/etc/init/hw/init.qcom.usb.rc +import /vendor/etc/init/hw/init.target.rc + +on early-init + + mount debugfs debugfs /sys/kernel/debug + chmod 0755 /sys/kernel/debug + + mkdir /firmware 0771 system system + mkdir /firmware-modem 0771 system system + + mkdir /persist 0771 system system + + mkdir /efs 0771 system radio + + symlink /data/tombstones /tombstones + +on init + + # Support legacy paths + symlink /sdcard /mnt/sdcard + symlink /sdcard /storage/sdcard0 + +on fs + wait /dev/block/platform/soc.0/${ro.boot.bootdevice} + symlink /dev/block/platform/soc.0/${ro.boot.bootdevice} /dev/block/bootdevice + + mount_all /vendor/etc/fstab.qcom + start fwlink + + # Support Preload install apks + # mkdir /preload 0771 system system + # wait /dev/block/platform/msm_sdcc.1/by-name/hidden + # mount ext4 /dev/block/platform/msm_sdcc.1/by-name/hidden /preload nosuid nodev ro barrier=1 + # setprop storage.preload.complete 1 + + #restorecon_recursive /efs + #restorecon_recursive /persist + + mkdir /persist/data 0700 system system + mkdir /persist/data/sfs 0700 system system + mkdir /persist/data/tz 0700 system system + + write /sys/kernel/boot_adsp/boot 1 + setprop qcom.audio.init complete + + # Kickstart the Wireless subsystem + write /dev/wcnss_wlan 1 + +on post-fs-data + # Fix headset h2w switch not recognized (theres no sammy phone with qcom + treble yet #FIRST #WINNER :D ) + setprop persist.sys.overlay.devinputjack false + + # Create the directories used by CnE subsystem + mkdir /data/connectivity 0771 system system + chown system system /data/connectivity + + # For WIFI TRP/TIS + chown system root /data/.psm.info + chmod 0664 /data/.psm.info + + # For WIFI Antena Selection + chown system root /data/.ant.info + chmod 0664 /data/.ant.info + + # For WIFI Version + write /data/.wifiver.info 0 + chown system root /data/.wifiver.info + chmod 0664 /data/.wifiver.info + + # For WIFI Cert + chmod 0664 /data/.bustxglom.info + chmod 0664 /data/.roamoff.info + chmod 0664 /data/.frameburst.info + chmod 0664 /data/.txbf.info + + # For WIFI MAC address + mkdir /efs/wifi 0775 radio system + chown system wifi /efs/wifi/.mac.info + chmod 0660 /efs/wifi/.mac.info + #restorecon /efs/wifi/.mac.info + chmod 0660 /efs/wifi/.mac.cob + + # Create directory used by audio subsystem + mkdir /data/misc/audio 0770 audio audio + + # Create directory used by radio subsystem + mkdir /data/radio 0770 radio radio + + # Create directory used by the DASH client + mkdir /data/misc/dash 0770 media audio + + # Mounting of persist is moved to 'on emmc-fs' and 'on fs' sections + # We chown/chmod /persist again so because mount is run as root + defaults + chown system system /persist + chmod 0771 /persist + chmod 0664 /sys/devices/platform/msm_sdcc.1/polling + chmod 0664 /sys/devices/platform/msm_sdcc.2/polling + chmod 0664 /sys/devices/platform/msm_sdcc.3/polling + chmod 0664 /sys/devices/platform/msm_sdcc.4/polling + + # Chown polling nodes as needed from UI running on system server + chown system system /sys/devices/platform/msm_sdcc.1/polling + chown system system /sys/devices/platform/msm_sdcc.2/polling + chown system system /sys/devices/platform/msm_sdcc.3/polling + chown system system /sys/devices/platform/msm_sdcc.4/polling + + # Create directories for Location services + mkdir /data/misc/location 0770 gps gps + mkdir /data/misc/location/gpsone_d 0770 system gps + mkdir /data/misc/location/mq 0770 gps gps + mkdir /data/misc/location/quipc 0770 system gps + mkdir /data/misc/location/xtwifi 0770 gps gps + + # Create directory from IMS services + mkdir /data/shared 0755 + chown system system /data/shared + + # Create directory for FOTA + mkdir /data/fota 0771 + chown system system /data/fota + + # Create /data/time folder for time-services + mkdir /data/time/ 0700 system system + + # Enable the setgid bit on the directory + mkdir /data/bluetooth 0770 bluetooth bluetooth + chmod 2770 /data/bluetooth + + # Enable the setgid bit on the directory + mkdir /data/audio/ 0770 media audio + chmod 2770 /data/audio + + # Create a folder for SRS to be able to create a usercfg file + mkdir /data/data/media 0770 media media + + # Gpio DVS + chown radio system /sys/class/secgpio_check/secgpio_check_all/secgpio_ctrl + + # Create thombstone folders + mkdir /data/tombstones 0771 system system + mkdir /tombstones/modem 0771 system system + mkdir /tombstones/lpass 0771 system system + mkdir /tombstones/wcnss 0771 system system + mkdir /tombstones/dsps 0771 system system + mkdir /tombstones/mdm 0771 system system + + # Create directory for ril data + mkdir /data/misc/radio 0775 radio radio + mkdir /data/misc/radio/hatp 0775 radio system + + # DRM and related files in EFS + mkdir /efs/drm 0774 drm system + mkdir /efs/drm/sdrm 0774 drm system + mkdir /efs/drm/sdrm/data_agent 0774 drm system + #restorecon /efs/drm + #restorecon /efs/drm/sdrm + #restorecon /efs/drm/sdrm/data_agent + + # DivX DRM + mkdir /efs/.files 0775 + mkdir /efs/.files/.dx1 0775 + mkdir /efs/.files/.dm33 0775 + mkdir /efs/.files/.mp301 0775 + chown media system /efs/.files/.dx1 + chown media system /efs/.files/.dm33 + chown media system /efs/.files/.mp301 + chmod 0775 /efs/.files/.dx1 + chmod 0775 /efs/.files/.dm33 + chmod 0775 /efs/.files/.mp301 + + # DRK permission + mkdir /efs/prov 0770 radio system + chown radio system /efs/prov/libdevkm.lock + chmod 0660 /efs/prov/libdevkm.lock + + # ICD + chown system system /dev/icd + chmod 0644 /dev/icd + chown system system /dev/icdr + chmod 0644 /dev/icdr + chown system system /dev/tzic + + # Symlink to bugreport storage location + symlink /data/data/com.android.shell/files/bugreports /data/bugreports + + # Remove symlinks to avoid issues with migrate after nandroid restores + # Will be recreated at end of boot + rm /data/data/com.android.providers.telephony/databases + rm /data/data/com.android.providers.telephony/shared_prefs + + # Remove the current apn as sometimes after a reboot it cant connect to 3g + # It will be regenerated by the system + rmdir /data/user_de/0/com.android.providers.telephony/shared_prefs + + setprop vold.post_fs_data_done 1 + +on early-boot + # Set RLIMIT_MEMLOCK to 64MB + setrlimit 8 67108864 67108864 + + # Allow subsystem (modem etc) debugging + write /sys/module/subsystem_restart/parameters/enable_debug ${persist.sys.ssr.enable_debug} + +on boot + mount debugfs /sys/kernel/debug /sys/kernel/debug + + # Permissions for bluetooth + mkdir /efs/bluetooth 0775 radio system + setprop ro.bt.bdaddr_path "/efs/bluetooth/bt_addr" + chown bluetooth radio ro.bt.bdaddr_path + chown radio bluetooth /efs/bluetooth/bt_addr + chmod 0755 /efs/bluetooth/bt_addr + #restorecon_recursive /efs/bluetooth + + # IMEI + mkdir /efs/imei 0775 radio radio + + # Create QMUX deamon socket area + mkdir /dev/socket/qmux_radio 0770 radio radio + chmod 2770 /dev/socket/qmux_radio + mkdir /dev/socket/qmux_audio 0770 media audio + chmod 2770 /dev/socket/qmux_audio + mkdir /dev/socket/qmux_bluetooth 0770 bluetooth bluetooth + chmod 2770 /dev/socket/qmux_bluetooth + mkdir /dev/socket/qmux_gps 0770 gps gps + chmod 2770 /dev/socket/qmux_gps + + # Allow QMUX daemon to assign port open wait time + chown radio radio /sys/devices/virtual/hsicctl/hsicctl0/modem_wait + + # Modem requires this + chown root radio /proc/cmdline + chmod 0644 /proc/cmdline + + # Remove SUID bit for iproute2 ip tool + chmod 0755 /system/bin/ip + + # For bridgemgr daemon to inform the USB driver of the correct transport + chown radio radio /sys/class/android_usb/f_rmnet_smd_sdio/transport + + # Allow RIL daemon to assign port open fd_wakelock + chown system radio /sys/devices/virtual/sec/mdm_hsic_pm/waketime + + # To allow interfaces to get v6 address when tethering is enabled + write /proc/sys/net/ipv6/conf/rmnet0/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet1/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet2/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet3/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet4/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet5/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet6/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet7/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio0/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio1/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio2/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio3/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio4/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio5/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio6/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_sdio7/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_usb0/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_usb1/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_usb2/accept_ra 2 + write /proc/sys/net/ipv6/conf/rmnet_usb3/accept_ra 2 + + # To prevent out of order acknowledgements from making + # connection tracking to treat them as not belonging to + # the connection they belong to. + # Otherwise, a weird issue happens in which some long + # connections on high-throughput links get dropped when + # an ack packet comes out of order + write /proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal 1 + + # Set the console loglevel to < KERN_INFO + # Set the default message loglevel to KERN_INFO + # modified by SEC, SEC use a loglevel path with another way. + # write /proc/sys/kernel/printk "6 6 1 7" + + # Flash storage isn't a good entropy source, and only causes locking + # overhead in the kernel. Turn it off. + write /sys/block/mmcblk0/queue/add_random 0 + + # MUIC + chown system radio /sys/class/sec/switch/adc + chown system radio /sys/class/sec/switch/reset_switch + chown radio system /sys/class/sec/switch/usb_state + + chown radio system /sys/devices/system/cpu/kernel_max + chmod 664 /sys/devices/system/cpu/kernel_max + + chown radio system /sys/class/kgsl/kgsl-3d0/max_pwrlevel + chmod 664 /sys/class/kgsl/kgsl-3d0/max_pwrlevel + chown radio system /sys/class/kgsl/kgsl-3d0/min_pwrlevel + chmod 664 /sys/class/kgsl/kgsl-3d0/min_pwrlevel + chown radio system /sys/class/kgsl/kgsl-3d0/gpu_available_frequencies + chmod 664 /sys/class/kgsl/kgsl-3d0/gpu_available_frequencies + + chown radio system /sys/class/devfreq/qcom,cpubw.68/available_frequencies + chmod 664 /sys/class/devfreq/qcom,cpubw.68/available_frequencies + chown radio system /sys/class/devfreq/qcom,cpubw.68/available_governors + chmod 664 /sys/class/devfreq/qcom,cpubw.68/available_governors + chown radio system /sys/class/devfreq/qcom,cpubw.68/governor + chmod 664 /sys/class/devfreq/qcom,cpubw.68/governor + chown radio system /sys/class/devfreq/qcom,cpubw.68/max_freq + chmod 664 /sys/class/devfreq/qcom,cpubw.68/max_freq + chown radio system /sys/class/devfreq/qcom,cpubw.68/min_freq + chmod 664 /sys/class/devfreq/qcom,cpubw.68/min_freq + + chown system system /sys/devices/system/cpu/cpufreq/interactive/timer_rate + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_rate + chown system system /sys/devices/system/cpu/cpufreq/interactive/timer_slack + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_slack + chown system system /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + chown system system /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + chown system system /sys/devices/system/cpu/cpufreq/interactive/target_loads + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/target_loads + chown system system /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + chown system system /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + chown system system /sys/devices/system/cpu/cpufreq/interactive/boost + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boost + chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostpulse + chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration + chown system system /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + + # Assume SMP uses shared cpufreq policy for all CPUs + chown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chmod 0660 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chmod 0660 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # Auto Brightness + chown system system /sys/class/backlight/panel/auto_brightness + chmod 0660 /sys/class/backlight/panel/auto_brightness + + # LCD mdnie and panel work + chown system system /sys/class/mdnie/mdnie/negative + chown system media_rw /sys/class/mdnie/mdnie/accessibility + + chown radio system /sys/class/lcd/panel/lcd_power + chown radio system /sys/class/lcd/panel/lcd_type + chown radio system /sys/class/lcd/panel/power_reduce + chown radio system /sys/class/lcd/panel/siop_enable + + chown system system /sys/class/leds/keyboard-backlight/brightness + chown system system /sys/class/leds/lcd-backlight/brightness + chown system system /sys/class/leds/button-backlight/brightness + + chown system system /sys/kernel/ipv4/tcp_wmem_min + chown system system /sys/kernel/ipv4/tcp_wmem_def + chown system system /sys/kernel/ipv4/tcp_wmem_max + chown system system /sys/kernel/ipv4/tcp_rmem_min + chown system system /sys/kernel/ipv4/tcp_rmem_def + chown system system /sys/kernel/ipv4/tcp_rmem_max + + # Adjust YUV to RGB Conversion(CSC_Conversion) + chown system media_rw /sys/class/graphics/fb0/csc_cfg + chmod 0660 /sys/class/graphics/fb0/csc_cfg + + # Display color calibration + chown system system /sys/devices/virtual/graphics/fb0/rgb + chmod 0660 /sys/devices/virtual/graphics/fb0/rgb + + # Essential node for usbservice + mkdir /dev/bus/ 755 root root + mkdir /dev/bus/usb 755 root root + + # Permissions for Camera + chown root system /sys/class/camera/rear/rear_camantibanding + chown system radio /sys/class/camera/rear/rear_camfw + chown system radio /sys/class/camera/rear/rear_camfw_full + chown system radio /sys/class/camera/rear/rear_camfw_load + chown system radio /sys/class/camera/rear/rear_camtype + chown system radio /sys/class/camera/rear/rear_corever + chown system radio /sys/class/camera/rear/rear_companionfw_full + chown system radio /sys/class/camera/rear/rear_calcheck + chown system radio /sys/class/camera/rear/rear_fwcheck + chown system radio /sys/class/camera/rear/isp_core + chown system radio /sys/class/camera/flash/rear_flash + chown system radio /sys/class/camera/front/front_camfw + chown system radio /sys/class/camera/front/front_camtype + + # Torch + chown system system /sys/class/leds/led:flash_torch/brightness + chmod 0666 /sys/class/leds/led:flash_torch/brightness + + # Permissions for SSRM + chmod 0664 /sys/devices/platform/sec-thermistor/temperature + chmod 0664 /sys/class/power_supply/battery/siop_level + chmod 0664 /sys/class/power_supply/battery/test_charge_current + chown radio system /sys/devices/platform/sec-thermistor/temperature + chown radio system /sys/class/power_supply/battery/siop_level + chown radio system /sys/class/power_supply/battery/test_charge_current + + # Permissions for Charging + chown system radio /sys/class/power_supply/battery/batt_reset_soc + chown system radio /sys/class/power_supply/battery/update + chown system radio /sys/class/power_supply/battery/factory_mode + chown system radio /sys/class/power_supply/battery/batt_slate_mode + chown sdcard_rw sdcard_rw /sys/class/power_supply/battery/call + chown sdcard_rw sdcard_rw /sys/class/power_supply/battery/video + chown sdcard_rw sdcard_rw /sys/class/power_supply/battery/music + chown sdcard_rw sdcard_rw /sys/class/power_supply/battery/browser + chown sdcard_rw sdcard_rw /sys/class/power_supply/battery/hotspot + chown sdcard_rw sdcard_rw /sys/class/power_supply/battery/camera + chown system radio /sys/class/power_supply/battery/talk_wcdma + chown system radio /sys/class/power_supply/battery/talk_gsm + chown system radio /sys/class/power_supply/battery/call + chown system radio /sys/class/power_supply/battery/data_call + chown system radio /sys/class/power_supply/battery/gps + chown system radio /sys/class/power_supply/battery/wifi + chown system radio /sys/class/power_supply/battery/lte + chown system radio /sys/class/power_supply/battery/wc_enable + chown system radio /sys/class/power_supply/battery/lcd + + # Permission for fast dormancy for RIL + chown system radio /sys/devices/virtual/sec/bamdmux/waketime + chmod 777 /sys/devices/virtual/sec/bamdmux/waketime + + # Permissions for gpio_keys + chown system radio /sys/class/sec/sec_key/wakeup_keys + write /sys/class/sec/sec_key/wakeup_keys 116,172 + + # Permission for HALL IC + chown system radio /sys/class/sec/sec_key/hall_detect + + # Vibetonz + chmod 0660 /dev/tspdrv + chown vibe vibe /dev/tspdrv + + # Vibrator + chmod 0644 /sys/class/timed_output/vibrator/pwm_value + chown system system /sys/class/timed_output/vibrator/pwm_value + chown system system /sys/class/timed_output/vibrator/enable + + # Permissions for TSP + chown system system /sys/class/sec/tsp/cmd + chown system system /sys/class/sec/tsp/input/enabled + chown system system /sys/class/input/input0/enabled + chown system system /sys/class/input/input1/enabled + chown system system /sys/class/input/input2/enabled + chmod 0664 /sys/class/sec/tsp/cmd + chmod 0660 /sys/class/sec/tsp/input/enabled + chmod 0664 /sys/class/input/input0/enabled + chmod 0664 /sys/class/input/input1/enabled + chmod 0664 /sys/class/input/input2/enabled + + # Permission for touchkey + chown system system /sys/class/sec/sec_touchkey/keypad_enable + chown system system /sys/class/sec/sec_touchkey/touchkey_brightness + chown system system /sys/class/sec/sec_touchkey/touchkey_menu + chown system system /sys/class/sec/sec_touchkey/touchkey_back + chown system system /sys/class/sec/sec_touchkey/touch_version + chown system system /sys/class/sec/sec_touchkey/touchkey_firm_version_panel + chown system system /sys/class/sec/sec_touchkey/touchkey_firm_version_phone + chown system system /sys/class/sec/sec_touchkey/touchkey_firm_update_status + chown system system /sys/class/sec/sec_touchkey/touchkey_firm_update + chown system system /sys/class/sec/sec_touchkey/touch_sensitivity + chown system system /sys/class/sec/sec_touchkey/touchkey_threshold + chown system system /sys/devices/virtual/sec/sec_touchkey/brightness + chmod 0664 /sys/class/sec/sec_touchkey/keypad_enable + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_brightness + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_menu + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_back + chmod 0664 /sys/class/sec/sec_touchkey/touch_version + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_firm_version_panel + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_firm_version_phone + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_firm_update_status + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_firm_update + chmod 0664 /sys/class/sec/sec_touchkey/touch_sensitivity + chmod 0664 /sys/class/sec/sec_touchkey/touchkey_threshold + chmod 0664 /sys/devices/virtual/sec/sec_touchkey/brightness + restorecon /sys/class/sec/sec_touchkey/keypad_enable + + # Assign TCP buffer thresholds to be ceiling value of technology maximums + # Increased technology maximums should be reflected here. + write /proc/sys/net/core/rmem_max 8388608 + write /proc/sys/net/core/wmem_max 8388608 + + # Wifi firmware reload path + chmod 0660 /sys/module/wlan/parameters/fwpath + chown wifi wifi /sys/module/wlan/parameters/fwpath + + # Mark wifi driver as unloaded - "ok" indicates loaded + setprop wlan.driver.status not_ok + + +on property:sys.boot_completed=1 + + # Configure the CPU governor + write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor bioshock + write /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor bioshock + write /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor bioshock + write /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor bioshock + # write /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay 20000 + # write /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load 99 + # write /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq 998400 + + # Disable all hotplugs + write /sys/module/intelli_plug/parameters/intelli_plug_active 0 + write /sys/module/intelli_plug/parameters/touch_boost_active 0 + write /sys/module/cpu_boost/parameters/input_boost_ms 0 + write /sys/module/msm_hotplug/msm_enabled 0 + + # we dont need M(ake)P(oor)decision + stop mpdecision + + # Bring all CPUs online, and set node permissions AFTER disabling hotplugs otherwise + # only 1 core will be active + write /sys/devices/system/cpu/cpu1/online 1 + write /sys/devices/system/cpu/cpu2/online 1 + write /sys/devices/system/cpu/cpu3/online 1 + chmod 664 /sys/devices/system/cpu/cpu1/online + chmod 664 /sys/devices/system/cpu/cpu2/online + chmod 664 /sys/devices/system/cpu/cpu3/online + chown root system /sys/devices/system/cpu/cpu1/online + chown root system /sys/devices/system/cpu/cpu2/online + chown root system /sys/devices/system/cpu/cpu3/online + + # Symlink directories to access telephony.db and preferred-apn.xml required by libsec-ril + symlink /data/user_de/0/com.android.providers.telephony/databases /data/data/com.android.providers.telephony/databases + symlink /data/user_de/0/com.android.providers.telephony/shared_prefs /data/data/com.android.providers.telephony/shared_prefs + restorecon /data/data/com.android.providers.telephony/databases + restorecon /data/data/com.android.providers.telephony/shared_pref + +on charger + wait /dev/block/platform/msm_sdcc.1/by-name/system + mount ext4 /dev/block/platform/msm_sdcc.1/by-name/system /system ro barrier=1 + class_start charger + +# Services +service adsprpcd /vendor/bin/adsprpcd + class main + user media + group media + +service charger /sbin/healthd -c + class charger + critical + seclabel u:r:charger:s0 + +service ds_fmc_appd /vendor/bin/ds_fmc_appd -p "rmnet0" -D + class late_start + user root + group radio wifi inet + disabled + oneshot + +on property:persist.data.ds_fmc_app.mode=1 + start ds_fmc_appd + +service hciattach /vendor/bin/init.qcom.bt.sh + class late_start + user root + group bluetooth net_bt_admin + disabled + oneshot + +on property:bluetooth.hciattach=true + start hciattach + +on property:bluetooth.hciattach=false + setprop bluetooth.status off + +service irsc_util /vendor/bin/irsc_util "/vendor/etc/sec_config" + class main + user root + oneshot + +service ril-daemon0 /vendor/bin/hw/rild + class main + user radio + group root radio cache inet misc audio log readproc wakelock oem_2901 diag oem_2950 + capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW + disabled + +service qmuxd /vendor/bin/qmuxd + class main + user root + group radio audio bluetooth gps oem_2950 diag log + +service netmgrd /vendor/bin/netmgrd + class main + user root + group radio audio bluetooth gps oem_2950 diag log + +service qseecomd /vendor/bin/qseecomd + class core + user root + group root + +service rfs_access /vendor/bin/rfs_access + class core + user root + group system net_raw + +service rmt_storage /vendor/bin/rmt_storage + class core + user root + disabled + +on property:ro.boot.emmc=true + start rfs_access + start rmt_storage + +service ril-fix /vendor/bin/init.ril.sh + class main + user root + oneshot + +# Limit to SoC reset (1) and independent SSR (3) +on property:persist.sys.ssr.restart_level=1 + write /sys/module/subsystem_restart/parameters/restart_level 1 + +on property:persist.sys.ssr.restart_level=3 + write /sys/module/subsystem_restart/parameters/restart_level 3 + +service thermal-engine /vendor/bin/thermal-engine -c /etc/thermal-engine-8226.conf + class core + seclabel u:r:thermal-engine:s0 + user root + group root + +service time_daemon /vendor/bin/time_daemon + class late_start + user root + group root + +service fwlink /vendor/bin/init.firmware.sh + user root + disabled + oneshot + +service wcnss-service /vendor/bin/wcnss_service + class late_start + user system + group system wifi + oneshot + +# WPA +service wpa_supplicant /vendor/bin/hw/wpa_supplicant \ + -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \ + -I/vendor/etc/wifi/p2p_supplicant_overlay.conf -N \ + -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \ + -I/vendor/etc/wifi/wpa_supplicant_overlay.conf \ + -puse_p2p_group_interface=1 \ + -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0 + # we will start as root and wpa_supplicant will switch to user wifi + # after setting up the capabilities required for WEXT + # user wifi + # group wifi inet keystore + class main + socket wpa_wlan0 dgram 660 wifi wifi + disabled + oneshot + +on property:init.svc.wpa_supplicant=stopped + stop dhcpcd + +service dhcpcd_wlan0 /system/bin/dhcpcd -ABKLG + class late_start + disabled + oneshot + +service dhcpcd_p2p /system/bin/dhcpcd -ABKLG + class late_start + disabled + oneshot + +service iprenew_wlan0 /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service iprenew_p2p /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service dhcpcd_bt-pan /system/bin/dhcpcd -BKLG + class late_start + disabled + oneshot + +service iprenew_bt-pan /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service dhcpcd_bnep0 /system/bin/dhcpcd -BKLG + disabled + oneshot + +service dhcpcd_bnep1 /system/bin/dhcpcd -BKLG + disabled + oneshot + +service dhcpcd_bnep2 /system/bin/dhcpcd -BKLG + disabled + oneshot + +service dhcpcd_bnep3 /system/bin/dhcpcd -BKLG + disabled + oneshot + +service dhcpcd_bnep4 /system/bin/dhcpcd -BKLG + disabled + oneshot diff --git a/rootdir/init.qcom.usb.rc b/rootdir/init.qcom.usb.rc new file mode 100644 index 0000000..08edb03 --- /dev/null +++ b/rootdir/init.qcom.usb.rc @@ -0,0 +1,816 @@ +# Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +on init + write /sys/class/android_usb/android0/iSerial ${ro.serialno} + write /sys/class/android_usb/android0/f_rndis/wceis 1 + write /sys/bus/platform/drivers/msm_hsic_host/unbind "msm_hsic_host" + chown system system /sys/class/android_usb/android0/usb30en + chmod 0660 /sys/class/android_usb/android0/usb30en + chown system system /sys/class/android_usb/android0/terminal_version + chmod 0660 /sys/class/android_usb/android0/terminal_version + +on charger + setprop sys.usb.config mass_storage + +on fs + mkdir /dev/usb-ffs 0770 shell shell + mkdir /dev/usb-ffs/adb 0770 shell shell + mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000 + write /sys/class/android_usb/android0/f_ffs/aliases adb + +# Following are the parameters required for usb functionality. They provide configurable options like +# product_id/vendor id and allows specifying required functions: +# +# Required parameters: +# +# /sys/class/android_usb/android0/enable: Enables/disables usb composition +# Value: 0 (disable), 1 (enable) +# +# /sys/class/android_usb/android0/idVendor: Stores Vendor ID +# Value: 05c6 (Vendor id for Qualcomm Inc) +# +# /sys/class/android_usb/android0/idProduct: Stores Product id corresponding to usb composition +# Value: 0x9xxx for composite interface, 0xFxxx for single interface +# +# /sys/class/android_usb/android0/f_diag/clients: Stores name of clients representing a diag interface. +# Value: Passed one per interface. e.g. diag[,diag_mdm, diag_qsc, diag_mdm2] +# +# /sys/class/android_usb/android0/functions: Stores name of the function drivers used in usb composition. +# Value: Passed one per function driver. e.g. diag[,adb] +# +#Optional parameters: +# +# /sys/class/android_usb/android0/f_serial/transports: Stores type of underlying transports used to +# communicate to serial interface. +# Value: Passed one per interface. One value represents control and data transport together. +# e.g. smd[,sdio,tty,hsic] +# Only required if serial interface is present. +# +# /sys/class/android_usb/android0/f_serial/transport_names: Stores name of the underlying transports +# used to communicate to serial interface. This is used to distinguish between more than one interface +# using same transport type. +# Value: Passed one per interface. One value represents control and data transport together. +# e.g. serial_hsic[,serial_hsusb] +# Only required for transport type hsic, optional for other transport types. +# +# /sys/class/android_usb/android0/f_rmnet/transports: Stores type of underlying transports used to +# communicate to rmnet interface. +# Value: Passed two per interface as control, data transport type pair. +# e.g. smd,bam[,hsuart,hsuart] +# Only required if rmnet interface is present. +# +# /sys/class/android_usb/android0/f_rmnet/transport_names: Stores name of the underlying transports +# used to communicate to rmnet interface. This is used to distinguish between more than one interface +# using same transport type. +# Value: Passed one per interface. One value represents control and data transport together. +# e.g. rmnet_hsic[,rmnet_hsusb] +# Only required for transport type hsic, optional for other transport types. + + +# USB Composite for Samsung USB Driver + +on property:sys.usb.config=mtp,conn_gadget + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions mtp,acm,conn_gadget + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,conn_gadget,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions mtp,acm,conn_gadget,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions mtp,acm + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/functions mtp,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions mtp,acm,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + + +on property:sys.usb.config=ptp + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6865 + write /sys/class/android_usb/android0/functions ptp + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=ptp,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6866 + write /sys/class/android_usb/android0/functions ptp,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6863 + write /sys/class/android_usb/android0/functions rndis + write /sys/class/android_usb/android0/bDeviceClass 224 + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6864 + write /sys/class/android_usb/android0/functions rndis,adb + write /sys/class/android_usb/android0/bDeviceClass 224 + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=ncm + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 685D + write /sys/class/android_usb/android0/functions ncm + write /sys/class/android_usb/android0/bDeviceClass 2 + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=ncm,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 685D + write /sys/class/android_usb/android0/functions ncm,adb + write /sys/class/android_usb/android0/bDeviceClass 2 + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# rndis,acm,diag and rmnet,acm,diag are used for IOT Hidden Menu +on property:sys.usb.config=rndis,acm,diag + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6864 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions rndis,acm,diag + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rmnet,acm,diag + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 685D + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,acm,rmnet + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 685D + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions diag,acm,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# For CDFS composite +on property:sys.usb.config=mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 685B + write /sys/class/android_usb/android0/functions mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 685E + write /sys/class/android_usb/android0/f_acm/instances 1 + write /sys/class/android_usb/android0/functions mass_storage,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mass_storage,mtp + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/functions mtp,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mass_storage,mtp,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 04E8 + write /sys/class/android_usb/android0/idProduct 6860 + write /sys/class/android_usb/android0/functions mtp,mass_storage,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# As request from the CHINA GOVERNMENT SECURITY POLICY +on property:sys.usb.config=askon + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/functions ${sys.usb.config} + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=askon,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/functions ${sys.usb.config} + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9025 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports smd,tty + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm_smd,acm_tty,rmnet_bam,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903D + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/acm_transports smd,tty + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,adb,acm,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,serial_smd,serial_tty,rmnet_bam,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9026 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports smd,tty + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm_smd,acm_tty,rmnet_bam,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903E + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/acm_transports smd,tty + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,serial_sdio,serial_smd,rmnet_smd_sdio,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9037 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_serial/transports sdio,smd + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet_smd_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,acm_sdio,acm_smd,rmnet_smd_sdio,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903B + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_acm/acm_transports sdio,smd + write /sys/class/android_usb/android0/functions diag,adb,acm,rmnet_smd_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,serial_sdio,serial_smd,rmnet_smd_sdio,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9038 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_serial/transports sdio,smd + write /sys/class/android_usb/android0/functions diag,serial,rmnet_smd_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,acm_sdio,acm_smd,rmnet_smd_sdio,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903C + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_acm/acm_transports sdio,smd + write /sys/class/android_usb/android0/functions diag,acm,rmnet_smd_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,serial_sdio,serial_tty,rmnet_sdio,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9031 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_serial/transports sdio,tty + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,acm_sdio,acm_tty,rmnet_sdio,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903B + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_acm/acm_transports sdio,tty + write /sys/class/android_usb/android0/functions diag,adb,acm,rmnet_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,serial_sdio,serial_tty,rmnet_sdio,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9032 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_serial/transports sdio,tty + write /sys/class/android_usb/android0/functions diag,serial,rmnet_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,acm_sdio,acm_tty,rmnet_sdio,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903C + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_acm/acm_transports sdio,tty + write /sys/class/android_usb/android0/functions diag,acm,rmnet_sdio,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,serial_tty,serial_tty,rmnet_smd,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9025 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports tty,tty + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + start port-bridge + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm_tty,acm_tty,rmnet_smd,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903D + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/acm_transports tty,tty + write /sys/class/android_usb/android0/functions diag,adb,acm,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + start port-bridge + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,serial_tty,serial_tty,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9026 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports tty,tty + write /sys/class/android_usb/android0/functions diag,serial,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + start port-bridge + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm_tty,acm_tty,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903E + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/acm_transports tty,tty + write /sys/class/android_usb/android0/functions diag,serial,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,serial_smd,serial_tty,rmnet_smd,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9025 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports smd,tty + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm_smd,acm_tty,rmnet_smd,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903D + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/acm_transports smd,tty + write /sys/class/android_usb/android0/functions diag,adb,acm,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + start port-bridge + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,serial_smd,serial_tty,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9026 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports smd,tty + write /sys/class/android_usb/android0/functions diag,serial,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,acm_smd,acm_tty,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903E + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_acm/acm_transports smd,tty + write /sys/class/android_usb/android0/functions diag,serial,rmnet_smd,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 composition +on property:sys.usb.config=diag,serial_hsic,serial_tty,rmnet_hsic,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9025 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_serial/transports hsic,tty + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 composition with diag_mdm and adb +on property:sys.usb.config=diag,diag_mdm,serial_hsic,serial_tty,rmnet_hsic,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9031 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_serial/transports hsic,tty + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 composition with diag_mdm +on property:sys.usb.config=diag,diag_mdm,serial_hsic,serial_tty,rmnet_hsic,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9032 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/f_serial/transports hsic,tty + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic + write /sys/class/android_usb/android0/functions diag,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 DSDA composition with adb +on property:sys.usb.config=diag,diag_mdm,diag_qsc,serial_hsic,serial_hsuart,rmnet_hsic,rmnet_hsuart,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9065 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/f_serial/transports hsic,hsuart + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic,serial_hsuart + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic,hsuart,hsuart + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic,rmnet_hsuart + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 DSDA composition without adb +on property:sys.usb.config=diag,diag_mdm,diag_qsc,serial_hsic,serial_hsuart,rmnet_hsic,rmnet_hsuart,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9066 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/f_serial/transports hsic,hsuart + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic,serial_hsuart + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic,hsuart,hsuart + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic,rmnet_hsuart + write /sys/class/android_usb/android0/functions diag,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 DSDA2 composition with adb +on property:sys.usb.config=diag,diag_mdm,diag_mdm2,serial_hsic,serial_hsusb,rmnet_hsic,rmnet_hsusb,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9065 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_mdm2 + write /sys/class/android_usb/android0/f_serial/transports hsic,hsic + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic,serial_hsusb + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic,hsic,hsic + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic,rmnet_hsusb + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# Fusion 3 DSDA2 composition without adb +on property:sys.usb.config=diag,diag_mdm,diag_mdm2,serial_hsic,serial_hsusb,rmnet_hsic,rmnet_hsusb,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9066 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_mdm2 + write /sys/class/android_usb/android0/f_serial/transports hsic,hsic + write /sys/class/android_usb/android0/f_serial/transport_names serial_hsic,serial_hsusb + write /sys/class/android_usb/android0/f_rmnet/transports hsic,hsic,hsic,hsic + write /sys/class/android_usb/android0/f_rmnet/transport_names rmnet_hsic,rmnet_hsusb + write /sys/class/android_usb/android0/functions diag,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +# Fusion 2.2 composition with diag_qsc and adb +on property:sys.usb.config=diag,diag_qsc,serial_smd,serial_tty,serial_hsuart,rmnet_hsuart,mass_storage,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9053 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_qsc + write /sys/class/android_usb/android0/f_serial/transports smd,tty,hsuart + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam,hsuart,hsuart + write /sys/class/android_usb/android0/functions diag,adb,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# Fusion 2.2 composition with diag_qsc +on property:sys.usb.config=diag,diag_qsc,serial_smd,serial_tty,serial_hsuart,rmnet_hsuart,mass_storage + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9054 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_qsc + write /sys/class/android_usb/android0/f_serial/transports smd,tty,hsuart + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam,hsuart,hsuart + write /sys/class/android_usb/android0/functions diag,serial,rmnet,mass_storage + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,diag,diag_mdm + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9041 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/functions rndis,diag + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,diag,diag_mdm,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9042 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/functions rndis,diag,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9086 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/functions rndis,diag + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,diag,diag_mdm,diag_qsc,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9087 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/functions rndis,diag,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,diag,diag_mdm + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9040 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/functions mtp,diag + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,diag,diag_mdm,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 903F + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/functions mtp,diag,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9088 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/functions mtp,diag + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=mtp,diag,diag_mdm,diag_qsc,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9089 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm,diag_qsc + write /sys/class/android_usb/android0/functions mtp,diag,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,ccid + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9045 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/functions diag,ccid + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,diag_mdm,ccid,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9044 + write /sys/class/android_usb/android0/f_diag/clients diag,diag_mdm + write /sys/class/android_usb/android0/functions diag,adb,ccid + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,qdss + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 904A + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/functions diag,qdss + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,qdss,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9060 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/functions diag,qdss,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,qdss,rmnet_bam + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9083 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,qdss,rmnet + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=diag,qdss,rmnet_bam,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9084 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/f_rmnet/transports smd,bam + write /sys/class/android_usb/android0/functions diag,qdss,adb,rmnet + write /sys/module/dwc3/parameters/tx_fifo_resize_enable 1 + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,diag,qdss + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9081 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/functions rndis,diag,qdss + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=rndis,diag,qdss,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 9082 + write /sys/class/android_usb/android0/f_diag/clients diag + write /sys/class/android_usb/android0/functions rndis,diag,qdss,adb + write /sys/module/dwc3/parameters/tx_fifo_resize_enable 1 + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=ncm + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 0525 + write /sys/class/android_usb/android0/idProduct A4A1 + write /sys/class/android_usb/android0/functions ncm + write /sys/class/android_usb/android0/enable 1 + setprop sys.usb.state ${sys.usb.config} + +on property:sys.usb.config=ncm,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 05C6 + write /sys/class/android_usb/android0/idProduct 908C + write /sys/class/android_usb/android0/functions ncm,adb + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# USB midi configuration +on property:sys.usb.config=midi + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 18D1 + write /sys/class/android_usb/android0/idProduct 4EE8 + write /sys/class/android_usb/android0/functions ${sys.usb.config} + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} + +# USB midi configuration, with adb +on property:sys.usb.config=midi,adb + write /sys/class/android_usb/android0/enable 0 + write /sys/class/android_usb/android0/idVendor 18D1 + write /sys/class/android_usb/android0/idProduct 4EE9 + write /sys/class/android_usb/android0/functions ${sys.usb.config} + write /sys/class/android_usb/android0/enable 1 + start adbd + setprop sys.usb.state ${sys.usb.config} diff --git a/rootdir/ueventd.qcom.rc b/rootdir/ueventd.qcom.rc new file mode 100644 index 0000000..7e86cf0 --- /dev/null +++ b/rootdir/ueventd.qcom.rc @@ -0,0 +1,204 @@ +# Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# the DIAG device node HAS TO BE world writable/readable, otherwise libdiag cant open the socket :/ +/dev/diag 0777 system oem_2950 + +/dev/genlock 0666 system system +/dev/kgsl 0666 system system +/dev/kgsl-3d0 0666 system system +/dev/kgsl-2d0 0666 root root +/dev/kgsl-2d1 0666 root root +/dev/ion 0664 system system +/dev/rtc0 0600 system system +/dev/smd0 0660 system system +/dev/smd4 0660 system system +/dev/smd_cxm_qmi 0640 radio radio +/dev/smd5 0660 system system +/dev/smd6 0660 system system +/dev/smd7 0660 bluetooth bluetooth + +# Permissions for CSVT +/dev/smd11 0660 radio radio + +/dev/radio0 0640 system system +/dev/rfcomm0 0660 bluetooth bluetooth +/dev/smdcntl0 0640 radio radio +/dev/smdcntl1 0640 radio radio +/dev/smdcntl2 0640 radio radio +/dev/smdcntl3 0640 radio radio +/dev/smdcntl4 0640 radio radio +/dev/smdcntl5 0640 radio radio +/dev/smdcntl6 0640 radio radio +/dev/smdcntl7 0640 radio radio +/dev/smdcntl8 0640 radio radio +/dev/smdcntl9 0640 radio radio +/dev/smdcntl10 0640 radio radio +/dev/smdcntl11 0640 radio radio +/dev/smdcnt_rev0 0640 radio radio +/dev/smdcnt_rev1 0640 radio radio +/dev/smdcnt_rev2 0640 radio radio +/dev/smdcnt_rev3 0640 radio radio +/dev/smdcnt_rev4 0640 radio radio +/dev/smdcnt_rev5 0640 radio radio +/dev/smdcnt_rev6 0640 radio radio +/dev/smdcnt_rev7 0640 radio radio +/dev/smdcnt_rev8 0640 radio radio +/dev/smuxctl32 0640 radio radio +/dev/sdioctl0 0640 radio radio +/dev/sdioctl1 0640 radio radio +/dev/sdioctl2 0640 radio radio +/dev/sdioctl3 0640 radio radio +/dev/sdioctl4 0640 radio radio +/dev/sdioctl5 0640 radio radio +/dev/sdioctl6 0640 radio radio +/dev/sdioctl7 0640 radio radio +/dev/sdioctl8 0640 radio radio +/dev/rmnet_mux_ctrl 0640 radio radio +/dev/hsicctl0 0640 radio radio +/dev/hsicctl1 0640 radio radio +/dev/hsicctl2 0640 radio radio +/dev/hsicctl3 0640 radio radio +/dev/hsicctl4 0640 radio radio +/dev/hsicctl5 0640 radio radio +/dev/hsicctl6 0640 radio radio +/dev/hsicctl7 0640 radio radio +/dev/hsicctl8 0640 radio radio +/dev/hsicctl9 0640 radio radio +/dev/hsicctl10 0640 radio radio +/dev/hsicctl11 0640 radio radio +/dev/hsicctl12 0640 radio radio +/dev/hsicctl13 0640 radio radio +/dev/hsicctl14 0640 radio radio +/dev/hsicctl15 0640 radio radio +/dev/hsicctl16 0640 radio radio +/dev/video* 0660 system camera +/dev/media* 0660 system camera +/dev/v4l-subdev* 0660 system camera +/dev/qseecom 0660 system drmrpc +/dev/gemini0 0660 system camera +/dev/jpeg0 0660 system camera +/dev/jpeg1 0660 system camera +/dev/jpeg2 0660 system camera +/dev/msm_camera/* 0660 system camera +/dev/gemini/ 0660 system camera +/dev/mercury0 0660 system camera +/dev/msm_vidc_reg 0660 system audio +/dev/msm_vidc_dec 0660 system audio +/dev/msm_vidc_dec_sec 0660 system audio +/dev/msm_vidc_enc 0660 system audio +/dev/msm_vidc_enc_sec 0660 system audio +/dev/msm_rotator 0660 system system +/dev/hw_random 0660 system system +/dev/adsprpc-smd 0664 media camera +/dev/graphics/* 0660 system graphics +/dev/tun 0660 system vpn + +# Permissions for audio +/dev/msm_qcelp 0660 system audio +/dev/msm_evrc 0660 system audio +/dev/msm_wma 0660 system audio +/dev/msm_wmapro 0660 system audio +/dev/msm_amrnb 0660 system audio +/dev/msm_amrwb 0660 system audio +/dev/msm_amrwb_in 0660 system audio +/dev/msm_amrwbplus 0660 system audio +/dev/msm_aac 0660 system audio +/dev/msm_multi_aac 0660 system audio +/dev/msm_aac_in 0660 system audio +/dev/msm_qcelp_in 0660 system audio +/dev/msm_evrc_in 0660 system audio +/dev/msm_amrnb_in 0640 system audio +/dev/msm_a2dp_in 0660 system audio +/dev/msm_ac3 0660 system audio +/dev/msm_acdb 0660 system audio +/dev/msm_cad 0660 system audio +/dev/msm_fm 0660 system audio +/dev/msm_mvs 0660 system audio +/dev/msm_pcm_lp_dec 0660 system audio +/dev/msm_preproc_ctl 0660 system audio +/dev/msm_rtac 0660 system audio +/dev/msm_sps 0660 system audio +/dev/msm_voicememo 0660 system audio +/dev/radio0 0640 fm_radio fm_radio +/dev/smd3 0660 bluetooth bluetooth +/dev/smd2 0660 bluetooth bluetooth +/dev/ttyHSL0 0660 radio system +/dev/ttyHSL1 0660 system system +/dev/mdm 0660 system radio +/dev/sdio_tty_ciq_00 0660 system system +/dev/tty_sdio_00 0660 system system +/dev/ttyGS0 0660 system system +/dev/i2c-5 0660 media media +/sys/devices/virtual/smdpkt/smdcntl* open_timeout 0664 radio radio + +# DVB devices +/dev/dvb/adapter0/demux* 0440 media media +/dev/dvb/adapter0/dvr* 0660 media media +/dev/dvb/adapter0/video* 0660 media media + +# Charger +/dev/keychord 0660 system system + +# Broadcast devices +/dev/tsc_mux0 0660 media media +/dev/tsc_ci0 0660 media media + +# Sensors +/sys/devices/i2c-12/12-* pollrate_ms 0664 system system +/sys/devices/f9925000.i2c/i2c-0/0-* enable 0660 input system +/sys/devices/f9925000.i2c/i2c-0/0-* poll_delay 0660 input system +/sys/devices/virtual/optical_sensors/proximity ps_adc 0660 input system +/sys/devices/virtual/optical_sensors/proximity ps_poll_delay 0660 input system +/sys/devices/virtual/optical_sensors/lightsensor ls_auto 0660 input system +/sys/devices/virtual/optical_sensors/lightsensor ls_poll_delay 0660 input system +/sys/devices/virtual/input/input* poll 0660 input system +/sys/devices/virtual/input/input* pollrate_ms 0660 input system + +# WLAN +/dev/wcnss_wlan 0660 system system +/dev/wcnss_ctrl 0660 system system + +# NFC permissions +/dev/nfc-nci 0660 nfc nfc +/dev/pn547 0660 nfc nfc +/sys/devices/f9925000.i2c/i2c-2/2-0028 init_deinit 0200 nfc nfc +/sys/devices/f9925000.i2c/i2c-2/2-0028 set_pwr 0200 nfc nfc +/sys/devices/f9925000.i2c/i2c-2/2-0028 res_ready 0400 nfc nfc +/sys/devices/f9925000.i2c/i2c-2/2-0028 recv_rsp 0600 nfc nfc +/sys/devices/f9925000.i2c/i2c-2/2-0028 send_cmd 0200 nfc nfc + +# UIO devices +/dev/uio0 0660 system system +/dev/uio1 0660 system system +/dev/uio2 0660 system system + +# Permission for dun +/dev/dun 0660 system system + +# Latin Mobile TV +/dev/isdbt 0660 system system diff --git a/seccomp_policy/mediacodec.policy b/seccomp_policy/mediacodec.policy new file mode 100644 index 0000000..7d20bca --- /dev/null +++ b/seccomp_policy/mediacodec.policy @@ -0,0 +1,11 @@ +# device specific syscalls +pselect6: 1 +eventfd2: 1 +sendto: 1 +recvfrom: 1 +_llseek: 1 +sysinfo: 1 +getcwd: 1 +getsockopt: 1 +# ffmpeg needs this +getdents64: 1 diff --git a/seccomp_policy/mediaextractor.policy b/seccomp_policy/mediaextractor.policy new file mode 100644 index 0000000..6831193 --- /dev/null +++ b/seccomp_policy/mediaextractor.policy @@ -0,0 +1,6 @@ +# device specific syscalls. +readlinkat: 1 +pread64: 1 +getsockopt: 1 +# ffmpeg needs this +nanosleep: 1 diff --git a/sensors/Android.bp b/sensors/Android.bp new file mode 100644 index 0000000..0eaf4b1 --- /dev/null +++ b/sensors/Android.bp @@ -0,0 +1,15 @@ +cc_library_static { + name: "multihal-samsung", + vendor: true, + srcs: [ + "multihal.cpp", + "SensorEventQueue.cpp" + ], + shared_libs: [ + "liblog", + "libcutils", + "libutils", + "libdl" + ], + export_include_dirs: ["."], +} diff --git a/sensors/Android.mk b/sensors/Android.mk new file mode 100644 index 0000000..842f0f6 --- /dev/null +++ b/sensors/Android.mk @@ -0,0 +1,66 @@ +# +# Copyright (C) 2013 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. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM) + +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_PROPRIETARY_MODULE := true + +LOCAL_CFLAGS := -DLOG_TAG=\"MultiHal\" + +LOCAL_SRC_FILES := \ + multihal.cpp \ + SensorEventQueue.cpp \ + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libdl \ + liblog \ + libutils \ + libhardware + +LOCAL_STRIP_MODULE := false +LOCAL_VENDOR_MODULE := true + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_PROPRIETARY_MODULE := true +LOCAL_MODULE := android.hardware.sensors@1.0-service.s3ve3g +LOCAL_INIT_RC := android.hardware.sensors@1.0-service.s3ve3g.rc +LOCAL_SRC_FILES := \ + service.cpp + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libdl \ + libbase \ + libutils + +LOCAL_SHARED_LIBRARIES += \ + libhidlbase \ + libhidltransport \ + android.hardware.sensors@1.0 + +include $(BUILD_EXECUTABLE) + +include $(call all-makefiles-under, $(LOCAL_PATH)) diff --git a/sensors/SensorEventQueue.cpp b/sensors/SensorEventQueue.cpp new file mode 100644 index 0000000..dff7ac9 --- /dev/null +++ b/sensors/SensorEventQueue.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2013 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. + */ + +#include +#include +#include +#include + +#include "SensorEventQueue.h" + +SensorEventQueue::SensorEventQueue(int capacity) { + mCapacity = capacity; + + mStart = 0; + mSize = 0; + mData = new sensors_event_t[mCapacity]; + pthread_cond_init(&mSpaceAvailableCondition, NULL); +} + +SensorEventQueue::~SensorEventQueue() { + delete[] mData; + mData = NULL; + pthread_cond_destroy(&mSpaceAvailableCondition); +} + +int SensorEventQueue::getWritableRegion(int requestedLength, sensors_event_t** out) { + if (mSize == mCapacity || requestedLength <= 0) { + *out = NULL; + return 0; + } + // Start writing after the last readable record. + int firstWritable = (mStart + mSize) % mCapacity; + + int lastWritable = firstWritable + requestedLength - 1; + + // Don't go past the end of the data array. + if (lastWritable > mCapacity - 1) { + lastWritable = mCapacity - 1; + } + // Don't go into the readable region. + if (firstWritable < mStart && lastWritable >= mStart) { + lastWritable = mStart - 1; + } + *out = &mData[firstWritable]; + return lastWritable - firstWritable + 1; +} + +void SensorEventQueue::markAsWritten(int count) { + mSize += count; +} + +int SensorEventQueue::getSize() { + return mSize; +} + +sensors_event_t* SensorEventQueue::peek() { + if (mSize == 0) return NULL; + return &mData[mStart]; +} + +void SensorEventQueue::dequeue() { + if (mSize == 0) return; + if (mSize == mCapacity) { + pthread_cond_broadcast(&mSpaceAvailableCondition); + } + mSize--; + mStart = (mStart + 1) % mCapacity; +} + +// returns true if it waited, or false if it was a no-op. +bool SensorEventQueue::waitForSpace(pthread_mutex_t* mutex) { + bool waited = false; + while (mSize == mCapacity) { + waited = true; + pthread_cond_wait(&mSpaceAvailableCondition, mutex); + } + return waited; +} diff --git a/sensors/SensorEventQueue.h b/sensors/SensorEventQueue.h new file mode 100644 index 0000000..9778e93 --- /dev/null +++ b/sensors/SensorEventQueue.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2013 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. + */ + +#ifndef SENSOREVENTQUEUE_H_ +#define SENSOREVENTQUEUE_H_ + +#include +#include + +/* + * Fixed-size circular queue, with an API developed around the sensor HAL poll() method. + * Poll() takes a pointer to a buffer, which is written by poll() before it returns. + * This class can provide a pointer to a spot in its internal buffer for poll() to + * write to, instead of using an intermediate buffer and a memcpy. + * + * Thread safety: + * Reading can be done safely after grabbing the mutex lock, while poll() writing in a separate + * thread without a mutex lock. But there can only be one writer at a time. + */ +class SensorEventQueue { + int mCapacity; + int mStart; // start of readable region + int mSize; // number of readable items + sensors_event_t* mData; + pthread_cond_t mSpaceAvailableCondition; + +public: + explicit SensorEventQueue(int capacity); + ~SensorEventQueue(); + + // Returns length of region, between zero and min(capacity, requestedLength). If there is any + // writable space, it will return a region of at least one. Because it must return + // a pointer to a contiguous region, it may return smaller regions as we approach the end of + // the data array. + // Only call while holding the lock. + // The region is not marked internally in any way. Subsequent calls may return overlapping + // regions. This class expects there to be exactly one writer at a time. + int getWritableRegion(int requestedLength, sensors_event_t** out); + + // After writing to the region returned by getWritableRegion(), call this to indicate how + // many records were actually written. + // This increases size() by count. + // Only call while holding the lock. + void markAsWritten(int count); + + // Gets the number of readable records. + // Only call while holding the lock. + int getSize(); + + // Returns pointer to the first readable record, or NULL if size() is zero. + // Only call this while holding the lock. + sensors_event_t* peek(); + + // This will decrease the size by one, freeing up the oldest readable event's slot for writing. + // Only call while holding the lock. + void dequeue(); + + // Blocks until space is available. No-op if there is already space. + // Returns true if it had to wait. + bool waitForSpace(pthread_mutex_t* mutex); +}; + +#endif // SENSOREVENTQUEUE_H_ diff --git a/sensors/android.hardware.sensors@1.0-service.s3ve3g.rc b/sensors/android.hardware.sensors@1.0-service.s3ve3g.rc new file mode 100644 index 0000000..58fd791 --- /dev/null +++ b/sensors/android.hardware.sensors@1.0-service.s3ve3g.rc @@ -0,0 +1,5 @@ +service sensors-hal-1-0 /vendor/bin/hw/android.hardware.sensors@1.0-service.s3ve3g + class hal + user root + group system input wakelock + capabilities BLOCK_SUSPEND SYS_NICE diff --git a/sensors/multihal.cpp b/sensors/multihal.cpp new file mode 100644 index 0000000..40c9e03 --- /dev/null +++ b/sensors/multihal.cpp @@ -0,0 +1,712 @@ +/* + * Copyright (C) 2013 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. + */ + +#include "SensorEventQueue.h" +#include "multihal.h" + +#define LOG_NDEBUG 1 +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static pthread_mutex_t init_modules_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t init_sensors_mutex = PTHREAD_MUTEX_INITIALIZER; + +// This mutex is shared by all queues +static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; + +// Used to pause the multihal poll(). Broadcasted by sub-polling tasks if waiting_for_data. +static pthread_cond_t data_available_cond = PTHREAD_COND_INITIALIZER; +bool waiting_for_data = false; + +/* + * Vector of sub modules, whose indexes are referred to in this file as module_index. + */ +static std::vector *sub_hw_modules = NULL; + +/* + * Comparable class that globally identifies a sensor, by module index and local handle. + * A module index is the module's index in sub_hw_modules. + * A local handle is the handle the sub-module assigns to a sensor. + */ +struct FullHandle { + int moduleIndex; + int localHandle; + + bool operator<(const FullHandle &that) const { + if (moduleIndex < that.moduleIndex) { + return true; + } + if (moduleIndex > that.moduleIndex) { + return false; + } + return localHandle < that.localHandle; + } + + bool operator==(const FullHandle &that) const { + return moduleIndex == that.moduleIndex && localHandle == that.localHandle; + } +}; + +std::map global_to_full; +std::map full_to_global; +int next_global_handle = 1; + +static int assign_global_handle(int module_index, int local_handle) { + int global_handle = next_global_handle++; + FullHandle full_handle; + full_handle.moduleIndex = module_index; + full_handle.localHandle = local_handle; + full_to_global[full_handle] = global_handle; + global_to_full[global_handle] = full_handle; + return global_handle; +} + +// Returns the local handle, or -1 if it does not exist. +static int get_local_handle(int global_handle) { + if (global_to_full.count(global_handle) == 0) { + ALOGW("Unknown global_handle %d", global_handle); + return -1; + } + return global_to_full[global_handle].localHandle; +} + +// Returns the sub_hw_modules index of the module that contains the sensor associates with this +// global_handle, or -1 if that global_handle does not exist. +static int get_module_index(int global_handle) { + if (global_to_full.count(global_handle) == 0) { + ALOGW("Unknown global_handle %d", global_handle); + return -1; + } + FullHandle f = global_to_full[global_handle]; + ALOGV("FullHandle for global_handle %d: moduleIndex %d, localHandle %d", + global_handle, f.moduleIndex, f.localHandle); + return f.moduleIndex; +} + +// Returns the global handle for this full_handle, or -1 if the full_handle is unknown. +static int get_global_handle(FullHandle* full_handle) { + int global_handle = -1; + if (full_to_global.count(*full_handle)) { + global_handle = full_to_global[*full_handle]; + } else { + ALOGW("Unknown FullHandle: moduleIndex %d, localHandle %d", + full_handle->moduleIndex, full_handle->localHandle); + } + return global_handle; +} + +static const int SENSOR_EVENT_QUEUE_CAPACITY = 36; + +struct TaskContext { + sensors_poll_device_t* device; + SensorEventQueue* queue; +}; + +void *writerTask(void* ptr) { + ALOGV("writerTask STARTS"); + TaskContext* ctx = (TaskContext*)ptr; + sensors_poll_device_t* device = ctx->device; + SensorEventQueue* queue = ctx->queue; + sensors_event_t* buffer; + int eventsPolled; + while (1) { + pthread_mutex_lock(&queue_mutex); + if (queue->waitForSpace(&queue_mutex)) { + ALOGV("writerTask waited for space"); + } + int bufferSize = queue->getWritableRegion(SENSOR_EVENT_QUEUE_CAPACITY, &buffer); + // Do blocking poll outside of lock + pthread_mutex_unlock(&queue_mutex); + + ALOGV("writerTask before poll() - bufferSize = %d", bufferSize); + eventsPolled = device->poll(device, buffer, bufferSize); + ALOGV("writerTask poll() got %d events.", eventsPolled); + if (eventsPolled <= 0) { + if (eventsPolled < 0) { + ALOGV("writerTask ignored error %d from %s", eventsPolled, device->common.module->name); + ALOGE("ERROR: Fix %s so it does not return error from poll()", device->common.module->name); + } + continue; + } + pthread_mutex_lock(&queue_mutex); + queue->markAsWritten(eventsPolled); + ALOGV("writerTask wrote %d events", eventsPolled); + if (waiting_for_data) { + ALOGV("writerTask - broadcast data_available_cond"); + pthread_cond_broadcast(&data_available_cond); + } + pthread_mutex_unlock(&queue_mutex); + } + // never actually returns + return NULL; +} + +/* + * Cache of all sensors, with original handles replaced by global handles. + * This will be handled to get_sensors_list() callers. + */ +static struct sensor_t const* global_sensors_list = NULL; +static int global_sensors_count = -1; + +/* + * Extends a sensors_poll_device_1 by including all the sub-module's devices. + */ +struct sensors_poll_context_t { + /* + * This is the device that SensorDevice.cpp uses to make API calls + * to the multihal, which fans them out to sub-HALs. + */ + sensors_poll_device_1 proxy_device; // must be first + + void addSubHwDevice(struct hw_device_t*); + + int activate(int handle, int enabled); + int setDelay(int handle, int64_t ns); + int poll(sensors_event_t* data, int count); + int batch(int handle, int flags, int64_t period_ns, int64_t timeout); + int flush(int handle); + int inject_sensor_data(struct sensors_poll_device_1 *dev, const sensors_event_t *data); + int close(); + + std::vector sub_hw_devices; + std::vector queues; + std::vector threads; + int nextReadIndex; + + sensors_poll_device_t* get_v0_device_by_handle(int global_handle); + sensors_poll_device_1_t* get_v1_device_by_handle(int global_handle); + int get_device_version_by_handle(int global_handle); + + void copy_event_remap_handle(sensors_event_t* src, sensors_event_t* dest, int sub_index); +}; + +void sensors_poll_context_t::addSubHwDevice(struct hw_device_t* sub_hw_device) { + ALOGV("addSubHwDevice"); + this->sub_hw_devices.push_back(sub_hw_device); + + SensorEventQueue *queue = new SensorEventQueue(SENSOR_EVENT_QUEUE_CAPACITY); + this->queues.push_back(queue); + + TaskContext* taskContext = new TaskContext(); + taskContext->device = (sensors_poll_device_t*) sub_hw_device; + taskContext->queue = queue; + + pthread_t writerThread; + pthread_create(&writerThread, NULL, writerTask, taskContext); + this->threads.push_back(writerThread); +} + +// Returns the device pointer, or NULL if the global handle is invalid. +sensors_poll_device_t* sensors_poll_context_t::get_v0_device_by_handle(int global_handle) { + int sub_index = get_module_index(global_handle); + if (sub_index < 0 || sub_index >= (int) this->sub_hw_devices.size()) { + return NULL; + } + return (sensors_poll_device_t*) this->sub_hw_devices[sub_index]; +} + +// Returns the device pointer, or NULL if the global handle is invalid. +sensors_poll_device_1_t* sensors_poll_context_t::get_v1_device_by_handle(int global_handle) { + int sub_index = get_module_index(global_handle); + if (sub_index < 0 || sub_index >= (int) this->sub_hw_devices.size()) { + return NULL; + } + return (sensors_poll_device_1_t*) this->sub_hw_devices[sub_index]; +} + +// Returns the device version, or -1 if the handle is invalid. +int sensors_poll_context_t::get_device_version_by_handle(int handle) { + sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle); + if (v0) { + return v0->common.version; + } else { + return -1; + } +} + +const char *apiNumToStr(int version) { + switch(version) { + case SENSORS_DEVICE_API_VERSION_1_0: + return "SENSORS_DEVICE_API_VERSION_1_0"; + case SENSORS_DEVICE_API_VERSION_1_1: + return "SENSORS_DEVICE_API_VERSION_1_1"; + case SENSORS_DEVICE_API_VERSION_1_2: + return "SENSORS_DEVICE_API_VERSION_1_2"; + case SENSORS_DEVICE_API_VERSION_1_3: + return "SENSORS_DEVICE_API_VERSION_1_3"; + case SENSORS_DEVICE_API_VERSION_1_4: + return "SENSORS_DEVICE_API_VERSION_1_4"; + default: + return "UNKNOWN"; + } +} + +int sensors_poll_context_t::activate(int handle, int enabled) { + int retval = -EINVAL; + ALOGV("activate"); + int local_handle = get_local_handle(handle); + sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle); + retval = v0->activate(v0, local_handle, enabled); + ALOGV("retval %d", retval); + return retval; +} + +int sensors_poll_context_t::setDelay(int handle, int64_t ns) { + int retval = -EINVAL; + ALOGV("setDelay"); + int local_handle = get_local_handle(handle); + sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle); + retval = v0->setDelay(v0, local_handle, ns); + ALOGV("retval %d", retval); + return retval; +} + +void sensors_poll_context_t::copy_event_remap_handle(sensors_event_t* dest, sensors_event_t* src, + int sub_index) { + memcpy(dest, src, sizeof(struct sensors_event_t)); + // A normal event's "sensor" field is a local handle. Convert it to a global handle. + // A meta-data event must have its sensor set to 0, but it has a nested event + // with a local handle that needs to be converted to a global handle. + FullHandle full_handle; + full_handle.moduleIndex = sub_index; + + // If it's a metadata event, rewrite the inner payload, not the sensor field. + // If the event's sensor field is unregistered for any reason, rewrite the sensor field + // with a -1, instead of writing an incorrect but plausible sensor number, because + // get_global_handle() returns -1 for unknown FullHandles. + if (dest->type == SENSOR_TYPE_META_DATA) { + full_handle.localHandle = dest->meta_data.sensor; + dest->meta_data.sensor = get_global_handle(&full_handle); + } else { + full_handle.localHandle = dest->sensor; + dest->sensor = get_global_handle(&full_handle); + } +} + +int sensors_poll_context_t::poll(sensors_event_t *data, int maxReads) { + ALOGV("poll"); + int empties = 0; + int queueCount = 0; + int eventsRead = 0; + + pthread_mutex_lock(&queue_mutex); + queueCount = (int)this->queues.size(); + while (eventsRead == 0) { + while (empties < queueCount && eventsRead < maxReads) { + SensorEventQueue* queue = this->queues.at(this->nextReadIndex); + sensors_event_t* event = queue->peek(); + if (event == NULL) { + empties++; + } else { + empties = 0; + this->copy_event_remap_handle(&data[eventsRead], event, nextReadIndex); + if (data[eventsRead].sensor == -1) { + // Bad handle, do not pass corrupted event upstream ! + ALOGW("Dropping bad local handle event packet on the floor"); + } else { + eventsRead++; + } + queue->dequeue(); + } + this->nextReadIndex = (this->nextReadIndex + 1) % queueCount; + } + if (eventsRead == 0) { + // The queues have been scanned and none contain data, so wait. + ALOGV("poll stopping to wait for data"); + waiting_for_data = true; + pthread_cond_wait(&data_available_cond, &queue_mutex); + waiting_for_data = false; + empties = 0; + } + } + pthread_mutex_unlock(&queue_mutex); + ALOGV("poll returning %d events.", eventsRead); + + return eventsRead; +} + +int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns, int64_t timeout) { + ALOGV("batch"); + int retval = -EINVAL; + int local_handle = get_local_handle(handle); + sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(handle); + retval = v1->batch(v1, local_handle, flags, period_ns, timeout); + ALOGV("retval %d", retval); + return retval; +} + +int sensors_poll_context_t::flush(int handle) { + ALOGV("flush"); + int retval = -EINVAL; + int local_handle = get_local_handle(handle); + sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(handle); + retval = v1->flush(v1, local_handle); + ALOGV("retval %d", retval); + return retval; +} + +int sensors_poll_context_t::inject_sensor_data(struct sensors_poll_device_1 *dev, + const sensors_event_t *data) { + int retval = -EINVAL; + ALOGV("inject_sensor_data"); + // Get handle for the sensor owning the event being injected + int local_handle = get_local_handle(data->sensor); + sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(data->sensor); + retval = v1->inject_sensor_data(dev, data); + ALOGV("retval %d", retval); + return retval; + +} + +int sensors_poll_context_t::close() { + ALOGV("close"); + for (std::vector::iterator it = this->sub_hw_devices.begin(); + it != this->sub_hw_devices.end(); it++) { + hw_device_t* dev = *it; + int retval = dev->close(dev); + ALOGV("retval %d", retval); + } + return 0; +} + + +static int device__close(struct hw_device_t *dev) { + sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; + if (ctx != NULL) { + int retval = ctx->close(); + delete ctx; + } + return 0; +} + +static int device__activate(struct sensors_poll_device_t *dev, int handle, + int enabled) { + sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; + return ctx->activate(handle, enabled); +} + +static int device__setDelay(struct sensors_poll_device_t *dev, int handle, + int64_t ns) { + sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; + return ctx->setDelay(handle, ns); +} + +static int device__poll(struct sensors_poll_device_t *dev, sensors_event_t* data, + int count) { + sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; + return ctx->poll(data, count); +} + +static int device__batch(struct sensors_poll_device_1 *dev, int handle, + int flags, int64_t period_ns, int64_t timeout) { + sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; + + ctx->setDelay(handle, period_ns); + + return 0; +} + +static int device__flush(struct sensors_poll_device_1 *dev, int handle) { + return -EINVAL; +} + +static int device__inject_sensor_data(struct sensors_poll_device_1 *dev, + const sensors_event_t *data) { + sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; + return ctx->inject_sensor_data(dev, data); +} + +static int open_sensors(const struct hw_module_t* module, const char* name, + struct hw_device_t** device); + +static bool starts_with(const char* s, const char* prefix) { + if (s == NULL || prefix == NULL) { + return false; + } + size_t s_size = strlen(s); + size_t prefix_size = strlen(prefix); + return s_size >= prefix_size && strncmp(s, prefix, prefix_size) == 0; +} + +/* + * Adds valid paths from the config file to the vector passed in. + * The vector must not be null. + */ +static void get_so_paths(std::vector *so_paths) { + const std::vector config_path_list( + { MULTI_HAL_CONFIG_FILE_PATH, DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH }); + + std::ifstream stream; + const char *path = nullptr; + for (auto i : config_path_list) { + std::ifstream f(i); + if (f) { + stream = std::move(f); + path = i; + break; + } + } + if(!stream) { + ALOGW("No multihal config file found"); + return; + } + + ALOGE_IF(strcmp(path, DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH) == 0, + "Multihal configuration file path %s is not compatible with Treble " + "requirements. Please move it to %s.", + path, MULTI_HAL_CONFIG_FILE_PATH); + + ALOGV("Multihal config file found at %s", path); + std::string line; + while (std::getline(stream, line)) { + ALOGV("config file line: '%s'", line.c_str()); + so_paths->push_back(line); + } +} + +/* + * Ensures that the sub-module array is initialized. + * This can be first called from get_sensors_list or from open_sensors. + */ +static void lazy_init_modules() { + pthread_mutex_lock(&init_modules_mutex); + if (sub_hw_modules != NULL) { + pthread_mutex_unlock(&init_modules_mutex); + return; + } + std::vector *so_paths = new std::vector(); + get_so_paths(so_paths); + + // dlopen the module files and cache their module symbols in sub_hw_modules + sub_hw_modules = new std::vector(); + dlerror(); // clear any old errors + const char* sym = HAL_MODULE_INFO_SYM_AS_STR; + for (std::vector::iterator it = so_paths->begin(); it != so_paths->end(); it++) { + const char* path = it->c_str(); + void* lib_handle = dlopen(path, RTLD_LAZY); + if (lib_handle == NULL) { + ALOGW("dlerror(): %s", dlerror()); + } else { + ALOGI("Loaded library from %s", path); + ALOGV("Opening symbol \"%s\"", sym); + // clear old errors + dlerror(); + struct hw_module_t* module = (hw_module_t*) dlsym(lib_handle, sym); + const char* error; + if ((error = dlerror()) != NULL) { + ALOGW("Error calling dlsym: %s", error); + } else if (module == NULL) { + ALOGW("module == NULL"); + } else { + ALOGV("Loaded symbols from \"%s\"", sym); + sub_hw_modules->push_back(module); + } + } + } + pthread_mutex_unlock(&init_modules_mutex); +} + +/* + * Fix the fields of the sensor to be compliant with the API version + * reported by the wrapper. + */ +static void fix_sensor_fields(sensor_t& sensor) { + /* + * Becasue batching and flushing don't work modify the + * sensor fields to not report any fifo counts. + */ + sensor.fifoReservedEventCount = 0; + sensor.fifoMaxEventCount = 0; + + switch (sensor.type) { + /* + * Use the flags suggested by the sensors documentation. + */ + case SENSOR_TYPE_TILT_DETECTOR: + sensor.flags = SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE; + break; + /* + * Report a proper range to fix doze proximity check. + */ + case SENSOR_TYPE_PROXIMITY: + sensor.flags = SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE; + sensor.maxRange = 5.0; + break; + } +} + +/* + * Lazy-initializes global_sensors_count, global_sensors_list, and module_sensor_handles. + */ +static void lazy_init_sensors_list() { + ALOGV("lazy_init_sensors_list"); + pthread_mutex_lock(&init_sensors_mutex); + if (global_sensors_list != NULL) { + // already initialized + pthread_mutex_unlock(&init_sensors_mutex); + ALOGV("lazy_init_sensors_list - early return"); + return; + } + + ALOGV("lazy_init_sensors_list needs to do work"); + lazy_init_modules(); + + // Count all the sensors, then allocate an array of blanks. + global_sensors_count = 0; + const struct sensor_t *subhal_sensors_list; + for (std::vector::iterator it = sub_hw_modules->begin(); + it != sub_hw_modules->end(); it++) { + struct sensors_module_t *module = (struct sensors_module_t*) *it; + global_sensors_count += module->get_sensors_list(module, &subhal_sensors_list); + ALOGV("increased global_sensors_count to %d", global_sensors_count); + } + + // The global_sensors_list is full of consts. + // Manipulate this non-const list, and point the const one to it when we're done. + sensor_t* mutable_sensor_list = new sensor_t[global_sensors_count]; + + // index of the next sensor to set in mutable_sensor_list + int mutable_sensor_index = 0; + int module_index = 0; + + for (std::vector::iterator it = sub_hw_modules->begin(); + it != sub_hw_modules->end(); it++) { + hw_module_t *hw_module = *it; + ALOGV("examine one module"); + // Read the sub-module's sensor list. + struct sensors_module_t *module = (struct sensors_module_t*) hw_module; + int module_sensor_count = module->get_sensors_list(module, &subhal_sensors_list); + ALOGV("the module has %d sensors", module_sensor_count); + + // Copy the HAL's sensor list into global_sensors_list, + // with the handle changed to be a global handle. + for (int i = 0; i < module_sensor_count; i++) { + ALOGV("examining one sensor"); + const struct sensor_t *local_sensor = &subhal_sensors_list[i]; + int local_handle = local_sensor->handle; + memcpy(&mutable_sensor_list[mutable_sensor_index], local_sensor, + sizeof(struct sensor_t)); + + // Overwrite the global version's handle with a global handle. + int global_handle = assign_global_handle(module_index, local_handle); + + mutable_sensor_list[mutable_sensor_index].handle = global_handle; + ALOGV("module_index %d, local_handle %d, global_handle %d", + module_index, local_handle, global_handle); + + fix_sensor_fields(mutable_sensor_list[mutable_sensor_index]); + mutable_sensor_index++; + } + module_index++; + } + // Set the const static global_sensors_list to the mutable one allocated by this function. + global_sensors_list = mutable_sensor_list; + + pthread_mutex_unlock(&init_sensors_mutex); + ALOGV("end lazy_init_sensors_list"); +} + +static int module__get_sensors_list(__unused struct sensors_module_t* module, + struct sensor_t const** list) { + ALOGV("module__get_sensors_list start"); + lazy_init_sensors_list(); + *list = global_sensors_list; + ALOGV("global_sensors_count: %d", global_sensors_count); + for (int i = 0; i < global_sensors_count; i++) { + ALOGV("sensor type: %d", global_sensors_list[i].type); + } + return global_sensors_count; +} + +static struct hw_module_methods_t sensors_module_methods = { + .open = open_sensors +}; + +struct sensors_module_t HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 1, + .id = SENSORS_HARDWARE_MODULE_ID, + .name = "MultiHal Sensor Module", + .author = "Google, Inc", + .methods = &sensors_module_methods, + .dso = NULL, + .reserved = {0}, + }, + .get_sensors_list = module__get_sensors_list +}; + +struct sensors_module_t *get_multi_hal_module_info() { + return (&HAL_MODULE_INFO_SYM); +} + +static int open_sensors(const struct hw_module_t* hw_module, const char* name, + struct hw_device_t** hw_device_out) { + ALOGV("open_sensors begin..."); + + lazy_init_modules(); + + // Create proxy device, to return later. + sensors_poll_context_t *dev = new sensors_poll_context_t(); + memset(dev, 0, sizeof(sensors_poll_device_1_t)); + dev->proxy_device.common.tag = HARDWARE_DEVICE_TAG; + dev->proxy_device.common.version = SENSORS_DEVICE_API_VERSION_1_3; + dev->proxy_device.common.module = const_cast(hw_module); + dev->proxy_device.common.close = device__close; + dev->proxy_device.activate = device__activate; + dev->proxy_device.setDelay = device__setDelay; + dev->proxy_device.poll = device__poll; + dev->proxy_device.batch = device__batch; + dev->proxy_device.flush = device__flush; + dev->proxy_device.inject_sensor_data = device__inject_sensor_data; + + dev->nextReadIndex = 0; + + // Open() the subhal modules. Remember their devices in a vector parallel to sub_hw_modules. + for (std::vector::iterator it = sub_hw_modules->begin(); + it != sub_hw_modules->end(); it++) { + sensors_module_t *sensors_module = (sensors_module_t*) *it; + struct hw_device_t* sub_hw_device; + int sub_open_result = sensors_module->common.methods->open(*it, name, &sub_hw_device); + if (!sub_open_result) { + dev->addSubHwDevice(sub_hw_device); + } + } + + // Prepare the output param and return + *hw_device_out = &dev->proxy_device.common; + ALOGV("...open_sensors end"); + return 0; +} diff --git a/sensors/multihal.h b/sensors/multihal.h new file mode 100644 index 0000000..e4fbe7e --- /dev/null +++ b/sensors/multihal.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2016 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. + */ +#ifndef HARDWARE_LIBHARDWARE_MODULES_SENSORS_MULTIHAL_H_ +#define HARDWARE_LIBHARDWARE_MODULES_SENSORS_MULTIHAL_H_ + +#include +#include + +static const char* MULTI_HAL_CONFIG_FILE_PATH = "/vendor/etc/sensors/_hals.conf"; + +// Depracated because system partition HAL config file does not satisfy treble requirements. +static const char* DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH = "/system/etc/sensors/_hals.conf"; + +struct sensors_module_t *get_multi_hal_module_info(void); + +#endif // HARDWARE_LIBHARDWARE_MODULES_SENSORS_MULTIHAL_H_ diff --git a/sensors/service.cpp b/sensors/service.cpp new file mode 100644 index 0000000..4fe495c --- /dev/null +++ b/sensors/service.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 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. + */ + +#define LOG_TAG "android.hardware.sensors@1.0-service.wt88047" + +#include +#include + +using android::hardware::sensors::V1_0::ISensors; +using android::hardware::defaultPassthroughServiceImplementation; + +int main() { + /* Sensors framework service needs at least two threads. + * One thread blocks on a "poll" + * The second thread is needed for all other HAL methods. + */ + return defaultPassthroughServiceImplementation(2); +} diff --git a/sensors/service/Android.mk b/sensors/service/Android.mk new file mode 100644 index 0000000..39e19d7 --- /dev/null +++ b/sensors/service/Android.mk @@ -0,0 +1,25 @@ +OLD_LOCAL_PATH := $(LOCAL_PATH) +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_PROPRIETARY_MODULE := true +LOCAL_MODULE := android.hardware.sensors@1.0-service.wt88047 +LOCAL_INIT_RC := android.hardware.sensors@1.0-service.wt88047.rc +LOCAL_SRC_FILES := \ + service.cpp + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libdl \ + libbase \ + libutils + +LOCAL_SHARED_LIBRARIES += \ + libhidlbase \ + libhidltransport \ + android.hardware.sensors@1.0 + +include $(BUILD_EXECUTABLE) +LOCAL_PATH := $(OLD_LOCAL_PATH) diff --git a/vendor.prop b/vendor.prop new file mode 100644 index 0000000..d192772 --- /dev/null +++ b/vendor.prop @@ -0,0 +1,103 @@ +# Audio +af.fast_track_multiplier=1 +audio_hal.period_size=192 +audio.offload.video=true +persist.audio.fluence.speaker=true +persist.audio.fluence.voicecall=true +persist.audio.fluence.voicerec=false +ro.qc.sdk.audio.fluencetype=fluence +use.voice.path.for.pcm.voip=false +use.dedicated.device.for.voip=true +audio.deep_buffer.media=true +audio.offload.pcm.16bit.enable=true +audio.offload.pcm.24bit.enable=true +audio.offload.multiple.enabled=false +audio.offload.buffer.size.kb=32 + +# Bluetooth +qcom.bluetooth.soc=smd +qcom.bt.le_dev_pwr_class=1 +ro.qualcomm.bluetooth.opp=true +ro.qualcomm.bluetooth.hfp=true +ro.qualcomm.bluetooth.hsp=true +ro.qualcomm.bluetooth.pbap=true +ro.qualcomm.bluetooth.ftp=true +ro.qualcomm.bluetooth.nap=true +ro.qualcomm.bluetooth.map=true +ro.bluetooth.sap=true +ro.bluetooth.dun=true +ro.bluetooth.hfp.ver=1.6 +ro.qualcomm.bt.hci_transport=smd + +# Camera / Media +camera2.portability.force_api=1 +media.stagefright.legacyencoder=true +media.stagefright.less-secure=true +persist.media.treble_omx=false + +sw.revision=4 + +# Dalvik +dalvik.vm.dex2oat-swap=false +dalvik.vm.heapstartsize=8m +dalvik.vm.heapgrowthlimit=128m +dalvik.vm.heapsize=512m +dalvik.vm.heaptargetutilization=0.75 +dalvik.vm.heapminfree=2m +dalvik.vm.heapmaxfree=8m + +# Display +debug.composition.type=c2d +ro.opengles.version=196608 +ro.qualcomm.cabl=0 +ro.sf.lcd_density=320 +debug.hwui.use_buffer_age=false + +# GPS +persist.gps.qc_nlp_in_use=1 +ro.gps.agps_provider=1 +ro.qc.sdk.izat.premium_enabled=0 +ro.qc.sdk.izat.service_mask=0x0 + +# IO Scheduler +sys.io.scheduler=bfq + +# Memory optimizations +ro.vendor.qti.am.reschedule_service=true + +# NFC +ro.nfc.port=I2C + +##### +# Radio +# this prop is only for samsung +# ro.debug_level=0x4948 +##### +persist.data.netmgrd.qos.enable=true +persist.data.qmi.adb_logmask=0 +persist.radio.add_power_save=1 +rild.libpath=/vendor/lib/libsec-ril.so +ro.telephony.mms_data_profile=5 +ro.ril.telephony.qan_resp_strings=6 + +# Ril sends only one RIL_UNSOL_CALL_RING, so set call_ring.multiple to false +ro.telephony.call_ring.multiple=0 + +# Subsystem +persist.sys.ssr.enable_debug=0 + +# Sensors +ro.qc.sdk.gestures.camera=false +ro.qc.sdk.camera.facialproc=false +ro.qc.sdk.sensors.gestures=true +debug.sensors=1 + +# Time +persist.timed.enable=true + +# Vendor security patch level +ro.lineage.build.vendor_security_patch=2019-02-27 + +# Wi-Fi +ro.disableWifiApFirmwareReload=true +wifi.interface=wlan0 diff --git a/vndk/Android.mk b/vndk/Android.mk new file mode 100644 index 0000000..7f8b819 --- /dev/null +++ b/vndk/Android.mk @@ -0,0 +1,76 @@ +VNDK_SP_LIBRARIES := + +EXTRA_VENDOR_LIBRARIES := \ + android.hidl.base@1.0 \ + android.hidl.manager@1.0 \ + libhardware_legacy \ + libbinder \ + libui \ + android.hardware.configstore@1.0 \ + android.hardware.configstore-utils \ + libstagefright_foundation \ + libstdc++ \ + libnativehelper \ + libgui \ + android.hidl.token@1.0-utils \ + android.hardware.graphics.bufferqueue@1.0 \ + android.hidl.token@1.0 \ + android.hardware.media.omx@1.0 \ + android.hardware.media@1.0 + +#------------------------------------------------------------------------------- +# VNDK Modules +#------------------------------------------------------------------------------- +LOCAL_PATH := $(call my-dir) + +define define-vndk-lib +include $$(CLEAR_VARS) +LOCAL_MODULE := $1.$2 +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_PREBUILT_MODULE_FILE := $$(TARGET_OUT_INTERMEDIATE_LIBRARIES)/$1.so +LOCAL_STRIP_MODULE := false +LOCAL_MULTILIB := first +LOCAL_MODULE_TAGS := optional +LOCAL_INSTALLED_MODULE_STEM := $1.so +LOCAL_MODULE_SUFFIX := .so +LOCAL_MODULE_RELATIVE_PATH := $3 +LOCAL_VENDOR_MODULE := $4 +include $$(BUILD_PREBUILT) + +ifneq ($$(TARGET_2ND_ARCH),) +ifneq ($$(TARGET_TRANSLATE_2ND_ARCH),true) +include $$(CLEAR_VARS) +LOCAL_MODULE := $1.$2 +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_PREBUILT_MODULE_FILE := $$($$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/$1.so +LOCAL_STRIP_MODULE := false +LOCAL_MULTILIB := 32 +LOCAL_MODULE_TAGS := optional +LOCAL_INSTALLED_MODULE_STEM := $1.so +LOCAL_MODULE_SUFFIX := .so +LOCAL_MODULE_RELATIVE_PATH := $3 +LOCAL_VENDOR_MODULE := $4 +include $$(BUILD_PREBUILT) +endif # TARGET_TRANSLATE_2ND_ARCH is not true +endif # TARGET_2ND_ARCH is not empty +endef + +$(foreach lib,$(VNDK_SP_LIBRARIES),\ + $(eval $(call define-vndk-lib,$(lib),vndk-sp-gen,vndk-sp,))) +$(foreach lib,$(VNDK_SP_EXT_LIBRARIES),\ + $(eval $(call define-vndk-lib,$(lib),vndk-sp-ext-gen,vndk-sp,true))) +$(foreach lib,$(EXTRA_VENDOR_LIBRARIES),\ + $(eval $(call define-vndk-lib,$(lib),vndk-ext-gen,,true))) + +#------------------------------------------------------------------------------- +# Phony Package +#------------------------------------------------------------------------------- + +include $(CLEAR_VARS) +LOCAL_MODULE := s3ve3g-vndk-extra +LOCAL_MODULE_TAGS := optional +LOCAL_REQUIRED_MODULES := \ + $(addsuffix .vndk-sp-gen,$(VNDK_SP_LIBRARIES)) \ + $(addsuffix .vndk-sp-ext-gen,$(VNDK_SP_EXT_LIBRARIES)) \ + $(addsuffix .vndk-ext-gen,$(EXTRA_VENDOR_LIBRARIES)) +include $(BUILD_PHONY_PACKAGE)