PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tel-plugin-imcmodem/src/vnet.c

https://review.tizen.org/git/
C | 139 lines | 91 code | 29 blank | 19 comment | 6 complexity | 5d690050ef53bbe899e4d83099b885f2 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
  1. /*
  2. * tel-plugin-imcmodem
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
  5. *
  6. * Contact: Kyoungyoup Park <gynaru.park@samsung.com>
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <fcntl.h>
  24. #include <unistd.h>
  25. #include <sys/ioctl.h>
  26. #include <netinet/in.h>
  27. #include <arpa/inet.h>
  28. #include <errno.h>
  29. #include <linux/types.h>
  30. #include <sys/types.h>
  31. #include <sys/socket.h>
  32. #include <linux/netlink.h>
  33. #include <net/if.h>
  34. #include <glib.h>
  35. #include <log.h>
  36. #include "vnet.h"
  37. #ifndef __USE_GNU
  38. #define __USE_GNU
  39. #endif
  40. #define MODEM_IMAGE_PATH "/boot/modem.bin"
  41. #define NV_DIR_PATH "/csa/nv"
  42. #define NV_FILE_PATH NV_DIR_PATH"/nvdata.bin"
  43. #define VNET_CH_PATH_BOOT0 "/dev/umts_boot0"
  44. #define VNET_CH_PATH_IPC0 "/dev/umts_ipc0"
  45. #define IOCTL_MODEM_STATUS _IO('o', 0x27)
  46. void vnet_start_cp_ramdump()
  47. {
  48. int ret;
  49. ret = system("/usr/bin/xmm6262-boot -o u &");
  50. dbg("system(/usr/bin/xmm6262-boot -o u &) ret[%d]",ret)
  51. }
  52. void vnet_start_cp_reset()
  53. {
  54. int ret;
  55. ret = system("/usr/bin/xmm6262-boot &");
  56. dbg("system(/usr/bin/xmm6262-boot &) ret[%d]",ret)
  57. }
  58. int vnet_get_cp_state( int fd )
  59. {
  60. enum vnet_cp_state state = VNET_CP_STATE_ONLINE;
  61. state = ioctl( fd, IOCTL_MODEM_STATUS );
  62. switch ( state ) {
  63. case VNET_CP_STATE_OFFLINE:
  64. dbg("cp state : offline");
  65. break;
  66. case VNET_CP_STATE_CRASH_RESET:
  67. dbg("cp state : crash_reset");
  68. break;
  69. case VNET_CP_STATE_CRASH_EXIT:
  70. dbg("cp state : crash_exit");
  71. break;
  72. case VNET_CP_STATE_BOOTING:
  73. dbg("cp state : boot");
  74. break;
  75. case VNET_CP_STATE_ONLINE:
  76. dbg("cp state : online");
  77. break;
  78. case VNET_CP_STATE_NV_REBUILDING:
  79. dbg("cp state : nv rebuild");
  80. break;
  81. case VNET_CP_STATE_LOADER_DONE:
  82. dbg("cp state : loader done");
  83. break;
  84. default:
  85. dbg("cp state : unknown state");
  86. return -1;
  87. }
  88. return (int)state;
  89. }
  90. int vnet_ipc0_open()
  91. {
  92. int state;
  93. int fd = 0, cnt = 0;
  94. fd = open ( VNET_CH_PATH_BOOT0, O_RDWR );
  95. if ( fd < 0 ) {
  96. dbg("error : open [ %s ] [ %s ]", VNET_CH_PATH_BOOT0, strerror(errno));
  97. return -1;
  98. }
  99. state = vnet_get_cp_state( fd );
  100. if ( (enum vnet_cp_state)state != VNET_CP_STATE_ONLINE ) {
  101. return -1;
  102. } else {
  103. fd = open ( VNET_CH_PATH_IPC0, O_RDWR );
  104. if ( fd < 0 ) {
  105. dbg("error : open [ %s ] [ %s ]", VNET_CH_PATH_IPC0, strerror(errno));
  106. return -1;
  107. }
  108. }
  109. return fd;
  110. }