summaryrefslogtreecommitdiff
path: root/maximus/python/maximus/station/sta.py
blob: 95d3942ecdca3944ab983a47e8a5eb56378ad7dc (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
#! usr/bin/env python

#print __name__

from maximus.station.config import *
from maximus.ethernet.buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer
from maximus.macframe.msdu import MSDU_TYPES
from maximus.mme import *
from maximus.mme.mmheader import SIZE_OF_MMHEADER, SIZE_OF_MMTYPE, SIZE_OF_FMI
from maximus.utils.exception import Error, OutOfRangeError
from maximus.utils.format import *

# Constants to check arguments validity
SIZE_OF_MAC_ADDRESS = SIZE_OF_U48 # in octets
MAX_VALUE_OF_MAC_ADDRESS = MAX_VALUE_OF_U48
MIN_SIZE_OF_NPW = 8 # in octets
MAX_SIZE_OF_NPW = 64 # in octets
MAX_SIZE_OF_DPW = MAX_SIZE_OF_NPW
MAX_SIZE_OF_HFID = MAX_SIZE_OF_DPW
MAX_VALUE_OF_SL = 2
MAX_VALUE_OF_SNID = 15

# Constants from 'hal/phy/defs.h'
PHY_CARRIER_NB = 1155 # number of OFDM carrier, defined by the hardware
PHY_CARRIER_OFFSET = 74 # number of first OFDM carrier, defined by the hardware
PHY_TONEMASK_SIZE = ((PHY_CARRIER_NB + 8 - 1) / 8) # number of bytes needed to define a tonemask

# Possible configuration modes to set station parameters
CONFIG_MODES = ['MME', 'fcall_process_drv', 'fcall_cp_station']

# Constants for MME responses
# Driver ID result
FAILURE = 0x00
SUCCESS = 0x01
RESERVED = 0x02 # to 0xFF
# Driver ID error code on failure
ERROR_CODES = {0x00:'Bad parameter', 0x01:'Unknown ID', 0x02:'Invalid value'}

# Filter function to receive only MME responses
def mme_filter(rsp):
	if rsp.get_type() is MSDU_TYPES[2]: # ETHERNET_TYPE_MME
		return True
	elif rsp.get_type() is MSDU_TYPES[6]: # ETHERNET_TYPE_BUFFER_RELEASED
		return False
	else:
		raise Error("Received unexpected message of type " + rsp.get_type())
		return False

class STA:
	"""The STA class is composed of the 16 following private attributes:
	maximus - a Maximus object
	station - a Sta object
	name - a Python string
	data_buffer_nb - a Python integer
	mme_buffer_nb - a Python integer
	interface_buffer_nb - a Python integer
	mme_config - a Python boolean
	mac_address - a Python tuple of 6 Python integers
	cco_preference - a Python boolean
	was_cco - a Python boolean
	npw - a Python string of length from 8 to 64 octets
	dpw - a Python string of length from 0 to 64 octets
	m_sta_hfid - a Python string of length from 0 to 64 octets
	u_sta_hfid - a Python string of length from 0 to 64 octets
	avln_hfid - a Python string of length from 0 to 64 octets
	sl - a Python integer from 0 to 2
	tonemask - a Python tuple of Python integers
	snid - a Python integer from 0 to 15
	"""
	def __init__(self,\
				 maximus,\
				 executable=None,\
				 debug=False,\
				 name=None,\
				 data_buffer_nb=0,\
				 mme_buffer_nb=1,\
				 interface_buffer_nb=0,\
				 config_mode=CONFIG_MODES[0],\
				 config=Config()):
		"""Initialize the STA with following attributes:
		maximus - a Maximus object (already initialized)
		executable - a Python string
		debug - a Python boolean
		name - a Python string
		data_buffer_nb - a Python integer
		mme_buffer_nb - a Python integer
		interface_buffer_nb - a Python integer
		config_mode - a Python string
		config - a Python Config object
		"""
		
		# Set Maximus
		self.__set_maximus(maximus)
		
		# Create station and launch debugger if requested
		self.__create_station(executable, debug)
		
		# Set station configuration
		self.set_name(name)
		self.set_data_buffer_nb(data_buffer_nb)
		self.set_mme_buffer_nb(mme_buffer_nb)
		self.set_interface_buffer_nb(interface_buffer_nb)
		self.set_config_mode(config_mode)
		self.set_config(config)
		
		# Start station
		self.__start()

	def __set_maximus(self, maximus):
		"""Set Maximus.
		Maximus must be a Maximus object (already initialized).
		"""
		self.__maximus = maximus

	def __create_station(self, executable, debug):
		"""Create the station and launch the debugger if requested.
		The station is a Sta object.
		"""
		if executable is None:
			self.__station = self.__get_maximus().create_sta()
		else:
			self.__station = self.__get_maximus().create_sta(executable)
		if debug is True:
			self.__station.debug()

	def __start(self):
		"""Send the MAC_START message to the station.
		"""
		if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_mac_start") \
									.send(self.get())
		else: # we need to build an MME
			
			# Computes MM Header
			if self.get_mac_address() is not None:
				osa = self.get_mac_address()
			else:
				osa = DEFAULT_MAC_ADDRESS
			mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_START + MME_TYPES['REQ'])
			
			# Create the MME
			mme = MME(MMHeader=mmheader)
			
			if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
				self.__get_maximus().create_fcall("maximus_mac_start") \
									.add_param("mme", mme.get()) \
									.send(self.get())
			else: # 'MME'
				# Allocate an MME buffer
				alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
				
				# Send the MME and wait for the response
				rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
				self.__check_cnf(rsp, DRV_STA_START)

	def stop(self):
		"""Send the MAC_STOP message to the station.
		"""
		if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_mac_stop") \
									.send(self.get())
		else: # we need to build an MME
			
			# Computes MM Header
			if self.get_mac_address() is not None:
				osa = self.get_mac_address()
			else:
				osa = DEFAULT_MAC_ADDRESS
			mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_STOP + MME_TYPES['REQ'])
			
			# Create the MME
			mme = MME(MMHeader=mmheader)
			
			if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
				self.__get_maximus().create_fcall("maximus_mac_stop") \
									.add_param("mme", mme.get()) \
									.send(self.get())
			else: # 'MME'
				# Allocate an MME buffer
				alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
				
				# Send the MME and wait for the response
				rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
				self.__check_cnf(rsp, DRV_STA_STOP)

	def set_name(self, name):
		"""Set the name.
		The name must be a Python string.
		"""
		self.__name = name
		
		# Configure the station name
		if self.get_name() is not None:
			self.get().set_name(name)

	def set_data_buffer_nb(self, data_buffer_nb):
		"""Set the number of data buffers to allocate into the station.
		The number of data buffers must be a Python integer.
		"""
		if type(data_buffer_nb) is int:
			if data_buffer_nb >= 0:
				self.__data_buffer_nb = data_buffer_nb
			else:
				raise OutOfRangeError("Number of data buffers")
		else:
			raise TypeError
		
		# Allocate data buffers
		if data_buffer_nb > 0:
			alloc_data_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=data_buffer_nb)

	def set_mme_buffer_nb(self, mme_buffer_nb):
		"""Set the number of MME buffers to allocate into the station.
		The number of MME buffers must be a Python integer.
		"""
		if type(mme_buffer_nb) is int:
			if mme_buffer_nb >= 0:
				self.__mme_buffer_nb = mme_buffer_nb
			else:
				raise OutOfRangeError("Number of MME buffers")
		else:
			raise TypeError
		
		# Allocate MME buffers
		if mme_buffer_nb > 0:
			alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=mme_buffer_nb)

	def set_interface_buffer_nb(self, interface_buffer_nb):
		"""Set the number of interface buffers to allocate into the station.
		The number of interface buffers must be a Python integer.
		"""
		if type(interface_buffer_nb) is int:
			if interface_buffer_nb >= 0:
				self.__interface_buffer_nb = interface_buffer_nb
			else:
				raise OutOfRangeError("Number of interface buffers")
		else:
			raise TypeError
		
		# Allocate interface buffers
		if interface_buffer_nb > 0:
			alloc_interface_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=interface_buffer_nb)

	def set_config_mode(self, config_mode):
		"""Set the configuration mode.
		The configuration mode must be a Python string of the CONFIG_MODES Python list.
		"""
		if type(config_mode) is str:
			if config_mode in CONFIG_MODES:
				self.__config_mode = config_mode
			else:
				raise OutOfRangeError("Configuration mode")
		else:
			raise TypeError

	def set_config(self, config):
		"""Set the station parameters.
		The station configuration must be a Python Config structure.
		"""
		self.set_mac_address(config.mac_address)
		self.set_cco_preference(config.cco_preference)
		self.set_was_cco(config.was_cco)
		self.set_npw(config.npw)
		self.set_dpw(config.dpw)
		self.set_m_sta_hfid(config.m_sta_hfid)
		self.set_u_sta_hfid(config.u_sta_hfid)
		self.set_avln_hfid(config.avln_hfid)
		self.set_sl(config.sl)
		self.set_tonemask(config.tonemask)
		self.set_snid(config.snid)

	def set_mac_address(self, mac_address):
		"""Set the MAC address.
		The MAC address can be a Python tuple of 6 Python integers,
		a Python long (decimal or hexadecimal value),
		a Python string of length equals to 6 octets,
		or a Python string of length equals to 17 octets.
		"""
		if type(mac_address) is str:
			if len(mac_address) == 3 * SIZE_OF_MAC_ADDRESS - 1:
				# MAC address is a Python string of length equals to 17 octets ('XX:XX:XX:XX:XX:XX')
				if mac_address.count(':') == SIZE_OF_MAC_ADDRESS - 1:
					self.__mac_address = unpack(6 * u8, pack(n + u64, int(mac_address.replace(':',''), 16))[SIZE_OF_U16:])
				else:
					raise OutOfRangeError("MAC address")
			elif len(mac_address) == SIZE_OF_MAC_ADDRESS:
				# MAC address is a Python string of length equals to 6 octets
				self.__mac_address = ntoh48_tuple(mac_address)
			else:
				raise OutOfRangeError("MAC address")
		elif type(mac_address) is long or type(mac_address) is int:
			# MAC address is a Python long
			if mac_address <= MAX_VALUE_OF_MAC_ADDRESS and mac_address >= 0:
				self.__mac_address = ntoh48_tuple(hton48(mac_address))
			else:
				raise OutOfRangeError("MAC address")
		elif type(mac_address) is tuple:
			# MAC address is a Python tuple
			if len(mac_address) == SIZE_OF_MAC_ADDRESS:
				self.__mac_address = mac_address
			else:
				raise OutOfRangeError("MAC address")
		elif mac_address is None:
			self.__mac_address = None
		else:
			raise TypeError("MAC address")
		
		# Send a message to the station to configure the MAC address
		self.__send_mac_address()

	def set_cco_preference(self, cco_preference):
		"""Set the CCo preference.
		The CCo preference must be a Python boolean.
		"""
		if type(cco_preference) is bool or cco_preference is None:
			self.__cco_preference = cco_preference
		else:
			raise TypeError("CCo preference")
		
		# Send a message to the station to configure the CCo preference
		self.__send_cco_preference()

	def set_was_cco(self, was_cco):
		"""Set the previous CCo status.
		The previous CCo status must be a Python boolean.
		"""
		if type(was_cco) is bool or was_cco is None:
			self.__was_cco = was_cco
		else:
			raise TypeError("Was CCo")
		
		# Send a message to the station to configure the previous CCo status
		self.__send_was_cco()

	def set_npw(self, npw):
		"""Set the Network PassWord.
		The NPW must be a Python string of length from 8 to 64 octets.
		"""
		if type(npw) is str:
			if len(npw) >= MIN_SIZE_OF_NPW and len(npw) <= MAX_SIZE_OF_NPW:
				self.__npw = npw
			else:
				raise OutOfRangeError("NPW")
		elif npw is None:
			self.__npw = npw
		else:
			raise TypeError("NPW")
		
		# Send a message to the station to configure the NPW
		self.__send_npw()

	def set_dpw(self, dpw):
		"""Set the Device PassWord.
		The DPW must be a Python string of length from 0 to 64 octets.
		"""
		if type(dpw) is str:
			if dpw is DEFAULT_DPW:
				self.__dpw = DEFAULT_DPW + str(self.get_station_id())
			elif len(dpw) <= MAX_SIZE_OF_DPW:
				self.__dpw = dpw
			else:
				raise OutOfRangeError("DPW")
		elif dpw is None:
			self.__dpw = dpw
		else:
			raise TypeError("DPW")
		
		# Send a message to the station to configure the DPW
		self.__send_dpw()

	def set_m_sta_hfid(self, m_sta_hfid):
		"""Set the Manufacturer STA HFID.
		The Manufacturer STA HFID must be a Python string of length from 0 to 64 octets.
		"""
		if type(m_sta_hfid) is str:
			if m_sta_hfid is DEFAULT_M_STA_HFID:
				self.__m_sta_hfid = DEFAULT_M_STA_HFID + str(self.get_station_id())
			elif len(m_sta_hfid) <= MAX_SIZE_OF_HFID:
				self.__m_sta_hfid = m_sta_hfid
			else:
				raise OutOfRangeError("Manufacturer STA HFID")
		elif m_sta_hfid is None:
			self.__m_sta_hfid = m_sta_hfid
		else:
			raise TypeError("Manufacturer STA HFID")
		
		# Send a message to the station to configure the Manufacturer STA HFID
		self.__send_m_sta_hfid()

	def set_u_sta_hfid(self, u_sta_hfid):
		"""Set the User STA HFID.
		The User STA HFID must be a Python string of length from 0 to 64 octets.
		"""
		if type(u_sta_hfid) is str:
			if u_sta_hfid is DEFAULT_U_STA_HFID:
				self.__u_sta_hfid = DEFAULT_U_STA_HFID + str(self.get_station_id())
			elif len(u_sta_hfid) <= MAX_SIZE_OF_HFID:
				self.__u_sta_hfid = u_sta_hfid
			else:
				raise OutOfRangeError("User STA HFID")
		elif u_sta_hfid is None:
			self.__u_sta_hfid = u_sta_hfid
		else:
			raise TypeError("User STA HFID")
		
		# Send a message to the station to configure the User STA HFID
		self.__send_u_sta_hfid()

	def set_avln_hfid(self, avln_hfid):
		"""Set the AVLN HFID.
		The AVLN HFID must be a Python string of length from 0 to 64 octets.
		"""
		if type(avln_hfid) is str:
			if len(avln_hfid) <= MAX_SIZE_OF_HFID:
				self.__avln_hfid = avln_hfid
			else:
				raise OutOfRangeError("AVLN HFID")
		elif avln_hfid is None:
			self.__avln_hfid = avln_hfid
		else:
			raise TypeError("AVLN HFID")
		
		# Send a message to the station to configure the AVLN HFID
		self.__send_avln_hfid()

	def set_sl(self, sl):
		"""Set the Security Level.
		The SL must be a Python integer from 0 to 2.
		"""
		if type(sl) is int:
			if sl >= 0 and sl <= MAX_VALUE_OF_SL:
				self.__sl = sl
			else:
				raise OutOfRangeError("Security Level")
		elif sl is None:
			self.__sl = sl
		else:
			raise TypeError("SL")
		
		# Send a message to the station to configure the SL
		self.__send_sl()

	def set_tonemask(self, carriers):
		"""Set the tonemask.
		The carriers must be a Python tuple of Python integers.
		"""
		if type(carriers) is tuple:
			# Use the algorithm from 'mac/common/src/tonemask.c'
			dtc_idx = 0
			dtc_stop = carriers[dtc_idx] - PHY_CARRIER_OFFSET
			dtc_on = False
			tonemask = [] # Python list
			for l in range(0, PHY_TONEMASK_SIZE):
				tonemask.append(0)
			for i in range(0, PHY_TONEMASK_SIZE):
				for j in range(0, 8):
					if i * 8 + j > dtc_stop:
						dtc_on = not dtc_on
						dtc_idx += 1
						dtc_stop = carriers[dtc_idx] - PHY_CARRIER_OFFSET
					if dtc_on is True:
						tonemask[i] |= 1 << j
			
			self.__tonemask = ''
			for t in tonemask:
				self.__tonemask += htohp8(t)
		elif carriers is None:
			self.__tonemask = carriers
		else:
			raise TypeError("Tonemask")
		
		# Send a message to the station to configure the tonemask
		self.__send_tonemask()

	def set_snid(self, snid):
		"""Set the SNID.
		The SNID must be a Python integer from 0 to 15.
		"""
		if type(snid) is int:
			if snid >= 0 and snid <= MAX_VALUE_OF_SNID:
				self.__snid = snid
			else:
				raise OutOfRangeError("SNID")
		elif snid is None:
			self.__snid = snid
		else:
			raise TypeError("SNID")
		
		# Send a message to the station to configure the SNID
		self.__send_snid()

	def __get_maximus(self):
		"""Get Maximus.
		Maximus is a Maximus object.
		"""
		return self.__maximus

	def get(self):
		"""Get the station.
		The station is a Sta object.
		"""
		return self.__station

	def get_name(self):
		"""Get the name.
		The name is a Python string.
		"""
		return self.__name

	def get_data_buffer_nb(self):
		"""Get the number of data buffers allocated into the station.
		The number of data buffers is a Python integer.
		"""
		return self.__data_buffer_nb

	def get_mme_buffer_nb(self):
		"""Get the number of MME buffers allocated into the station.
		The number of MME buffers is a Python integer.
		"""
		return self.__mme_buffer_nb

	def get_interface_buffer_nb(self):
		"""Get the number of interface buffers allocated into the station.
		The number of interface buffers is a Python integer.
		"""
		return self.__interface_buffer_nb

	def get_config_mode(self):
		"""Get the configuration mode.
		The configuration mode is a Python string of the CONFIG_MODES Python list.
		"""
		return self.__config_mode

	def get_config(self):
		"""Get the station parameters.
		The station configuration is a Python Config structure.
		"""
		return Config(mac_address=self.get_mac_address(), \
				      cco_preference=self.get_cco_preference(), \
				      was_cco=self.get_was_cco(), \
					  npw=self.get_npw(), \
					  dpw=self.get_dpw(), \
 					  m_sta_hfid=self.get_m_sta_hfid(), \
					  u_sta_hfid=self.get_u_sta_hfid(), \
					  avln_hfid=self.get_avln_hfid(), \
					  sl=self.get_sl(), \
 					  tonemask=self.get_tonemask())

	def get_mac_address(self):
		"""Get the MAC address.
		The MAC address is a Python tuple of 6 Python integers.
		"""
		return self.__mac_address

	def get_cco_preference(self):
		"""Get the CCo preference.
		The CCo preference is a Python boolean.
		"""
		return self.__cco_preference

	def get_was_cco(self):
		"""Get the previous CCo status.
		The previous CCo status is a Python boolean.
		"""
		return self.__was_cco

	def get_npw(self):
		"""Get the Network PassWord.
		The NPW is a Python string of length from 8 to 64 octets.
		"""
		return self.__npw

	def get_dpw(self):
		"""Get the Device PassWord.
		The DPW is a Python string of length from 0 to 64 octets.
		"""
		return self.__dpw

	def get_m_sta_hfid(self):
		"""Get the Manufacturer STA HFID.
		The Manufacturer STA HFID is a Python string of length from 0 to 64 octets.
		"""
		return self.__m_sta_hfid

	def get_u_sta_hfid(self):
		"""Get the User STA HFID.
		The User STA HFID is a Python string of length from 0 to 64 octets.
		"""
		return self.__u_sta_hfid

	def get_avln_hfid(self):
		"""Get the AVLN HFID.
		The AVLN HFID is a Python string of length from 0 to 64 octets.
		"""
		return self.__avln_hfid

	def get_sl(self):
		"""Get the Security Level.
		The SL is a Python integer.
		"""
		return self.__sl

	def get_tonemask(self):
		"""Get the tonemask.
		The tonemask is a bits field.
		"""
		return self.__tonemask

	def get_snid(self):
		"""Get the SNID.
		The SNID is a Python integer.
		"""
		return self.__snid

	def __send_mac_address(self):
		"""Send a message to the station to configure the MAC address.
		"""
		if self.get_mac_address() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_mac_address") \
									.add_param_n_u8("mac_address", self.get_mac_address()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=self.get_mac_address(), MMV=0x01, MMTYPE = DRV_STA_SET_MAC_ADDR + MME_TYPES['REQ'])
				
				# Computes MM Entry: Mac address of the station
				# Octet Number = 0 - 5
				# Field Size (Octets) = 6
				StaMAC = ''
				for t in self.get_mac_address():
					StaMAC += htohp8(t)
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=StaMAC)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_mac_address") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_MAC_ADDR)

	def __send_cco_preference(self):
		"""Send a message to the station to configure the CCo preference.
		"""
		if self.get_cco_preference() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_cco_preference") \
									.add_param_bool("cco_preference", self.get_cco_preference()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_CCO_PREF + MME_TYPES['REQ'])
				
				# Computes MM Entry:
				# - 0x00 = Station is not CCo
				# - 0x01 = Station is CCo
				# - 0x02 - 0xFF = Reserved
				# Octet Number = 0
				# Field Size (Octets) = 1
				if self.get_cco_preference() is True:
					CCoPref = htohp8(0x01)
				else:
					CCoPref = htohp8(0x00)
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=CCoPref)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_cco_preference") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_CCO_PREF)

	def __send_was_cco(self):
		"""Send a message to the station to configure the previous CCo status.
		"""
		if self.get_was_cco() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_was_cco") \
									.add_param_bool("was_cco", self.get_was_cco()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_WAS_CCO + MME_TYPES['REQ'])
				
				# Computes MM Entry:
				# - 0x00 = Station was not CCo
				# - 0x01 = Station was previously CCo
				# - 0x02 - 0xFF = Reserved
				# Octet Number = 0
				# Field Size (Octets) = 1
				if self.get_was_cco() is True:
					WasCCo = htohp8(0x01)
				else:
					WasCCo = htohp8(0x00)
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=WasCCo)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_was_cco") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_WAS_CCO)

	def __send_npw(self):
		"""Send a message to the station to configure the NPW.
		"""
		if self.get_npw() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_npw") \
									.add_param("npw", self.get_npw()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_NPW + MME_TYPES['REQ'])
				
				# Computes MM Entry: Human-Readable (ASCII) Station Network Password
				# Octet Number = 0 - 63
				# Field Size (Octets) = 64
				StaNPW = self.get_npw()
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=StaNPW)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_npw") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_NPW)

	def __send_dpw(self):
		"""Send a message to the station to configure the DPW.
		"""
		if self.get_dpw() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_dpw") \
									.add_param("dpw", self.get_dpw()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_DPW + MME_TYPES['REQ'])
				
				# Computes MM Entry: Human-Readable (ASCII) Station Device Password
				# Octet Number = 0 - 63
				# Field Size (Octets) = 64
				StaDPW = self.get_dpw()
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=StaDPW)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_dpw") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_DPW)

	def __send_m_sta_hfid(self):
		"""Send a message to the station to configure the Manufacturer STA HFID.
		"""
		if self.get_m_sta_hfid() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_m_sta_hfid") \
									.add_param("m_sta_hfid", self.get_m_sta_hfid()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_M_STA_HFID + MME_TYPES['REQ'])
				
				# Computes MM Entry: Manufacturer Station Human-Friendly ID in ASCII format
				# Octet Number = 0 - 63
				# Field Size (Octets) = 64
				Sta_m_HFID = self.get_m_sta_hfid()
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=Sta_m_HFID)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_m_sta_hfid") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_M_STA_HFID)

	def __send_u_sta_hfid(self):
		"""Send a message to the station to configure the User STA HFID.
		"""
		if self.get_u_sta_hfid() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_u_sta_hfid") \
									.add_param("u_sta_hfid", self.get_u_sta_hfid()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_U_STA_HFID + MME_TYPES['REQ'])
				
				# Computes MM Entry: User Station Human-Friendly ID in ASCII format
				# Octet Number = 0 - 63
				# Field Size (Octets) = 64
				Sta_u_HFID = self.get_u_sta_hfid()
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=Sta_u_HFID)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_u_sta_hfid") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_U_STA_HFID)

	def __send_avln_hfid(self):
		"""Send a message to the station to configure the AVLN HFID.
		"""
		if self.get_avln_hfid() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_avln_hfid") \
									.add_param("avln_hfid", self.get_avln_hfid()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_AVLN_HFID + MME_TYPES['REQ'])
				
				# Computes MM Entry: AVLN Station Human-Readable ID in ASCII format
				# Octet Number = 0 - 63
				# Field Size (Octets) = 64
				Sta_AVLN_HFID = self.get_avln_hfid()
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=Sta_AVLN_HFID)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_avln_hfid") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_AVLN_HFID)

	def __send_sl(self):
		"""Send a message to the station to configure the SL.
		"""
		if self.get_sl() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_sl") \
									.add_param_uchar("sl", self.get_sl()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_SL + MME_TYPES['REQ'])
				
				# Computes MM Entry: Security Level for New NMK
				# Octet Number = 0
				# Field Size (Octets) = 1
				SL = htohp8(self.get_sl())
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=SL)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_sl") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_SL)

	def __send_tonemask(self):
		"""Send a message to the station to configure the tonemask.
		"""
		if self.get_tonemask() is not None:
			if self.get_config_mode() is CONFIG_MODES[2]: # 'fcall_cp_station'
				self.__get_maximus().create_fcall("maximus_set_tonemask") \
									.add_param("tonemask", self.get_tonemask()) \
									.send(self.get())
			else: # we need to build an MME
				
				# Computes MM Header
				if self.get_mac_address() is not None:
					osa = self.get_mac_address()
				else:
					osa = DEFAULT_MAC_ADDRESS
				mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_TONEMASK + MME_TYPES['REQ'])
				
				# Computes MM Entry:
				
				# First carrier offset
				# Octet Number = 0 - 1
				# Field Size (Octets) = 2
				Tonemask_offset = htohp16(PHY_CARRIER_OFFSET)
				
				# Size of tonemask in bits
				# Octet Number = 2 - 3
				# Field Size (Octets) = 2
				Tonemask_length = htohp16(PHY_CARRIER_NB)
				
				# Station Tonemask bitfield
				# Octet Number = 0 - 191
				# Field Size (Octets) = 192
				Sta_Tonemask = self.get_tonemask()
				
				# Create the MME
				mme = MME(MMHeader=mmheader, MMEntry=Tonemask_offset+Tonemask_length+Sta_Tonemask)
				
				if self.get_config_mode() is CONFIG_MODES[1]: # 'fcall_process_drv'
					self.__get_maximus().create_fcall("maximus_set_tonemask") \
										.add_param("mme", mme.get()) \
										.send(self.get())
				else: # 'MME'
					# Allocate an MME buffer
					alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get())
					
					# Send the MME and wait for the response
					rsp = mme.sendnrecv(maximus=self.__get_maximus(), station=self.get(), filter=mme_filter)
					self.__check_cnf(rsp, DRV_STA_SET_TONEMASK)

	def __send_snid(self):
		"""Send a message to the station to configure the SNID.
		"""
		if self.get_snid() is not None:
			# allways 'fcall_cp_station'
			self.__get_maximus().create_fcall("maximus_set_snid") \
								.add_param_uchar("snid", self.get_snid()) \
								.send(self.get())

	def __check_cnf(self, rsp, name):
		"""Check the MME response validity.
		"""
		mmtype = hptoh16(rsp[0].get_mmheader()[SIZE_OF_MMHEADER - SIZE_OF_FMI - SIZE_OF_MMTYPE:SIZE_OF_MMHEADER - SIZE_OF_FMI])
		if mmtype != name + MME_TYPES['CNF']:
			raise Error("Received unexpected message of type " + hex(mmtype))
		result = hptoh8(rsp[0].get_mmentry()[0])
		if result == FAILURE:
			err_code = hptoh8(rsp[0].get_mmentry()[1])
			try:
				err_msg = ERROR_CODES[err_code]
			except KeyError:
				err_msg = "Unknow error code"
			raise Error(hex(name) + ".CNF => Failure: " + err_msg)
		elif result >= RESERVED:
			raise Error(hex(name) + ".CNF => Reserved: " + hex(result))

	# Following functions just are encapsulation of interface module Boost Python functions.
	#

	def remove(self):
		return self.get().remove()

	def deactivate(self):
		return self.get().deactivate()

	def activate(self):
		return self.get().activate()

	def debug(self):
		return self.get().debug()

	def is_idle(self):
		return self.get().is_idle()

	def get_station_id(self):
		return self.get().get_station_id()