Advertisement
jfrog

Untitled

Jun 6th, 2022
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. #!/usr/bin/lua
  2.  
  3. drv = {}
  4. idV = arg[1]
  5. idP = arg[2]
  6. pflag = arg[3]
  7. if pflag == nil then
  8. pflag = 1
  9. end
  10.  
  11. special = {}
  12. -- PPP special cases
  13. -- VID PID port #
  14. special[1] = "1bbb" ; special[2] = "0017" ; special[3] = 13
  15. special[4] = "12d1" ; special[5] = nil ; special[6] = 10
  16. special[7] = "1546" ; special[8] = "01a6" ; special[9] = 0
  17. special[10] = "1546" ; special[11] = "01a5" ; special[12] = 0
  18. special[13] = "1199" ; special[14] = "68a3" ; special[15] = 14
  19. special[16] = "2001" ; special[17] = "7e35" ; special[18] = 15
  20.  
  21.  
  22. retval = 0
  23. echo = 1
  24.  
  25. printf = function(s,...)
  26. if pflag ~= 0 then
  27. io.write(s:format(...))
  28. local ss = s:format(...)
  29. if echo == 1 then
  30. os.execute("/usr/lib/rooter/logprint.sh " .. ss)
  31. end
  32. end
  33. end
  34.  
  35. function trim(s)
  36. return (s:gsub("^%s*(.-)%s*$", "%1"))
  37. end
  38.  
  39. function checkserial()
  40. local got = 0
  41. j = 1
  42. repeat
  43. if drv[j] ~= nil then
  44. if drv[j] == "option" or drv[j] == "qcserial" or drv[j] == "usb_serial" or drv[j] == "sierra" then
  45. got = 1
  46. break
  47. end
  48. j = j + 1
  49. end
  50. until drv[j] == nil
  51. return got
  52. end
  53.  
  54. function countserial()
  55. local got = 0
  56. j = 1
  57. repeat
  58. if drv[j] ~= nil then
  59. if drv[j] == "option" or drv[j] == "sierra" or drv[j] == "usb_serial" or drv[j] == "qcserial" then
  60. got = got + 1
  61. end
  62. j = j + 1
  63. end
  64. until drv[j] == nil
  65. return got
  66. end
  67.  
  68. -- MAIN
  69.  
  70. local t = {}
  71.  
  72. local i=0
  73. local file = io.open("/tmp/wdrv", "r")
  74. repeat
  75. local line = file:read("*line")
  76. if line == nil then
  77. break
  78. end
  79. if string.len(line) > 5 then
  80. s, e = line:find("Vendor=")
  81. if s ~= nil then
  82. cs, ce = line:find(" ", e)
  83. m_idV = trim(line:sub(e+1, cs-1))
  84. s, e = line:find("ProdID=")
  85. cs, ce = line:find(" ", e)
  86. m_idP = trim(line:sub(e+1, cs-1))
  87. if m_idV == idV and m_idP == idP then
  88. repeat
  89. line = file:read("*line")
  90. if line == nil then
  91. break
  92. end
  93. if string.len(line) > 5 then
  94. s, e = line:find("T:")
  95. if s ~= nil then
  96. break
  97. end
  98. s, e = line:find("Cls=02")
  99. if s ~= nil then
  100. t[i] = trim(line:sub(63))
  101. i = i + 1
  102. end
  103. s, e = line:find("Cls=ff")
  104. if s ~= nil then
  105. t[i] = trim(line:sub(63))
  106. i = i + 1
  107. end
  108. s, e = line:find("1 Cls=e0")
  109. if s ~= nil then
  110. t[i] = trim(line:sub(63))
  111. i = i + 1
  112. end
  113. s, e = line:find("Cls=0a")
  114. if s ~= nil then
  115. t[i] = trim(line:sub(63))
  116. i = i + 1
  117. end
  118. s, e = line:find("Cls=0e")
  119. if s ~= nil then
  120. t[i] = trim(line:sub(63))
  121. i = i + 1
  122. end
  123. s, e = line:find("Cls=07")
  124. if s ~= nil then
  125. t[i] = trim(line:sub(63))
  126. i = i + 1
  127. end
  128. s, e = line:find("Cls=08")
  129. if s ~= nil then
  130. t[i] = trim(line:sub(63))
  131. i = i + 1
  132. end
  133. end
  134. until 1==0
  135. break
  136. end
  137. end
  138. end
  139. until 1==0
  140. file:close()
  141. if i > 0 then
  142. file = io.open("/tmp/drv", "w")
  143. for j=0,i-1 do
  144. drv[j+1] = t[j]
  145. drver = string.format("%s%d%s%q", "DRIVER", j+1, "=", t[j])
  146. file:write(drver .. "\n")
  147. end
  148. ports = countserial()
  149. drver = string.format("%s%s%d%s", "PORTN", "=\"", ports, "\"")
  150. file:write(drver .. "\n")
  151. file:close()
  152. end
  153.  
  154. i = 1
  155. repeat
  156. if drv[i] ~= nil then
  157. printf("Driver Name : %d %s\n", i, drv[i])
  158. i = i + 1
  159. end
  160. until drv[i] == nil
  161.  
  162. i = 1
  163. repeat
  164. if drv[i] ~= nil then
  165. if drv[i] == "sierra_net" then
  166. retval = 1
  167. break
  168. end
  169. if drv[i] == "qmi_wwan" then
  170. retval = 2
  171. break
  172. end
  173. if drv[i] == "cdc_mbim" then
  174. retval = 3
  175. break
  176. end
  177. if drv[i] == "huawei_cdc_ncm" then
  178. if i == 2 then
  179. retval = 4
  180. else
  181. if i == 3 then
  182. retval = 6
  183. else
  184. retval = 7
  185. end
  186. end
  187. break
  188. end
  189. if drv[i] == "cdc_ncm" then
  190. if i == 2 then
  191. retval = 24
  192. else
  193. if i == 3 then
  194. retval = 26
  195. else
  196. retval = 27
  197. end
  198. end
  199. break
  200. end
  201. if drv[i] == "cdc_ether" or drv[i] == "rndis_host" then
  202. retval = 5
  203. end
  204. if drv[i] == "ipheth" then
  205. retval = 9
  206. break
  207. end
  208. if drv[i] == "uvcvideo" then
  209. retval = 99
  210. break
  211. end
  212. if drv[i] == "usblp" then
  213. retval = 98
  214. break
  215. end
  216. if drv[i] == "usb-storage" then
  217. retval = 97
  218. end
  219. i = i + 1
  220. end
  221. until drv[i] == nil
  222.  
  223. if retval == 0 then
  224. if checkserial() == 1 then
  225. retval = 11
  226. k = 1
  227. vendor = special[k]
  228. while vendor ~= nil do
  229. if idV == vendor then
  230. if special[k+1] == nil then
  231. retval = special[k+2]
  232. break
  233. else
  234. if special[k+1] == idP then
  235. retval = special[k+2]
  236. break
  237. end
  238. end
  239. end
  240. k = k + 3
  241. vendor = special[k]
  242. end
  243. end
  244. end
  245.  
  246. os.exit(retval)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement