当前位置:   article > 正文

Android RIL 动态切换 4G 模块适配_android 4g拨号上网ril

android 4g拨号上网ril

目录

修改的文件

文件修改说明

runtime.h

Android.mk(在 rild 目录下)

rild.c

Android.mk(在 runtime-ril-port 目录下)

runtime_port.c

如何适配


这个补丁是我加在全志A40 4.4上面的做模块动态适配的 , 毋庸置疑 后面的Android 版本也是适用的 , 比如rockchip 也是没问题的 只是我懒得搞了而已。

调试4G模块非常简单 只是说早期模块经常切换 , 换了还得换固件 , 固件其实只是更换了so库而已。因为kernel driver 已经对vid/pid进行了适配。

这个补丁是直接在hal 层rild 做的vid/pid 然后选择so库文件的。

这个补丁主要修改了 Android RIL (Radio Interface Layer) 的部分代码,以支持动态切换不同的 3G/4G 模块。

修改的文件

  • android/hardware/ril/include/runtime/runtime.h
  • android/hardware/ril/rild/Android.mk
  • android/hardware/ril/rild/rild.c
  • android/hardware/ril/runtime-ril-port/Android.mk
  • android/hardware/ril/runtime-ril-port/runtime_port.c

文件修改说明

runtime.h

这是一个新文件,定义了一些函数和变量,用于启动 uevent 监视器,获取当前的 3G 端口设备,数据和类型。

Android.mk(在 rild 目录下)

在这个 makefile 文件中,添加了 libruntime-ril-portLOCAL_SHARED_LIBRARIES,这样 rild 就可以链接到这个新的库。

rild.c

这个文件中的修改主要是在 rild 的主函数中,添加了对 3G 模块类型的检测,并根据检测到的模块类型,动态地设置 RIL 库的路径。此外,还添加了对 uevent 的监视,当检测到 3G 模块的变化时,会重新启动 rild。

Android.mk(在 runtime-ril-port 目录下)

这是一个新文件,用于编译 runtime_port.c,生成 libruntime-ril-port 库。

runtime_port.c

这是一个新文件,实现了在 runtime.h 中定义的函数。这些函数主要用于检测当前的 3G 模块类型,以及启动对 uevent 的监视。

