Files
modem-auto-config/modem_auto_config.c
2024-12-05 00:41:36 +08:00

80 lines
2.7 KiB
C

/*
* Copyright (C) 2024, kuailexs <952415538@qq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <hybris/properties/properties.h>
#include <hybris/common/binding.h>
// Remove comment to enable debug
#define DEBUG
#ifdef DEBUG
#define LOG_DEBUG(...) fprintf(stdout, __VA_ARGS__)
#else
#define LOG_DEBUG(...) do {} while (0)
#endif
#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__)
#define ERR -1
// int pdc_init(void);
// int pdc_enable_auto_selection(int enable, int slot);
// void pdc_clean();
static int (*pdc_init)(void) = NULL;
static int (*pdc_enable_auto_selection)(int enable, int slot) = NULL;
static int (*pdc_clean)(void) = NULL;
int main(int argc, char* argv[])
{
char libpath[50] = {"\0"};
int length = property_get("vendor.rild.libpath", libpath, "0");
if (length <= 0) {
LOG_ERR("Failed to get prop.\n");
return -1;
}
LOG_DEBUG("vendor.rild.libpath %s\n", libpath);
void *rild_lib = android_dlopen(libpath, RTLD_LAZY);
if(rild_lib == NULL){
LOG_ERR("Failed android_dlopen.\n");
return -1;
}
//pdc_init = (int (*)(void))android_dlsym(rild_lib,"_Z8pdc_initv");
//pdc_enable_auto_selection = (int (*)(int, int))android_dlsym(rild_lib, "_Z25pdc_enable_auto_selectionii");
//pdc_clean = (int (*)(void))android_dlsym(rild_lib, "_Z9pdc_cleanv");
pdc_init = (int (*)(void))android_dlsym(rild_lib,"pdc_init");
pdc_enable_auto_selection = (int (*)(int, int))android_dlsym(rild_lib, "pdc_enable_auto_selection");
pdc_clean = (int (*)(void))android_dlsym(rild_lib, "pdc_clean");
if(pdc_init == NULL || pdc_enable_auto_selection == NULL || pdc_clean == NULL){
LOG_ERR("Failed to get fns %p %p %p\n",pdc_init,pdc_enable_auto_selection,pdc_clean);
android_dlclose(rild_lib);
return -1;
}
pdc_init();
LOG_DEBUG("enabling auto\n");
pdc_enable_auto_selection(1,0);
pdc_enable_auto_selection(1,1);
pdc_clean();
android_dlclose(rild_lib);
return 0;
}