-
Notifications
You must be signed in to change notification settings - Fork 4
/
rbmode.py
78 lines (62 loc) · 1.95 KB
/
rbmode.py
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
#!/usr/bin/env python2
__author__ = 'Michael Niewoehner <c0d3z3r0>'
__email__ = 'mniewoeh@stud.hs-offenburg.de'
import smbus, argparse, time
# SMBUS data
# noline
# port 0: 08-02-fd-01-fe-01-fe-88-77 -> 0x02, 0x01, 0x01
# port 1: 08-02-fd-00-ff-01-fe-88-77 -> 0x02, 0x00, 0x01
#
# universal
# port 0: 06-03-fc-01-fe-66-99 -> 0x03, 0x01
# port 1: 06-03-fc-00-ff-66-99 -> 0x03, 0x00
#
# bridge
# port 0: 08-02-fd-01-fe-00-ff-88-77 -> 0x02, 0x01, 0x00
# port 1: 08-02-fd-00-ff-00-ff-88-77 -> 0x02, 0x00, 0x00
modes = {'b': [0x02, None, 0x00],
'n': [0x02, None, 0x01],
'u': [0x03, None]
}
def calcChecksums(cmd):
cmd_cs = []
for c in cmd:
cmd_cs.extend([c, 0xff-c])
l = len(cmd_cs)+2
l += l << 4
cmd_cs.extend([l, 0xff-l])
return cmd_cs
def setMode(mode):
s = smbus.SMBus(0)
cmd = modes[mode]
cmd_0 = list(cmd)
cmd_1 = list(cmd)
cmd_0[1] = 0x01
cmd_1[1] = 0x00
s.write_block_data(0x24, 0x55, calcChecksums(cmd_0))
time.sleep(0.1)
s.write_block_data(0x24, 0x55, calcChecksums(cmd_1))
s.close()
def main():
parser = argparse.ArgumentParser(description='rbMode')
group = parser.add_mutually_exclusive_group()
group.add_argument('--list', '-l', action='store_true', help='Show modes')
group.add_argument('mode', nargs='?',
help='Modes: n(oline)|b(ridge)|u(niversal)')
args = parser.parse_args()
if args.list:
print("""\
Brigde mode (b): Connects LAN and WAN port directly
Universal mode (u): Use LAN and WAN as normal network interfaces
Noline mode (n): Physically disconnect both ports""")
elif args.mode:
if modes.has_key(args.mode):
print("Setting mode to " +
{'b': 'bridge', 'n': 'noline', 'u': 'universal'}[args.mode])
setMode(args.mode)
else:
parser.print_help()
else:
parser.print_help()
if __name__ == '__main__':
main()