如何适配

  1. 将这个补丁应用到你的 Android 源码树中。
  2. 根据你的 3G 模块的特性,修改 runtime_port.c 中的 modem_3g_device_table
  3. 编译并刷入你的 Android 系统。
  4. 当你的设备启动时,rild 会自动检测当前的 3G 模块类型,并加载相应的 RIL 库。

     
    1. diff --git a/android/hardware/ril/include/runtime/runtime.h b/android/hardware/ril/include/runtime/runtime.h
    2. new file mode 100755
    3. index 0000000000..c381b4f2f8
    4. --- /dev/null
    5. +++ b/android/hardware/ril/include/runtime/runtime.h
    6. @@ -0,0 +1,22 @@
    7. +/*
    8. + * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
    9. + */
    10. +
    11. +#ifndef RUNTIME_H
    12. +#define RUNTIME_H
    13. +
    14. +extern int start_uevent_monitor(void);
    15. +extern const char *runtime_3g_port_device(void);
    16. +extern const char *runtime_3g_port_data(void);
    17. +extern int runtime_3g_port_type(void);
    18. +enum {
    19. + ME909S_MODEM = 0,
    20. + U9300C_MODEM,
    21. + EC20_MODEM,
    22. + EM8000_MODEM,
    23. + UNKNOWN_MODEM,
    24. +};
    25. +
    26. +extern int current_modem_type;
    27. +
    28. +#endif
    29. diff --git a/android/hardware/ril/rild/Android.mk b/android/hardware/ril/rild/Android.mk
    30. index d8ca6d368d..83c0a1a130 100755
    31. --- a/android/hardware/ril/rild/Android.mk
    32. +++ b/android/hardware/ril/rild/Android.mk
    33. @@ -13,7 +13,8 @@ LOCAL_SHARED_LIBRARIES := \
    34. liblog \
    35. libcutils \
    36. libril \
    37. - libdl
    38. + libdl \
    39. + libruntime-ril-port
    40. # temporary hack for broken vendor rils
    41. #LOCAL_WHOLE_STATIC_LIBRARIES := \
    42. diff --git a/android/hardware/ril/rild/rild.c b/android/hardware/ril/rild/rild.c
    43. index 4a555f275c..e79cd3cb71 100755
    44. --- a/android/hardware/ril/rild/rild.c
    45. +++ b/android/hardware/ril/rild/rild.c
    46. @@ -36,10 +36,19 @@
    47. #include "hardware/qemu_pipe.h"
    48. #include "radio_monitor.h"
    49. -
    50. +#include <runtime/runtime.h>
    51. #define LIB_PATH_PROPERTY "rild.libpath"
    52. #define LIB_ARGS_PROPERTY "rild.libargs"
    53. #define MAX_LIB_ARGS 16
    54. +#define MAX_POLL_DEVICE_CNT 8
    55. +
    56. +
    57. +
    58. +
    59. +#define REFERENCE_RIL_ME909S_PATH "/system/lib/libreference_me909s-ril.so"
    60. +#define REFERENCE_RIL_U9300C_PATH "/system/lib/libreference_u9300c-ril.so"
    61. +#define REFERENCE_RIL_EC20_PATH "/system/lib/libreference_ec20-ril.so"
    62. +#define REFERENCE_RIL_EM8000_PATH "/system/lib/libreference_em8000-ril.so"
    63. static void usage(const char *argv0)
    64. {
    65. @@ -64,6 +73,7 @@ static struct RIL_Env s_rilEnv = {
    66. RIL_onUnsolicitedResponse,
    67. RIL_requestTimedCallback
    68. };
    69. +static int s_poll_device_cnt = 0;
    70. extern void RIL_startEventLoop();
    71. @@ -109,44 +119,21 @@ int main(int argc, char **argv)
    72. char libPath[PROPERTY_VALUE_MAX];
    73. unsigned char hasLibArgs = 0;
    74. int ret = 0;
    75. + int modem_type = UNKNOWN_MODEM;
    76. int i;
    77. char platform[PROPERTY_VALUE_MAX] = {0};
    78. //is telephony platform?
    79. if(property_get("ro.sw.embeded.telephony", platform, NULL)){
    80. if(strcmp(platform, "true")) {
    81. - RLOGI("platform: wifi-only");
    82. + RLOGI("platform: wifi-only --1");
    83. radio_monitor();
    84. }else{
    85. - RLOGI("platform: telephony");
    86. + RLOGI("platform: telephony --2");
    87. }
    88. }
    89. -#if 0
    90. - umask(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
    91. - for (i = 1; i < argc ;) {
    92. - if (0 == strcmp(argv[i], "-l") && (argc - i > 1)) {
    93. - rilLibPath = argv[i + 1];
    94. - i += 2;
    95. - } else if (0 == strcmp(argv[i], "--")) {
    96. - i++;
    97. - hasLibArgs = 1;
    98. - break;
    99. - } else {
    100. - usage(argv[0]);
    101. - }
    102. - }
    103. - if (rilLibPath == NULL) {
    104. - if ( 0 == property_get(LIB_PATH_PROPERTY, libPath, NULL)) {
    105. - // No lib sepcified on the command line, and nothing set in props.
    106. - // Assume "no-ril" case.
    107. - goto done;
    108. - } else {
    109. - rilLibPath = libPath;
    110. - }
    111. - }
    112. -#else
    113. ret = property_get(LIB_PATH_PROPERTY, libPath, NULL);
    114. if (ret <= 0) {
    115. /* nothing to do */
    116. @@ -174,9 +161,62 @@ int main(int argc, char **argv)
    117. RLOGD("err: get rilLibPath failed\n");
    118. goto done;
    119. }
    120. + ///$shh$20180906$add$Dynamic switching module$
    121. + //Wait for device ready.
    122. + // if (rilLibPath == NULL) {
    123. + while(UNKNOWN_MODEM == modem_type){
    124. + modem_type = runtime_3g_port_type();
    125. + ALOGD("111 -Couldn't find proper modem, retrying...");
    126. + s_poll_device_cnt++;
    127. + if (s_poll_device_cnt > MAX_POLL_DEVICE_CNT){
    128. + /*
    129. + *Maybe no device right now, start to monitor
    130. + *hotplug event later.
    131. + */
    132. + start_uevent_monitor();
    133. + goto done;
    134. + }
    135. + sleep(5);
    136. + }
    137. + //}
    138. -#endif
    139. - RLOGD("\nrilLibPath = %s\n\n", rilLibPath);
    140. + start_uevent_monitor();
    141. +
    142. + switch (modem_type){
    143. + case ME909S_MODEM:
    144. + {
    145. + rilLibPath = REFERENCE_RIL_ME909S_PATH;
    146. + break;
    147. + }
    148. + case U9300C_MODEM:
    149. + {
    150. + rilLibPath = REFERENCE_RIL_U9300C_PATH;
    151. + break;
    152. + }
    153. + case EC20_MODEM:
    154. + {
    155. + rilLibPath = REFERENCE_RIL_EC20_PATH;
    156. + break;
    157. + }
    158. + case EM8000_MODEM:
    159. + {
    160. + rilLibPath = REFERENCE_RIL_EM8000_PATH;
    161. + printf("");
    162. + break;
    163. + }
    164. +
    165. + if (rilLibPath == NULL) {
    166. + if ( 0 == property_get(LIB_PATH_PROPERTY, libPath, NULL)) {
    167. + // No lib sepcified on the command line, and nothing set in props.
    168. + // Assume "no-ril" case.
    169. + goto done;
    170. + } else {
    171. + rilLibPath = libPath;
    172. + }
    173. + }
    174. + }
    175. + RLOGD("shh->rilLibPath:%s,modem_type=%d",rilLibPath,modem_type);
    176. + ///$shh$20180906$add$Dynamic switching module$
    177. /* special override when in the emulator */
    178. #if 0 //ignore this by SW
    179. diff --git a/android/hardware/ril/runtime-ril-port/Android.mk b/android/hardware/ril/runtime-ril-port/Android.mk
    180. new file mode 100755
    181. index 0000000000..fdf21f4844
    182. --- /dev/null
    183. +++ b/android/hardware/ril/runtime-ril-port/Android.mk
    184. @@ -0,0 +1,19 @@
    185. +# Copyright 2006 The Android Open Source Project
    186. +
    187. +LOCAL_PATH:= $(call my-dir)
    188. +include $(CLEAR_VARS)
    189. +
    190. +LOCAL_SRC_FILES:= \
    191. + runtime_port.c
    192. +
    193. +LOCAL_SHARED_LIBRARIES := \
    194. + libutils \
    195. + libcutils
    196. +
    197. +LOCAL_CFLAGS :=
    198. +
    199. +LOCAL_MODULE_TAGS := optional
    200. +LOCAL_MODULE:= libruntime-ril-port
    201. +
    202. +
    203. +include $(BUILD_SHARED_LIBRARY)
    204. diff --git a/android/hardware/ril/runtime-ril-port/runtime_port.c b/android/hardware/ril/runtime-ril-port/runtime_port.c
    205. new file mode 100755
    206. index 0000000000..f7682c7df1
    207. --- /dev/null
    208. +++ b/android/hardware/ril/runtime-ril-port/runtime_port.c
    209. @@ -0,0 +1,452 @@
    210. +/*
    211. + * Licensed under the Apache License, Version 2.0 (the "License");
    212. + * you may not use this file except in compliance with the License.
    213. + * You may obtain a copy of the License at
    214. + *
    215. + * http://www.apache.org/licenses/LICENSE-2.0
    216. + *
    217. + * Unless required by applicable law or agreed to in writing, software
    218. + * distributed under the License is distributed on an "AS IS" BASIS,
    219. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    220. + * See the License for the specific language governing permissions and
    221. + * limitations under the License.
    222. + */
    223. +
    224. +/*
    225. + * Copyright 2011-2015 Freescale Semiconductor, Inc. All Rights Reserved.
    226. + */
    227. +
    228. +#include <stdio.h>
    229. +#include <string.h>
    230. +#include <stdlib.h>
    231. +#include <dirent.h>
    232. +#include <errno.h>
    233. +#include <fcntl.h>
    234. +#define LOG_TAG "RIL"
    235. +#include <utils/Log.h>
    236. +
    237. +#include <pthread.h>
    238. +#include <sys/types.h>
    239. +#include <sys/socket.h>
    240. +#include <sys/poll.h>
    241. +#include <linux/netlink.h>
    242. +
    243. +#include <signal.h>
    244. +#include <unistd.h>
    245. +#include <runtime/runtime.h>
    246. +
    247. +int current_modem_type = UNKNOWN_MODEM;
    248. +
    249. +#define FAKE_PORT "/dev/ttyFAKEPort"
    250. +/* Rild need a fake port to pass continue init job,
    251. + * return a fake port make it runable.
    252. + * Or the system will enter 15s in early suspend.
    253. + */
    254. +
    255. +struct modem_3g_device {
    256. + const char *idVendor;
    257. + const char *idProduct;
    258. + const char *deviceport; /* sending AT command */
    259. + const char *dataport; /* sending 3g data */
    260. + const char *name;
    261. + const int type;
    262. +};
    263. +
    264. +#define PATH_SIZE 1024
    265. +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
    266. +static const char *USB_DIR_BASE = "/sys/bus/usb/devices/";
    267. +
    268. +static struct modem_3g_device modem_3g_device_table[] = {
    269. +
    270. + {
    271. + .name = "ME909S_MODEM",
    272. + .idVendor = "12d1",
    273. + .idProduct = "15c1",
    274. + .deviceport = "/dev/ttyUSB0",
    275. + .dataport = "/dev/ttyUSB2",
    276. + .type = ME909S_MODEM,
    277. + },
    278. +
    279. +
    280. + {
    281. + .name = "U9300C_MODEM",
    282. + .idVendor = "1c9e",
    283. + .idProduct = "9b3c",
    284. + .deviceport = "/dev/ttyUSB1",
    285. + .dataport = "/dev/ttyUSB2",
    286. + .type = U9300C_MODEM,
    287. + },
    288. + {
    289. + .name = "EC20_MODEM",
    290. + .idVendor = "2c7c",
    291. + .idProduct = "0125",
    292. + .deviceport = "/dev/ttyUSB0",
    293. + .dataport = "/dev/ttyUSB2",
    294. + .type = EC20_MODEM,
    295. + },
    296. + {
    297. + .name = "EM8000_MODEM",
    298. + .idVendor = "19d2",
    299. + .idProduct = "0532",
    300. + .deviceport = "/dev/ttyUSB0",
    301. + .dataport = "/dev/ttyUSB2",
    302. + .type = EM8000_MODEM,
    303. + },
    304. +};
    305. +
    306. +/* -------------------------------------------------------------- */
    307. +
    308. +#define DEBUG_UEVENT 0
    309. +#define UEVENT_PARAMS_MAX 32
    310. +
    311. +enum uevent_action { action_add, action_remove, action_change };
    312. +
    313. +struct uevent {
    314. + char *path;
    315. + enum uevent_action action;
    316. + char *subsystem;
    317. + char *param[UEVENT_PARAMS_MAX];
    318. + unsigned int seqnum;
    319. +};
    320. +
    321. +static void dump_uevent(struct uevent *event);
    322. +
    323. +int readfile(char *path, char *content, size_t size)
    324. +{
    325. + int ret;
    326. + FILE *f;
    327. + f = fopen(path, "r");
    328. + if (f == NULL)
    329. + return -1;
    330. +
    331. + ret = fread(content, 1, size, f);
    332. + fclose(f);
    333. + return ret;
    334. +}
    335. +
    336. +int is_device_equal(struct modem_3g_device *device,
    337. + const char *idv, const char *idp)
    338. +{
    339. + long pvid = 0xffff, ppid = 0xffff;
    340. + long t_vid, t_pid;
    341. + if (device == NULL)
    342. + return 0;
    343. + t_vid = strtol(device->idVendor, NULL, 16);
    344. + t_pid = strtol(device->idProduct, NULL, 16);
    345. + pvid = strtol(idv, NULL, 16);
    346. + ppid = strtol(idp, NULL, 16);
    347. +
    348. + return (t_vid == pvid && t_pid == ppid);
    349. +}
    350. +
    351. +struct modem_3g_device *
    352. +find_devices_in_table(const char *idvendor, const char *idproduct)
    353. +{
    354. + int i;
    355. + int size = ARRAY_SIZE(modem_3g_device_table);
    356. + struct modem_3g_device *device;
    357. +
    358. + for (i = 0; i < size; i++) {
    359. + device = &modem_3g_device_table[i];
    360. +
    361. + if (is_device_equal(device, idvendor, idproduct)) {
    362. + ALOGI("Runtime 3G port found matched device with "
    363. + "Name:%s idVendor:%s idProduct:%s",
    364. + device->name, device->idVendor, device->idProduct);
    365. +
    366. + return device;
    367. + }
    368. + }
    369. +
    370. + return NULL;
    371. +}
    372. +
    373. +struct modem_3g_device *find_matched_device(void)
    374. +{
    375. + struct dirent *dent;
    376. + DIR *usbdir;
    377. + struct modem_3g_device *device = NULL;
    378. + char *path, *path2;
    379. + char idvendor[64];
    380. + char idproduct[64];
    381. + int ret, i;
    382. +
    383. + path = malloc(PATH_SIZE);
    384. + if (!path)
    385. + return NULL;
    386. +
    387. + path2 = malloc(PATH_SIZE);
    388. + if (!path2) {
    389. + free(path);
    390. + return NULL;
    391. + }
    392. +
    393. + usbdir = opendir(USB_DIR_BASE);
    394. + if (usbdir == NULL) {
    395. + free(path);
    396. + free(path2);
    397. + return NULL;
    398. + }
    399. +
    400. + memset(path, 0, PATH_SIZE);
    401. + memset(path2, 0, PATH_SIZE);
    402. +
    403. + while ((dent = readdir(usbdir)) != NULL) {
    404. + if (strcmp(dent->d_name, ".") == 0
    405. + || strcmp(dent->d_name, "..") == 0)
    406. + continue;
    407. + memset(idvendor, 0, sizeof(idvendor));
    408. + memset(idproduct, 0, sizeof(idproduct));
    409. + path = strcpy(path, USB_DIR_BASE);
    410. + path = strcat(path, dent->d_name);
    411. + strcpy(path2, path);
    412. + path = strcat(path, "/idVendor");
    413. + path2 = strcat(path2, "/idProduct");
    414. +
    415. + ret = readfile(path, idvendor, 4);
    416. + if (ret <= 0)
    417. + continue;
    418. + ret = readfile(path2, idproduct, 4);
    419. + if (ret <= 0)
    420. + continue;
    421. + device = find_devices_in_table(idvendor, idproduct);
    422. + if (device != NULL)
    423. + goto out;
    424. + }
    425. +
    426. + if (device == NULL)
    427. + ALOGI("Runtime 3G can't find supported modem");
    428. +out:
    429. + closedir(usbdir);
    430. + free(path);
    431. + free(path2);
    432. +
    433. + return device;
    434. +}
    435. +
    436. +
    437. +const char *runtime_3g_port_device(void)
    438. +{
    439. + struct modem_3g_device *device;
    440. + device = find_matched_device();
    441. + if (device == NULL)
    442. + return FAKE_PORT;
    443. +
    444. + /* Set gobal modem type. */
    445. + current_modem_type = device->type;
    446. +
    447. + ALOGI("Current modem type = %d", current_modem_type);
    448. +
    449. + return device->deviceport;
    450. +}
    451. +
    452. +const char *runtime_3g_port_data(void)
    453. +{
    454. + struct modem_3g_device *device;
    455. +
    456. + device = find_matched_device();
    457. + if (device == NULL)
    458. + return FAKE_PORT;
    459. + return device->dataport;
    460. +}
    461. +
    462. +int runtime_3g_port_type(void)
    463. +{
    464. + struct modem_3g_device *device;
    465. + int type = UNKNOWN_MODEM;
    466. + if (UNKNOWN_MODEM == current_modem_type){
    467. + if (NULL != (device = find_matched_device())){
    468. + /* Set gobal modem type. */
    469. + type = device->type;
    470. + }
    471. + }else{
    472. + type = current_modem_type;
    473. + }
    474. +
    475. + ALOGI("Current modem type = %d", type);
    476. +
    477. + return type;
    478. +}
    479. +
    480. +static void free_uevent(struct uevent *event)
    481. +{
    482. + int i;
    483. + free(event->path);
    484. + free(event->subsystem);
    485. + for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
    486. + if (!event->param[i])
    487. + break;
    488. + free(event->param[i]);
    489. + }
    490. + free(event);
    491. +}
    492. +
    493. +static int dispatch_uevent(struct uevent *event)
    494. +{
    495. + /* if it's a usb tty event in our table. make the rild reboot. */
    496. + int i;
    497. + int ret;
    498. + for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
    499. + if (!event->param[i])
    500. + break;
    501. + if (strncmp(event->param[i], "PRODUCT=", 8) == 0) {
    502. + char vbuf[5], pbuf[5];
    503. + ret = sscanf(event->param[i],
    504. + "PRODUCT=%4s/%4s/", vbuf, pbuf);
    505. + if (ret < 0)
    506. + return -1;
    507. + if (find_devices_in_table(vbuf, pbuf))
    508. + alarm(1);
    509. + /* Restart in 1 second, since USB usually have
    510. + * many devices, this avoid rild restart too
    511. + * many times. */
    512. + }
    513. + }
    514. + return 0;
    515. +}
    516. +
    517. +int process_uevent_message(int sock)
    518. +{
    519. + char buffer[64 * 1024];
    520. + char *s = buffer, *p;
    521. + char *end;
    522. + int count, param_idx = 0, ret;
    523. + struct uevent *event;
    524. + count = recv(sock, buffer, sizeof(buffer), 0);
    525. + if (count < 0) {
    526. + ALOGE("Error receiving uevent (%s)", strerror(errno));
    527. + return -errno;
    528. + }
    529. + event = malloc(sizeof(struct uevent));
    530. + if (!event) {
    531. + ALOGE("Error allcating memroy (%s)", strerror(errno));
    532. + return -errno;
    533. + }
    534. + memset(event, 0, sizeof(struct uevent));
    535. +
    536. + end = s + count;
    537. +
    538. + for (p = s; *p != '@'; p++)
    539. + ;
    540. + p++;
    541. + event->path = strdup(p);
    542. + s += strlen(s) + 1;
    543. +
    544. + while (s < end) {
    545. + if (!strncmp(s, "ACTION=", strlen("ACTION="))) {
    546. + char *a = s + strlen("ACTION=");
    547. + if (!strcmp(a, "add"))
    548. + event->action = action_add;
    549. + else if (!strcmp(a, "change"))
    550. + event->action = action_change;
    551. + else if (!strcmp(a, "remove"))
    552. + event->action = action_remove;
    553. + } else if (!strncmp(s, "SEQNUM=", strlen("SEQNUM=")))
    554. + event->seqnum = atoi(s + strlen("SEQNUM="));
    555. + else if (!strncmp(s, "SUBSYSTEM=", strlen("SUBSYSTEM=")))
    556. + event->subsystem = strdup(s + strlen("SUBSYSTEM="));
    557. + else
    558. + event->param[param_idx++] = strdup(s);
    559. + s += strlen(s) + 1;
    560. + }
    561. +
    562. + ret = dispatch_uevent(event);
    563. +#if DEBUG_UEVENT
    564. + dump_uevent(event);
    565. +#endif
    566. + free_uevent(event);
    567. + return ret;
    568. +}
    569. +
    570. +static void dump_uevent(struct uevent *event)
    571. +{
    572. + int i;
    573. +
    574. + ALOGD("[UEVENT] Sq: %u S: %s A: %d P: %s",
    575. + event->seqnum, event->subsystem, event->action, event->path);
    576. + for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
    577. + if (!event->param[i])
    578. + break;
    579. + ALOGD("%s", event->param[i]);
    580. + }
    581. +}
    582. +
    583. +void restart_rild(int p)
    584. +{
    585. + ALOGI("3G Modem changed,RILD will restart...");
    586. + exit(-1);
    587. +}
    588. +
    589. +void *usb_tty_monitor_thread(void *arg)
    590. +{
    591. + struct sockaddr_nl nladdr;
    592. + struct pollfd pollfds[2];
    593. + int uevent_sock;
    594. + int ret, max = 0;
    595. + int uevent_sz = 64 * 1024;
    596. + int timeout = -1;
    597. + struct sigaction timeoutsigact;
    598. +
    599. + ALOGI("3G modem monitor thread is start");
    600. +
    601. + timeoutsigact.sa_handler = restart_rild;
    602. + sigemptyset(&timeoutsigact.sa_mask);
    603. + sigaddset(&timeoutsigact.sa_mask, SIGALRM);
    604. + sigaction(SIGALRM, &timeoutsigact, 0);
    605. +
    606. + memset(&nladdr, 0, sizeof(nladdr));
    607. + nladdr.nl_family = AF_NETLINK;
    608. + nladdr.nl_pid = getpid();
    609. + nladdr.nl_groups = 0xffffffff;
    610. +
    611. + uevent_sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
    612. + if (uevent_sock < 0) {
    613. + ALOGE(" Netlink socket faild, usb monitor exiting...");
    614. + return NULL;
    615. + }
    616. +
    617. + if (setsockopt(uevent_sock, SOL_SOCKET, SO_RCVBUFFORCE, &uevent_sz,
    618. + sizeof(uevent_sz)) < 0) {
    619. + ALOGE("Unable to set uevent socket options: %s", strerror(errno));
    620. + return NULL;
    621. + }
    622. +
    623. + if (bind(uevent_sock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) {
    624. + ALOGE("Unable to bind uevent socket: %s", strerror(errno));
    625. + return NULL;
    626. + }
    627. + pollfds[0].fd = uevent_sock;
    628. + pollfds[0].events = POLLIN;
    629. +
    630. + ret = fcntl(uevent_sock,F_SETFL, O_NONBLOCK);
    631. + if (ret < 0)
    632. + ALOGE("Error on fcntl:%s", strerror(errno));
    633. +
    634. + while (1) {
    635. + ret = poll(pollfds, 1, timeout);
    636. +
    637. + switch (ret) {
    638. + case 0:
    639. + ALOGD("poll timeout");
    640. + continue;
    641. + case -1:
    642. + ALOGD("poll error:%s", strerror(errno));
    643. + break;
    644. +
    645. + default:
    646. + if (pollfds[0].revents & POLLIN)
    647. + process_uevent_message(uevent_sock);
    648. + }
    649. + }
    650. +
    651. + close(uevent_sock);
    652. +}
    653. +
    654. +int start_uevent_monitor(void)
    655. +{
    656. + pthread_t pth_uevent_monitor;
    657. + return pthread_create(&pth_uevent_monitor, NULL,
    658. + usb_tty_monitor_thread, NULL);
    659. +}
    660. +
    661. +

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/611914
推荐阅读
相关标签
  

闽ICP备14008679号