From 19d352fb376f2cbc2eeb07312b7358ec3dd3739a Mon Sep 17 00:00:00 2001 From: mame82 Date: Sun, 27 May 2018 23:33:41 +0000 Subject: [PATCH] Started HID implementatio + wifi client functionality --- hid/keyboard.go | 90 ++++++ hid/keyboard_const.go | 321 +++++++++++++++++++ hid/keymaps/de.go | 276 ++++++++++++++++ proto/gopherjs/grpc.pb.gopherjs.go | 193 +++++++---- proto/grpc.pb.go | 274 +++++++++------- proto/grpc.proto | 27 +- service/defaults.go | 28 +- service/dhcp.go | 7 +- service/rpc_server.go | 10 + service/ugly.go | 123 ++++++++ service/wifi.go | 492 +++++++++++++++++++++++++++++ 11 files changed, 1646 insertions(+), 195 deletions(-) create mode 100644 hid/keyboard.go create mode 100644 hid/keyboard_const.go create mode 100644 hid/keymaps/de.go create mode 100644 service/wifi.go diff --git a/hid/keyboard.go b/hid/keyboard.go new file mode 100644 index 0000000..f01411c --- /dev/null +++ b/hid/keyboard.go @@ -0,0 +1,90 @@ +package hid + +import ( + "errors" + "io/ioutil" + "os" + "log" +) + + + +type KeyboardOutReport struct { + Modifiers byte + //Reserved byte + Keys [6]byte +} + +func (rep KeyboardOutReport) Serialize() (out []byte) { + out = []byte { + rep.Modifiers, + byte(0), + rep.Keys[0], + rep.Keys[1], + rep.Keys[2], + rep.Keys[3], + rep.Keys[4], + rep.Keys[5], + } + return +} + +func (rep KeyboardOutReport) Deserialize(data []byte) (err error) { + if len(data) != 8 { + err = errors.New("Wrong data length, keyboard out report has to be 8 bytes in length") + } + rep = KeyboardOutReport{ + Modifiers: data[0], + //data[1] should be empty, we ignore it + Keys: [6]byte{ + data[2], + data[3], + data[4], + data[5], + data[6], + data[7], + }, + } + return +} + +func (rep KeyboardOutReport) WriteTo(filePath string) (err error) { + return ioutil.WriteFile(filePath, rep.Serialize(), os.ModePerm) //Serialize Report and write to specified file +} + + + +func NewKeyboardOutReport(modifiers byte, keys ...byte) (res KeyboardOutReport) { + res = KeyboardOutReport{ + Keys: [6]byte {0, 0, 0, 0, 0, 0,}, + } + res.Modifiers = modifiers + for i, key := range keys { + if i < 6 { + res.Keys[i] = key + } + } + return +} + +func Test() { + filepath := "/dev/hidg0" + kbdRepEmpty := NewKeyboardOutReport(0) + kbdRep_a := NewKeyboardOutReport(0, HID_KEY_A) + kbdRep_A := NewKeyboardOutReport(HID_MOD_KEY_LEFT_SHIFT, HID_KEY_A) + + err := kbdRepEmpty.WriteTo(filepath) + if err != nil {log.Fatal(err)} + err = kbdRep_a.WriteTo(filepath) + if err != nil {log.Fatal(err)} + err = kbdRepEmpty.WriteTo(filepath) + if err != nil {log.Fatal(err)} + err = kbdRep_A.WriteTo(filepath) + if err != nil {log.Fatal(err)} + err = kbdRepEmpty.WriteTo(filepath) + if err != nil {log.Fatal(err)} + err = kbdRep_A.WriteTo(filepath) + if err != nil {log.Fatal(err)} + err = kbdRepEmpty.WriteTo(filepath) + if err != nil {log.Fatal(err)} +} diff --git a/hid/keyboard_const.go b/hid/keyboard_const.go new file mode 100644 index 0000000..3ab9246 --- /dev/null +++ b/hid/keyboard_const.go @@ -0,0 +1,321 @@ +package hid + +/* +Keyboard descriptor used + + +USAGE_PAGE (Generic Desktop) 05 01 +USAGE (Keyboard) 09 06 +COLLECTION (Application) A1 01 + USAGE_PAGE (Keyboard) 05 07 + USAGE_MINIMUM (Keyboard LeftControl) 19 E0 + USAGE_MAXIMUM (Keyboard Right GUI) 29 E7 + LOGICAL_MINIMUM (0) 15 00 + LOGICAL_MAXIMUM (1) 25 01 + REPORT_SIZE (1) 75 01 + REPORT_COUNT (8) 95 08 + INPUT (Data,Var,Abs) 81 02 + REPORT_COUNT (1) 95 01 + REPORT_SIZE (8) 75 08 + INPUT (Cnst,Var,Abs) 81 03 + REPORT_COUNT (5) 95 05 + REPORT_SIZE (1) 75 01 + USAGE_PAGE (LEDs) 05 08 + USAGE_MINIMUM (Num Lock) 19 01 + USAGE_MAXIMUM (Kana) 29 05 + OUTPUT (Data,Var,Abs) 91 02 + REPORT_COUNT (1) 95 01 + REPORT_SIZE (3) 75 03 + OUTPUT (Cnst,Var,Abs) 91 03 + REPORT_COUNT (6) 95 06 + REPORT_SIZE (8) 75 08 + LOGICAL_MINIMUM (0) 15 00 + LOGICAL_MAXIMUM (101) 25 65 + USAGE_PAGE (Keyboard) 05 07 + USAGE_MINIMUM (Reserved (no event indicated)) 19 00 + USAGE_MAXIMUM (Keyboard Application) 29 65 + INPUT (Data,Ary,Abs) 81 00 +END_COLLECTION C0 + +--> Report format INPUT +Byte 0: INPUT - Modifier BitMask + Bit 0: Keyboard LeftControl + Bit 7: Keyboard Right GUI +Byte 1: INPUT - Constant field +Byte 2: INPUT Keyboard (Values between "reserved (no event)" (0x00) and "Keyboard Application" (0x65)) +Byte 3: INPUT Keyboard (Values between "reserved (no event)" (0x00) and "Keyboard Application" (0x65)) +Byte 4: INPUT Keyboard (Values between "reserved (no event)" (0x00) and "Keyboard Application" (0x65)) +Byte 5: INPUT Keyboard (Values between "reserved (no event)" (0x00) and "Keyboard Application" (0x65)) +Byte 6: INPUT Keyboard (Values between "reserved (no event)" (0x00) and "Keyboard Application" (0x65)) +Byte 7: INPUT Keyboard (Values between "reserved (no event)" (0x00) and "Keyboard Application" (0x65)) + +see: http://www.usb.org/developers/hidpage/Hut1_12v2.pdf + +--> Report format OUTPUT +Byte 0: OUTPUT - LED BitMask //Only present in output reports + Bit 0: Num Lock + Bit 4: Kana + Bit 5 .. 7: Constant + */ + +const ( + HID_MOD_KEY_LEFT_CONTROL = 0x01 + HID_MOD_KEY_LEFT_SHIFT = 0x02 + HID_MOD_KEY_LEFT_ALT = 0x04 + HID_MOD_KEY_LEFT_GUI = 0x08 + HID_MOD_KEY_RIGHT_CONTROL = 0x10 + HID_MOD_KEY_RIGHT_SHIFT = 0x20 + HID_MOD_KEY_RIGHT_ALT = 0x40 + HID_MOD_KEY_RIGHT_GUI = 0x80 + + HID_KEY_RESERVED = 0x00 + HID_KEY_ERROR_ROLLOVER = 0x01 + HID_KEY_POST_FAIL = 0x02 + HID_KEY_ERROR_UNDEFINED = 0x03 + HID_KEY_A= 0x04 + HID_KEY_B= 0x05 + HID_KEY_C= 0x06 + HID_KEY_D = 0x07 // Keyboard d and D + HID_KEY_E = 0x08 // Keyboard e and E + HID_KEY_F = 0x09 // Keyboard f and F + HID_KEY_G = 0x0a // Keyboard g and G + HID_KEY_H = 0x0b // Keyboard h and H + HID_KEY_I = 0x0c // Keyboard i and I + HID_KEY_J = 0x0d // Keyboard j and J + HID_KEY_K = 0x0e // Keyboard k and K + HID_KEY_L = 0x0f // Keyboard l and L + HID_KEY_M = 0x10 // Keyboard m and M + HID_KEY_N = 0x11 // Keyboard n and N + HID_KEY_O = 0x12 // Keyboard o and O + HID_KEY_P = 0x13 // Keyboard p and P + HID_KEY_Q = 0x14 // Keyboard q and Q + HID_KEY_R = 0x15 // Keyboard r and R + HID_KEY_S = 0x16 // Keyboard s and S + HID_KEY_T = 0x17 // Keyboard t and T + HID_KEY_U = 0x18 // Keyboard u and U + HID_KEY_V = 0x19 // Keyboard v and V + HID_KEY_W = 0x1a // Keyboard w and W + HID_KEY_X = 0x1b // Keyboard x and X + HID_KEY_Y = 0x1c // Keyboard y and Y + HID_KEY_Z = 0x1d // Keyboard z and Z + + HID_KEY_1 = 0x1e // Keyboard 1 and ! + HID_KEY_2 = 0x1f // Keyboard 2 and @ + HID_KEY_3 = 0x20 // Keyboard 3 and # + HID_KEY_4 = 0x21 // Keyboard 4 and $ + HID_KEY_5 = 0x22 // Keyboard 5 and % + HID_KEY_6 = 0x23 // Keyboard 6 and ^ + HID_KEY_7 = 0x24 // Keyboard 7 and & + HID_KEY_8 = 0x25 // Keyboard 8 and * + HID_KEY_9 = 0x26 // Keyboard 9 and ( + HID_KEY_0 = 0x27 // Keyboard 0 and ) + + HID_KEY_ENTER = 0x28 // Keyboard Return (ENTER) + HID_KEY_ESC = 0x29 // Keyboard ESCAPE + HID_KEY_BACKSPACE = 0x2a // Keyboard DELETE (Backspace) + HID_KEY_TAB = 0x2b // Keyboard Tab + HID_KEY_SPACE = 0x2c // Keyboard Spacebar + HID_KEY_MINUS = 0x2d // Keyboard - and _ + HID_KEY_EQUAL = 0x2e // Keyboard = and + + HID_KEY_LEFTBRACE = 0x2f // Keyboard [ and { + HID_KEY_RIGHTBRACE = 0x30 // Keyboard ] and } + HID_KEY_BACKSLASH = 0x31 // Keyboard \ and | + HID_KEY_HASHTILDE = 0x32 // Keyboard Non-US # and ~ + HID_KEY_SEMICOLON = 0x33 // Keyboard ; and : + HID_KEY_APOSTROPHE = 0x34 // Keyboard ' and " + HID_KEY_GRAVE = 0x35 // Keyboard ` and ~ + HID_KEY_COMMA = 0x36 // Keyboard , and < + HID_KEY_DOT = 0x37 // Keyboard . and > + HID_KEY_SLASH = 0x38 // Keyboard / and ? + HID_KEY_CAPSLOCK = 0x39 // Keyboard Caps Lock + + HID_KEY_F1 = 0x3a // Keyboard F1 + HID_KEY_F2 = 0x3b // Keyboard F2 + HID_KEY_F3 = 0x3c // Keyboard F3 + HID_KEY_F4 = 0x3d // Keyboard F4 + HID_KEY_F5 = 0x3e // Keyboard F5 + HID_KEY_F6 = 0x3f // Keyboard F6 + HID_KEY_F7 = 0x40 // Keyboard F7 + HID_KEY_F8 = 0x41 // Keyboard F8 + HID_KEY_F9 = 0x42 // Keyboard F9 + HID_KEY_F10 = 0x43 // Keyboard F10 + HID_KEY_F11 = 0x44 // Keyboard F11 + HID_KEY_F12 = 0x45 // Keyboard F12 + + HID_KEY_SYSRQ = 0x46 // Keyboard Print Screen + HID_KEY_SCROLLLOCK = 0x47 // Keyboard Scroll Lock + HID_KEY_PAUSE = 0x48 // Keyboard Pause + HID_KEY_INSERT = 0x49 // Keyboard Insert + HID_KEY_HOME = 0x4a // Keyboard Home + HID_KEY_PAGEUP = 0x4b // Keyboard Page Up + HID_KEY_DELETE = 0x4c // Keyboard Delete Forward + HID_KEY_END = 0x4d // Keyboard End + HID_KEY_PAGEDOWN = 0x4e // Keyboard Page Down + HID_KEY_RIGHT = 0x4f // Keyboard Right Arrow + HID_KEY_LEFT = 0x50 // Keyboard Left Arrow + HID_KEY_DOWN = 0x51 // Keyboard Down Arrow + HID_KEY_UP = 0x52 // Keyboard Up Arrow + + HID_KEY_NUMLOCK = 0x53 // Keyboard Num Lock and Clear + HID_KEY_KPSLASH = 0x54 // Keypad / + HID_KEY_KPASTERISK = 0x55 // Keypad * + HID_KEY_KPMINUS = 0x56 // Keypad - + HID_KEY_KPPLUS = 0x57 // Keypad + + HID_KEY_KPENTER = 0x58 // Keypad ENTER + HID_KEY_KP1 = 0x59 // Keypad 1 and End + HID_KEY_KP2 = 0x5a // Keypad 2 and Down Arrow + HID_KEY_KP3 = 0x5b // Keypad 3 and PageDn + HID_KEY_KP4 = 0x5c // Keypad 4 and Left Arrow + HID_KEY_KP5 = 0x5d // Keypad 5 + HID_KEY_KP6 = 0x5e // Keypad 6 and Right Arrow + HID_KEY_KP7 = 0x5f // Keypad 7 and Home + HID_KEY_KP8 = 0x60 // Keypad 8 and Up Arrow + HID_KEY_KP9 = 0x61 // Keypad 9 and Page Up + HID_KEY_KP0 = 0x62 // Keypad 0 and Insert + HID_KEY_KPDOT = 0x63 // Keypad . and Delete + + HID_KEY_102ND = 0x64 // Keyboard Non-US \ and | + HID_KEY_COMPOSE = 0x65 // Keyboard Application + HID_KEY_POWER = 0x66 // Keyboard Power + HID_KEY_KPEQUAL = 0x67 // Keypad = + + HID_KEY_F13 = 0x68 // Keyboard F13 + HID_KEY_F14 = 0x69 // Keyboard F14 + HID_KEY_F15 = 0x6a // Keyboard F15 + HID_KEY_F16 = 0x6b // Keyboard F16 + HID_KEY_F17 = 0x6c // Keyboard F17 + HID_KEY_F18 = 0x6d // Keyboard F18 + HID_KEY_F19 = 0x6e // Keyboard F19 + HID_KEY_F20 = 0x6f // Keyboard F20 + HID_KEY_F21 = 0x70 // Keyboard F21 + HID_KEY_F22 = 0x71 // Keyboard F22 + HID_KEY_F23 = 0x72 // Keyboard F23 + HID_KEY_F24 = 0x73 // Keyboard F24 + + HID_KEY_OPEN = 0x74 // Keyboard Execute + HID_KEY_HELP = 0x75 // Keyboard Help + HID_KEY_PROPS = 0x76 // Keyboard Menu + HID_KEY_FRONT = 0x77 // Keyboard Select + HID_KEY_STOP = 0x78 // Keyboard Stop + HID_KEY_AGAIN = 0x79 // Keyboard Again + HID_KEY_UNDO = 0x7a // Keyboard Undo + HID_KEY_CUT = 0x7b // Keyboard Cut + HID_KEY_COPY = 0x7c // Keyboard Copy + HID_KEY_PASTE = 0x7d // Keyboard Paste + HID_KEY_FIND = 0x7e // Keyboard Find + HID_KEY_MUTE = 0x7f // Keyboard Mute + HID_KEY_VOLUMEUP = 0x80 // Keyboard Volume Up + HID_KEY_VOLUMEDOWN = 0x81 // Keyboard Volume Down + // = 0x82 Keyboard Locking Caps Lock + // = 0x83 Keyboard Locking Num Lock + // = 0x84 Keyboard Locking Scroll Lock + HID_KEY_KPCOMMA = 0x85 // Keypad Comma + // = 0x86 Keypad Equal Sign + HID_KEY_RO = 0x87 // Keyboard International1 + HID_KEY_KATAKANAHIRAGANA = 0x88 // Keyboard International2 + HID_KEY_YEN = 0x89 // Keyboard International3 + HID_KEY_HENKAN = 0x8a // Keyboard International4 + HID_KEY_MUHENKAN = 0x8b // Keyboard International5 + HID_KEY_KPJPCOMMA = 0x8c // Keyboard International6 + // = 0x8d Keyboard International7 + // = 0x8e Keyboard International8 + // = 0x8f Keyboard International9 + HID_KEY_HANGEUL = 0x90 // Keyboard LANG1 + HID_KEY_HANJA = 0x91 // Keyboard LANG2 + HID_KEY_KATAKANA = 0x92 // Keyboard LANG3 + HID_KEY_HIRAGANA = 0x93 // Keyboard LANG4 + HID_KEY_ZENKAKUHANKAKU = 0x94 // Keyboard LANG5 + // = 0x95 Keyboard LANG6 + // = 0x96 Keyboard LANG7 + // = 0x97 Keyboard LANG8 + // = 0x98 Keyboard LANG9 + // = 0x99 Keyboard Alternate Erase + // = 0x9a Keyboard SysReq/Attention + // = 0x9b Keyboard Cancel + // = 0x9c Keyboard Clear + // = 0x9d Keyboard Prior + // = 0x9e Keyboard Return + // = 0x9f Keyboard Separator + // = 0xa0 Keyboard Out + // = 0xa1 Keyboard Oper + // = 0xa2 Keyboard Clear/Again + // = 0xa3 Keyboard CrSel/Props + // = 0xa4 Keyboard ExSel + + // = 0xb0 Keypad 00 + // = 0xb1 Keypad 000 + // = 0xb2 Thousands Separator + // = 0xb3 Decimal Separator + // = 0xb4 Currency Unit + // = 0xb5 Currency Sub-unit + HID_KEY_KPLEFTPAREN = 0xb6 // Keypad ( + HID_KEY_KPRIGHTPAREN = 0xb7 // Keypad ) + // = 0xb8 Keypad { + // = 0xb9 Keypad } + // = 0xba Keypad Tab + // = 0xbb Keypad Backspace + // = 0xbc Keypad A + // = 0xbd Keypad B + // = 0xbe Keypad C + // = 0xbf Keypad D + // = 0xc0 Keypad E + // = 0xc1 Keypad F + // = 0xc2 Keypad XOR + // = 0xc3 Keypad ^ + // = 0xc4 Keypad % + // = 0xc5 Keypad < + // = 0xc6 Keypad > + // = 0xc7 Keypad & + // = 0xc8 Keypad && + // = 0xc9 Keypad | + // = 0xca Keypad || + // = 0xcb Keypad : + // = 0xcc Keypad # + // = 0xcd Keypad Space + // = 0xce Keypad @ + // = 0xcf Keypad ! + // = 0xd0 Keypad Memory Store + // = 0xd1 Keypad Memory Recall + // = 0xd2 Keypad Memory Clear + // = 0xd3 Keypad Memory Add + // = 0xd4 Keypad Memory Subtract + // = 0xd5 Keypad Memory Multiply + // = 0xd6 Keypad Memory Divide + // = 0xd7 Keypad +/- + // = 0xd8 Keypad Clear + // = 0xd9 Keypad Clear Entry + // = 0xda Keypad Binary + // = 0xdb Keypad Octal + // = 0xdc Keypad Decimal + // = 0xdd Keypad Hexadecimal + + HID_KEY_LEFTCTRL = 0xe0 // Keyboard Left Control + HID_KEY_LEFTSHIFT = 0xe1 // Keyboard Left Shift + HID_KEY_LEFTALT = 0xe2 // Keyboard Left Alt + HID_KEY_LEFTMETA = 0xe3 // Keyboard Left GUI + HID_KEY_RIGHTCTRL = 0xe4 // Keyboard Right Control + HID_KEY_RIGHTSHIFT = 0xe5 // Keyboard Right Shift + HID_KEY_RIGHTALT = 0xe6 // Keyboard Right Alt + HID_KEY_RIGHTMETA = 0xe7 // Keyboard Right GUI + + HID_KEY_MEDIA_PLAYPAUSE = 0xe8 + HID_KEY_MEDIA_STOPCD = 0xe9 + HID_KEY_MEDIA_PREVIOUSSONG = 0xea + HID_KEY_MEDIA_NEXTSONG = 0xeb + HID_KEY_MEDIA_EJECTCD = 0xec + HID_KEY_MEDIA_VOLUMEUP = 0xed + HID_KEY_MEDIA_VOLUMEDOWN = 0xee + HID_KEY_MEDIA_MUTE = 0xef + HID_KEY_MEDIA_WWW = 0xf0 + HID_KEY_MEDIA_BACK = 0xf1 + HID_KEY_MEDIA_FORWARD = 0xf2 + HID_KEY_MEDIA_STOP = 0xf3 + HID_KEY_MEDIA_FIND = 0xf4 + HID_KEY_MEDIA_SCROLLUP = 0xf5 + HID_KEY_MEDIA_SCROLLDOWN = 0xf6 + HID_KEY_MEDIA_EDIT = 0xf7 + HID_KEY_MEDIA_SLEEP = 0xf8 + HID_KEY_MEDIA_COFFEE = 0xf9 + HID_KEY_MEDIA_REFRESH = 0xfa + HID_KEY_MEDIA_CALC = 0xfb +) diff --git a/hid/keymaps/de.go b/hid/keymaps/de.go new file mode 100644 index 0000000..e5918b8 --- /dev/null +++ b/hid/keymaps/de.go @@ -0,0 +1,276 @@ +package keymaps + +import ( + ".." +) + +var ( + ascii_de = map[string][]byte { + "\t": hid.NewKeyboardOutReport(0, hid.HID_KEY_TAB).Serialize(), + "\n": hid.NewKeyboardOutReport(0, hid.HID_KEY_ENTER).Serialize(), + " ": hid.NewKeyboardOutReport(0, hid.HID_KEY_SPACE).Serialize(), + "!": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_1).Serialize(), + "\"": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_2).Serialize(), + "#": hid.NewKeyboardOutReport(0, hid.HID_KEY_BACKSLASH).Serialize(), + "$": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_4).Serialize(), + "%": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_5).Serialize(), + "&": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_6).Serialize(), + "'": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_BACKSLASH).Serialize(), + "(": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_8).Serialize(), + ")": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_9).Serialize(), + "*": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_RIGHTBRACE).Serialize(), + "+": hid.NewKeyboardOutReport(0, hid.HID_KEY_RIGHTBRACE).Serialize(), + ",": hid.NewKeyboardOutReport(0, hid.HID_KEY_COMMA).Serialize(), + "-": hid.NewKeyboardOutReport(0, hid.HID_KEY_SLASH).Serialize(), + ".": hid.NewKeyboardOutReport(0, hid.HID_KEY_DOT).Serialize(), + "/": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_7).Serialize(), + "0": hid.NewKeyboardOutReport(0, hid.HID_KEY_0).Serialize(), + "1": hid.NewKeyboardOutReport(0, hid.HID_KEY_1).Serialize(), + "2": hid.NewKeyboardOutReport(0, hid.HID_KEY_2).Serialize(), + "3": hid.NewKeyboardOutReport(0, hid.HID_KEY_3).Serialize(), + "4": hid.NewKeyboardOutReport(0, hid.HID_KEY_4).Serialize(), + "5": hid.NewKeyboardOutReport(0, hid.HID_KEY_5).Serialize(), + "6": hid.NewKeyboardOutReport(0, hid.HID_KEY_6).Serialize(), + "7": hid.NewKeyboardOutReport(0, hid.HID_KEY_7).Serialize(), + "8": hid.NewKeyboardOutReport(0, hid.HID_KEY_8).Serialize(), + "9": hid.NewKeyboardOutReport(0, hid.HID_KEY_9).Serialize(), + ":": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_DOT).Serialize(), + ";": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_COMMA).Serialize(), + "<": hid.NewKeyboardOutReport(0, hid.HID_KEY_102ND).Serialize(), + "=": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_0).Serialize(), + ">": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_102ND).Serialize(), + "?": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_MINUS).Serialize(), + "@": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_RIGHT_ALT, hid.HID_KEY_Q).Serialize(), + + "A": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_A).Serialize(), + "B": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_B).Serialize(), + "C": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_C).Serialize(), + "D": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_D).Serialize(), + "E": hid.NewKeyboardOutReport(hid.HID_MOD_KEY_LEFT_SHIFT, hid.HID_KEY_E).Serialize(), + + + } +) + +/* +ASCII_41 = KEY_A, MODIFIERKEY_SHIFT +// 65 A +ASCII_42 = KEY_B, MODIFIERKEY_SHIFT +// 66 B +ASCII_43 = KEY_C, MODIFIERKEY_SHIFT +// 67 C +ASCII_44 = KEY_D, MODIFIERKEY_SHIFT +// 68 D +ASCII_45 = KEY_E, MODIFIERKEY_SHIFT +// 69 E +ASCII_46 = KEY_F, MODIFIERKEY_SHIFT +// 70 F +ASCII_47 = KEY_G, MODIFIERKEY_SHIFT +// 71 G +ASCII_48 = KEY_H, MODIFIERKEY_SHIFT +// 72 H +ASCII_49 = KEY_I, MODIFIERKEY_SHIFT +// 73 I +ASCII_4A = KEY_J, MODIFIERKEY_SHIFT +// 74 J +ASCII_4B = KEY_K, MODIFIERKEY_SHIFT +// 75 K +ASCII_4C = KEY_L, MODIFIERKEY_SHIFT +// 76 L +ASCII_4D = KEY_M, MODIFIERKEY_SHIFT +// 77 M +ASCII_4E = KEY_N, MODIFIERKEY_SHIFT +// 78 N +ASCII_4F = KEY_O, MODIFIERKEY_SHIFT +// 79 O +ASCII_50 = KEY_P, MODIFIERKEY_SHIFT +// 80 P +ASCII_51 = KEY_Q, MODIFIERKEY_SHIFT +// 81 Q +ASCII_52 = KEY_R, MODIFIERKEY_SHIFT +// 82 R +ASCII_53 = KEY_S, MODIFIERKEY_SHIFT +// 83 S +ASCII_54 = KEY_T, MODIFIERKEY_SHIFT +// 84 T +ASCII_55 = KEY_U, MODIFIERKEY_SHIFT +// 85 U +ASCII_56 = KEY_V, MODIFIERKEY_SHIFT +// 86 V +ASCII_57 = KEY_W, MODIFIERKEY_SHIFT +// 87 W +ASCII_58 = KEY_X, MODIFIERKEY_SHIFT +// 88 X +ASCII_59 = KEY_Z, MODIFIERKEY_SHIFT +// 89 Y +ASCII_5A = KEY_Y, MODIFIERKEY_SHIFT +// 90 Z +ASCII_5B = KEY_8, MODIFIERKEY_RIGHT_ALT +// 91 [ +ASCII_5C = KEY_MINUS, MODIFIERKEY_RIGHT_ALT +// 92 +ASCII_5D = KEY_9, MODIFIERKEY_RIGHT_ALT +// 93 ] +ASCII_5E = KEY_TILDE +// 94 ^ +ASCII_5F = KEY_SLASH, MODIFIERKEY_SHIFT +// 95 _ +ASCII_60 = KEY_EQUAL, MODIFIERKEY_SHIFT +//GRAVE_ACCENT_BITS + KEY_SPACE +// 96 ` +ASCII_61 = KEY_A +// 97 a +ASCII_62 = KEY_B +// 98 b +ASCII_63 = KEY_C +// 99 c +ASCII_64 = KEY_D +// 100 d +ASCII_65 = KEY_E +// 101 e +ASCII_66 = KEY_F +// 102 f +ASCII_67 = KEY_G +// 103 g +ASCII_68 = KEY_H +// 104 h +ASCII_69 = KEY_I +// 105 i +ASCII_6A = KEY_J +// 106 j +ASCII_6B = KEY_K +// 107 k +ASCII_6C = KEY_L +// 108 l +ASCII_6D = KEY_M +// 109 m +ASCII_6E = KEY_N +// 110 n +ASCII_6F = KEY_O +// 111 o +ASCII_70 = KEY_P +// 112 p +ASCII_71 = KEY_Q +// 113 q +ASCII_72 = KEY_R +// 114 r +ASCII_73 = KEY_S +// 115 s +ASCII_74 = KEY_T +// 116 t +ASCII_75 = KEY_U +// 117 u +ASCII_76 = KEY_V +// 118 v +ASCII_77 = KEY_W +// 119 w +ASCII_78 = KEY_X +// 120 x +ASCII_79 = KEY_Z +// 121 y +ASCII_7A = KEY_Y +// 122 z +ASCII_7B = KEY_7, MODIFIERKEY_RIGHT_ALT +// 123 { +ASCII_7C = KEY_NON_US_100, MODIFIERKEY_RIGHT_ALT +// 124 | +ASCII_7D = KEY_0, MODIFIERKEY_RIGHT_ALT +// 125 } +ASCII_7E = KEY_RIGHT_BRACE, MODIFIERKEY_RIGHT_ALT +// 126 ~ +ASCII_7F = KEY_BACKSPACE +// 127 +ISO_8859_1_A0 = KEY_SPACE +// 160 Nonbreakng Space +ISO_8859_1_A4 = KEY_E, MODIFIERKEY_RIGHT_ALT +// 164 ¤ Currency Sign +ISO_8859_1_A7 = KEY_3, MODIFIERKEY_SHIFT +// 167 § SECTION SIGN +ISO_8859_1_B0 = KEY_TILDE, MODIFIERKEY_SHIFT +// 176 ° DEGREE SIGN +ISO_8859_1_B2 = KEY_2, MODIFIERKEY_RIGHT_ALT +// 178 ² SUPERSCRIPT TWO +ISO_8859_1_B3 = KEY_3, MODIFIERKEY_RIGHT_ALT +// 179 ³ SUPERSCRIPT THREE +//ISO_8859_1_C0 = GRAVE_ACCENT_BITS + KEY_A, MODIFIERKEY_SHIFT +// 192 À A GRAVE +//ISO_8859_1_C1 = ACUTE_ACCENT_BITS + KEY_A, MODIFIERKEY_SHIFT +// 193 Á A ACUTE +//ISO_8859_1_C2 = CIRCUMFLEX_BITS = + KEY_A, MODIFIERKEY_SHIFT +// 194 Â A CIRCUMFLEX +ISO_8859_1_C4 = KEY_QUOTE, MODIFIERKEY_SHIFT +// 196 Ä A DIAERESIS +//ISO_8859_1_C8 = GRAVE_ACCENT_BITS + KEY_E, MODIFIERKEY_SHIFT +// 200 È E GRAVE +//ISO_8859_1_C9 = ACUTE_ACCENT_BITS + KEY_E, MODIFIERKEY_SHIFT +// 201 É E ACUTE +//ISO_8859_1_CA = CIRCUMFLEX_BITS + KEY_E, MODIFIERKEY_SHIFT +// 202 Ê E CIRCUMFLEX +//ISO_8859_1_CC = GRAVE_ACCENT_BITS + KEY_I, MODIFIERKEY_SHIFT +// 204 Ì I GRAVE +//ISO_8859_1_CD = ACUTE_ACCENT_BITS + KEY_I, MODIFIERKEY_SHIFT +// 205 Í I ACUTE +//ISO_8859_1_CE = CIRCUMFLEX_BITS + KEY_I, MODIFIERKEY_SHIFT +// 206 Î I CIRCUMFLEX +//ISO_8859_1_D2 = GRAVE_ACCENT_BITS + KEY_O, MODIFIERKEY_SHIFT +// 210 Ò O GRAVE +//ISO_8859_1_D3 = ACUTE_ACCENT_BITS + KEY_O, MODIFIERKEY_SHIFT +// 211 Ó O ACUTE +//ISO_8859_1_D4 = CIRCUMFLEX_BITS + KEY_O, MODIFIERKEY_SHIFT +// 212 Ô O CIRCUMFLEX +ISO_8859_1_D6 = KEY_SEMICOLON, MODIFIERKEY_SHIFT +// 214 Ö O DIAERESIS +//ISO_8859_1_D9 = GRAVE_ACCENT_BITS + KEY_U, MODIFIERKEY_SHIFT +// 217 Ù U GRAVE +//ISO_8859_1_DA = ACUTE_ACCENT_BITS + KEY_U, MODIFIERKEY_SHIFT +// 218 Ú U ACUTE +//ISO_8859_1_DB = CIRCUMFLEX_BITS + KEY_U, MODIFIERKEY_SHIFT +// 219 Û U CIRCUMFLEX +ISO_8859_1_DC = KEY_LEFT_BRACE, MODIFIERKEY_SHIFT +// 220 Ü U DIAERESIS +//ISO_8859_1_DD = ACUTE_ACCENT_BITS + KEY_Z, MODIFIERKEY_SHIFT +// 221 Ý Y ACUTE +ISO_8859_1_DF = KEY_MINUS +// 223 ß SHARP S +//ISO_8859_1_E0 = GRAVE_ACCENT_BITS + KEY_A +// 224 à a GRAVE +//ISO_8859_1_E1 = ACUTE_ACCENT_BITS + KEY_A +// 225 á a ACUTE +//ISO_8859_1_E2 = CIRCUMFLEX_BITS + KEY_A +// 226 â a CIRCUMFLEX +ISO_8859_1_E4 = KEY_QUOTE +// 228 ä a DIAERESIS +//ISO_8859_1_E8 = GRAVE_ACCENT_BITS + KEY_E +// 232 è e GRAVE +//ISO_8859_1_E9 = ACUTE_ACCENT_BITS + KEY_E +// 233 é e ACUTE +//ISO_8859_1_EA = CIRCUMFLEX_BITS + KEY_E +// 234 ê e CIRCUMFLEX +//ISO_8859_1_EC = GRAVE_ACCENT_BITS + KEY_I +// 236 ì i GRAVE +//ISO_8859_1_ED = ACUTE_ACCENT_BITS + KEY_I +// 237 í i ACUTE +//ISO_8859_1_EE = CIRCUMFLEX_BITS + KEY_I +// 238 î i CIRCUMFLEX +//ISO_8859_1_F2 = GRAVE_ACCENT_BITS + KEY_O +// 242 ò o GRAVE +//ISO_8859_1_F3 = ACUTE_ACCENT_BITS + KEY_O +// 243 ó o ACUTE +//ISO_8859_1_F4 = CIRCUMFLEX_BITS + KEY_O +// 244 ô o CIRCUMFLEX +ISO_8859_1_F6 = KEY_SEMICOLON +// 246 ö o DIAERESIS +//ISO_8859_1_F9 = GRAVE_ACCENT_BITS + KEY_U +// 249 ù u GRAVE +//ISO_8859_1_FA = ACUTE_ACCENT_BITS + KEY_U +// 250 ú u ACUTE +//ISO_8859_1_FB = CIRCUMFLEX_BITS + KEY_U +// 251 û u CIRCUMFLEX +ISO_8859_1_FC = KEY_LEFT_BRACE +// 252 ü u DIAERESIS +//ISO_8859_1_FD = ACUTE_ACCENT_BITS + KEY_Z +// 253 ý y ACUTE +UNICODE_20AC = KEY_E, MODIFIERKEY_RIGHT_ALT +// € Euro Sign + +*/ \ No newline at end of file diff --git a/proto/gopherjs/grpc.pb.gopherjs.go b/proto/gopherjs/grpc.pb.gopherjs.go index 53ca281..60eb1f9 100644 --- a/proto/gopherjs/grpc.pb.gopherjs.go +++ b/proto/gopherjs/grpc.pb.gopherjs.go @@ -17,6 +17,7 @@ DHCPServerRange DHCPServerStaticHost WiFiSettings + BSSCfg Empty */ package P4wnP1_grpc @@ -1150,25 +1151,23 @@ func (m *DHCPServerStaticHost) Unmarshal(rawBytes []byte) (*DHCPServerStaticHost // WiFi type WiFiSettings struct { - Diasabled bool + Disabled bool Reg string Mode WiFiSettings_Mode - ApSsid string AuthMode WiFiSettings_APAuthMode ApChannel uint32 - ApPsk string + BssCfgAP *BSSCfg + BssCfgClient *BSSCfg ApHideSsid bool - ClientSsid string - ClientPsk string DisableNexmon bool } -// GetDiasabled gets the Diasabled of the WiFiSettings. -func (m *WiFiSettings) GetDiasabled() (x bool) { +// GetDisabled gets the Disabled of the WiFiSettings. +func (m *WiFiSettings) GetDisabled() (x bool) { if m == nil { return x } - return m.Diasabled + return m.Disabled } // GetReg gets the Reg of the WiFiSettings. @@ -1187,14 +1186,6 @@ func (m *WiFiSettings) GetMode() (x WiFiSettings_Mode) { return m.Mode } -// GetApSsid gets the ApSsid of the WiFiSettings. -func (m *WiFiSettings) GetApSsid() (x string) { - if m == nil { - return x - } - return m.ApSsid -} - // GetAuthMode gets the AuthMode of the WiFiSettings. func (m *WiFiSettings) GetAuthMode() (x WiFiSettings_APAuthMode) { if m == nil { @@ -1211,12 +1202,20 @@ func (m *WiFiSettings) GetApChannel() (x uint32) { return m.ApChannel } -// GetApPsk gets the ApPsk of the WiFiSettings. -func (m *WiFiSettings) GetApPsk() (x string) { +// GetBssCfgAP gets the BssCfgAP of the WiFiSettings. +func (m *WiFiSettings) GetBssCfgAP() (x *BSSCfg) { if m == nil { return x } - return m.ApPsk + return m.BssCfgAP +} + +// GetBssCfgClient gets the BssCfgClient of the WiFiSettings. +func (m *WiFiSettings) GetBssCfgClient() (x *BSSCfg) { + if m == nil { + return x + } + return m.BssCfgClient } // GetApHideSsid gets the ApHideSsid of the WiFiSettings. @@ -1227,22 +1226,6 @@ func (m *WiFiSettings) GetApHideSsid() (x bool) { return m.ApHideSsid } -// GetClientSsid gets the ClientSsid of the WiFiSettings. -func (m *WiFiSettings) GetClientSsid() (x string) { - if m == nil { - return x - } - return m.ClientSsid -} - -// GetClientPsk gets the ClientPsk of the WiFiSettings. -func (m *WiFiSettings) GetClientPsk() (x string) { - if m == nil { - return x - } - return m.ClientPsk -} - // GetDisableNexmon gets the DisableNexmon of the WiFiSettings. func (m *WiFiSettings) GetDisableNexmon() (x bool) { if m == nil { @@ -1257,8 +1240,8 @@ func (m *WiFiSettings) MarshalToWriter(writer jspb.Writer) { return } - if m.Diasabled { - writer.WriteBool(1, m.Diasabled) + if m.Disabled { + writer.WriteBool(1, m.Disabled) } if len(m.Reg) > 0 { @@ -1269,36 +1252,32 @@ func (m *WiFiSettings) MarshalToWriter(writer jspb.Writer) { writer.WriteEnum(3, int(m.Mode)) } - if len(m.ApSsid) > 0 { - writer.WriteString(4, m.ApSsid) - } - if int(m.AuthMode) != 0 { - writer.WriteEnum(5, int(m.AuthMode)) + writer.WriteEnum(4, int(m.AuthMode)) } if m.ApChannel != 0 { - writer.WriteUint32(6, m.ApChannel) + writer.WriteUint32(5, m.ApChannel) } - if len(m.ApPsk) > 0 { - writer.WriteString(7, m.ApPsk) + if m.BssCfgAP != nil { + writer.WriteMessage(6, func() { + m.BssCfgAP.MarshalToWriter(writer) + }) + } + + if m.BssCfgClient != nil { + writer.WriteMessage(7, func() { + m.BssCfgClient.MarshalToWriter(writer) + }) } if m.ApHideSsid { writer.WriteBool(8, m.ApHideSsid) } - if len(m.ClientSsid) > 0 { - writer.WriteString(9, m.ClientSsid) - } - - if len(m.ClientPsk) > 0 { - writer.WriteString(10, m.ClientPsk) - } - if m.DisableNexmon { - writer.WriteBool(11, m.DisableNexmon) + writer.WriteBool(10, m.DisableNexmon) } return @@ -1320,26 +1299,26 @@ func (m *WiFiSettings) UnmarshalFromReader(reader jspb.Reader) *WiFiSettings { switch reader.GetFieldNumber() { case 1: - m.Diasabled = reader.ReadBool() + m.Disabled = reader.ReadBool() case 2: m.Reg = reader.ReadString() case 3: m.Mode = WiFiSettings_Mode(reader.ReadEnum()) case 4: - m.ApSsid = reader.ReadString() - case 5: m.AuthMode = WiFiSettings_APAuthMode(reader.ReadEnum()) - case 6: + case 5: m.ApChannel = reader.ReadUint32() + case 6: + reader.ReadMessage(func() { + m.BssCfgAP = m.BssCfgAP.UnmarshalFromReader(reader) + }) case 7: - m.ApPsk = reader.ReadString() + reader.ReadMessage(func() { + m.BssCfgClient = m.BssCfgClient.UnmarshalFromReader(reader) + }) case 8: m.ApHideSsid = reader.ReadBool() - case 9: - m.ClientSsid = reader.ReadString() case 10: - m.ClientPsk = reader.ReadString() - case 11: m.DisableNexmon = reader.ReadBool() default: reader.SkipField() @@ -1362,6 +1341,84 @@ func (m *WiFiSettings) Unmarshal(rawBytes []byte) (*WiFiSettings, error) { return m, nil } +type BSSCfg struct { + SSID string + PSK string +} + +// GetSSID gets the SSID of the BSSCfg. +func (m *BSSCfg) GetSSID() (x string) { + if m == nil { + return x + } + return m.SSID +} + +// GetPSK gets the PSK of the BSSCfg. +func (m *BSSCfg) GetPSK() (x string) { + if m == nil { + return x + } + return m.PSK +} + +// MarshalToWriter marshals BSSCfg to the provided writer. +func (m *BSSCfg) MarshalToWriter(writer jspb.Writer) { + if m == nil { + return + } + + if len(m.SSID) > 0 { + writer.WriteString(1, m.SSID) + } + + if len(m.PSK) > 0 { + writer.WriteString(2, m.PSK) + } + + return +} + +// Marshal marshals BSSCfg to a slice of bytes. +func (m *BSSCfg) Marshal() []byte { + writer := jspb.NewWriter() + m.MarshalToWriter(writer) + return writer.GetResult() +} + +// UnmarshalFromReader unmarshals a BSSCfg from the provided reader. +func (m *BSSCfg) UnmarshalFromReader(reader jspb.Reader) *BSSCfg { + for reader.Next() { + if m == nil { + m = &BSSCfg{} + } + + switch reader.GetFieldNumber() { + case 1: + m.SSID = reader.ReadString() + case 2: + m.PSK = reader.ReadString() + default: + reader.SkipField() + } + } + + return m +} + +// Unmarshal unmarshals a BSSCfg from a slice of bytes. +func (m *BSSCfg) Unmarshal(rawBytes []byte) (*BSSCfg, error) { + reader := jspb.NewReader(rawBytes) + + m = m.UnmarshalFromReader(reader) + + if err := reader.Err(); err != nil { + return nil, err + } + + return m, nil +} + type Empty struct { } @@ -1429,6 +1486,7 @@ type P4WNP1Client interface { SetLEDSettings(ctx context.Context, in *LEDSettings, opts ...grpcweb.CallOption) (*Empty, error) MountUMSFile(ctx context.Context, in *GadgetSettingsUMS, opts ...grpcweb.CallOption) (*Empty, error) DeployEthernetInterfaceSettings(ctx context.Context, in *EthernetInterfaceSettings, opts ...grpcweb.CallOption) (*Empty, error) + DeployWifiSettings(ctx context.Context, in *WiFiSettings, opts ...grpcweb.CallOption) (*Empty, error) } type p4WNP1Client struct { @@ -1513,3 +1571,12 @@ func (c *p4WNP1Client) DeployEthernetInterfaceSettings(ctx context.Context, in * return new(Empty).Unmarshal(resp) } + +func (c *p4WNP1Client) DeployWifiSettings(ctx context.Context, in *WiFiSettings, opts ...grpcweb.CallOption) (*Empty, error) { + resp, err := c.client.RPCCall(ctx, "DeployWifiSettings", in.Marshal(), opts...) + if err != nil { + return nil, err + } + + return new(Empty).Unmarshal(resp) +} diff --git a/proto/grpc.pb.go b/proto/grpc.pb.go index 5d8f56c..f640469 100644 --- a/proto/grpc.pb.go +++ b/proto/grpc.pb.go @@ -17,6 +17,7 @@ It has these top-level messages: DHCPServerRange DHCPServerStaticHost WiFiSettings + BSSCfg Empty */ package P4wnP1_grpc @@ -512,17 +513,15 @@ func (m *DHCPServerStaticHost) GetIp() string { // WiFi type WiFiSettings struct { - Diasabled bool `protobuf:"varint,1,opt,name=diasabled" json:"diasabled,omitempty"` + Disabled bool `protobuf:"varint,1,opt,name=disabled" json:"disabled,omitempty"` Reg string `protobuf:"bytes,2,opt,name=reg" json:"reg,omitempty"` Mode WiFiSettings_Mode `protobuf:"varint,3,opt,name=mode,enum=P4wnP1_grpc.WiFiSettings_Mode" json:"mode,omitempty"` - ApSsid string `protobuf:"bytes,4,opt,name=ap_ssid,json=apSsid" json:"ap_ssid,omitempty"` - AuthMode WiFiSettings_APAuthMode `protobuf:"varint,5,opt,name=auth_mode,json=authMode,enum=P4wnP1_grpc.WiFiSettings_APAuthMode" json:"auth_mode,omitempty"` - ApChannel uint32 `protobuf:"varint,6,opt,name=ap_channel,json=apChannel" json:"ap_channel,omitempty"` - ApPsk string `protobuf:"bytes,7,opt,name=ap_psk,json=apPsk" json:"ap_psk,omitempty"` + AuthMode WiFiSettings_APAuthMode `protobuf:"varint,4,opt,name=auth_mode,json=authMode,enum=P4wnP1_grpc.WiFiSettings_APAuthMode" json:"auth_mode,omitempty"` + ApChannel uint32 `protobuf:"varint,5,opt,name=ap_channel,json=apChannel" json:"ap_channel,omitempty"` + BssCfgAP *BSSCfg `protobuf:"bytes,6,opt,name=BssCfgAP" json:"BssCfgAP,omitempty"` + BssCfgClient *BSSCfg `protobuf:"bytes,7,opt,name=BssCfgClient" json:"BssCfgClient,omitempty"` ApHideSsid bool `protobuf:"varint,8,opt,name=ap_hide_ssid,json=apHideSsid" json:"ap_hide_ssid,omitempty"` - ClientSsid string `protobuf:"bytes,9,opt,name=client_ssid,json=clientSsid" json:"client_ssid,omitempty"` - ClientPsk string `protobuf:"bytes,10,opt,name=client_psk,json=clientPsk" json:"client_psk,omitempty"` - DisableNexmon bool `protobuf:"varint,11,opt,name=disable_nexmon,json=disableNexmon" json:"disable_nexmon,omitempty"` + DisableNexmon bool `protobuf:"varint,10,opt,name=disable_nexmon,json=disableNexmon" json:"disable_nexmon,omitempty"` } func (m *WiFiSettings) Reset() { *m = WiFiSettings{} } @@ -530,9 +529,9 @@ func (m *WiFiSettings) String() string { return proto.CompactTextStri func (*WiFiSettings) ProtoMessage() {} func (*WiFiSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } -func (m *WiFiSettings) GetDiasabled() bool { +func (m *WiFiSettings) GetDisabled() bool { if m != nil { - return m.Diasabled + return m.Disabled } return false } @@ -551,13 +550,6 @@ func (m *WiFiSettings) GetMode() WiFiSettings_Mode { return WiFiSettings_AP } -func (m *WiFiSettings) GetApSsid() string { - if m != nil { - return m.ApSsid - } - return "" -} - func (m *WiFiSettings) GetAuthMode() WiFiSettings_APAuthMode { if m != nil { return m.AuthMode @@ -572,11 +564,18 @@ func (m *WiFiSettings) GetApChannel() uint32 { return 0 } -func (m *WiFiSettings) GetApPsk() string { +func (m *WiFiSettings) GetBssCfgAP() *BSSCfg { if m != nil { - return m.ApPsk + return m.BssCfgAP } - return "" + return nil +} + +func (m *WiFiSettings) GetBssCfgClient() *BSSCfg { + if m != nil { + return m.BssCfgClient + } + return nil } func (m *WiFiSettings) GetApHideSsid() bool { @@ -586,20 +585,6 @@ func (m *WiFiSettings) GetApHideSsid() bool { return false } -func (m *WiFiSettings) GetClientSsid() string { - if m != nil { - return m.ClientSsid - } - return "" -} - -func (m *WiFiSettings) GetClientPsk() string { - if m != nil { - return m.ClientPsk - } - return "" -} - func (m *WiFiSettings) GetDisableNexmon() bool { if m != nil { return m.DisableNexmon @@ -607,13 +592,37 @@ func (m *WiFiSettings) GetDisableNexmon() bool { return false } +type BSSCfg struct { + SSID string `protobuf:"bytes,1,opt,name=SSID" json:"SSID,omitempty"` + PSK string `protobuf:"bytes,2,opt,name=PSK" json:"PSK,omitempty"` +} + +func (m *BSSCfg) Reset() { *m = BSSCfg{} } +func (m *BSSCfg) String() string { return proto.CompactTextString(m) } +func (*BSSCfg) ProtoMessage() {} +func (*BSSCfg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } + +func (m *BSSCfg) GetSSID() string { + if m != nil { + return m.SSID + } + return "" +} + +func (m *BSSCfg) GetPSK() string { + if m != nil { + return m.PSK + } + return "" +} + type Empty struct { } func (m *Empty) Reset() { *m = Empty{} } func (m *Empty) String() string { return proto.CompactTextString(m) } func (*Empty) ProtoMessage() {} -func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } +func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } func init() { proto.RegisterType((*LEDSettings)(nil), "P4wnP1_grpc.LEDSettings") @@ -625,6 +634,7 @@ func init() { proto.RegisterType((*DHCPServerRange)(nil), "P4wnP1_grpc.DHCPServerRange") proto.RegisterType((*DHCPServerStaticHost)(nil), "P4wnP1_grpc.DHCPServerStaticHost") proto.RegisterType((*WiFiSettings)(nil), "P4wnP1_grpc.WiFiSettings") + proto.RegisterType((*BSSCfg)(nil), "P4wnP1_grpc.BSSCfg") proto.RegisterType((*Empty)(nil), "P4wnP1_grpc.Empty") proto.RegisterEnum("P4wnP1_grpc.EthernetInterfaceSettings_Mode", EthernetInterfaceSettings_Mode_name, EthernetInterfaceSettings_Mode_value) proto.RegisterEnum("P4wnP1_grpc.WiFiSettings_Mode", WiFiSettings_Mode_name, WiFiSettings_Mode_value) @@ -650,6 +660,7 @@ type P4WNP1Client interface { SetLEDSettings(ctx context.Context, in *LEDSettings, opts ...grpc.CallOption) (*Empty, error) MountUMSFile(ctx context.Context, in *GadgetSettingsUMS, opts ...grpc.CallOption) (*Empty, error) DeployEthernetInterfaceSettings(ctx context.Context, in *EthernetInterfaceSettings, opts ...grpc.CallOption) (*Empty, error) + DeployWifiSettings(ctx context.Context, in *WiFiSettings, opts ...grpc.CallOption) (*Empty, error) } type p4WNP1Client struct { @@ -732,6 +743,15 @@ func (c *p4WNP1Client) DeployEthernetInterfaceSettings(ctx context.Context, in * return out, nil } +func (c *p4WNP1Client) DeployWifiSettings(ctx context.Context, in *WiFiSettings, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/DeployWifiSettings", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for P4WNP1 service type P4WNP1Server interface { @@ -743,6 +763,7 @@ type P4WNP1Server interface { SetLEDSettings(context.Context, *LEDSettings) (*Empty, error) MountUMSFile(context.Context, *GadgetSettingsUMS) (*Empty, error) DeployEthernetInterfaceSettings(context.Context, *EthernetInterfaceSettings) (*Empty, error) + DeployWifiSettings(context.Context, *WiFiSettings) (*Empty, error) } func RegisterP4WNP1Server(s *grpc.Server, srv P4WNP1Server) { @@ -893,6 +914,24 @@ func _P4WNP1_DeployEthernetInterfaceSettings_Handler(srv interface{}, ctx contex return interceptor(ctx, in, info, handler) } +func _P4WNP1_DeployWifiSettings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WiFiSettings) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).DeployWifiSettings(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/DeployWifiSettings", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).DeployWifiSettings(ctx, req.(*WiFiSettings)) + } + return interceptor(ctx, in, info, handler) +} + var _P4WNP1_serviceDesc = grpc.ServiceDesc{ ServiceName: "P4wnP1_grpc.P4WNP1", HandlerType: (*P4WNP1Server)(nil), @@ -929,6 +968,10 @@ var _P4WNP1_serviceDesc = grpc.ServiceDesc{ MethodName: "DeployEthernetInterfaceSettings", Handler: _P4WNP1_DeployEthernetInterfaceSettings_Handler, }, + { + MethodName: "DeployWifiSettings", + Handler: _P4WNP1_DeployWifiSettings_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "grpc.proto", @@ -937,84 +980,85 @@ var _P4WNP1_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 1255 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x6d, 0x6f, 0xdb, 0xb6, - 0x13, 0x8f, 0x1d, 0xc7, 0x0f, 0x67, 0xc7, 0x71, 0xd9, 0xfe, 0x5b, 0x35, 0x7d, 0x48, 0xfe, 0x5a, - 0x57, 0x04, 0x5b, 0x61, 0xa0, 0x5e, 0x5e, 0x14, 0x05, 0x86, 0x4d, 0xb5, 0x95, 0xd8, 0x6b, 0x6c, - 0x0b, 0x52, 0xdc, 0x60, 0xaf, 0x04, 0x46, 0x64, 0x63, 0x22, 0xb6, 0x24, 0x88, 0x54, 0xba, 0x7c, - 0xc8, 0x7d, 0x88, 0xbd, 0xe8, 0xe7, 0xd8, 0x40, 0x4a, 0x56, 0xe4, 0xc4, 0x6e, 0x8b, 0xed, 0x1d, - 0xef, 0x77, 0x77, 0x3f, 0x1e, 0x79, 0xbc, 0x3b, 0x02, 0x5c, 0x44, 0xa1, 0xd7, 0x0e, 0xa3, 0x40, - 0x04, 0xa8, 0x6e, 0x1d, 0x7e, 0xf2, 0xad, 0xd7, 0xae, 0x84, 0xf4, 0x36, 0xd4, 0x4f, 0xcc, 0x9e, - 0x43, 0x85, 0x60, 0xfe, 0x05, 0x47, 0x7b, 0x50, 0x3f, 0x9f, 0x31, 0xff, 0xd2, 0xf5, 0x82, 0xd8, - 0x17, 0x5a, 0x61, 0xbf, 0x70, 0xb0, 0x6d, 0x83, 0x82, 0xba, 0x12, 0xd1, 0x3f, 0x97, 0xa0, 0x79, - 0x8c, 0xc9, 0x05, 0x15, 0x99, 0x8f, 0x06, 0x15, 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x7f, 0xfa, 0x27, 0x00, 0x00, 0xff, 0xff, 0x58, - 0x27, 0xc0, 0xba, 0x9c, 0x0b, 0x00, 0x00, + // 1279 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xef, 0x6e, 0xdb, 0x36, + 0x10, 0x8f, 0x1d, 0xc7, 0x7f, 0xce, 0x8e, 0xe3, 0xb2, 0x45, 0xa7, 0xa6, 0x5d, 0x9b, 0x69, 0x5d, + 0x11, 0x6c, 0x85, 0x87, 0x7a, 0x01, 0x56, 0x14, 0x18, 0x36, 0x45, 0x56, 0x62, 0x2f, 0xb1, 0x2d, + 0x48, 0x71, 0x83, 0x7d, 0x12, 0x14, 0x91, 0xb1, 0x89, 0xd8, 0x92, 0x20, 0x51, 0xe9, 0xf2, 0x4e, + 0x7b, 0x95, 0x3d, 0xc0, 0x1e, 0x60, 0xcf, 0xb1, 0x81, 0xd4, 0x9f, 0x48, 0x89, 0xdd, 0x16, 0xdb, + 0x37, 0xf2, 0x77, 0x77, 0xbf, 0x3b, 0xf2, 0x78, 0x77, 0x04, 0x98, 0x05, 0xbe, 0xd3, 0xf5, 0x03, + 0x8f, 0x79, 0xa8, 0xa9, 0x1f, 0x7c, 0x70, 0xf5, 0x37, 0x16, 0x87, 0xe4, 0x2e, 0x34, 0x4f, 0xb5, + 0xbe, 0x49, 0x18, 0xa3, 0xee, 0x2c, 0x44, 0x2f, 0xa0, 0x79, 0xb1, 0xa0, 0xee, 0x95, 0xe5, 0x78, + 0x91, 0xcb, 0xa4, 0xd2, 0x5e, 0x69, 0x7f, 0xdb, 0x00, 0x01, 0xa9, 0x1c, 0x91, 0xff, 0xae, 0x40, + 0xfb, 0xd8, 0xc6, 0x33, 0xc2, 0x32, 0x1b, 0x09, 0x6a, 0xc4, 0xb5, 0x2f, 0x16, 0x04, 0x0b, 0xfd, + 0xba, 0x91, 0x6e, 0x51, 0x07, 0x36, 0xaf, 0x29, 0x96, 0xca, 0x7b, 0xa5, 0xfd, 0x86, 0xc1, 0x97, + 0x1c, 0xf1, 0x29, 0x96, 0x36, 0x63, 0xc4, 0xa7, 0x18, 0xc9, 0xd0, 0x5a, 0xda, 0x6e, 0x74, 0x69, + 0x3b, 0x2c, 0x0a, 0x48, 0x20, 0x55, 0x84, 0xa8, 0x80, 0x71, 0x0f, 0x7e, 0xe0, 0xe1, 0xc8, 0x61, + 0xd2, 0x96, 0x10, 0xa7, 0x5b, 0xf4, 0x18, 0xaa, 0x21, 0x09, 0xa8, 0xbd, 0x90, 0xaa, 0x42, 0x90, + 0xec, 0xd0, 0x73, 0x68, 0x46, 0x21, 0xb1, 0xd4, 0xbe, 0x6a, 0x69, 0xea, 0x48, 0xaa, 0x89, 0xb8, + 0x1a, 0x51, 0x48, 0xd4, 0xbe, 0xaa, 0xa9, 0x23, 0xf4, 0x14, 0xf8, 0xc6, 0x32, 0xc6, 0xfd, 0xa1, + 0x29, 0xd5, 0x85, 0xb4, 0x1e, 0x85, 0x44, 0xec, 0xd1, 0x3e, 0x74, 0xb8, 0x70, 0x30, 0xec, 0x5b, + 0x27, 0xda, 0x6f, 0x87, 0x13, 0xc5, 0xe8, 0x4b, 0x0d, 0xa1, 0xd3, 0x8e, 0x42, 0x32, 0x18, 0xf6, + 0x53, 0x14, 0xc9, 0xb0, 0x9d, 0x6a, 0x8e, 0x26, 0x53, 0x53, 0x93, 0x40, 0xa8, 0x35, 0x63, 0x35, + 0x01, 0xa5, 0xa1, 0x70, 0x1d, 0x43, 0x39, 0x97, 0x9a, 0x59, 0x28, 0x83, 0x61, 0xdf, 0x50, 0xce, + 0xd1, 0x17, 0x50, 0xe3, 0xf2, 0xe9, 0xc8, 0x94, 0x5a, 0x42, 0x56, 0x8d, 0x42, 0x32, 0x1d, 0x99, + 0xe8, 0x4b, 0x00, 0x2e, 0x30, 0x35, 0x63, 0xa8, 0x9c, 0x4a, 0xdb, 0x99, 0x5d, 0x0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 0xb9, 0xa8, 0x8a, 0xdf, 0xff, + 0x0f, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x8c, 0x5f, 0xb2, 0xa4, 0x0b, 0x0c, 0x00, 0x00, } diff --git a/proto/grpc.proto b/proto/grpc.proto index e3ff9d2..b03bef7 100644 --- a/proto/grpc.proto +++ b/proto/grpc.proto @@ -12,6 +12,8 @@ service P4WNP1 { rpc MountUMSFile (GadgetSettingsUMS) returns (Empty) {} rpc DeployEthernetInterfaceSettings(EthernetInterfaceSettings) returns (Empty) {} + + rpc DeployWifiSettings(WiFiSettings) returns (Empty) {} } /* LED */ @@ -99,28 +101,33 @@ message DHCPServerStaticHost { /* WiFi */ message WiFiSettings { - bool diasabled = 1; - string reg = 2; //Regulatory domain per ISO/IEC 3166-1 alpha2 enum Mode { AP = 0; //acts as access point STA = 1; //acts as station for an existing access point STA_FAILOVER_AP = 2; //acts as station, if connection to the given AP isn't possible spawns an own AP } - Mode mode = 3; - string ap_ssid = 4; //SSID of AP to spawn + enum APAuthMode { WPA2_PSK = 0; //AP uses WPA2 pre-shared key OPEN = 1; //Open System Authentication (no authentication) } - APAuthMode auth_mode = 5; - uint32 ap_channel = 6; - string ap_psk = 7; //pre-shared key if auth_mode == WPA2_PSK + + bool disabled = 1; + string reg = 2; //Regulatory domain per ISO/IEC 3166-1 alpha2 + Mode mode = 3; + APAuthMode auth_mode = 4; + uint32 ap_channel = 5; + + BSSCfg BssCfgAP = 6; //SSID of AP to spawn + PSK if needed + BSSCfg BssCfgClient = 7; //SSID of Infra to join + PSK if needed bool ap_hide_ssid = 8; //if true, SSID gets hidden for spawned AP - string client_ssid = 9; - string client_psk = 10; + bool disable_nexmon = 10; //if true, legacy driver / firmware is used instead of nexmon +} - bool disable_nexmon = 11; //if true, legacy driver / firmware is used instead of nexmon +message BSSCfg { + string SSID = 1; + string PSK = 2; } /* End WiFI */ diff --git a/service/defaults.go b/service/defaults.go index ee1d62a..e6604ca 100644 --- a/service/defaults.go +++ b/service/defaults.go @@ -21,7 +21,9 @@ func GetDefaultNetworkSettingsWiFi() (*pb.EthernetInterfaceSettings) { ifSettings := &pb.EthernetInterfaceSettings { Enabled: true, Name: "wlan0", - Mode: pb.EthernetInterfaceSettings_DHCP_CLIENT, + Mode: pb.EthernetInterfaceSettings_MANUAL, + IpAddress4: "172.24.0.1", + Netmask4: "255.255.255.252", } return ifSettings } @@ -58,13 +60,13 @@ func GetDefaultGadgetSettings() (res pb.GadgetSettings) { res = pb.GadgetSettings{ Enabled: true, Vid: "0x1d6b", - Pid: "0x1337", + Pid: "0x1347", Manufacturer: "MaMe82", Product: "P4wnP1 by MaMe82", Serial: "deadbeef1337", Use_CDC_ECM: false, Use_RNDIS: true, - Use_HID_KEYBOARD: false, + Use_HID_KEYBOARD: true, Use_HID_MOUSE: false, Use_HID_RAW: false, Use_UMS: false, @@ -84,4 +86,22 @@ func GetDefaultGadgetSettings() (res pb.GadgetSettings) { } return res -} \ No newline at end of file +} + +func GetDefaultWiFiSettings() (res *pb.WiFiSettings) { + res = &pb.WiFiSettings{ + Mode: pb.WiFiSettings_AP, + AuthMode: pb.WiFiSettings_WPA2_PSK, + Disabled: false, + Reg: "US", + ApChannel: 6, + ApHideSsid: false, + BssCfgAP: &pb.BSSCfg{ + SSID: "P4wnP1", + PSK: "MaMe82-P4wnP1", + }, + DisableNexmon: true, + BssCfgClient: nil, //not needed + } + return +} diff --git a/service/dhcp.go b/service/dhcp.go index afe8b00..0ab668f 100644 --- a/service/dhcp.go +++ b/service/dhcp.go @@ -53,7 +53,8 @@ func StartDHCPClient(nameIface string) (err error) { //We use the run command and allow dhcpcd to daemonize - proc := exec.Command("/sbin/dhcpcd", nameIface) + + proc := exec.Command("/sbin/dhcpcd", "-C", "wpa_supplicant", nameIface) //we avoid starting wpa_supplicant along with the dhcp client dhcpcd_out, err := proc.CombinedOutput() //err = proc.Run() if err != nil { return err} @@ -133,8 +134,8 @@ func StartDHCPServer(nameIface string, configPath string) (err error) { } //Check if there's already a DHCP server running for the given interface - running, _, err_r := IsDHCPServerRunning(nameIface) - if err != nil { return errors.New(fmt.Sprintf("Error fetching state of DHCP server: %v\n", err_r)) } + running, _, err := IsDHCPServerRunning(nameIface) + if err != nil { return errors.New(fmt.Sprintf("Error fetching state of DHCP server: %v\n", err)) } if running {return errors.New(fmt.Sprintf("Error starting DHCP server for interface '%s', there is already a DHCP server running\n", nameIface))} //We use the run command and allow dnsmasq to daemonize diff --git a/service/rpc_server.go b/service/rpc_server.go index 76727bd..d2e3584 100644 --- a/service/rpc_server.go +++ b/service/rpc_server.go @@ -21,6 +21,16 @@ import ( type server struct {} +func (s *server) DeployWifiSettings(ctx context.Context, ws *pb.WiFiSettings) (empty *pb.Empty, err error) { + log.Printf("Trying to deploy WiFi settings %v", ws) + empty = &pb.Empty{} + err = DeployWifiSettings(ws) + if err != nil { + log.Printf("Error deploying WiFi settings settings %v", err) + } + return +} + func (s *server) DeployEthernetInterfaceSettings(ctx context.Context, es *pb.EthernetInterfaceSettings) (empty *pb.Empty, err error) { log.Printf("Trying to deploy ethernet interface settings %v", es) diff --git a/service/ugly.go b/service/ugly.go index 28ccca9..7fe7bd0 100644 --- a/service/ugly.go +++ b/service/ugly.go @@ -5,3 +5,126 @@ worse, the external binaries are glued together with /bin/bash tricks. */ package service + +import ( + "os/exec" + "strings" + "fmt" + "regexp" + "errors" + "net" + "strconv" + "time" +) + +func binaryAvailable(binname string) bool { + cmd := exec.Command("which", binname) + out,err := cmd.CombinedOutput() + if err != nil { return false} + if len(out) == 0 { return false } + + if strings.Contains(string(out), binname) { + return true + } + return false +} + +//ToDo: Create netlink based implementation (not relying on 'iw'): low priority +func ParseIwScan(scanresult string) (bsslist []BSS, err error) { + //fmt.Printf("Parsing:\n%s\n", scanresult) + + //split into BSS sections + rp := regexp.MustCompile("(?msU)^BSS.*") + strBSSList := rp.Split(scanresult, -1) + if len(strBSSList) < 1 { + return nil, errors.New("Error parsing iw scan result") //splitting should always result in one element at least + } + + bsslist = []BSS{} + + rp_bssid := regexp.MustCompile("[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}") + rp_freq := regexp.MustCompile("(?m)freq:\\s*([0-9]{4})") + rp_ssid := regexp.MustCompile("(?m)SSID:\\s*(.*)\n") + rp_beacon_intv := regexp.MustCompile("(?m)beacon interval:\\s*([0-9]*)TU") + + rp_WEP := regexp.MustCompile("(?m)WEP:") + rp_WPA := regexp.MustCompile("(?m)WPA:") + rp_WPA2 := regexp.MustCompile("(?m)RSN:") + rp_PSK := regexp.MustCompile("(?m)Authentication suites: PSK") //ToDo: check if PSK occurs under respective IE (RSN or WPA, when either is chosen) + + //signal: -75.00 dBm + rp_signal := regexp.MustCompile("(?m)signal:\\s*(-?[0-9]*\\.[0-9]*)") + for idx, strBSS := range strBSSList[1:] { + currentBSS := BSS{} + //fmt.Printf("BSS %d\n================\n%s\n", idx, strBSS) + fmt.Printf("BSS %d\n================\n", idx) + + //BSSID (should be in first line) + strBSSID := rp_bssid.FindString(strBSS) + fmt.Printf("BSSID: %s\n", strBSSID) + currentBSS.BSSID, err = net.ParseMAC(strBSSID) + if err != nil { return nil,err} + + //freq + strFreq_sub := rp_freq.FindStringSubmatch(strBSS) + strFreq := "0" + if len(strFreq_sub) > 1 { strFreq = strFreq_sub[1]} + fmt.Printf("Freq: %s\n", strFreq) + tmpI64, err := strconv.ParseInt(strFreq, 10,32) + if err != nil { return nil, err } + currentBSS.Frequency = int(tmpI64) + + //ssid + strSsid_sub := rp_ssid.FindStringSubmatch(strBSS) + strSSID := "" + if len(strSsid_sub) > 1 { strSSID = strSsid_sub[1]} + fmt.Printf("SSID: '%s'\n", strSSID) + currentBSS.SSID = strSSID + + //beacon interval + strBI_sub := rp_beacon_intv.FindStringSubmatch(strBSS) + strBI := "100" + if len(strBI_sub) > 1 { strBI = strBI_sub[1]} + fmt.Printf("Beacon Interval: %s\n", strBI) + tmpI64, err = strconv.ParseInt(strBI, 10,32) + if err != nil { return nil, err } + currentBSS.BeaconInterval = time.Microsecond * time.Duration(tmpI64 * 1024) //1TU = 1024 microseconds (not 1000) + + //auth type + //assume OPEN + //if "WEP: is present assume UNSUPPORTED + //if "WPA:" is present assume WPA (overwrite WEP/UNSUPPORTED) + //if "RSN:" is present assume WPA2 (overwrite WPA/UNSUPPORTED) + //in case of WPA/WPA2 check for presence of "Authentication suites: PSK" to assure PSK support, otherwise assume unsupported (no EAP/CHAP support for now) + currentBSS.AuthMode = WiFiAuthMode_OPEN + if rp_WEP.MatchString(strBSS) {currentBSS.AuthMode = WiFiAuthMode_UNSUPPORTED} + if rp_WPA.MatchString(strBSS) {currentBSS.AuthMode = WiFiAuthMode_WPA_PSK} + if rp_WPA2.MatchString(strBSS) {currentBSS.AuthMode = WiFiAuthMode_WPA2_PSK} + if currentBSS.AuthMode == WiFiAuthMode_WPA_PSK || currentBSS.AuthMode == WiFiAuthMode_WPA2_PSK { + if !rp_PSK.MatchString(strBSS) {currentBSS.AuthMode = WiFiAuthMode_UNSUPPORTED} + } + switch currentBSS.AuthMode { + case WiFiAuthMode_UNSUPPORTED: + fmt.Println("AuthMode: UNSUPPORTED") + case WiFiAuthMode_OPEN: + fmt.Println("AuthMode: OPEN") + case WiFiAuthMode_WPA_PSK: + fmt.Println("AuthMode: WPA PSK") + case WiFiAuthMode_WPA2_PSK: + fmt.Println("AuthMode: WPA2 PSK") + } + + //signal + strSignal_sub := rp_signal.FindStringSubmatch(strBSS) + strSignal := "0.0" + if len(strSignal_sub) > 1 { strSignal = strSignal_sub[1]} + tmpFloat, err := strconv.ParseFloat(strSignal, 32) + if err != nil { return nil, err } + currentBSS.Signal = float32(tmpFloat) + fmt.Printf("Signal: %s dBm\n", strSignal) + + bsslist = append(bsslist, currentBSS) + } + + return bsslist,nil +} \ No newline at end of file diff --git a/service/wifi.go b/service/wifi.go new file mode 100644 index 0000000..4f8e87a --- /dev/null +++ b/service/wifi.go @@ -0,0 +1,492 @@ +package service + +import ( + pb "../proto" + "log" + "github.com/docker/libcontainer/netlink" + "net" + "errors" + "fmt" + "os/exec" + "strings" + "os" + "io/ioutil" + "strconv" + "syscall" + "time" +) + +const ( + wifi_if_name string = "wlan0" +) + +//ToDo: big to do ... move all the shitty command tool line wrapping/parsing (iw, hostapd, wpa_supplicant etc.) to dedicated netlink/nl80211 implementation +//VERY LOW PRIORITY, as this basically means reimplementing the whole toolset for a way too small benefit + +type WiFiAuthMode int +const ( + WiFiAuthMode_OPEN WiFiAuthMode = iota + //WiFiAuthMode_WEP + WiFiAuthMode_WPA_PSK + WiFiAuthMode_WPA2_PSK + WiFiAuthMode_UNSUPPORTED +) + +type BSS struct { + SSID string + BSSID net.HardwareAddr + Frequency int + BeaconInterval time.Duration //carefull, on IE level beacon interval isn't meassured in milliseconds + AuthMode WiFiAuthMode + Signal float32 //Signal strength in dBm +} + +func DeployWifiSettings(ws *pb.WiFiSettings) (err error) { + log.Printf("Trying to deploy WiFi settings:\n%v\n", ws) + ifName := wifi_if_name + + //Get Interface + iface, err := net.InterfaceByName(ifName) + if err != nil { + return errors.New(fmt.Sprintf("No WiFi interface present: %v\n", err)) + } + + + if ws.DisableNexmon { + //load legacy driver + firmware + if wifiIsNexmonLoaded() { + err = wifiLoadLegacy() + if err != nil {return} + } + } else { + //load nexmon driver + firmware + if !wifiIsNexmonLoaded() { + err = wifiLoadNexmon() + if err != nil {return} + } + } + + if ws.Disabled { + log.Printf("Setting WiFi interface %s to DOWN\n", iface.Name) + err = netlink.NetworkLinkDown(iface) + } else { + log.Printf("Setting WiFi interface %s to UP\n", iface.Name) + err = netlink.NetworkLinkUp(iface) + } + + //set proper regulatory dom + err = wifiSetReg(ws.Reg) + if err != nil { + log.Printf("Error setting WiFi regulatory domain '%s': %v\n", ws.Reg, err) //we don't abort on error here + } + + switch ws.Mode { + case pb.WiFiSettings_AP: + //generate hostapd.conf (overwrite old one) + hostapdCreateConfigFile(ws, confFileHostapd(ifName)) + + //start hostapd + err = wifiStartHostapd(ifName) + if err != nil { return err } + case pb.WiFiSettings_STA: + //kill hostapd in case it is still running + err = wifiStopHostapd(ifName) + if err != nil { return err } + + if ws.BssCfgClient == nil { return errors.New("Error: WiFi mode set to station (STA) but no BSS configuration for target WiFi provided")} + if len(ws.BssCfgClient.SSID) == 0 { return errors.New("Error: WiFi mode set to station (STA) but no SSID provided to identify BSS to join")} + + //stop wpa_supplicant if needed (avoid conflicts with scanning) + wifiStopWpaSupplicant(wifi_if_name) + + //scan for provided wifi + scanres, err := WifiScan(ifName) + if err != nil { + return errors.New(fmt.Sprintf("Scanning for existing WiFi networks failed: %v", err)) + } + var matchingBss *BSS = nil + for _,bss := range scanres { + if bss.SSID == ws.BssCfgClient.SSID { + matchingBss = &bss + break + } + } + if matchingBss == nil { + return errors.New(fmt.Sprintf("SSID not found during scan: '%s'", ws.BssCfgClient.SSID)) + } + + + if len(ws.BssCfgClient.PSK) == 0 { + //seems we should connect an OPEN AUTHENTICATION network + if matchingBss.AuthMode != WiFiAuthMode_OPEN { + return errors.New(fmt.Sprintf("WiFi SSID '%s' found during scan, but authentication mode isn't OPEN and no PSK was provided", ws.BssCfgClient.SSID)) + } + + //ToDo: try to connect open network + } else { + err = WifiCreateWpaSupplicantConfigFile(ws.BssCfgClient.SSID, ws.BssCfgClient.PSK, confFileWpaSupplicant(wifi_if_name)) + if err != nil { return err } + //ToDo: proper error handling, in case connection not possible + err = wifiStartWpaSupplicant(wifi_if_name) + if err != nil { return err } + } + + + + } + + log.Printf("... WiFi settings deployed successfully\n") + return nil +} + +//check if nexmon driver + firmware is active is loaded +func wifiIsNexmonLoaded() bool { + return true +} + +func wifiLoadNexmon() error { + log.Println("Loading nexmon WiFi firmware") + return nil +} + +func wifiLoadLegacy() error { + log.Println("Loading leagcy WiFi firmware") + return nil +} + +func wifiSetReg(reg string) (err error) { + if len(reg) == 0 { + reg = "US" //default + log.Printf("No ISO/IEC 3166-1 alpha2 regulatory domain provided, defaulting to '%s'\n", reg) + } + + reg = strings.ToUpper(reg) + + proc := exec.Command("/sbin/iw", "reg", "set", reg) + err = proc.Run() + if err != nil { return err} + + log.Printf("Notified kernel to use ISO/IEC 3166-1 alpha2 regulatory domain '%s'\n", reg) + return nil +} + +func WifiScan(ifName string) (result []BSS, err error) { + if !wifiIwAvailable() { return nil,errors.New("The tool 'iw' is missing, please install it to make this work")} + + proc := exec.Command("/sbin/iw", ifName, "scan") + res, err := proc.CombinedOutput() + if err != nil { + return nil,errors.New(fmt.Sprintf("Error running scan: '%s'\niw outpur: %s", err, res)) + } + + result, err = ParseIwScan(string(res)) + + return +} + +func WifiCreateWpaSupplicantConfigFile(ssid string, psk string, filename string) (err error) { + log.Printf("Creating wpa_suuplicant configuration file at '%s'\n", filename) + fileContent, err := wifiCreateWpaSupplicantConfString(ssid, psk) + if err != nil {return} + err = ioutil.WriteFile(filename, []byte(fileContent), os.ModePerm) + return +} + +func wifiCreateWpaSupplicantConfString(ssid string, psk string) (config string, err error) { + if !wifiWpaPassphraseAvailable() { return "",errors.New("The tool 'wpa_passphrase' is missing, please install it to make this work")} + + + proc := exec.Command("/usr/bin/wpa_passphrase", ssid, psk) + cres, err := proc.CombinedOutput() + + if err != nil { + return "",errors.New(fmt.Sprintf("Error craeting wpa_supplicant.conf for SSID '%s' with PSK '%s': %s", ssid, psk, string(cres))) + } + config = string(cres) + + return +} + +func wifiCreateHostapdConfString(ws *pb.WiFiSettings) (config string, err error) { + if ws.Mode != pb.WiFiSettings_STA_FAILOVER_AP && ws.Mode != pb.WiFiSettings_AP { + return "", errors.New("WiFiSettings don't use an AP") + } + + if ws.BssCfgAP == nil { + return "", errors.New("WiFiSettings don't contain a BSS configuration for an AP") + } + + config = fmt.Sprintf("interface=%s\n", wifi_if_name) + + config += fmt.Sprintf("driver=nl80211\n") //netlink capable driver + config += fmt.Sprintf("hw_mode=g\n") //Use 2.4GHz band + config += fmt.Sprintf("ieee80211n=1\n") //Enable 802.111n + config += fmt.Sprintf("wmm_enabled=1\n") //Enable WMM + config += fmt.Sprintf("ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]\n") // 40MHz channels with 20ns guard interval + config += fmt.Sprintf("macaddr_acl=0\n") //Accept all MAC addresses + + config += fmt.Sprintf("ssid=%s\n", ws.BssCfgAP.SSID) + config += fmt.Sprintf("channel=%d\n", ws.ApChannel) + + if ws.AuthMode == pb.WiFiSettings_WPA2_PSK { + config += fmt.Sprintf("auth_algs=1\n") //Use WPA authentication + config += fmt.Sprintf("wpa=2\n") //Use WPA2 + //ToDo: check if PSK could be provided encrypted + config += fmt.Sprintf("wpa_key_mgmt=WPA-PSK\n") //Use a pre-shared key + + config += fmt.Sprintf("wpa_passphrase=%s\n", ws.BssCfgAP.PSK) //Set PSK + config += fmt.Sprintf("rsn_pairwise=CCMP\n") //Use Use AES, instead of TKIP + } else { + config += fmt.Sprintf("auth_algs=3\n") //Both, open and shared auth + } + + if ws.ApHideSsid { + config += fmt.Sprintf("ignore_broadcast_ssid=2\n") //Require clients to know the SSID + } else { + config += fmt.Sprintf("ignore_broadcast_ssid=0\n") //Send beacons + probes + } + + return +} + +func WifiTest() { + fmt.Println("Hostapd settings:") + conf, err := wifiCreateHostapdConfString(GetDefaultWiFiSettings()) + if err == nil { + fmt.Println(conf) + } else { + fmt.Printf("Error creating hostapd config: %v\n", err) + } + + fmt.Println("End of hostapd settings:") +} + +func hostapdCreateConfigFile(s *pb.WiFiSettings, filename string) (err error) { + log.Printf("Creating hostapd configuration file at '%s'\n", filename) + fileContent, err := wifiCreateHostapdConfString(s) + if err != nil {return} + err = ioutil.WriteFile(filename, []byte(fileContent), os.ModePerm) + return +} + +func wifiWpaSupplicantAvailable() bool { + return binaryAvailable("wpa_supplicant") +} + +func wifiWpaPassphraseAvailable() bool { + return binaryAvailable("wpa_passphrase") +} + +func wifiHostapdAvailable() bool { + return binaryAvailable("hostapd") +} + +func wifiIwAvailable() bool { + return binaryAvailable("iw") +} + +func wifiStartHostapd(nameIface string) (err error) { + log.Printf("Starting hostapd for interface '%s'...\n", nameIface) + + //check if interface is valid + if_exists,_ := CheckInterfaceExistence(nameIface) + if !if_exists { + return errors.New(fmt.Sprintf("The given interface '%s' doesn't exist", nameIface)) + } + + if !wifiHostapdAvailable() { + return errors.New("hostapd seems to be missing, please install it") + } + + confpath := confFileHostapd(nameIface) + + //stop hostapd if already running + wifiStopHostapd(nameIface) + + + //We use the run command and allow hostapd to daemonize + proc := exec.Command("/usr/sbin/hostapd", "-B", "-P", pidFileHostapd(nameIface), "-f", logFileHostapd(nameIface), confpath) + err = proc.Run() + if err != nil { return err} + + + log.Printf("... hostapd for interface '%s' started\n", nameIface) + return nil +} + +func wifiStopHostapd(nameIface string) (err error) { + log.Printf("... stop running hostapd processes for interface '%s'\n", nameIface) + running,pid,err := wifiIsHostapdRunning(wifi_if_name) + if err != nil { return err } + if !running { + log.Printf("... hostapd for interface '%s' isn't running, no need to stop it\n", nameIface) + return nil + } + //kill the pid + err = syscall.Kill(pid, syscall.SIGTERM) + if err != nil { return } + + time.Sleep(500*time.Millisecond) + + //check if stopped + running,pid,err = wifiIsHostapdRunning(nameIface) + if err != nil { return } + if (running) { + log.Printf("... couldn't terminate hostapd for interface '%s'\n", nameIface) + } else { + log.Printf("... hostapd for interface '%s' stopped\n", nameIface) + } + + //Delete PID file + os.Remove(pidFileHostapd(nameIface)) + + return nil +} + +func wifiStartWpaSupplicant(nameIface string) (err error) { + log.Printf("Starting wpa_supplicant for interface '%s'...\n", nameIface) + + //check if interface is valid + if_exists,_ := CheckInterfaceExistence(nameIface) + if !if_exists { + return errors.New(fmt.Sprintf("The given interface '%s' doesn't exist", nameIface)) + } + + if !wifiWpaSupplicantAvailable() { + return errors.New("wpa_supplicant seems to be missing, please install it") + } + + confpath := confFileWpaSupplicant(nameIface) + + //stop hostapd if already running + wifiStopWpaSupplicant(nameIface) + + + //We use the run command and allow hostapd to daemonize + //wpa_supplicant -P /tmp/wpa_supplicant.pid -i wlan0 -c /tmp/wpa_supplicant.conf -B + proc := exec.Command("/sbin/wpa_supplicant", "-B", "-P", pidFileWpaSupplicant(nameIface), "-f", logFileWpaSupplicant(nameIface), "-c", confpath, "-i", nameIface) + err = proc.Run() + if err != nil { return err} + + + log.Printf("... wpa_supplicant for interface '%s' started\n", nameIface) + return nil +} + + +func wifiStopWpaSupplicant(nameIface string) (err error) { + log.Printf("... stop running wpa_supplicant processes for interface '%s'\n", nameIface) + running,pid,err := wifiIsWpaSupplicantRunning(wifi_if_name) + if err != nil { return err } + if !running { + log.Printf("... wpa_supplicant for interface '%s' isn't running, no need to stop it\n", nameIface) + return nil + } + //kill the pid + err = syscall.Kill(pid, syscall.SIGTERM) + if err != nil { return } + + time.Sleep(500*time.Millisecond) + + //check if stopped + running,pid,err = wifiIsHostapdRunning(nameIface) + if err != nil { return } + if (running) { + log.Printf("... couldn't terminate wpa_supplicant for interface '%s'\n", nameIface) + } else { + log.Printf("... wpa_supplicant for interface '%s' stopped\n", nameIface) + } + + //Delete PID file + os.Remove(pidFileHostapd(nameIface)) + + return nil +} + +func pidFileHostapd(nameIface string) string { + return fmt.Sprintf("/var/run/hostapd_%s.pid", nameIface) +} + +func logFileHostapd(nameIface string) string { + return fmt.Sprintf("/tmp/hostapd_%s.log", nameIface) +} + +func confFileHostapd(nameIface string) string { + return fmt.Sprintf("/tmp/hostapd_%s.conf", nameIface) +} + + +func confFileWpaSupplicant(nameIface string) string { + return fmt.Sprintf("/tmp/wpa_supplicant_%s.conf", nameIface) +} + +func logFileWpaSupplicant(nameIface string) string { + return fmt.Sprintf("/tmp/wpa_supplicant_%s.log", nameIface) +} + +func pidFileWpaSupplicant(nameIface string) string { + return fmt.Sprintf("/var/run/wpa_supplicant_%s.pid", nameIface) +} + + +func wifiIsHostapdRunning(nameIface string) (running bool, pid int, err error) { + pid_file := pidFileHostapd(nameIface) + + //Check if the pidFile exists + if _, err := os.Stat(pid_file); os.IsNotExist(err) { + return false, 0,nil //file doesn't exist, so we assume hostapd isn't running + } + + //File exists, read the PID + content, err := ioutil.ReadFile(pid_file) + if err != nil { return false, 0, err} + pid, err = strconv.Atoi(strings.TrimSuffix(string(content), "\n")) + if err != nil { return false, 0, errors.New(fmt.Sprintf("Error parsing PID file %s: %v", pid_file, err))} + + //With PID given, check if the process is indeed running (pid_file could stay, even if the hostapd process has died already) + err_kill := syscall.Kill(pid, 0) //sig 0: doesn't send a signal, but error checking is still performed + switch err_kill{ + case nil: + //ToDo: Check if the running process image is indeed hostapd + return true, pid, nil //Process is running + case syscall.ESRCH: + //Process doesn't exist + return false, pid, nil + case syscall.EPERM: + //process exists, but we have no access permission + return true, pid, err_kill + default: + return false, pid, err_kill + } +} + +func wifiIsWpaSupplicantRunning(nameIface string) (running bool, pid int, err error) { + pid_file := pidFileWpaSupplicant(nameIface) + + //Check if the pidFile exists + if _, err := os.Stat(pid_file); os.IsNotExist(err) { + return false, 0,nil //file doesn't exist, so we assume wpa_supplicant isn't running + } + + //File exists, read the PID + content, err := ioutil.ReadFile(pid_file) + if err != nil { return false, 0, err} + pid, err = strconv.Atoi(strings.TrimSuffix(string(content), "\n")) + if err != nil { return false, 0, errors.New(fmt.Sprintf("Error parsing PID file %s: %v", pid_file, err))} + + //With PID given, check if the process is indeed running (pid_file could stay, even if the wpa_supplicant process has died already) + err_kill := syscall.Kill(pid, 0) //sig 0: doesn't send a signal, but error checking is still performed + switch err_kill{ + case nil: + //ToDo: Check if the running process image is indeed wpa_supplicant + return true, pid, nil //Process is running + case syscall.ESRCH: + //Process doesn't exist + return false, pid, nil + case syscall.EPERM: + //process exists, but we have no access permission + return true, pid, err_kill + default: + return false, pid, err_kill + } +} \ No newline at end of file