diff --git a/P4wnP1_client_cli/cli_client.go b/P4wnP1_client_cli/cli_client.go new file mode 100644 index 0000000..b12d93b --- /dev/null +++ b/P4wnP1_client_cli/cli_client.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + "time" + "reflect" + + "golang.org/x/net/context" + "google.golang.org/grpc" + pb "../proto" +) + +const ( + address = "localhost:50051" +) + +func main() { + // Set up a connection to the server. + conn, err := grpc.Dial(address, grpc.WithInsecure()) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + c := pb.NewP4WNP1Client(conn) + + // Contact the server and print out its response. + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.GetGadgetSettings(ctx, &pb.Empty{}) + if err != nil { + log.Fatalf("could not get GadgetSettings: %v", err) + } + log.Printf("USB Settings %s: %+v", reflect.TypeOf(*r), *r) +} diff --git a/P4wnP1_service/service.go b/P4wnP1_service/service.go new file mode 100644 index 0000000..91f0923 --- /dev/null +++ b/P4wnP1_service/service.go @@ -0,0 +1,87 @@ +package main + +import ( + "log" + "net" + "encoding/json" + + "golang.org/x/net/context" + "google.golang.org/grpc" + pb "../proto" + "google.golang.org/grpc/reflection" +) + + +type server struct{} + +//Attach handler function implementing the "GetGadgetSettings" interface to server +func (s *server) GetGadgetSettings(context.Context, *pb.Empty) (*pb.GadgetSettings, error) { + usbset := &pb.GadgetSettings { + Pid: "0x1337", + Vid: "0x1222", + Manufacturer: "MaMe82", + Serial: "deadbeef13371337", + Product: "P4wnP1 by MaMe82", + Use_RNDIS: false, + Use_CDC_ECM: true, + Use_HID_KEYBOARD: false, + Use_HID_MOUSE: false, + Use_HID_RAW: false, + Use_UMS: false, + Use_SERIAL: false, + + RndisSettings: &pb.GadgetSettingsEthernet { HostAddr: "11:22:33:44:55:66", DevAddr: "66:55:44:33:22:11", }, + CdcEcmSettings: &pb.GadgetSettingsEthernet { HostAddr: "11:22:33:54:76:98", DevAddr: "66:55:44:98:76:54", }, + } + j_usbset, _ := json.Marshal(usbset) + log.Printf("Gadget settings requested %v", string(j_usbset)) + + return usbset, nil +} + +//Attach handler function implementing the "SetGadgetSettings" interface to server +func (s *server) SetGadgetSettings(context.Context, *pb.GadgetSettings) (*pb.Error, error) { + return &pb.Error{Err: 0}, nil +} + +//Attach handler function implementing the "StartGadget" interface to server +func (s *server) StartGadget(context.Context, *pb.Empty) (*pb.Error, error) { + return &pb.Error{Err: 0}, nil +} + +//Attach handler function implementing the "StopGadget" interface to server +func (s *server) StopGadget(context.Context, *pb.Empty) (*pb.Error, error) { + return &pb.Error{Err: 0}, nil +} + +func (s *server) GetLEDSettings(context.Context, *pb.Empty) (*pb.LEDSettings, error) { + led_settings := &pb.LEDSettings{} + return led_settings, nil +} + +func (s *server) SetLEDSettings(context.Context, *pb.LEDSettings) (*pb.Error, error) { + return &pb.Error{Err: 0}, nil +} + +func start_rpc_server(host string, port string) { + listen_address := host+":"+port + //Open TCP listener + log.Printf("P4wnP1 RPC server lsitening on " + listen_address) + lis, err := net.Listen("tcp", listen_address) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + + //Create gRPC Server + s := grpc.NewServer() + pb.RegisterP4WNP1Server(s, &server{}) + // Register reflection service on gRPC server. + reflection.Register(s) + if err := s.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } +} + +func main() { + start_rpc_server("127.0.0.1", "50051") +} diff --git a/build_proto.sh b/build_proto.sh new file mode 100755 index 0000000..37a3dda --- /dev/null +++ b/build_proto.sh @@ -0,0 +1,2 @@ +#!/bin/bash +protoc -I proto/ proto/grpc.proto --go_out=plugins=grpc:proto diff --git a/core/led.go b/core/led.go new file mode 100644 index 0000000..c22430e --- /dev/null +++ b/core/led.go @@ -0,0 +1,66 @@ +//package led +package main + +import( + "os" + "log" + "io/ioutil" + "time" + + pb "../proto" +) + +const ( + LED_TRIGGER_PATH = "/sys/class/leds/led0/trigger" + LED_BRIGHTNESS_PATH = "/sys/class/leds/led0/brightness" + LED_TRIGGER_MANUAL = "none" + LED_ON = "0" + LED_OFF = "1" + LED_DELAY_ON = 200 * time.Millisecond + LED_DELAY_OFF = 200 * time.Millisecond + LED_DELAY_PAUSE = 500 * time.Millisecond +) + +func initLed(led_on bool) (error) { + //set trigger of LED to manual + log.Println("Setting LED to manual trigger ...") + ioutil.WriteFile(LED_TRIGGER_PATH, []byte(LED_TRIGGER_MANUAL), os.ModePerm) + if led_on { + log.Println("Setting LED to ON ...") + ioutil.WriteFile(LED_BRIGHTNESS_PATH, []byte(LED_ON), os.ModePerm) + } else { + log.Println("Setting LED to OFF ...") + ioutil.WriteFile(LED_BRIGHTNESS_PATH, []byte(LED_OFF), os.ModePerm) + } + return nil +} + +func led_loop() { + blink_count := 10 + for { + for i := 0; i <= blink_count; i++ { + ioutil.WriteFile(LED_BRIGHTNESS_PATH, []byte(LED_ON), os.ModePerm) + time.Sleep(LED_DELAY_ON) + ioutil.WriteFile(LED_BRIGHTNESS_PATH, []byte(LED_OFF), os.ModePerm) + time.Sleep(LED_DELAY_OFF) + } + time.Sleep(LED_DELAY_PAUSE) + } +} + +func setLed(s pb.LEDSettings) (error) { + + + return nil +} + +func main() { + initLed(false) + + log.Println("testing led") + settings := pb.LEDSettings{} + setLed(settings) + + go led_loop() + time.Sleep(10 * time.Second) +} diff --git a/install.sh b/install.sh index a42793f..f826348 100755 --- a/install.sh +++ b/install.sh @@ -5,3 +5,4 @@ sudo tar -C /usr/local -xzf go1.9.linux-armv6l.tar.gz export PATH=$PATH:/usr/local/go/bin # put into ~/.profile echo export PATH=$PATH:/usr/local/go/bin >> ~/.profile sudo bash -c 'echo export PATH=\$PATH:/usr/local/go/bin >> ~/.profile' +go get google.golang.org/grpc diff --git a/proto/grpc.pb.go b/proto/grpc.pb.go new file mode 100644 index 0000000..bf59e0d --- /dev/null +++ b/proto/grpc.pb.go @@ -0,0 +1,667 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: grpc.proto + +/* +Package P4wnP1_grpc is a generated protocol buffer package. + +It is generated from these files: + grpc.proto + +It has these top-level messages: + LEDSettings + GadgetSettingsEthernet + GadgetSettings + WiFiSettings + Error + Empty +*/ +package P4wnP1_grpc + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type WiFiSettings_Mode int32 + +const ( + WiFiSettings_AP WiFiSettings_Mode = 0 + WiFiSettings_STA WiFiSettings_Mode = 1 + WiFiSettings_STA_FAILOVER_AP WiFiSettings_Mode = 2 +) + +var WiFiSettings_Mode_name = map[int32]string{ + 0: "AP", + 1: "STA", + 2: "STA_FAILOVER_AP", +} +var WiFiSettings_Mode_value = map[string]int32{ + "AP": 0, + "STA": 1, + "STA_FAILOVER_AP": 2, +} + +func (x WiFiSettings_Mode) String() string { + return proto.EnumName(WiFiSettings_Mode_name, int32(x)) +} +func (WiFiSettings_Mode) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{3, 0} } + +type WiFiSettings_APAuthMode int32 + +const ( + WiFiSettings_WPA2_PSK WiFiSettings_APAuthMode = 0 + WiFiSettings_OPEN WiFiSettings_APAuthMode = 1 +) + +var WiFiSettings_APAuthMode_name = map[int32]string{ + 0: "WPA2_PSK", + 1: "OPEN", +} +var WiFiSettings_APAuthMode_value = map[string]int32{ + "WPA2_PSK": 0, + "OPEN": 1, +} + +func (x WiFiSettings_APAuthMode) String() string { + return proto.EnumName(WiFiSettings_APAuthMode_name, int32(x)) +} +func (WiFiSettings_APAuthMode) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{3, 1} } + +type LEDSettings struct { + BlinkCount uint32 `protobuf:"varint,1,opt,name=blink_count,json=blinkCount" json:"blink_count,omitempty"` +} + +func (m *LEDSettings) Reset() { *m = LEDSettings{} } +func (m *LEDSettings) String() string { return proto.CompactTextString(m) } +func (*LEDSettings) ProtoMessage() {} +func (*LEDSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +func (m *LEDSettings) GetBlinkCount() uint32 { + if m != nil { + return m.BlinkCount + } + return 0 +} + +type GadgetSettingsEthernet struct { + HostAddr string `protobuf:"bytes,1,opt,name=host_addr,json=hostAddr" json:"host_addr,omitempty"` + DevAddr string `protobuf:"bytes,2,opt,name=dev_addr,json=devAddr" json:"dev_addr,omitempty"` +} + +func (m *GadgetSettingsEthernet) Reset() { *m = GadgetSettingsEthernet{} } +func (m *GadgetSettingsEthernet) String() string { return proto.CompactTextString(m) } +func (*GadgetSettingsEthernet) ProtoMessage() {} +func (*GadgetSettingsEthernet) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *GadgetSettingsEthernet) GetHostAddr() string { + if m != nil { + return m.HostAddr + } + return "" +} + +func (m *GadgetSettingsEthernet) GetDevAddr() string { + if m != nil { + return m.DevAddr + } + return "" +} + +type GadgetSettings struct { + Vid string `protobuf:"bytes,1,opt,name=vid" json:"vid,omitempty"` + Pid string `protobuf:"bytes,2,opt,name=pid" json:"pid,omitempty"` + Manufacturer string `protobuf:"bytes,3,opt,name=manufacturer" json:"manufacturer,omitempty"` + Product string `protobuf:"bytes,4,opt,name=product" json:"product,omitempty"` + Serial string `protobuf:"bytes,5,opt,name=serial" json:"serial,omitempty"` + Use_CDC_ECM bool `protobuf:"varint,6,opt,name=use_CDC_ECM,json=useCDCECM" json:"use_CDC_ECM,omitempty"` + Use_RNDIS bool `protobuf:"varint,7,opt,name=use_RNDIS,json=useRNDIS" json:"use_RNDIS,omitempty"` + Use_HID_KEYBOARD bool `protobuf:"varint,8,opt,name=use_HID_KEYBOARD,json=useHIDKEYBOARD" json:"use_HID_KEYBOARD,omitempty"` + Use_HID_MOUSE bool `protobuf:"varint,9,opt,name=use_HID_MOUSE,json=useHIDMOUSE" json:"use_HID_MOUSE,omitempty"` + Use_HID_RAW bool `protobuf:"varint,10,opt,name=use_HID_RAW,json=useHIDRAW" json:"use_HID_RAW,omitempty"` + Use_UMS bool `protobuf:"varint,11,opt,name=use_UMS,json=useUMS" json:"use_UMS,omitempty"` + Use_SERIAL bool `protobuf:"varint,12,opt,name=use_SERIAL,json=useSERIAL" json:"use_SERIAL,omitempty"` + RndisSettings *GadgetSettingsEthernet `protobuf:"bytes,13,opt,name=rndis_settings,json=rndisSettings" json:"rndis_settings,omitempty"` + CdcEcmSettings *GadgetSettingsEthernet `protobuf:"bytes,14,opt,name=cdc_ecm_settings,json=cdcEcmSettings" json:"cdc_ecm_settings,omitempty"` +} + +func (m *GadgetSettings) Reset() { *m = GadgetSettings{} } +func (m *GadgetSettings) String() string { return proto.CompactTextString(m) } +func (*GadgetSettings) ProtoMessage() {} +func (*GadgetSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *GadgetSettings) GetVid() string { + if m != nil { + return m.Vid + } + return "" +} + +func (m *GadgetSettings) GetPid() string { + if m != nil { + return m.Pid + } + return "" +} + +func (m *GadgetSettings) GetManufacturer() string { + if m != nil { + return m.Manufacturer + } + return "" +} + +func (m *GadgetSettings) GetProduct() string { + if m != nil { + return m.Product + } + return "" +} + +func (m *GadgetSettings) GetSerial() string { + if m != nil { + return m.Serial + } + return "" +} + +func (m *GadgetSettings) GetUse_CDC_ECM() bool { + if m != nil { + return m.Use_CDC_ECM + } + return false +} + +func (m *GadgetSettings) GetUse_RNDIS() bool { + if m != nil { + return m.Use_RNDIS + } + return false +} + +func (m *GadgetSettings) GetUse_HID_KEYBOARD() bool { + if m != nil { + return m.Use_HID_KEYBOARD + } + return false +} + +func (m *GadgetSettings) GetUse_HID_MOUSE() bool { + if m != nil { + return m.Use_HID_MOUSE + } + return false +} + +func (m *GadgetSettings) GetUse_HID_RAW() bool { + if m != nil { + return m.Use_HID_RAW + } + return false +} + +func (m *GadgetSettings) GetUse_UMS() bool { + if m != nil { + return m.Use_UMS + } + return false +} + +func (m *GadgetSettings) GetUse_SERIAL() bool { + if m != nil { + return m.Use_SERIAL + } + return false +} + +func (m *GadgetSettings) GetRndisSettings() *GadgetSettingsEthernet { + if m != nil { + return m.RndisSettings + } + return nil +} + +func (m *GadgetSettings) GetCdcEcmSettings() *GadgetSettingsEthernet { + if m != nil { + return m.CdcEcmSettings + } + return nil +} + +type WiFiSettings struct { + Diasabled bool `protobuf:"varint,1,opt,name=diasabled" json:"diasabled,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"` + 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"` +} + +func (m *WiFiSettings) Reset() { *m = WiFiSettings{} } +func (m *WiFiSettings) String() string { return proto.CompactTextString(m) } +func (*WiFiSettings) ProtoMessage() {} +func (*WiFiSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +func (m *WiFiSettings) GetDiasabled() bool { + if m != nil { + return m.Diasabled + } + return false +} + +func (m *WiFiSettings) GetReg() string { + if m != nil { + return m.Reg + } + return "" +} + +func (m *WiFiSettings) GetMode() WiFiSettings_Mode { + if m != nil { + return m.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 + } + return WiFiSettings_WPA2_PSK +} + +func (m *WiFiSettings) GetApChannel() uint32 { + if m != nil { + return m.ApChannel + } + return 0 +} + +func (m *WiFiSettings) GetApPsk() string { + if m != nil { + return m.ApPsk + } + return "" +} + +func (m *WiFiSettings) GetApHideSsid() bool { + if m != nil { + return m.ApHideSsid + } + 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 + } + return false +} + +type Error struct { + Err int32 `protobuf:"varint,1,opt,name=err" json:"err,omitempty"` +} + +func (m *Error) Reset() { *m = Error{} } +func (m *Error) String() string { return proto.CompactTextString(m) } +func (*Error) ProtoMessage() {} +func (*Error) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } + +func (m *Error) GetErr() int32 { + if m != nil { + return m.Err + } + return 0 +} + +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{5} } + +func init() { + proto.RegisterType((*LEDSettings)(nil), "P4wnP1_grpc.LEDSettings") + proto.RegisterType((*GadgetSettingsEthernet)(nil), "P4wnP1_grpc.GadgetSettingsEthernet") + proto.RegisterType((*GadgetSettings)(nil), "P4wnP1_grpc.GadgetSettings") + proto.RegisterType((*WiFiSettings)(nil), "P4wnP1_grpc.WiFiSettings") + proto.RegisterType((*Error)(nil), "P4wnP1_grpc.Error") + proto.RegisterType((*Empty)(nil), "P4wnP1_grpc.Empty") + proto.RegisterEnum("P4wnP1_grpc.WiFiSettings_Mode", WiFiSettings_Mode_name, WiFiSettings_Mode_value) + proto.RegisterEnum("P4wnP1_grpc.WiFiSettings_APAuthMode", WiFiSettings_APAuthMode_name, WiFiSettings_APAuthMode_value) +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// Client API for P4WNP1 service + +type P4WNP1Client interface { + GetGadgetSettings(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*GadgetSettings, error) + SetGadgetSettings(ctx context.Context, in *GadgetSettings, opts ...grpc.CallOption) (*Error, error) + GetLEDSettings(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LEDSettings, error) + SetLEDSettings(ctx context.Context, in *LEDSettings, opts ...grpc.CallOption) (*Error, error) + StopGadget(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Error, error) + StartGadget(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Error, error) +} + +type p4WNP1Client struct { + cc *grpc.ClientConn +} + +func NewP4WNP1Client(cc *grpc.ClientConn) P4WNP1Client { + return &p4WNP1Client{cc} +} + +func (c *p4WNP1Client) GetGadgetSettings(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*GadgetSettings, error) { + out := new(GadgetSettings) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/GetGadgetSettings", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p4WNP1Client) SetGadgetSettings(ctx context.Context, in *GadgetSettings, opts ...grpc.CallOption) (*Error, error) { + out := new(Error) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/SetGadgetSettings", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p4WNP1Client) GetLEDSettings(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LEDSettings, error) { + out := new(LEDSettings) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/GetLEDSettings", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p4WNP1Client) SetLEDSettings(ctx context.Context, in *LEDSettings, opts ...grpc.CallOption) (*Error, error) { + out := new(Error) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/SetLEDSettings", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p4WNP1Client) StopGadget(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Error, error) { + out := new(Error) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/StopGadget", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p4WNP1Client) StartGadget(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Error, error) { + out := new(Error) + err := grpc.Invoke(ctx, "/P4wnP1_grpc.P4WNP1/StartGadget", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for P4WNP1 service + +type P4WNP1Server interface { + GetGadgetSettings(context.Context, *Empty) (*GadgetSettings, error) + SetGadgetSettings(context.Context, *GadgetSettings) (*Error, error) + GetLEDSettings(context.Context, *Empty) (*LEDSettings, error) + SetLEDSettings(context.Context, *LEDSettings) (*Error, error) + StopGadget(context.Context, *Empty) (*Error, error) + StartGadget(context.Context, *Empty) (*Error, error) +} + +func RegisterP4WNP1Server(s *grpc.Server, srv P4WNP1Server) { + s.RegisterService(&_P4WNP1_serviceDesc, srv) +} + +func _P4WNP1_GetGadgetSettings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).GetGadgetSettings(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/GetGadgetSettings", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).GetGadgetSettings(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _P4WNP1_SetGadgetSettings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GadgetSettings) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).SetGadgetSettings(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/SetGadgetSettings", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).SetGadgetSettings(ctx, req.(*GadgetSettings)) + } + return interceptor(ctx, in, info, handler) +} + +func _P4WNP1_GetLEDSettings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).GetLEDSettings(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/GetLEDSettings", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).GetLEDSettings(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _P4WNP1_SetLEDSettings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LEDSettings) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).SetLEDSettings(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/SetLEDSettings", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).SetLEDSettings(ctx, req.(*LEDSettings)) + } + return interceptor(ctx, in, info, handler) +} + +func _P4WNP1_StopGadget_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).StopGadget(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/StopGadget", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).StopGadget(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _P4WNP1_StartGadget_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P4WNP1Server).StartGadget(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/P4wnP1_grpc.P4WNP1/StartGadget", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P4WNP1Server).StartGadget(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +var _P4WNP1_serviceDesc = grpc.ServiceDesc{ + ServiceName: "P4wnP1_grpc.P4WNP1", + HandlerType: (*P4WNP1Server)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetGadgetSettings", + Handler: _P4WNP1_GetGadgetSettings_Handler, + }, + { + MethodName: "SetGadgetSettings", + Handler: _P4WNP1_SetGadgetSettings_Handler, + }, + { + MethodName: "GetLEDSettings", + Handler: _P4WNP1_GetLEDSettings_Handler, + }, + { + MethodName: "SetLEDSettings", + Handler: _P4WNP1_SetLEDSettings_Handler, + }, + { + MethodName: "StopGadget", + Handler: _P4WNP1_StopGadget_Handler, + }, + { + MethodName: "StartGadget", + Handler: _P4WNP1_StartGadget_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "grpc.proto", +} + +func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 791 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x5d, 0x6f, 0xdb, 0x36, + 0x14, 0x8d, 0xe3, 0x2f, 0xe9, 0xca, 0xd6, 0x34, 0x0e, 0xeb, 0xd4, 0x76, 0x6d, 0x03, 0xad, 0x03, + 0xf2, 0x30, 0x18, 0xa8, 0x57, 0x6c, 0xaf, 0xd3, 0x24, 0x25, 0xf1, 0x1a, 0x27, 0x82, 0xd4, 0xcc, + 0xd8, 0x13, 0xc1, 0x88, 0x9c, 0x2d, 0xc4, 0x96, 0x04, 0x92, 0xca, 0xb6, 0x7f, 0xb0, 0x97, 0xfd, + 0xc8, 0xfd, 0x93, 0x81, 0x94, 0x9c, 0xc4, 0x9d, 0x53, 0x6c, 0x6f, 0xe4, 0x39, 0xf7, 0x1c, 0x5e, + 0xf1, 0x1e, 0x50, 0x00, 0x4b, 0x5e, 0x65, 0x93, 0x8a, 0x97, 0xb2, 0x44, 0x56, 0xfc, 0xf6, 0xb7, + 0x22, 0x7e, 0x83, 0x15, 0xe4, 0x4d, 0xc0, 0x3a, 0x8f, 0xc2, 0x94, 0x49, 0x99, 0x17, 0x4b, 0x81, + 0x5e, 0x81, 0x75, 0xbd, 0xce, 0x8b, 0x1b, 0x9c, 0x95, 0x75, 0x21, 0xdd, 0xce, 0x51, 0xe7, 0x78, + 0x9c, 0x80, 0x86, 0x02, 0x85, 0x78, 0x31, 0x3c, 0x39, 0x25, 0x74, 0xc9, 0xe4, 0x56, 0x12, 0xc9, + 0x15, 0xe3, 0x05, 0x93, 0xe8, 0x39, 0x98, 0xab, 0x52, 0x48, 0x4c, 0x28, 0xe5, 0x5a, 0x68, 0x26, + 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, 0xf3, 0x8f, 0x04, 0xce, 0x3b, 0x50, 0x3e, 0xe9, 0xbf, 0x7c, 0x3e, 0xa6, 0x79, + 0xf6, 0xc1, 0x21, 0xaa, 0x67, 0xef, 0x00, 0xfd, 0x00, 0xf6, 0x29, 0x93, 0x0f, 0x9f, 0xcc, 0x7d, + 0xcd, 0xb8, 0x3b, 0xd8, 0x83, 0xea, 0xc6, 0x21, 0xdd, 0x75, 0x78, 0xb4, 0xfa, 0x91, 0x1e, 0xbe, + 0x03, 0x48, 0x65, 0x59, 0x35, 0xfd, 0xee, 0x3d, 0x7f, 0xbf, 0xee, 0x7b, 0xb0, 0x52, 0x49, 0xb8, + 0xfc, 0xbf, 0xc2, 0xeb, 0x81, 0xfe, 0x71, 0x7c, 0xfb, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x18, + 0x23, 0xdf, 0x1e, 0x46, 0x06, 0x00, 0x00, +} diff --git a/proto/grpc.proto b/proto/grpc.proto new file mode 100644 index 0000000..1331356 --- /dev/null +++ b/proto/grpc.proto @@ -0,0 +1,70 @@ +syntax = "proto3"; + +package P4wnP1_grpc; + +service P4WNP1 { + rpc GetGadgetSettings (Empty) returns (GadgetSettings) {} + rpc SetGadgetSettings (GadgetSettings) returns (Error) {} + rpc GetLEDSettings (Empty) returns (LEDSettings) {} + rpc SetLEDSettings (LEDSettings) returns (Error) {} + rpc StopGadget (Empty) returns (Error) {} + rpc StartGadget (Empty) returns (Error) {} +} + +message LEDSettings { + uint32 blink_count = 1; +} + +message GadgetSettingsEthernet { + string host_addr = 1; + string dev_addr = 2; +} + +message GadgetSettings { + string vid = 1; + string pid = 2; + string manufacturer = 3; + string product = 4; + string serial = 5; + bool use_CDC_ECM = 6; + bool use_RNDIS = 7; + bool use_HID_KEYBOARD = 8; + bool use_HID_MOUSE = 9; + bool use_HID_RAW = 10; + bool use_UMS = 11; + bool use_SERIAL = 12; + GadgetSettingsEthernet rndis_settings = 13; + GadgetSettingsEthernet cdc_ecm_settings = 14; + +} + +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 ap_hide_ssid = 8; //if true, SSID gets hidden for spawned AP + + string client_ssid = 9; + string client_psk = 10; + + bool disable_nexmon = 11; //if true, legacy driver / firmware is used instead of nexmon +} + +message Error { + int32 err = 1; +} + +message Empty {}