You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1190 lines
28 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright � 2000-2017. All Rights Reserved.
  4. // Version 2.0 7/20/2017
  5. // Last modification: 7/20/2017
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: mojoHardwareManager.cpp
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of mojoHardwareManager.cpp
  13. //----------------------------------------------------------------------------
  14. //
  15. #include "mojoHardwareManager.h"
  16. #include "../hardware/hid/hid_dc.h"
  17. #include <hidapi/hidapi.h>
  18. #include <ifaddrs.h>
  19. #include <linux/serial.h>
  20. #include <linux/videodev2.h>
  21. #include <sys/ioctl.h>
  22. #include <sys/resource.h>
  23. #include <sys/time.h>
  24. #include <sys/types.h>
  25. #define LOG(X) m_pLog->Log("MHWM", this, X)
  26. #ifdef DEBUG
  27. #define LOG_ERROR(X) \
  28. { \
  29. char _tBfrErrMSG2w34[256]; \
  30. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  31. m_pLog->Log("MHWM", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  32. }
  33. #else
  34. #define LOG_ERROR(X) m_pLog->Log("MHWM", this, _LOG_ERROR, X);
  35. #endif
  36. mojoHardwareManager * mojoHardwareManager::_instance = NULL;
  37. /**
  38. * Returns the single instance of the object.
  39. */
  40. mojoHardwareManager * mojoHardwareManager::getInstance(config_setting_t * Settings)
  41. {
  42. // check if the instance has been created yet
  43. if (0 == _instance)
  44. {
  45. // if not, then create it
  46. _instance = new mojoHardwareManager(Settings);
  47. };
  48. // return the single instance
  49. return _instance;
  50. }
  51. // Constructor implementation
  52. mojoHardwareManager::mojoHardwareManager(config_setting_t * SNode)
  53. {
  54. m_pLog = basicLogCollection::getInstance();
  55. m_pSettingsProvider = basicSettingsProvider::getInstance();
  56. m_nMemoryLimitHeapSize = 0;
  57. if (m_pSettingsProvider)
  58. {
  59. m_pSettings = m_pSettingsProvider->getSubNode(SNode, "HARDWARE_MANAGER");
  60. if (m_pSettingsProvider->isCompromised())
  61. {
  62. m_pSettingsProvider->validate();
  63. };
  64. }
  65. else
  66. {
  67. m_pSettings = NULL;
  68. };
  69. m_pDBC = mojoDBC::getInstance();
  70. char tB[128];
  71. struct rlimit rl = {0};
  72. getrlimit(RLIMIT_STACK, &rl);
  73. sprintf(tB, "Stack Size: %d", rl.rlim_cur); // RLIM_INFINITY
  74. LOG(tB);
  75. sprintf(tB, "MAX Stack Size: %d", rl.rlim_max);
  76. LOG(tB);
  77. m_bInitOK = false;
  78. }
  79. mojoHardwareManager::~mojoHardwareManager()
  80. {
  81. _instance = NULL;
  82. }
  83. bool mojoHardwareManager::validate()
  84. {
  85. bool RetVal = true;
  86. // Mem Validator
  87. if (m_nMemoryLimitHeapSize)
  88. {
  89. size_t memStat = getCurrentRSS();
  90. #ifdef DEBUG_EXTRA
  91. char MEM_MSG[128];
  92. sprintf(MEM_MSG, "MEM: %d TARG: %d", memStat, m_nMemoryLimitHeapSize);
  93. LOG(MEM_MSG);
  94. #endif
  95. RetVal = (memStat < m_nMemoryLimitHeapSize);
  96. if (! RetVal)
  97. {
  98. LOG_ERROR("Memory Consumption too BIG!");
  99. };
  100. };
  101. return RetVal;
  102. }
  103. int xioctl(int fh, int request, void * arg)
  104. {
  105. int r;
  106. do
  107. {
  108. r = ioctl(fh, request, arg);
  109. }
  110. while (-1 == r && EINTR == errno);
  111. return r;
  112. }
  113. #define CLEAR(x) memset(&(x), 0, sizeof(x))
  114. void mojoHardwareManager::getMAC(CSTR if_name, CSTR buf)
  115. {
  116. char tB[128];
  117. FILE * fd = NULL;
  118. if (buf)
  119. {
  120. sprintf(tB, "/sys/class/net/%s/address", if_name);
  121. #ifdef DEBUG
  122. LOG(tB);
  123. #endif
  124. fd = fopen(tB, "r");
  125. if (fd)
  126. {
  127. fread(buf, 1, INET6_ADDRSTRLEN, fd);
  128. fclose(fd);
  129. buf = trim(buf);
  130. }
  131. else
  132. {
  133. memset(buf, 0, INET6_ADDRSTRLEN);
  134. };
  135. #ifdef DEBUG
  136. LOG(buf);
  137. #endif
  138. };
  139. }
  140. void mojoHardwareManager::getGW(CSTR if_name, CSTR buf)
  141. {
  142. FILE * fd = popen("route -n", "r");
  143. char tB[1024];
  144. // char expBuf[1024];
  145. memset(buf, 0, INET6_ADDRSTRLEN);
  146. if (fd)
  147. {
  148. while (! feof(fd))
  149. {
  150. fgets((CSTR) tB, 1024, fd);
  151. trim((CSTR) tB);
  152. if (strlen(tB))
  153. {
  154. if (strstr(tB, if_name) != NULL)
  155. {
  156. // strncpy( expBuf, tB, 1024 );
  157. CArray * CA = explode(' ', tB);
  158. if (CA)
  159. {
  160. // for (int i=0; i< CA->size(); i++ ) {
  161. // char tB[128];
  162. // trim( CA->at(i) );
  163. // sprintf( tB, "GW# %d: %s", i, CA->at(i) );
  164. // LOG( tB );
  165. // };
  166. trim(CA->at(1));
  167. if (strstr(CA->at(1), "0.0.0.0") == NULL)
  168. {
  169. strncpy(buf, CA->at(1), INET6_ADDRSTRLEN);
  170. };
  171. delete(CA);
  172. };
  173. };
  174. };
  175. };
  176. fclose(fd);
  177. };
  178. if (strlen(buf) == 0)
  179. {
  180. strncpy(buf, "0.0.0.0", INET6_ADDRSTRLEN);
  181. }
  182. }
  183. void mojoHardwareManager::getTTyDesc(CSTR dev_name, CSTR buf)
  184. {
  185. FILE * fd = popen("dmesg | grep tty", "r");
  186. char tB[1024];
  187. // char expBuf[1024];
  188. memset(buf, 0, DBC_RESOURCE_DESC_SIZE);
  189. if (fd)
  190. {
  191. while (! feof(fd))
  192. {
  193. fgets((CSTR) tB, 1024, fd);
  194. trim((CSTR) tB);
  195. if (strlen(tB))
  196. {
  197. if (strstr(tB, dev_name) != NULL)
  198. {
  199. // strncpy( expBuf, tB, 1024 );
  200. CArray * CA = explode(':', tB);
  201. if (CA)
  202. {
  203. // for (int i=0; i< CA->size(); i++ ) {
  204. // char tB[128];
  205. // trim( CA->at(i) );
  206. // sprintf( tB, "GW# %d: %s", i, CA->at(i) );
  207. // LOG( tB );
  208. // };
  209. trim(CA->at(1));
  210. strncpy(buf, CA->at(1), DBC_RESOURCE_DESC_SIZE);
  211. buf[DBC_RESOURCE_DESC_SIZE - 1] = (char) 0;
  212. delete(CA);
  213. };
  214. };
  215. };
  216. };
  217. fclose(fd);
  218. };
  219. if (strlen(buf) == 0)
  220. {
  221. strncpy(buf, "--Unknown--", DBC_RESOURCE_DESC_SIZE);
  222. buf[DBC_RESOURCE_DESC_SIZE - 1] = (char) 0;
  223. };
  224. }
  225. PARSE_RESULT_NET_INTERFACES * mojoHardwareManager::parse_neconfig(CSTR if_name)
  226. {
  227. PARSE_RESULT_NET_INTERFACES * tVal = NULL;
  228. FILE * fd;
  229. bool cConfig = false;
  230. fd = fopen("/etc/network/interfaces", "r");
  231. if (fd)
  232. {
  233. char tB[1024];
  234. char expBuf[1024];
  235. tVal = (PARSE_RESULT_NET_INTERFACES *) malloc(sizeof(PARSE_RESULT_NET_INTERFACES));
  236. if (tVal)
  237. {
  238. memset(tVal, 0, sizeof(PARSE_RESULT_NET_INTERFACES));
  239. while (! feof(fd))
  240. {
  241. fgets((CSTR) tB, 1024, fd);
  242. trim((CSTR) tB);
  243. if (strlen(tB))
  244. {
  245. strncpy(expBuf, tB, 1024);
  246. CArray * CA = explode(' ', expBuf);
  247. if (CA)
  248. {
  249. for (CArray::iterator idx = CA->begin(); idx < CA->end(); idx++)
  250. {
  251. if ((*idx)[0] == '#')
  252. {
  253. break;
  254. }
  255. if (strstr(*idx, "auto") != NULL)
  256. {
  257. if (strstr(tB, if_name) != NULL)
  258. {
  259. tVal->enabled = true;
  260. }
  261. }
  262. if (strstr(*idx, "allow-hotplug") != NULL)
  263. {
  264. if (strstr(tB, if_name) != NULL)
  265. {
  266. tVal->hot_plug = true;
  267. }
  268. }
  269. if (strstr(*idx, "iface") != NULL)
  270. {
  271. if (strstr(tB, if_name) != NULL)
  272. {
  273. if (strstr(tB, "static") != NULL)
  274. {
  275. tVal->if_static = true;
  276. }
  277. cConfig = true;
  278. }
  279. else
  280. {
  281. cConfig = false;
  282. }
  283. }
  284. if (strstr(*idx, "address") != NULL)
  285. {
  286. if (cConfig)
  287. {
  288. idx++;
  289. if (strstr(*idx, "/") != NULL)
  290. {
  291. int8_t sh = strstr(*idx, "/") - (*idx);
  292. strncpy(tVal->address, *idx, sh);
  293. tVal->address[sh] = (char) 0;
  294. int8_t bm = atoi((*idx) + sh + 1);
  295. union
  296. {
  297. uint32_t mm;
  298. uint8_t nm[4];
  299. } nmu = {0};
  300. for (sh = 0; sh < bm; sh++)
  301. {
  302. nmu.mm |= (1 << sh);
  303. }
  304. sprintf(tVal->netmask, "%d.%d.%d.%d", nmu.nm[0], nmu.nm[1], nmu.nm[2], nmu.nm[3]);
  305. }
  306. else
  307. {
  308. strncpy(tVal->address, *idx, INET6_ADDRSTRLEN);
  309. };
  310. };
  311. }
  312. if (strstr(*idx, "netmask") != NULL)
  313. {
  314. if (cConfig)
  315. {
  316. LOG("netMSK");
  317. idx++;
  318. LOG(*idx);
  319. strncpy(tVal->netmask, *idx, INET6_ADDRSTRLEN);
  320. };
  321. }
  322. // if(strstr((*idx), "bridge_ports")!= NULL ) cMode = 6;
  323. // if(strstr((*idx), "bridge_stp")!= NULL ) cMode = 7;
  324. // if(strstr((*idx), "bridge_waitport")!= NULL ) cMode = 8;
  325. // if(strstr((*idx), "bridge_fd")!= NULL ) cMode = 9;
  326. };
  327. delete(CA);
  328. };
  329. };
  330. };
  331. };
  332. fclose(fd);
  333. };
  334. #ifdef DEBUG
  335. if (tVal)
  336. {
  337. if (tVal->enabled)
  338. {
  339. LOG("NIF Enabled");
  340. }
  341. else
  342. {
  343. LOG("NIF Disabled");
  344. }
  345. if (tVal->hot_plug)
  346. {
  347. LOG("NIF Hot Plugable");
  348. }
  349. else
  350. {
  351. LOG("NIF not Hot Plugable");
  352. }
  353. if (tVal->if_static)
  354. {
  355. LOG("Address is static");
  356. }
  357. else
  358. {
  359. LOG("Address is Dynamic");
  360. }
  361. if (strlen(tVal->address))
  362. {
  363. LOG(tVal->address);
  364. }
  365. if (strlen(tVal->netmask))
  366. {
  367. LOG(tVal->netmask);
  368. }
  369. };
  370. #endif
  371. return tVal;
  372. }
  373. PARSE_RESULT_WIFI_SETTINGS * mojoHardwareManager::parse_wifi(CSTR if_name)
  374. {
  375. PARSE_RESULT_WIFI_SETTINGS * tVal = NULL;
  376. FILE * fd;
  377. bool cConfig = false;
  378. tVal = (PARSE_RESULT_WIFI_SETTINGS *) malloc(sizeof(PARSE_RESULT_WIFI_SETTINGS));
  379. if (tVal)
  380. {
  381. memset(tVal, 0, sizeof(PARSE_RESULT_WIFI_SETTINGS));
  382. fd = fopen("/etc/dnsmasq.conf", "r");
  383. if (fd)
  384. {
  385. char tB[1024];
  386. char expBuf[1024];
  387. while (! feof(fd))
  388. {
  389. fgets((CSTR) tB, 1024, fd);
  390. trim((CSTR) tB);
  391. if (strlen(tB))
  392. {
  393. strncpy(expBuf, tB, 1024);
  394. CArray * CA = explode('=', expBuf);
  395. if (CA)
  396. {
  397. if (CA->size())
  398. {
  399. if (CA->at(0)[0] == '#')
  400. {
  401. continue;
  402. }
  403. if (strstr(CA->at(0), "interface") != NULL)
  404. {
  405. if (strstr(tB, if_name) != NULL)
  406. {
  407. cConfig = true;
  408. tVal->dhcp_enabled = true;
  409. };
  410. };
  411. if (cConfig)
  412. {
  413. if (strstr(CA->at(0), "dhcp-range") != NULL)
  414. {
  415. char tT[1024];
  416. strncpy(tT, CA->at(1), 1024);
  417. CArray * CB = explode(',', tT);
  418. if (CB)
  419. {
  420. if (CB->size() > 3)
  421. {
  422. strncpy(tVal->range_start, CB->at(0), INET6_ADDRSTRLEN);
  423. strncpy(tVal->range_stop, CB->at(1), INET6_ADDRSTRLEN);
  424. strncpy(tVal->netmask, CB->at(2), INET6_ADDRSTRLEN);
  425. strncpy(tVal->lease_period, CB->at(3), INET6_ADDRSTRLEN);
  426. };
  427. delete(CB);
  428. };
  429. };
  430. };
  431. };
  432. delete(CA);
  433. };
  434. };
  435. };
  436. fclose(fd);
  437. };
  438. // Check WiFi
  439. if (strstr(if_name, "w") != NULL)
  440. {
  441. char tName[128];
  442. sprintf(tName, "iwconfig %s", if_name);
  443. fd = popen(tName, "r");
  444. if (fd)
  445. {
  446. char tB[1024];
  447. while (! feof(fd))
  448. {
  449. fgets((CSTR) tB, 1024, fd);
  450. trim(tB);
  451. if (strstr(tB, "Mode") != NULL)
  452. {
  453. if (strstr(tB, "Master") != NULL)
  454. {
  455. tVal->access_point = true;
  456. }
  457. }
  458. };
  459. fclose(fd);
  460. };
  461. };
  462. if (tVal->access_point)
  463. {
  464. fd = fopen("/etc/hostapd/hostapd.conf", "r");
  465. if (fd)
  466. {
  467. char tB[1024];
  468. char expBuf[1024];
  469. while (! feof(fd))
  470. {
  471. fgets((CSTR) tB, 1024, fd);
  472. trim(tB);
  473. if (strlen(tB))
  474. {
  475. if (tB[0] == '#')
  476. {
  477. continue;
  478. }
  479. strncpy(expBuf, tB, 1024);
  480. CArray * CA = explode('=', expBuf);
  481. if (CA)
  482. {
  483. if (CA->size())
  484. {
  485. if (strstr(CA->at(0), "ssid") != NULL)
  486. {
  487. if (strstr(CA->at(0), "ignore_broadcast_ssid") == NULL)
  488. {
  489. strncpy(tVal->SSID, CA->at(1), 64);
  490. }
  491. else
  492. {
  493. tVal->hiden_ssid = (bool) atoi(CA->at(1));
  494. }
  495. }
  496. if (strstr(CA->at(0), "wpa_passphrase") != NULL)
  497. {
  498. strncpy(tVal->password, CA->at(1), 64);
  499. }
  500. if (strstr(CA->at(0), "country_code") != NULL)
  501. {
  502. strncpy(tVal->country_code, CA->at(1), 3);
  503. }
  504. if (strstr(CA->at(0), "channel") != NULL)
  505. {
  506. tVal->channel = atoi(CA->at(1));
  507. }
  508. };
  509. delete(CA);
  510. };
  511. };
  512. };
  513. fclose(fd);
  514. };
  515. }
  516. else
  517. {
  518. fd = fopen("/etc/wpa_supplicant/wpa_supplicant.conf", "r");
  519. if (fd)
  520. {
  521. fclose(fd);
  522. };
  523. };
  524. fd = fopen("/etc/rc.local", "r");
  525. if (fd)
  526. {
  527. char tB[1024];
  528. char expBuf[1024];
  529. while (! feof(fd))
  530. {
  531. fgets((CSTR) tB, 1024, fd);
  532. trim((CSTR) tB);
  533. if (strlen(tB))
  534. {
  535. strncpy(expBuf, tB, 1024);
  536. CArray * CA = explode(' ', expBuf);
  537. if (CA)
  538. {
  539. if (CA->size())
  540. {
  541. if (CA->at(0)[0] == '#')
  542. {
  543. continue;
  544. }
  545. if (strstr(CA->at(0), "iptables-restore") != NULL)
  546. {
  547. char zB[1024];
  548. FILE * afd = fopen(CA->at(2), "r");
  549. if (afd)
  550. {
  551. while (! feof(afd))
  552. {
  553. fgets((CSTR) zB, 1024, afd);
  554. if (strstr(zB, "POSTROUTING") != NULL)
  555. {
  556. if (strstr(zB, "MASQUERADE") != NULL)
  557. {
  558. if (strstr(zB, if_name) == NULL)
  559. {
  560. CArray * CB = explode(' ', zB);
  561. if (CB)
  562. {
  563. if (CB->size() > 3)
  564. {
  565. strncpy(tVal->router_outbond, CB->at(3), INET6_ADDRSTRLEN);
  566. };
  567. delete(CB);
  568. };
  569. tVal->router_enabled = true;
  570. };
  571. }
  572. }
  573. };
  574. fclose(afd);
  575. }
  576. else
  577. {
  578. LOG("Error Opening Firewall Rules!");
  579. }
  580. };
  581. };
  582. delete(CA);
  583. };
  584. };
  585. };
  586. fclose(fd);
  587. }
  588. else
  589. {
  590. LOG_ERROR("Can not open rc.local!");
  591. }
  592. };
  593. #ifdef DEBUG
  594. if (tVal)
  595. {
  596. if (tVal->access_point)
  597. {
  598. LOG("AP Mode");
  599. }
  600. else
  601. {
  602. LOG("WiFi Mode");
  603. }
  604. LOG(tVal->SSID);
  605. if (tVal->hiden_ssid)
  606. {
  607. LOG("SSID is hidden");
  608. }
  609. LOG(tVal->password);
  610. if (tVal->dhcp_enabled)
  611. {
  612. LOG("DHCP Service");
  613. LOG(tVal->range_start);
  614. LOG(tVal->range_stop);
  615. LOG(tVal->lease_period);
  616. }
  617. else
  618. {
  619. LOG("DHCP Disabled");
  620. }
  621. if (tVal->router_enabled)
  622. {
  623. LOG("Routing Enabled");
  624. LOG(tVal->router_outbond);
  625. }
  626. else
  627. {
  628. LOG("Routing Disabled");
  629. }
  630. };
  631. #endif
  632. return tVal;
  633. }
  634. void mojoHardwareManager::enumerateNIFS(void)
  635. {
  636. struct ifaddrs * ifaddr = NULL;
  637. char tBuffer[128];
  638. // if( m_pKernel == NULL ) return;
  639. if (m_pDBC == NULL)
  640. {
  641. return;
  642. }
  643. if (-1 == getifaddrs(&ifaddr))
  644. {
  645. LOG_ERROR("No NET INTERFACES?!");
  646. }
  647. else
  648. {
  649. #ifdef DEBUG
  650. LOG("Enumerating Network Interfaces");
  651. #endif
  652. struct ifaddrs * ifa;
  653. for (ifa = ifaddr; ifa; ifa = ifa->ifa_next)
  654. {
  655. char addr[INET6_ADDRSTRLEN];
  656. char mask[INET6_ADDRSTRLEN];
  657. char gw[INET6_ADDRSTRLEN];
  658. char bc[INET6_ADDRSTRLEN];
  659. char mac[INET6_ADDRSTRLEN];
  660. char device[INET6_ADDRSTRLEN];
  661. uint32_t nif_id = 0;
  662. uint32_t nif_aux_id = 0;
  663. uint32_t router_id = 0;
  664. ARGUS_NIF_TYPE nif_type = NIF_LOOPBACK;
  665. ARGUS_NETWORK_TYPE net_type = NETWORK_IPV4;
  666. ARGUS_RESOURCE_TYPE res_type = ARGUS_HARDWARE_NIF_LOOPBACK;
  667. ARGUS_NIF_MODE nif_mode = ADDRESS_DISABLED;
  668. #ifdef DEBUG_EXTRA
  669. LOG("NIF ***");
  670. #endif
  671. strncpy(device, ifa->ifa_name, INET6_ADDRSTRLEN);
  672. strncpy(mac, "--no-mac--", INET6_ADDRSTRLEN);
  673. // Filter Loopback if
  674. if (strstr(device, "lo") != NULL)
  675. {
  676. nif_type = NIF_LOOPBACK;
  677. res_type = ARGUS_HARDWARE_NIF_LOOPBACK;
  678. // Not Implemented
  679. continue;
  680. };
  681. // Filter vpn TUN if
  682. if (strstr(device, "tun") != NULL)
  683. {
  684. nif_type = NIF_VPN_TUNEL;
  685. res_type = ARGUS_HARDWARE_NIF_TUNEL;
  686. // Not Implemented Yet
  687. continue;
  688. };
  689. if (strstr(device, "eth") != NULL)
  690. {
  691. LOG(device);
  692. nif_type = NIF_ETHERNET;
  693. res_type = ARGUS_HARDWARE_NIF_ETHERNET;
  694. };
  695. if (strstr(device, "wlan") != NULL)
  696. {
  697. LOG(device);
  698. nif_type = NIF_WIFI;
  699. res_type = ARGUS_HARDWARE_NIF_WIFI;
  700. };
  701. if (strstr(device, "wwan") != NULL)
  702. {
  703. LOG(device);
  704. nif_type = NIF_WAN;
  705. res_type = ARGUS_HARDWARE_NIF_WAN;
  706. };
  707. if (ifa->ifa_addr != NULL)
  708. {
  709. if (ifa->ifa_addr->sa_family != AF_INET && ifa->ifa_addr->sa_family != AF_INET6)
  710. {
  711. LOG("CONT");
  712. continue;
  713. }
  714. }
  715. else
  716. {
  717. LOG("ifa->ifa_addr is NULL");
  718. continue;
  719. };
  720. LOG("GETMAC");
  721. getMAC(device, mac);
  722. getGW(device, gw);
  723. LOG(mac);
  724. LOG(gw);
  725. PARSE_RESULT_NET_INTERFACES * tt = NULL;
  726. PARSE_RESULT_WIFI_SETTINGS * tw = NULL;
  727. tt = parse_neconfig(device);
  728. tw = parse_wifi(device);
  729. if (tt)
  730. {
  731. if (tt->enabled)
  732. {
  733. if (tt->if_static)
  734. {
  735. nif_mode = ADDRESS_STATIC;
  736. }
  737. else
  738. {
  739. nif_mode = ADDRESS_DYNAMIC;
  740. };
  741. }
  742. else
  743. {
  744. nif_mode = ADDRESS_DISABLED;
  745. };
  746. }
  747. else
  748. {
  749. LOG_ERROR("Error Parsing System NIF Settings!");
  750. continue;
  751. };
  752. if (tw)
  753. {
  754. if (nif_mode == ADDRESS_STATIC)
  755. {
  756. if (tw->dhcp_enabled)
  757. {
  758. nif_mode = ADDRESS_STATIC_RAP;
  759. };
  760. };
  761. if (nif_type == NIF_WIFI)
  762. {
  763. nif_id = m_pDBC->addLocalNIF(device, mac, nif_type, nif_mode);
  764. if (nif_id == 0)
  765. {
  766. continue;
  767. }
  768. ARGUS_WIFI_MODE w_mode;
  769. if (! tt->enabled)
  770. {
  771. w_mode = WIFI_DISABLED;
  772. }
  773. else
  774. {
  775. if (tt->if_static)
  776. {
  777. if (tw->access_point)
  778. {
  779. w_mode = WIFI_IS_AP;
  780. uint32_t outbond_id = 0;
  781. if (tw->router_enabled)
  782. {
  783. outbond_id = m_pDBC->getNIF_IDbyDevice(tw->router_outbond);
  784. };
  785. if (tw->dhcp_enabled)
  786. {
  787. router_id = m_pDBC->addLocalNetworkInfrastructure(nif_id, outbond_id, true, tw->range_start, tw->range_stop, tw->netmask, tw->lease_period);
  788. }
  789. else
  790. {
  791. router_id = m_pDBC->addLocalNetworkInfrastructure(nif_id, outbond_id);
  792. };
  793. }
  794. else
  795. {
  796. w_mode = WIFI_CONNECTED_TO_AP;
  797. };
  798. };
  799. };
  800. nif_aux_id = m_pDBC->addLocalWiFi(nif_id, w_mode, tw->SSID, tw->password, ENCRIPTION_WPA_PSK, router_id);
  801. };
  802. if (nif_type == NIF_ETHERNET || nif_type == NIF_ETHERNET_VIRTUAL)
  803. {
  804. };
  805. free(tt);
  806. free(tw);
  807. }
  808. else
  809. {
  810. LOG_ERROR("Error Parsing System Router/AP Settings!");
  811. free(tt);
  812. continue;
  813. };
  814. nif_id = m_pDBC->addLocalNIF(device, mac, nif_type, nif_mode, nif_aux_id);
  815. if (nif_id == 0)
  816. {
  817. continue;
  818. }
  819. LOG("NIF added!");
  820. m_pDBC->addResource(1, res_type, device, nif_id);
  821. if (ifa->ifa_addr->sa_family == AF_INET)
  822. {
  823. net_type = NETWORK_IPV4;
  824. // create IPv4 string
  825. struct sockaddr_in * in = (struct sockaddr_in *) ifa->ifa_addr;
  826. inet_ntop(AF_INET, &in->sin_addr, addr, sizeof(addr));
  827. sprintf(mask, "%d.%d.%d.%d", (uint8_t) ifa->ifa_netmask->sa_data[2], (uint8_t) ifa->ifa_netmask->sa_data[3], (uint8_t) ifa->ifa_netmask->sa_data[4], (uint8_t) ifa->ifa_netmask->sa_data[5]);
  828. sprintf(bc, "%d.%d.%d.%d", (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[2], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[3], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[4], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[5]);
  829. }
  830. else
  831. { // AF_INET6
  832. net_type = NETWORK_IPV6;
  833. // create IPv6 string
  834. struct sockaddr_in6 * in6 = (struct sockaddr_in6 *) ifa->ifa_addr;
  835. inet_ntop(AF_INET6, &in6->sin6_addr, addr, sizeof(addr));
  836. sprintf(mask, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", (uint8_t) ifa->ifa_netmask->sa_data[2], (uint8_t) ifa->ifa_netmask->sa_data[3], (uint8_t) ifa->ifa_netmask->sa_data[4],
  837. (uint8_t) ifa->ifa_netmask->sa_data[5], (uint8_t) ifa->ifa_netmask->sa_data[6], (uint8_t) ifa->ifa_netmask->sa_data[7], (uint8_t) ifa->ifa_netmask->sa_data[8], (uint8_t) ifa->ifa_netmask->sa_data[9],
  838. (uint8_t) ifa->ifa_netmask->sa_data[10], (uint8_t) ifa->ifa_netmask->sa_data[11], (uint8_t) ifa->ifa_netmask->sa_data[12], (uint8_t) ifa->ifa_netmask->sa_data[13], (uint8_t) ifa->ifa_netmask->sa_data[14],
  839. (uint8_t) ifa->ifa_netmask->sa_data[15], (uint8_t) ifa->ifa_netmask->sa_data[16], (uint8_t) ifa->ifa_netmask->sa_data[17]);
  840. if (ifa->ifa_ifu.ifu_broadaddr != NULL)
  841. {
  842. sprintf(bc, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[2], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[3],
  843. (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[4], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[5], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[6], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[7],
  844. (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[8], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[9], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[10], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[11],
  845. (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[12], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[13], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[14], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[15],
  846. (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[16], (uint8_t) ifa->ifa_ifu.ifu_broadaddr->sa_data[17]);
  847. }
  848. else
  849. {
  850. sprintf(bc, "");
  851. };
  852. };
  853. m_pDBC->addLocalNetwork(nif_id, net_type, addr, mask, gw, bc);
  854. #ifdef DEBUG
  855. sprintf(tBuffer, "Detected Network Interface: %s [%s]", ifa->ifa_name, addr);
  856. LOG(tBuffer);
  857. #endif
  858. };
  859. freeifaddrs(ifaddr);
  860. };
  861. }
  862. void mojoHardwareManager::enumerateHardware(void)
  863. {
  864. char tBuffer[CTEXT];
  865. DIR * dFD = NULL;
  866. struct dirent * pDR = NULL;
  867. // ToDo: Check Ability to work without Kernel and DBC
  868. // if( m_pKernel == NULL ) return;
  869. if (m_pDBC == NULL)
  870. {
  871. return;
  872. }
  873. #ifdef DEBUG
  874. LOG("HW Enumeration Started!");
  875. #endif
  876. // Moved to a constructor!!
  877. // m_nServerNodeID = m_pKernel->getServerNodeId();
  878. // m_nServerID = m_pKernel->getServerId();
  879. // m_nSiteID = m_pKernel->getSiteId();
  880. /* Add Network Interfaces */
  881. m_pDBC->cleanResources(1, true);
  882. enumerateNIFS();
  883. /* Check HID Devices */
  884. struct hid_device_info * pDevs;
  885. uint8_t DCBCount;
  886. // Enumerate USB devices with the given IDs
  887. pDevs = hid_enumerate(0x16c0, 0x05df);
  888. if (pDevs != NULL)
  889. {
  890. struct hid_device_info * pCDev = pDevs;
  891. // Count the number of returned devices
  892. for (DCBCount = 0; pCDev != NULL; DCBCount++)
  893. {
  894. pCDev = pCDev->next;
  895. }
  896. // Allocate a buffer for the relays
  897. if (DCBCount > 0)
  898. {
  899. DC_BOARD tDCB;
  900. // Fill the relay structs
  901. pCDev = pDevs;
  902. for (int idx = 0; idx < DCBCount; idx++)
  903. {
  904. // Save the path to this device
  905. memset(tDCB.path, 0, MAX_PATH_LEN);
  906. strncpy(tDCB.path, pCDev->path, MAX_PATH_LEN);
  907. // The product string is USBRelayx where x is number of relays read to the \0 in case there are more than 9
  908. tDCB.relay_count = atoi((const char *) &pCDev->product_string[8]);
  909. // Open it to get more details
  910. hid_device * handle;
  911. handle = hid_open_path(tDCB.path);
  912. if (handle)
  913. {
  914. unsigned char buf[9];
  915. // Get the features of the device
  916. buf[0] = 0x01;
  917. if (hid_get_feature_report(handle, buf, sizeof(buf)) == -1)
  918. {
  919. LOG_ERROR("hid_get_feature_report");
  920. pCDev = pCDev->next;
  921. hid_close(handle);
  922. continue;
  923. };
  924. // Set the serial number (0x0 for termination)
  925. memset(tDCB.serial, 0x0, HID_DCR_SERIIAL_LENGTH + 1);
  926. memcpy(tDCB.serial, buf, HID_DCR_SERIIAL_LENGTH);
  927. // Byte 7 in the response contains the target_state of the relays
  928. tDCB.state = buf[7];
  929. hid_close(handle);
  930. #ifdef DEBUG
  931. // Output the device enumeration details if verbose is on
  932. LOG("HID DCB Found");
  933. sprintf(tBuffer, " Type: %04hx::%04hx", pCDev->vendor_id, pCDev->product_id);
  934. LOG(tBuffer);
  935. sprintf(tBuffer, " Path: %s", pCDev->path);
  936. LOG(tBuffer);
  937. sprintf(tBuffer, " Serial_number: %ls", pCDev->serial_number);
  938. LOG(tBuffer);
  939. sprintf(tBuffer, " Manufacturer: %ls", pCDev->manufacturer_string);
  940. LOG(tBuffer);
  941. sprintf(tBuffer, " Product: %ls", pCDev->product_string);
  942. LOG(tBuffer);
  943. sprintf(tBuffer, " Release: %hx", pCDev->release_number);
  944. LOG(tBuffer);
  945. sprintf(tBuffer, " Interface: %d", pCDev->interface_number);
  946. LOG(tBuffer);
  947. sprintf(tBuffer, " Number of Relays = %d", tDCB.relay_count);
  948. LOG(tBuffer);
  949. // If debug are on, output individual relay details
  950. for (int k = 0; k < tDCB.relay_count; k++)
  951. {
  952. if (tDCB.state & 1 << k)
  953. {
  954. sprintf(tBuffer, " %s_%d=1", tDCB.serial, k + 1);
  955. }
  956. else
  957. {
  958. sprintf(tBuffer, " %s_%d=0", tDCB.serial, k + 1);
  959. };
  960. LOG(tBuffer);
  961. };
  962. #endif
  963. m_pDBC->addLocalDCB(1, pCDev->path, tDCB.serial, tDCB.relay_count, tDCB.state);
  964. }
  965. else
  966. {
  967. LOG_ERROR("unable to open HID device");
  968. };
  969. pCDev = pCDev->next;
  970. };
  971. };
  972. hid_free_enumeration(pDevs);
  973. };
  974. /* Add devices from DEV */
  975. dFD = opendir("/dev");
  976. if (dFD != NULL)
  977. {
  978. while ((pDR = readdir(dFD)) != NULL)
  979. {
  980. if (strcasestr(pDR->d_name, "video") == pDR->d_name)
  981. {
  982. createResourceVIDEO(pDR->d_name);
  983. continue;
  984. };
  985. if (strcasestr(pDR->d_name, "ttyS") == pDR->d_name)
  986. {
  987. createResourceUART(pDR->d_name);
  988. continue;
  989. };
  990. // RaspberyPI Hardware
  991. if (strcasestr(pDR->d_name, "ttyAMA") == pDR->d_name)
  992. {
  993. createResourceUART(pDR->d_name);
  994. continue;
  995. };
  996. if (strcasestr(pDR->d_name, "ttyUSB") == pDR->d_name)
  997. {
  998. createResourceUART(pDR->d_name);
  999. continue;
  1000. };
  1001. };
  1002. closedir(dFD);
  1003. };
  1004. // m_bHardwareEnumerated = true;
  1005. }
  1006. uint32_t mojoHardwareManager::createResourceUART(CSTR devName)
  1007. {
  1008. uint32_t RetVal = 0;
  1009. char tBuffer[256];
  1010. /* Enumerate BuiltIn Serial */
  1011. #ifdef DEBUG_EXTRA
  1012. sprintf(tBuffer, "Serial Device: %s", devName);
  1013. LOG(tBuffer);
  1014. #endif
  1015. char dev_name[CTEXT];
  1016. int fd = -1;
  1017. struct serial_struct ss;
  1018. sprintf(dev_name, "/dev/%s", devName);
  1019. fd = open(dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
  1020. if (-1 == fd)
  1021. {
  1022. sprintf(tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
  1023. LOG_ERROR(tBuffer);
  1024. }
  1025. else
  1026. {
  1027. if (0 && (-1 == xioctl(fd, TIOCGSERIAL, &ss)))
  1028. {
  1029. LOG_ERROR("TIOCGSERIAL");
  1030. }
  1031. else
  1032. {
  1033. #ifdef DEBUG_EXTRA
  1034. sprintf(tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]", ss.port, ss.irq, ss.baud_base, ss.line, ss.type, ss.flags);
  1035. LOG(tBuffer);
  1036. #endif
  1037. getTTyDesc(devName, tBuffer);
  1038. uint32_t tID = m_pDBC->addLocalUART(1, 1, 19200, 8, 'N', 1.0f, dev_name);
  1039. if (tID)
  1040. {
  1041. m_pDBC->addResource(1, ARGUS_HARDWARE_UART, tBuffer, tID);
  1042. };
  1043. };
  1044. close(fd);
  1045. };
  1046. return RetVal;
  1047. }
  1048. uint32_t mojoHardwareManager::createResourceVIDEO(CSTR devName)
  1049. {
  1050. uint32_t RetVal = 0;
  1051. char tBuffer[256];
  1052. /* Enumerate Video Capture */
  1053. #ifdef DEBUG_EXTRA
  1054. sprintf(tBuffer, "Video Source: %s", devName);
  1055. LOG(tBuffer);
  1056. #endif
  1057. struct v4l2_capability cap;
  1058. // struct v4l2_cropcap cropcap;
  1059. // struct v4l2_crop crop;
  1060. struct v4l2_format fmt;
  1061. char dev_name[CTEXT];
  1062. int fd = -1;
  1063. struct stat st;
  1064. sprintf(dev_name, "/dev/%s", devName);
  1065. if (-1 == stat(dev_name, &st))
  1066. {
  1067. sprintf(tBuffer, "Cannot identify '%s': %d, %s\\n", dev_name, errno, strerror(errno));
  1068. LOG_ERROR(tBuffer);
  1069. return 0;
  1070. };
  1071. if (! S_ISCHR(st.st_mode))
  1072. {
  1073. sprintf(tBuffer, "%s is no devicen", dev_name);
  1074. LOG_ERROR(tBuffer);
  1075. return 0;
  1076. };
  1077. fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
  1078. if (-1 == fd)
  1079. {
  1080. sprintf(tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
  1081. LOG_ERROR(tBuffer);
  1082. }
  1083. else
  1084. {
  1085. if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap))
  1086. {
  1087. if (EINVAL == errno)
  1088. {
  1089. sprintf(tBuffer, "%s is no V4L2 device", dev_name);
  1090. LOG_ERROR(tBuffer);
  1091. }
  1092. else
  1093. {
  1094. LOG_ERROR("VIDIOC_QUERYCAP");
  1095. };
  1096. close(fd);
  1097. return 0;
  1098. };
  1099. if (! (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
  1100. {
  1101. #ifdef DEBUG_EXTRA
  1102. sprintf(tBuffer, "%s is no video capture device", dev_name);
  1103. LOG_ERROR(tBuffer);
  1104. #endif
  1105. close(fd);
  1106. return 0;
  1107. };
  1108. CLEAR(fmt);
  1109. fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1110. /* Preserve original settings as set by v4l2-ctl for example */
  1111. if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
  1112. {
  1113. // LOG_ERROR("VIDIOC_G_FMT");
  1114. }
  1115. else
  1116. {
  1117. #ifdef DEBUG_EXTRA
  1118. sprintf(tBuffer, "Grabber[%dx%d]", fmt.fmt.pix.width, fmt.fmt.pix.height);
  1119. LOG(tBuffer);
  1120. #endif
  1121. uint64_t mid = m_pDBC->addLocalMediaSource(1, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height);
  1122. // m_pDBC->addNodeSocket( m_nServerNodeID, mid, ARGUS_NODE_SOCK_TYPE_ANALOG_VIDEO_GRABBER, ARGUS_NODE_SOCK_MODE_OUT, false, dev_name, tBuffer );
  1123. RetVal = m_pDBC->addResource(1, ARGUS_HARDWARE_ANALOG_VIDEO_IN, dev_name, mid);
  1124. };
  1125. close(fd);
  1126. };
  1127. return RetVal;
  1128. }
  1129. uint32_t mojoHardwareManager::createResourceUDCB(CSTR devName)
  1130. {
  1131. uint32_t RetVal = 0;
  1132. char tBuffer[256];
  1133. return RetVal;
  1134. }
  1135. /*
  1136. killWifi(){
  1137. ifconfig wlan0 down
  1138. ifconfig wlan0 up
  1139. iw dev wlan0 station dump
  1140. }
  1141. */
  1142. #undef LOG
  1143. #undef LOG_ERROR