-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlm_main.c
More file actions
4951 lines (4382 loc) · 172 KB
/
lm_main.c
File metadata and controls
4951 lines (4382 loc) · 172 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2015 RDK Management
*
* 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.
*/
/**********************************************************************
Copyright [2014] [Cisco Systems, Inc.]
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.
**********************************************************************/
/**************************************************************************
module: cosa_apis_hosts.c
For COSA Data Model Library Development
-------------------------------------------------------------------
description:
This file implementes back-end apis for the COSA Data Model Library
-------------------------------------------------------------------
environment:
platform independent
-------------------------------------------------------------------
author:
COSA XML TOOL CODE GENERATOR 1.0
-------------------------------------------------------------------
revision:
09/16/2011 initial revision.
**************************************************************************/
#define _GNU_SOURCE
#include <time.h>
#include <sys/sysinfo.h>
#include <string.h>
#include "ansc_platform.h"
#include "ccsp_base_api.h"
#include "lm_main.h"
#include "lm_util.h"
#ifdef WAN_TRAFFIC_COUNT_SUPPORT
#include "cosa_wantraffic_api.h"
#endif
#include "webpa_interface.h"
#include "lm_wrapper.h"
#include "lm_api.h"
#include "lm_wrapper_priv.h"
#include "ccsp_lmliteLog_wrapper.h"
#include "network_devices_interface.h"
#include "syscfg/syscfg.h"
#include "ccsp_memory.h"
#include "cosa_plugin_api.h"
#include "safec_lib_common.h"
#include "secure_wrapper.h"
#ifdef FEATURE_SUPPORT_ONBOARD_LOGGING
#define OnboardLog(...) rdk_log_onboard("LM", __VA_ARGS__)
#else
#define OnboardLog(...)
#endif
#include <telemetry_busmessage_sender.h>
#define TELEMETRY_MAX_BUFFER 256
#define LM_IPC_SUPPORT
#include "ccsp_dm_api.h"
#define NAME_DM_LEN 257
#define STRNCPY_NULL_CHK1(dest, src) { if((dest) != NULL ) AnscFreeMemory((dest));\
(dest) = _CloneString((src));}
#define DNS_LEASE "/nvram/dnsmasq.leases"
#define DEBUG_INI_NAME "/etc/debug.ini"
#define HOST_ENTRY_LIMIT 175
#define HOST_OBJECT_SIZE 200
#define ARP_IPv6 0
#define DIBBLER_IPv6 1
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <mqueue.h>
#define EVENT_QUEUE_NAME "/Event_queue"
#define DNSMASQ_NOTIFY_QUEUE_NAME "/dnsmasq_eventqueue"
#define MAX_SIZE 2048
#define MAX_SIZE_DNSMASQ_Q 512
#define MAX_SIZE_EVT 1024
#define CHECK(x) \
do { \
if (!(x)) { \
fprintf(stderr, "%s:%d: ", __func__, __LINE__); \
perror(#x); \
return; \
} \
} while (0) \
#define MSG_TYPE_EMPTY 0
#define MSG_TYPE_ETH 1
#define MSG_TYPE_WIFI 2
#if !defined (NO_MOCA_FEATURE_SUPPORT)
#define MSG_TYPE_MOCA 3
#endif
#define MSG_TYPE_RFC 5
#define MSG_TYPE_DNSMASQ 6
#define VALIDATE_QUEUE_NAME "/Validate_host_queue"
#define MAX_SIZE_VALIDATE_QUEUE sizeof(ValidateHostQData)
#define MAX_COUNT_VALIDATE_RETRY (3)
#define MAX_WAIT_VALIDATE_RETRY (15)
#define ARP_CACHE "/tmp/arp.txt"
#define DNSMASQ_CACHE "/tmp/dns.txt"
#define DNSMASQ_FILE "/nvram/dnsmasq.leases"
#define ACTION_FLAG_ADD (1)
#define ACTION_FLAG_DEL (2)
typedef enum {
CLIENT_STATE_OFFLINE,
CLIENT_STATE_DISCONNECT,
CLIENT_STATE_ONLINE,
CLIENT_STATE_CONNECT
} ClientConnectState;
typedef struct _EventQData
{
char Msg[MAX_SIZE_EVT];
int MsgType; // Ethernet = 1, WiFi = 2, MoCA = 3
}EventQData;
typedef struct _Eth_data
{
char MacAddr[18];
int Active; // Online = 1, offline = 0
}Eth_data;
typedef struct _Name_DM
{
char name[NAME_DM_LEN];
char dm[NAME_DM_LEN];
}Name_DM_t;
typedef struct _ValidateHostQData
{
char phyAddr[18];
char apList [MAX_MLO_LINKS][LM_GEN_STR_SIZE];
char ssidList[MAX_MLO_LINKS][LM_GEN_STR_SIZE];
int rssiList[MAX_MLO_LINKS];
int Status;
int mloEnable;
int linkCount;
} ValidateHostQData;
typedef struct _RetryHostList
{
ValidateHostQData host;
int retryCount;
struct _RetryHostList *next;
} RetryHostList;
RetryHostList *pListHead = NULL;
int g_IPIfNameDMListNum = 0;
Name_DM_t *g_pIPIfNameDMList = NULL;
#if !defined (NO_MOCA_FEATURE_SUPPORT)
int g_MoCAADListNum = 0;
Name_DM_t *g_pMoCAADList = NULL;
#endif
int g_DHCPv4ListNum = 0;
Name_DM_t *g_pDHCPv4List = NULL;
static int firstFlg = 0;
#if !defined (RESOURCE_OPTIMIZATION)
static int xfirstFlg = 0;
#endif
extern int bWifiHost;
extern char* pComponentName;
#if defined (RDKB_EXTENDER_ENABLED)
extern char dev_Mode[20] ;
#endif
int g_Client_Poll_interval;
/* Presence Notification - Payload */
typedef struct {
PLmObjectHost pHost;
char interface[32];
ClientConnectState status;
char *ipv4;
char *hostName;
char *physAddr;
} LMPresenceNotifyAddressInfo;
typedef struct RetryNotifyHostList {
struct RetryNotifyHostList *next;
LMPresenceNotifyAddressInfo *ctx;
int retry_count;
} RetryNotifyHostList;
static RetryNotifyHostList *pNotifyListHead = NULL;
static pthread_mutex_t LmRetryNotifyHostListMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t LmNotifyCond = PTHREAD_COND_INITIALIZER;
static pthread_t NotifyIPMonitorThread;
static bool worker_thread_running = false;
#define IP_RETRY_INTERVAL 10
#define IP_MAX_RETRIES 6
/***********************************************************************
IMPORTANT NOTE:
According to TR69 spec:
On successful receipt of a SetParameterValues RPC, the CPE MUST apply
the changes to all of the specified Parameters atomically. That is, either
all of the value changes are applied together, or none of the changes are
applied at all. In the latter case, the CPE MUST return a fault response
indicating the reason for the failure to apply the changes.
The CPE MUST NOT apply any of the specified changes without applying all
of them.
In order to set parameter values correctly, the back-end is required to
hold the updated values until "Validate" and "Commit" are called. Only after
all the "Validate" passed in different objects, the "Commit" will be called.
Otherwise, "Rollback" will be called instead.
The sequence in COSA Data Model will be:
SetParamBoolValue/SetParamIntValue/SetParamUlongValue/SetParamStringValue
-- Backup the updated values;
if( Validate_XXX())
{
Commit_XXX(); -- Commit the update all together in the same object
}
else
{
Rollback_XXX(); -- Remove the update at backup;
}
***********************************************************************/
pthread_mutex_t LmRetryHostListMutex;
#define LM_HOST_OBJECT_NAME_HEADER "Device.Hosts.Host."
#define LM_HOST_RETRY_LIMIT 30
//#define TIME_NO_NEGATIVE(x) ((long)(x) < 0 ? 0 : (x))
#define STRNCPY_NULL_CHK(x, y, z) if((y) != NULL) strncpy((x),(y),(z)); else *(unsigned char*)(x) = 0;
LmObjectHosts lmHosts = {
.pHostBoolParaName = {"Active","X_RDKCENTRAL-COM_PresenceNotificationEnabled","RDK_PresenceActive","X_RDK-MldClient"},
.pHostIntParaName = {"X_CISCO_COM_ActiveTime", "X_CISCO_COM_InactiveTime", "X_CISCO_COM_RSSI"},
.pHostUlongParaName = {"X_CISCO_COM_DeviceType", "X_CISCO_COM_NetworkInterface", "X_CISCO_COM_ConnectionStatus", "X_CISCO_COM_OSType","X_COMCAST-COM_LastChange","RDK_PresenceActiveLastChange","X_RDK-MloLinkNumberofEntries"},
.pHostStringParaName = {"Alias", "PhysAddress", "IPAddress", "DHCPClient", "AssociatedDevice", "Layer1Interface", "Layer3Interface", "HostName",
"X_CISCO_COM_UPnPDevice", "X_CISCO_COM_HNAPDevice", "X_CISCO_COM_DNSRecords", "X_CISCO_COM_HardwareVendor",
"X_CISCO_COM_SoftwareVendor", "X_CISCO_COM_SerialNumbre", "X_CISCO_COM_DefinedDeviceType",
"X_CISCO_COM_DefinedHWVendor", "X_CISCO_COM_DefinedSWVendor", "AddressSource", "Comments",
"X_RDKCENTRAL-COM_Parent", "X_RDKCENTRAL-COM_DeviceType", "X_RDKCENTRAL-COM_Layer1Interface"
#ifdef VENDOR_CLASS_ID
, "VendorClassID"
#endif
},
.pIPv4AddressStringParaName = {"IPAddress"},
.pIPv6AddressStringParaName = {"IPAddress"}
};
#if !defined (RESOURCE_OPTIMIZATION)
LmObjectHosts XlmHosts = {
.pHostBoolParaName = {"Active","X_RDKCENTRAL-COM_PresenceNotificationEnabled","RDK_PresenceActive","X_RDK-MldClient"},
.pHostIntParaName = {"X_CISCO_COM_ActiveTime", "X_CISCO_COM_InactiveTime", "X_CISCO_COM_RSSI"},
.pHostUlongParaName = {"X_CISCO_COM_DeviceType", "X_CISCO_COM_NetworkInterface", "X_CISCO_COM_ConnectionStatus", "X_CISCO_COM_OSType","X_COMCAST-COM_LastChange","RDK_PresenceActiveLastChange","X_RDK-MloLinkNumberofEntries"},
.pHostStringParaName = {"Alias", "PhysAddress", "IPAddress", "DHCPClient", "AssociatedDevice", "Layer1Interface", "Layer3Interface", "HostName",
"X_CISCO_COM_UPnPDevice", "X_CISCO_COM_HNAPDevice", "X_CISCO_COM_DNSRecords", "X_CISCO_COM_HardwareVendor",
"X_CISCO_COM_SoftwareVendor", "X_CISCO_COM_SerialNumbre", "X_CISCO_COM_DefinedDeviceType",
"X_CISCO_COM_DefinedHWVendor", "X_CISCO_COM_DefinedSWVendor", "AddressSource", "Comments",
"X_RDKCENTRAL-COM_Parent", "X_RDKCENTRAL-COM_DeviceType", "X_RDKCENTRAL-COM_Layer1Interface"
#ifdef VENDOR_CLASS_ID
, "VendorClassID"
#endif
},
.pIPv4AddressStringParaName = {"IPAddress"},
.pIPv6AddressStringParaName = {"IPAddress"}
};
#endif
ANSC_STATUS COSAGetParamValueByPathName(void* bus_handle, parameterValStruct_t *val, ULONG *parameterValueLength);
/* It may be updated by different threads at the same time? */
ULONG HostsUpdateTime = 0;
#if !defined (RESOURCE_OPTIMIZATION)
ULONG XHostsUpdateTime = 0;
#endif
pthread_mutex_t HostNameMutex;
pthread_mutex_t PollHostMutex;
pthread_mutex_t LmHostObjectMutex;
extern pthread_mutex_t PresenceDetectionMutex;
#if !defined (RESOURCE_OPTIMIZATION)
pthread_mutex_t XLmHostObjectMutex;
#endif
static void Wifi_ServerSyncHost(char *phyAddr, char apList[][LM_GEN_STR_SIZE], char ssidList[][LM_GEN_STR_SIZE], int rssiList[], int Status, int mloEnable, int linkCount);
static void Host_FreeIPAddress(PLmObjectHost pHost, int version);
static void Host_FreeMloLinks (PLmObjectHost pHost);
static void Hosts_SyncDHCP(void);
static void Sendmsg_dnsmasq(BOOL enablePresenceFeature);
static void Send_Eth_Host_Sync_Req(void);
#if defined (CONFIG_SYSTEM_MOCA)
static void Send_MoCA_Host_Sync_Req(void);
#endif
static char *_CloneString (const char *src);
#ifdef USE_NOTIFY_COMPONENT
extern ANSC_HANDLE bus_handle;
static void DelAndShuffleAssoDevIndx (PLmObjectHost pHost);
static void Send_PresenceNotification (char *interface, char *mac, ClientConnectState status, char *hostname,
char *ipv4)
{
char str[500];
parameterValStruct_t notif_val[1];
char *param_name = "Device.NotifyComponent.SetNotifi_ParamName";
char *compo = "eRT.com.cisco.spvtg.ccsp.notifycomponent";
char *bus = "/com/cisco/spvtg/ccsp/notifycomponent";
char *faultParam = NULL;
char *status_str;
int ret;
CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *) bus_handle;
if (mac && strlen(mac))
{
switch (status) {
case CLIENT_STATE_OFFLINE:
status_str = "Presence Leave Detected";
break;
case CLIENT_STATE_ONLINE:
status_str = "Presence Join Detected";
break;
default:
status_str = "NULL";
break;
}
snprintf (str, sizeof(str), "PresenceNotification,%s,%s,%s,%s,%s",
interface != NULL ? (strlen(interface) > 0 ? interface : "NULL") : "NULL",
mac,
status_str,
hostname != NULL ? (strlen(hostname) > 0 ? hostname : "NULL") : "NULL",
ipv4 != NULL ? (strlen(ipv4) > 0 ? ipv4 : "") : "");
CcspTraceWarning(("\n%s\n",str));
notif_val[0].parameterName = param_name;
notif_val[0].parameterValue = str;
notif_val[0].type = ccsp_string;
ret = CcspBaseIf_setParameterValues (
bus_handle,
compo,
bus,
0,
0,
notif_val,
1,
TRUE,
&faultParam);
if (ret != CCSP_SUCCESS)
{
CcspTraceWarning(("\n LMLite <%s> <%d > Notification Failure %d \n",__FUNCTION__,__LINE__, ret));
if (faultParam)
{
bus_info->freefunc(faultParam);
}
}
else
{
CcspTraceWarning(("RDKB_PRESENCE: Mac %s status %s Notification sent successfully\n",mac,status_str));
}
}
else
{
CcspTraceWarning(("RDKB_PRESENCE: MacAddress is NULL, hence Presence notifications are not sent\n"));
//printf("RDKB_CONNECTED_CLIENTS: MacAddress is NULL, hence Connected-Client notifications are not sent\n");
}
}
static void Send_Notification (char *interface, char *mac, ClientConnectState status, char *hostname)
{
char str[500];
parameterValStruct_t notif_val[1];
char *param_name = "Device.NotifyComponent.SetNotifi_ParamName";
char *compo = "eRT.com.cisco.spvtg.ccsp.notifycomponent";
char *bus = "/com/cisco/spvtg/ccsp/notifycomponent";
char *faultParam = NULL;
char *status_str;
int ret;
CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *) bus_handle;
if (mac && strlen(mac))
{
switch (status) {
case CLIENT_STATE_OFFLINE:
status_str = "Offline";
break;
case CLIENT_STATE_DISCONNECT:
status_str = "Disconnected";
break;
case CLIENT_STATE_ONLINE:
status_str = "Online";
break;
case CLIENT_STATE_CONNECT:
status_str = "Connected";
break;
default:
status_str = "NULL";
break;
}
snprintf (str, sizeof(str), "Connected-Client,%s,%s,%s,%s",
interface != NULL ? (strlen(interface) > 0 ? interface : "NULL") : "NULL",
mac,
status_str,
hostname != NULL ? (strlen(hostname) > 0 ? hostname : "NULL") : "NULL");
CcspTraceWarning (("\n%s\n",str));
notif_val[0].parameterName = param_name;
notif_val[0].parameterValue = str;
notif_val[0].type = ccsp_string;
ret = CcspBaseIf_setParameterValues (
bus_handle,
compo,
bus,
0,
0,
notif_val,
1,
TRUE,
&faultParam);
if (ret != CCSP_SUCCESS)
{
CcspTraceWarning(("\n LMLite <%s> <%d > Notification Failure %d \n",__FUNCTION__,__LINE__, ret));
if (faultParam)
{
bus_info->freefunc(faultParam);
}
}
}
else
{
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: MacAddress is NULL, hence Connected-Client notifications are not sent\n"));
//printf("RDKB_CONNECTED_CLIENTS: MacAddress is NULL, hence Connected-Client notifications are not sent\n");
}
}
#endif
static int FindHostInLeases (char *Temp, char *FileName)
{
char buf[200];
FILE *fp;
int ret = 1;
if ((fp = fopen (FileName, "r")) == NULL)
{
return 1;
}
while (fgets (buf, sizeof(buf), fp) != NULL)
{
if (strstr (buf, Temp))
{
ret = 0;
break;
}
}
fclose (fp);
return ret;
}
static void LanManager_StringToLower (char *pstring)
{
int i;
for (i = 0; pstring[i] != '\0'; i++)
{
if ((pstring[i] >= 'A') && (pstring[i] <= 'Z'))
{
pstring[i] += ('a' - 'A');
}
}
}
static int logOnlineDevicesCount (void)
{
PLmObjectHost pHost;
int NumOfOnlineDevices = 0;
int i;
for (i = 0; i < lmHosts.numHost; i++)
{
pHost = lmHosts.hostArray[i];
if (pHost->bBoolParaValue[LM_HOST_ActiveId])
{
NumOfOnlineDevices++;
}
}
CcspTraceWarning(("CONNECTED_CLIENTS_COUNT : %d \n",NumOfOnlineDevices));
return NumOfOnlineDevices;
}
static void get_uptime (int *uptime)
{
struct sysinfo info;
sysinfo( &info );
*uptime = info.uptime;
}
#ifdef VENDOR_CLASS_ID
static void get_vendor_class_id (char* physAddress, char* vendor_class)
{
char buffer[512] ={0}, *tmp_vendor=NULL;
char client_mac[32] = {0};
FILE* fpv = fopen(DNSMASQ_VENDORCLASS_FILE, "r");
if(fpv != NULL)
{
while((fgets(buffer, sizeof(buffer), fpv)) != NULL)
{
memset(client_mac, 0, sizeof(client_mac));
sscanf(buffer, "%s", client_mac);
if (strcasecmp(physAddress, client_mac) == 0)
{
tmp_vendor = strstr(buffer, " ");
if(tmp_vendor)
{
strtok(tmp_vendor, "\n");
tmp_vendor++;
strncpy(vendor_class, tmp_vendor, 256);
break;
}
}
}
fclose(fpv);
}
}
#endif
#define LM_SET_ACTIVE_STATE_TIME(x, y) LM_SET_ACTIVE_STATE_TIME_(__LINE__, x, y)
static void LM_SET_ACTIVE_STATE_TIME_(int line, LmObjectHost *pHost,BOOL state){
UNREFERENCED_PARAMETER(line);
char interface[32] = {0};
int uptime = 0;
errno_t rc = -1;
if(pHost->bBoolParaValue[LM_HOST_ActiveId] != state){
char addressSource[20] = {0};
char IPAddress[50] = {0};
memset(addressSource,0,sizeof(addressSource));
memset(IPAddress,0,sizeof(IPAddress));
memset(interface,0,sizeof(interface));
if ( ! pHost->pStringParaValue[LM_HOST_IPAddressId] )
{
getIPAddress(pHost->pStringParaValue[LM_HOST_PhysAddressId], IPAddress);
LanManager_CheckCloneCopy(&(pHost->pStringParaValue[LM_HOST_IPAddressId]) , IPAddress);
}
/*
getAddressSource(pHost->pStringParaValue[LM_HOST_PhysAddressId], addressSource);
if ( (pHost->pStringParaValue[LM_HOST_AddressSource]) && (strlen(addressSource)))
{
LanManager_CheckCloneCopy(&(pHost->pStringParaValue[LM_HOST_AddressSource]) , addressSource);
}
*/
if(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId] != NULL)
{
if((strstr(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],"WiFi")))
{
if(state)
{
if(pHost->ipv4Active == TRUE)
{
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is WiFi, MacAddress is %s and HostName is %s appeared online\n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: Client type is WiFi, MacAddress is %s and HostName is %s appeared online\n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: IP Address : %s , address source : %s, HostName : %s \n",pHost->pStringParaValue[LM_HOST_IPAddressId],pHost->pStringParaValue[LM_HOST_AddressSource],pHost->pStringParaValue[LM_HOST_HostNameId]));
}
}
else
{
if(pHost->ipv4Active == TRUE)
{
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Wifi client with %s MacAddress and %s HostName gone offline\n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: Wifi client with %s MacAddress and %s HostName gone offline\n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
t2_event_d("WIFI_INFO_clientdisconnect", 1);
}
#ifndef USE_NOTIFY_COMPONENT
remove_Mac_to_band_mapping(pHost->pStringParaValue[LM_HOST_PhysAddressId]);
#endif
}
rc = strcpy_s(interface, sizeof(interface),"WiFi");
ERR_CHK(rc);
}
#if !defined (NO_MOCA_FEATURE_SUPPORT)
else if ((strstr(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],"MoCA")))
{
if(pHost->ipv4Active == TRUE)
{
if(state) {
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is MoCA, MacAddress is %s and HostName is %s appeared online \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: Client type is MoCA, MacAddress is %s and HostName is %s appeared online \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: IP Address : %s , address source : %s, HostName : %s \n",pHost->pStringParaValue[LM_HOST_IPAddressId],pHost->pStringParaValue[LM_HOST_AddressSource],pHost->pStringParaValue[LM_HOST_HostNameId]));
} else {
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: MoCA client with %s MacAddress and HostName is %s gone offline \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: MoCA client with %s MacAddress and HostName is %s gone offline \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
}
}
rc = strcpy_s(interface, sizeof(interface),"MoCA");
ERR_CHK(rc);
}
#endif
else if ((strstr(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],"Ethernet")))
{
if(pHost->ipv4Active == TRUE)
{
if(state) {
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is Ethernet, MacAddress is %s and HostName is %s appeared online \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: Client type is Ethernet, MacAddress is %s and HostName is %s appeared online \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: IP Address : %s , address source : %s, HostName : %s \n",pHost->pStringParaValue[LM_HOST_IPAddressId],pHost->pStringParaValue[LM_HOST_AddressSource],pHost->pStringParaValue[LM_HOST_HostNameId]));
} else {
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Ethernet client with %s MacAddress and %s HostName gone offline \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: Ethernet client with %s MacAddress and %s HostName gone offline \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
}
}
rc = strcpy_s(interface, sizeof(interface),"Ethernet");
ERR_CHK(rc);
}
else
{
if(state) {
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is %s , MacAddress is %s and HostName is %s appeared online \n",pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: Client type is %s , MacAddress is %s and HostName is %s appeared online \n",pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: IP Address : %s , address source : %s, HostName : %s \n",pHost->pStringParaValue[LM_HOST_IPAddressId],pHost->pStringParaValue[LM_HOST_AddressSource],pHost->pStringParaValue[LM_HOST_HostNameId]));
} else {
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: client with %s MacAddress and %s HostName gone offline \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
OnboardLog("RDKB_CONNECTED_CLIENTS: client with %s MacAddress and %s HostName gone offline \n",pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]);
}
rc = strcpy_s(interface, sizeof(interface),"Other");
ERR_CHK(rc);
}
if(pHost->ipv4Active == TRUE) {
if (state) {
if(0 == FindHostInLeases(pHost->pStringParaValue[LM_HOST_IPAddressId], DNS_LEASE)){
char lan_ip_address[32] = {0};
char lan_net_mask[32] = {0};
syscfg_get( NULL, "lan_ipaddr", lan_ip_address, sizeof(lan_ip_address));
syscfg_get( NULL, "lan_netmask", lan_net_mask, sizeof(lan_net_mask));
if(!lm_wrap_checkIPv4AddressInRange(lan_ip_address, pHost->pStringParaValue[LM_HOST_IPAddressId], lan_net_mask))
{
CcspTraceWarning(("<%s> IPAddress out of range : IPAddress = %s, MAC Addr = %s \n",__FUNCTION__, pHost->pStringParaValue[LM_HOST_IPAddressId], pHost->pStringParaValue[LM_HOST_PhysAddressId]));
t2_event_d("SYS_ERROR_IPAOR", 1);
}
}
else {
CcspTraceWarning(("<%s> IPAddress not found in lease file : IPAddress = %s, MAC Addr = %s \n",__FUNCTION__, pHost->pStringParaValue[LM_HOST_IPAddressId], pHost->pStringParaValue[LM_HOST_PhysAddressId]));
CcspTraceWarning(("<%s> SETHU: IPAddress not found in lease file : IPAddress = %s, MAC Addr = %s \n",__FUNCTION__, pHost->pStringParaValue[LM_HOST_IPAddressId], pHost->pStringParaValue[LM_HOST_PhysAddressId]));
#if defined (_CBR_PRODUCT_REQ_) || defined (_ONESTACK_PRODUCT_REQ_)
char device_mode[32] = {0};
char dhcp_server_enabled[32] = {0};
CcspTraceWarning((" SETHU: _ONESTACK_PRODUCT_REQ_ \n"));
#if defined (_ONESTACK_PRODUCT_REQ_)
if(!syscfg_get( NULL, "devicemode", device_mode, sizeof(device_mode)))
{
CcspTraceWarning((" SETHU: devicemode: %s\n", device_mode));
if(strncmp(device_mode, "business", strlen("business")) == 0)
{
#endif
if(!syscfg_get( NULL, "dhcp_server_enabled", dhcp_server_enabled, sizeof(dhcp_server_enabled)))
{
CcspTraceWarning((" SETHU: dhcp_server_enabled: %s\n", dhcp_server_enabled));
if(strncmp(dhcp_server_enabled, "0", strlen("0")) == 0)
{
free(pHost->pStringParaValue[LM_HOST_IPAddressId]);
pHost->pStringParaValue[LM_HOST_IPAddressId] = NULL;
free(pHost->ipv4AddrArray);
pHost->ipv4AddrArray = NULL;
pHost->numIPv4Addr = 0;
}
}
#if defined (_ONESTACK_PRODUCT_REQ_)
}
}
#endif
#endif
}
}
}
pHost->bBoolParaValue[LM_HOST_ActiveId] = state;
pHost->activityChangeTime = time((time_t*)NULL);
logOnlineDevicesCount();
}
PRINTD("%d: mac %s, state %d time %d\n",line ,pHost->pStringParaValue[LM_HOST_PhysAddressId], state, pHost->activityChangeTime);
}
#ifdef USE_NOTIFY_COMPONENT
if(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId] != NULL)
{
if((strstr(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],"WiFi"))) {
rc = strcpy_s(interface, sizeof(interface),"WiFi");
ERR_CHK(rc);
}
#if !defined (NO_MOCA_FEATURE_SUPPORT)
else if ((strstr(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],"MoCA")))
{
rc = strcpy_s(interface, sizeof(interface),"MoCA");
ERR_CHK(rc);
}
#endif
else if ((strstr(pHost->pStringParaValue[LM_HOST_Layer1InterfaceId],"Ethernet")))
{
rc = strcpy_s(interface, sizeof(interface),"Ethernet");
ERR_CHK(rc);
}
else
{
rc = strcpy_s(interface, sizeof(interface),"Other");
ERR_CHK(rc);
}
if(state == FALSE)
{
#if 0
if(FindHostInLeases(pHost->pStringParaValue[LM_HOST_PhysAddressId], DNS_LEASE))
{
if(pHost->ipv4Active == TRUE)
{
if(pHost->bNotify == TRUE)
{
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is %s, MacAddress is %s Disconnected \n",interface,pHost->pStringParaValue[LM_HOST_PhysAddressId]));
lmHosts.lastActivity++;
Send_Notification(interface, pHost->pStringParaValue[LM_HOST_PhysAddressId], CLINET_STATE_DISCONNECT, pHost->pStringParaValue[LM_HOST_HostNameId]);
char buf[12] = {0};
snprintf(buf,sizeof(buf)-1,"%lu",lmHosts.lastActivity);
pHost->ipv4Active = FALSE;
if (syscfg_set(NULL, "X_RDKCENTRAL-COM_HostVersionId", buf) != 0)
{
AnscTraceWarning(("syscfg_set failed\n"));
}
else
{
if (syscfg_commit() != 0)
{
AnscTraceWarning(("syscfg_commit failed\n"));
}
}
pHost->bNotify = FALSE;
}
}
}
#endif
#if defined(FEATURE_SUPPORT_MESH)
// We are going to send offline notifications to mesh when clients go offline.
if(pHost->bNotify == TRUE)
{
//CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is %s, MacAddress is %s Offline \n",interface,pHost->pStringParaValue[LM_HOST_PhysAddressId]));
Send_Notification(interface, pHost->pStringParaValue[LM_HOST_PhysAddressId], CLIENT_STATE_OFFLINE, pHost->pStringParaValue[LM_HOST_HostNameId]);
}
#endif
}
else
{
{
if(pHost->bNotify == FALSE)
{
if(access("/tmp/.conn_cli_flag", F_OK) != 0)
{
/* CID :257716 Resource leak */
int fd;
/* CID 257720 Time of check time of use */
if ((fd = open("/tmp/.conn_cli_flag", O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_CLOEXEC)) >= 0)
{
close(fd);
}
get_uptime(&uptime);
CcspTraceWarning(("Client_Connect_complete:%d\n",uptime));
OnboardLog("Client_Connect_complete:%d\n",uptime);
t2_event_d("btime_clientconn_split", uptime);
}
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is %s, MacAddress is %s and HostName is %s Connected \n",interface,pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
lmHosts.lastActivity++;
pHost->bClientReady = TRUE;
if(pHost->pStringParaValue[LM_HOST_HostNameId])
{
if(0 == strcmp(pHost->pStringParaValue[LM_HOST_HostNameId],pHost->pStringParaValue[LM_HOST_PhysAddressId]))
{
char HostName[50];
if (get_HostName(pHost->pStringParaValue[LM_HOST_PhysAddressId],HostName,sizeof(HostName)) == 1)
LanManager_CheckCloneCopy(&(pHost->pStringParaValue[LM_HOST_HostNameId]), HostName);
CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is %s, MacAddress is %s and HostName is %s Connected \n",interface,pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
}
}
//CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: %s pHost->bClientReady = %d \n",interface,pHost->bClientReady));
Send_Notification(interface, pHost->pStringParaValue[LM_HOST_PhysAddressId], CLIENT_STATE_CONNECT, pHost->pStringParaValue[LM_HOST_HostNameId]);
if (syscfg_set_u_commit(NULL, "X_RDKCENTRAL-COM_HostVersionId", lmHosts.lastActivity) != 0)
{
AnscTraceWarning(("syscfg_set failed\n"));
}
pHost->bNotify = TRUE;
}
else
{
// This case is for "Online" events after we have send a connection message. WebPA apparently only wants a
// single connect request and no online/offline events.
//CcspTraceWarning(("RDKB_CONNECTED_CLIENTS: Client type is %s, MacAddress is %s and HostName is %s Online \n",interface,pHost->pStringParaValue[LM_HOST_PhysAddressId],pHost->pStringParaValue[LM_HOST_HostNameId]));
Send_Notification(interface, pHost->pStringParaValue[LM_HOST_PhysAddressId], CLIENT_STATE_ONLINE, pHost->pStringParaValue[LM_HOST_HostNameId]);
}
}
}
}
#endif
}
#define LM_SET_PSTRINGPARAVALUE(var, val) if((var)) AnscFreeMemory(var);var = AnscCloneString(val);
/***********************************************************************
APIs for Object:
Hosts.
* Hosts_Init
* Hosts_SavePsmValueRecord
***********************************************************************/
static void _getLanHostComments(char *physAddress, char *pComments)
{
lm_wrapper_priv_getLanHostComments(physAddress, pComments);
}
static inline BOOL _isIPv6Addr(const char* ipAddr)
{
if(strchr(ipAddr, ':') != NULL)
{
return TRUE;
}
else
{
return FALSE;
}
}
#if 0
static void Hosts_FindHostByIPv4Address
(
const char *ipv4Addr,
char hostList[],
int *hostListSize,
void * userData,
enum DeviceType userDataType
)
{
if(!ipv4Addr) return;
int i, j, firstOne = 1;
for(i=0; i<lmHosts.numHost; i++)
{
for(j=0; j<lmHosts.hostArray[i]->numIPv4Addr; j++)
{
if (strcasecmp(ipv4Addr, lmHosts.hostArray[i]->ipv4AddrArray[j]->pStringParaValue[LM_HOST_IPAddress_IPAddressId]) == 0)
{
if(!firstOne){
strcat(hostList, ",");
*hostListSize--;
}
else firstOne = 0;
size_t len = strlen(lmHosts.hostArray[i]->objectName);
if(*hostListSize < len) return;
strcat(hostList, lmHosts.hostArray[i]->objectName);
*hostListSize -= len;
Host_SetExtensionParameters(lmHosts.hostArray[i], userData, userDataType);
break;
}
}
}
}
#endif
static void Hosts_FreeHost (PLmObjectHost pHost)
{
int i;
if(pHost == NULL)
return;
pHost->bBoolParaValue[LM_HOST_PresenceActiveId] = FALSE;
if (pHost->bBoolParaValue[LM_HOST_PresenceNotificationEnabledId])
{
pHost->bBoolParaValue[LM_HOST_PresenceNotificationEnabledId] = FALSE;
Hosts_UpdateDeviceIntoPresenceDetection(pHost,FALSE, FALSE);
}
for(i=0; i<LM_HOST_NumStringPara; i++)
{
if(NULL != pHost->pStringParaValue[i])
AnscFreeMemory(pHost->pStringParaValue[i]);
pHost->pStringParaValue[i] = NULL;
}
if(pHost->objectName != NULL)
AnscFreeMemory(pHost->objectName);
if(pHost->Layer3Interface != NULL)
AnscFreeMemory(pHost->Layer3Interface);
pHost->objectName = NULL;
pHost->Layer3Interface = NULL;
Host_FreeIPAddress(pHost, 4);
Host_FreeIPAddress(pHost, 6);
Host_FreeMloLinks(pHost); /* free MLO link sub-table */
AnscFreeMemory(pHost);
pHost = NULL;
lmHosts.numHost--;
lmHosts.availableInstanceNum--;
}
static void Hosts_RmHosts (void)
{
int i;
if(lmHosts.numHost == 0)
return;