summaryrefslogtreecommitdiff
path: root/application/agent/src/Underlayer.cpp
blob: b12436b96c01deee6314fe35134ee14595eec136 (plain)
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
/*
 ****************************************************************************
 *                            PROGRAM MODULE
 *
 *     $Workfile: Underlayer.cpp $
 *     $Author: CBu $
 *     $Date: 2008/07/29 $
 *
 *     Copyright (C) 2008 by SPiDCOM Technologies All rights reserved.
 *
 *****************************************************************************
 */
#include "underlayer.h"
#include "mib-interface.h"
#include "systemmanager.h"

/* spidlib is a C-library */
extern "C"
{
  #include "spidlib.h"
}

/*
 * GET/SET METHODS
 */


/* SARFT MIB */


// PROPERTY-MIB


// AnalogPropertyTable


// TODO


// DiscretePropertyTable


// TODO


// CurrentAlarmTable


// TODO


// ALARM-MIB


int Underlayer::getAlarmLogNumberOfEntries ( int *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return 0;
}


int Underlayer::getAlarmLogLastIndex ( int *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return 0;
}


// AlarmLogTable


// TODO


// GENERAL-MIB


// MasterAdminGroup


int Underlayer::getAdminLogicalId ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_admin_logical_id(get_value, SPIDLIB_ADMIN_LOGICAL_ID_STRING_MAX_LENGTH);
}


int Underlayer::setAdminLogicalId ( const char *set_value )
{
  if (NULL == set_value)
  {
    return -1;
  }

  return spidlib_set_admin_logical_id(set_value);
}


int Underlayer::getAdminManufactoryInfo ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_manufactory_info(get_value, DEFAULT_SNMP_STRING_MAX_LENGTH);
}


int Underlayer::getAdminModelNumber ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_model_number(get_value, DEFAULT_SNMP_STRING_MAX_LENGTH);
}


int Underlayer::getAdminSerialNumber ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_serial_number(get_value, DEFAULT_SNMP_STRING_MAX_LENGTH);
}


int Underlayer::getAdminSoftwareVersion ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_software_version(get_value, DEFAULT_SNMP_STRING_MAX_LENGTH);
}


int Underlayer::getAdminVendorSpecialInfo ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_vendor_info(get_value, DEFAULT_SNMP_STRING_MAX_LENGTH);
}


int Underlayer::getAdminIpData ( const char *iface, char *address, char *netmask, char *broadcast, char *gateway )
{
  if ( (NULL == iface)
       || (NULL == address)
       || (NULL == netmask)
       || (NULL == broadcast)
       || (NULL == gateway) )
  {
  	return -1;
  }

  return spidlib_get_ip_data(iface, address, netmask, broadcast, gateway);
}


int Underlayer::setAdminIpData ( const char *iface, char *address, char *netmask, char *broadcast, char *gateway )
{
  if ( (NULL == iface)
       || (NULL == address)
       || (NULL == netmask)
       || (NULL == broadcast)
       || (NULL == gateway) )
  {
  	return -1;
  }

  return spidlib_set_ip_data(iface, address, netmask, broadcast, gateway);
}


int Underlayer::getAdminEmsIpAddress ( char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return mib_get_admin_ems_ip_address(get_value);
}


int Underlayer::setAdminEmsIpAddress ( const char *set_value )
{
  if (NULL == set_value)
  {
    return -1;
  }

  return mib_set_admin_ems_ip_address(set_value);
}


int Underlayer::getAdminResetCause ( admin_reset_cause_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return -1;
}


int Underlayer::getAdminStatus ( unsigned char *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return 0;
}


// RfGroup


int Underlayer::getRfMasterOutputLevel ( int *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_output_level(get_value);
}


int Underlayer::setRfMasterOutputLevel ( int set_value )
{
  // Spidlib output level range is 103 - 129 dBuV
  if (set_value < RF_OUTPUT_LEVEL_MIN_VALUE)
  {
    set_value = RF_OUTPUT_LEVEL_MIN_VALUE;
  }
  else if (set_value > RF_OUTPUT_LEVEL_MAX_VALUE)
  {
    set_value = RF_OUTPUT_LEVEL_MAX_VALUE;
  }

  return spidlib_set_output_level(set_value);
}


// MacGroup


int Underlayer::getMacVlanEnable ( spidlib_boolean_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_vlan_enable(get_value);
}


int Underlayer::setMacVlanEnable ( spidlib_boolean_t set_value )
{
  return spidlib_set_vlan_enable(set_value);
}


int Underlayer::getMacVlanIdLimitation ( int *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_vlan_id_limitation(get_value);
}


int Underlayer::setMacVlanIdLimitation ( int set_value )
{
  return spidlib_set_vlan_id_limitation(set_value);
}


int Underlayer::getMacVlan ( spidlib_vlan_link_t vlan_direction, spidlib_vlan_rule_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_vlan(vlan_direction, get_value); 
}


