commit ca45538b630790e738cef02c88b5e817079f550f Author: qiurui Date: Mon Apr 8 18:50:01 2024 +0800 Init commit diff --git a/etc/init.d/init.d/bootstrapping.sh b/etc/init.d/init.d/bootstrapping.sh new file mode 100644 index 0000000..a2dedfe --- /dev/null +++ b/etc/init.d/init.d/bootstrapping.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +sleep 5 +if [[ ! -f "~/debugwifi.log" ]];then + touch ~/debugwifi.log +fi + +echo "connect start" > ~/debugwifi.log +timedatectl >> ~/debugwifi.log + +nmcli dev wifi list > /dev/null +sleep 1 +/usr/bin/python3 /usr/bin/easywifi-root.py & +echo "connect success" + + +#mount -t configfs none /sys/kernel/config/ +modprobe usb_f_hid +mkdir /sys/kernel/config/usb_gadget/g1 +echo 0x0525 >/sys/kernel/config/usb_gadget/g1/idVendor +echo 0xa4ac >/sys/kernel/config/usb_gadget/g1/idProduct +mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 +mkdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0 +echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/protocol +echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/subclass +echo 512 >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_length +echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc +mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 +echo 0xc0 >/sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes +echo 500 >/sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower +mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 +ln -s /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ + + +/usr/bin/python /usr/bin/server.py > /dev/null & diff --git a/etc/init.d/rc3.d/S99bootstrapping b/etc/init.d/rc3.d/S99bootstrapping new file mode 100644 index 0000000..a2dedfe --- /dev/null +++ b/etc/init.d/rc3.d/S99bootstrapping @@ -0,0 +1,35 @@ +#!/bin/bash + +sleep 5 +if [[ ! -f "~/debugwifi.log" ]];then + touch ~/debugwifi.log +fi + +echo "connect start" > ~/debugwifi.log +timedatectl >> ~/debugwifi.log + +nmcli dev wifi list > /dev/null +sleep 1 +/usr/bin/python3 /usr/bin/easywifi-root.py & +echo "connect success" + + +#mount -t configfs none /sys/kernel/config/ +modprobe usb_f_hid +mkdir /sys/kernel/config/usb_gadget/g1 +echo 0x0525 >/sys/kernel/config/usb_gadget/g1/idVendor +echo 0xa4ac >/sys/kernel/config/usb_gadget/g1/idProduct +mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 +mkdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0 +echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/protocol +echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/subclass +echo 512 >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_length +echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc +mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 +echo 0xc0 >/sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes +echo 500 >/sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower +mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 +ln -s /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ + + +/usr/bin/python /usr/bin/server.py > /dev/null & diff --git a/usr/bin/easywifi-root.py b/usr/bin/easywifi-root.py new file mode 100644 index 0000000..5eb2c1a --- /dev/null +++ b/usr/bin/easywifi-root.py @@ -0,0 +1,64 @@ +import subprocess +import os + + +def sub_command_run(cmd,grep): + result = subprocess.Popen(cmd, stdout=subprocess.PIPE) + if grep == 1: + value = subprocess.Popen(['grep','/dev/mmcblk0p1'], stdin=result.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + value = result + out = value.communicate()[0].decode('utf-8') + return out + +def is_mounted(part): + result = subprocess.run('mount',capture_output=True,text=True) + output = result.stdout + if part in output: + return True + else: + return False +''' +def get_activited_ssid(SSID): + cmd = "iwgetid -r" + cmd = cmd.split() + result = sub_command_run(cmd,0) + return result +''' + +if os.path.exists("/dev/mmcblk0p2") == False: + cmd="fdisk -l /dev/mmcblk0" + cmd=cmd.split() + password="orangepi" + result = sub_command_run(cmd,1) + sector_list = result.split() + sector_start = int(sector_list[2]) + 1 + format_cmd = "/bin/bash /usr/bin/format.sh " + str(sector_start) + format_cmd = format_cmd.split() + sub_command_run(format_cmd,0) + +part = "/dev/mmcblk0p2" + +if is_mounted(part) == False: + cmd = "mount " + part + " /mnt" + cmd = cmd.split() + sub_command_run(cmd,0) + +if os.path.exists("/mnt/wifi.txt") == True: + f=open("/mnt/wifi.txt") + count=0 + Lines=f.readlines() + for line in Lines: + count +=1 + if count==1: + network=line.strip().split("=")[1] + elif count==2: + password=line.strip().split("=")[1] + else: + break +else: + network="Q" + password="123123123" + +result = subprocess.run(['nmcli', "d", "wifi", "connect", network, "password", str(password)], stdout=subprocess.PIPE) +print(result.stdout.decode('utf-8')) \ No newline at end of file diff --git a/usr/bin/server.py b/usr/bin/server.py new file mode 100644 index 0000000..1f1de82 --- /dev/null +++ b/usr/bin/server.py @@ -0,0 +1,43 @@ +#coding:utf-8 +import os +from socket import * + +NULL_CHAR = chr(0) + +def write_report(report): + with open('/dev/hidg0','rb+') as fd: + fd.write(report) + +#''代表服务器为 localhost +myHost = '' +#在一个非保留端口号上进行监听 +myPort = 50009 +#设置一个TCP socket对象 +sockobj = socket(AF_INET, SOCK_STREAM) +#绑定端口号 +sockobj.bind((myHost, myPort)) +#监听,允许5个连结 +sockobj.listen(5) +#直到进程结束时才结束循环 +while True: + #等待客户端连接 + connection, address = sockobj.accept( ) + #连接是一个新的socket + print ('Server connected by', address) + while True: + #读取客户端套接字的下一行 + data = connection.recv(1024) + #如果没有数量的话,那么跳出循环 + if not data: break + if data == "hid open": + os.popen('ls /sys/class/udc | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC') + print("hid open") + elif data == "hid close": + os.popen('echo > /sys/kernel/config/usb_gadget/g1/UDC') + print("hid close") + else: + write_report(data) + #发送一个回复至客户端 + connection.send('server => ' + data) + #当socket关闭时eof + connection.close( )