-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.sh
101 lines (81 loc) · 2.26 KB
/
manage.sh
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
import os
import sys
VID = sys.argv[1]
PID = sys.argv[2]
file = open('uframe.h', 'r')
data = file.readlines()
file.close()
data[5] = '#define VID 0x' + VID + '\n'
data[6] = '#define PID 0x' + PID + '\n'
file = open('uframe.h', 'w')
file.write("".join(data))
file.close()
os.system("make")
os.system("sudo insmod udriver.ko")
interface = 0
os.system("lsusb > lsusb.txt")
file = open('lsusb.txt', 'r')
data = file.readlines()
file.close()
os.system("rm lsusb.txt")
target = "ID " + VID + ":" + PID
deviceDetails = ""
for line in data:
if target in line:
deviceDetails = line
break
if deviceDetails != "":
bus = deviceDetails[4:7]
device = deviceDetails[15:18]
print("bus: " + bus)
print("device: " + device)
os.system("lsusb -D /dev/bus/usb/" + bus + "/" + device + " > deviceDiscriptor.txt")
file = open("deviceDiscriptor.txt", "r")
data = file.readlines()
file.close()
#os.system("rm deviceDiscriptor.txt")
target = "Endpoint Descriptor:"
ep = open("endpoints.txt", "w")
ep.write(target + "\n")
deviceDetails = ""
counter = 0
for line in data:
if target in line:
for i in range(counter + 1, len(data)-1) :
ep.write(data[i])
ep.close()
break
counter += 1
endpointCounter = 0
type = ""
direction = ""
#creating control endpoint
os.system("bash create_node.sh " + " " + VID + " " + PID + " " + str(interface) + " " + "Control" + " " + "{0:03}".format(0) + " " + str(endpointCounter))
target = "Endpoint Descriptor:"
ep = open("endpoints.txt", "r")
data = ep.readlines()
counter = 0
for line in data:
if target in line:
type = ""
direction = ""
for i in range(counter + 1, len(data)-1) :
if "bEndpointAddress" in data[i]:
endpointCounter += 1
if "IN" in data[i]:
direction = "{0:03}".format(1 + endpointCounter*10) #IN
else:
direction = "{0:03}".format(0 + endpointCounter*10) #OUT
if "Transfer Type" in data[i]:
if "Interrupt":
type = "Interrupt"
elif "Bulk":
type = "Bulk"
elif "Isochronous":
type = "Isochronous"
if type != "" and direction != "":
os.system("bash create_node.sh " + " " + VID + " " + PID + " " + str(interface) + " " + type + " " + direction + " " + str(endpointCounter))
break
counter += 1
else :
print ("device is not connected")