int Underlayer::getMacVlanCommon ( spidlib_vlan_common_rule_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_vlan_common(get_value);
}


int Underlayer::getMacVlanAll ( spidlib_vlan_link_t vlan_direction, spidlib_vlan_rule_t *get_value, int *nb_rules )
{
  if ((NULL == nb_rules) || (NULL == get_value))
  {
    return -1;
  }

  return spidlib_get_vlan_all(vlan_direction, get_value, nb_rules);
}


int Underlayer::getMacVlanCommonAll ( spidlib_vlan_common_rule_t *get_value, int *nb_rules )
{
   if ((NULL == nb_rules) || (NULL == get_value))
  {
    return -1;
  }

  return spidlib_get_vlan_common_all(get_value, nb_rules);
}


int Underlayer::setMacVlan ( spidlib_vlan_link_t vlan_direction, const spidlib_vlan_rule_t *set_value )
{
  if (NULL == set_value)
  {
    return -1;
  }

  return spidlib_set_vlan(vlan_direction, set_value);
}


int Underlayer::setMacVlanCommon ( const spidlib_vlan_common_rule_t *set_value )
{
  if (NULL == set_value)
  {
    return -1;
  }

  return spidlib_set_vlan_common(set_value);
}


int Underlayer::getMacBroadcastRestriction ( spidlib_boolean_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return 0;
}


int Underlayer::setMacBroadcastRestriction ( spidlib_boolean_t set_value )
{
  // TODO
  return 0;
}


int Underlayer::getMacUnknownRestriction ( spidlib_boolean_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return 0;
}


int Underlayer::setMacUnknownRestriction ( spidlib_boolean_t set_value )
{
  // TODO
  return 0;
}


int Underlayer::getMacPortIsolation ( spidlib_boolean_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  // TODO
  return 0;
}


int Underlayer::setMacPortIsolation ( spidlib_boolean_t set_value )
{
  // TODO
  return 0;
}


// commonSoftwareGroup


int Underlayer::softwareUpload ( char *ftp_ip, uint16_t ftp_port, char *login, char *passwd, char *master_file, char *slave_file )
{
  int ret = 0;

  if ((NULL == ftp_ip)
  	  || (NULL == login)
  	  || (NULL == passwd)
  	  || (NULL == master_file)
  	  || (NULL == slave_file))
  {
    return -1;
  }

  /* 1. Upgrade the master software */
  ret += mib_upgradeSoftware(ftp_ip, ftp_port, login, passwd, master_file); // this function calls 'boottable_create()'

  /* 2. Call SMM upgrade for all online slaves */

  // Go through the host list
  for (int index=0; index<PLCP_MAX_HOST; index++)
  {
    if ((SystemManager::instance()->isHostActive(index)) // check if host is online
        && (SystemManager::instance()->isHostAuthorized(index))) // check if host is in white list (N.B.: for the moment, always return true)
    {
      /* TODO FOR BENJAMIN: To update according to SMM specs about slaves software upload. */
      //ret += smm_...(slave_file);
      // Note that the function must return 0 if all has been processed correctly,
      // otherwise, return must be whatever different from 0
    }
  }

  return ret;
};


// TODO: for online slaves, call the SMM function smm_get_vlan() / smm_set_vlan()


// commonSlaveGroup


int Underlayer::getWhiteList ( spidlib_white_list_register_t *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_white_list(get_value);
}


int Underlayer::getWhiteListAll ( spidlib_white_list_register_t *get_value, int *nb_registered )
{
  if ( (NULL == get_value) || (NULL == nb_registered) )
  {
    return -1;
  }

  return spidlib_get_white_list_all(get_value, nb_registered);
}


int Underlayer::setWhiteList ( const spidlib_white_list_register_t *set_value )
{
  if (NULL == set_value)
  {
    return -1;
  }

  return spidlib_set_white_list(set_value);
}


int Underlayer::onlineAllReset ( )
{
  int ret = 0;

  for (int index=0; index<PLCP_MAX_HOST; index++)
  {
    if ((SystemManager::instance()->isHostActive(index))
        && (SystemManager::instance()->isHostAuthorized(index)))
    {
      ret += smm_reboot((const unsigned char *)SystemManager::instance()->PlcHost(index).macAddress, mMaxRetries);
    }
  }

  return ret;
}


int Underlayer::getMacLimit ( unsigned int *get_value )
{
  if (NULL == get_value)
  {
  	return -1;
  }

  return spidlib_get_plc_mac_limit(get_value);
}


int Underlayer::setMacLimit ( unsigned int set_value )
{
  int ret = 0;

  // for all online slaves (commonOnlineAllExtMACLimitation)
  for (int index=0; index<PLCP_MAX_HOST; index++)
  {
    if ((SystemManager::instance()->isHostActive(index))
        && (SystemManager::instance()->isHostAuthorized(index)))
    {
  	  ret += smm_set_mac_limit((const unsigned char *)SystemManager::instance()->PlcHost(index).macAddress, mMaxRetries, set_value);
    }
  }

  // save locally the online slaves mac limit which has been set
  if (0 == ret)
  {
    ret = spidlib_set_plc_mac_limit(set_value);
  }

  return ret;
}


int Underlayer::getMacLimit ( const unsigned char *mac_address, unsigned int *get_value )
{
  if ( (NULL == mac_address) || (NULL == get_value) )
  {
  	return -1;
  }

  // for one slave (commonOnlineExtPCLimitation)
  return smm_get_mac_limit(mac_address, mMaxRetries, get_value);
}


int Underlayer::setMacLimit ( const unsigned char *mac_address, unsigned int set_value )
{
  if (NULL == mac_address)
  {
  	return -1;
  }

  // for one slave (commonOnlineExtPCLimitation)
  return smm_set_mac_limit(mac_address, mMaxRetries, set_value);
}


int Underlayer::getOnlineAllRfOutputLevel ( int *get_value )
{
  if (NULL == get_value)
  {
    return -1;
  }

  return spidlib_get_remote_output_level(get_value);
}


int Underlayer::setOnlineAllRfOutputLevel ( int set_value )
{
  int ret = 0;

  // Spidlib output level range is 103 - 129 dBuV
  if (set_value < RF_OUTPUT_LEVEL_MIN_VALUE)
  {
    set_value = RF_OUTPUT_LEVEL_MIN_VALUE;
  }
  else if (set_value > RF_OUTPUT_LEVEL_MAX_VALUE)
  {
    set_value = RF_OUTPUT_LEVEL_MAX_VALUE;
  }

  // Send SMM set requests to all online slaves
  for (int index=0; index<PLCP_MAX_HOST; index++)
  {
    if ((SystemManager::instance()->isHostActive(index))
        && (SystemManager::instance()->isHostAuthorized(index)))
    {
      ret += smm_set_plc_output_level((const unsigned char *)SystemManager::instance()->PlcHost(index).macAddress,
                                      mMaxRetries,
                                      set_value);
    }
  }

  // Save locally the online slave output level which has been set
  if (0 == ret)
  {
    ret = spidlib_set_remote_output_level(set_value);
  }

  return ret;
}


int Underlayer::getOnlineIp ( const unsigned char *mac_address, struct online_ip & ip )
{
  if (NULL == mac_address)
  {
    return -1;
  }

  return smm_get_ip(mac_address,
                    mMaxRetries,
                    INTERFACE_BR0, /* Be careful, it's not the same value as _DEFAULT_SNMP_BRIDGE_IF_INDEX */
                    &(ip.address),
                    &(ip.mask),
                    &(ip.gateway),
                    &(ip.mode));
}


int Underlayer::setOnlineIp ( const unsigned char *mac_address, const struct online_ip & ip )
{
  if (NULL == mac_address)
  {
    return -1;
  }

  return smm_set_ip(mac_address,
                    mMaxRetries,
                    INTERFACE_BR0, /* Be careful, it's not the same value as _DEFAULT_SNMP_BRIDGE_IF_INDEX */
                    &(ip.address),
                    &(ip.mask),
                    &(ip.gateway),
                    ip.mode);
}


int Underlayer::getOnlineModelNumber ( const unsigned char *mac_address, char *online_model_number, size_t len )
{
  if ((NULL == mac_address) || (NULL == online_model_number) || (0 == len))
  {
    return -1;
  }

  return smm_get_model_number(mac_address,
                              mMaxRetries,
                              online_model_number,
                              len);
}


int Underlayer::getOnlineInfo ( const unsigned char *mac_address, smm_online_info_t *online_info )
{
  if ((NULL == mac_address) || (NULL == online_info))
  {
    return -1;
  }

  return smm_get_info(mac_address,
                      mMaxRetries,
                      online_info->software_v,
                      online_info->boot_v,
                      online_info->board_v,
                      online_info->afe_v,
                      online_info->uptime);
}


int Underlayer::onlineReset ( const unsigned char *mac_address )
{
  if (NULL == mac_address)
  {
    return -1;
  }

  return smm_reboot(mac_address, mMaxRetries);
}


int Underlayer::getOnlineOutputLevel ( const unsigned char *mac_address, int *get_value )
{
  if ((NULL == mac_address) || (NULL == get_value))
  {
    return -1;
  }

  return smm_get_plc_output_level(mac_address, mMaxRetries, get_value);
}


int Underlayer::setOnlineOutputLevel ( const unsigned char *mac_address, int set_value )
{
  if (NULL == mac_address)
  {
    return -1;
  }

  return smm_set_plc_output_level(mac_address, mMaxRetries, set_value);  
}