From 8e0131e18a91b55a209fa497b98148f4df9d164c Mon Sep 17 00:00:00 2001 From: Jon Bright Date: Thu, 1 Jul 2021 16:53:17 +0200 Subject: [PATCH 01/11] Adapt go.mod to fork --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 924c183..1c50d8a 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/bettercap/gatt +module github.com/Jon-Bright/gatt go 1.13 From cf1e81002573935583109b61c0e81b3a370b8d5f Mon Sep 17 00:00:00 2001 From: Jon Bright Date: Fri, 2 Jul 2021 16:19:52 +0200 Subject: [PATCH 02/11] Implement processing of L2CAP Connection Parameter Update Requests. This checks that the request is valid, replies to the other side in any event (with an accept/reject) and, if accepted, also updates the connection parameters to HCI. --- linux/l2cap.go | 102 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/linux/l2cap.go b/linux/l2cap.go index a4f1c5d..946f7b8 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -190,7 +190,105 @@ func (c *conn) Close() error { // 0x15 LE Credit Based Connection response 0x0005 // 0x16 LE Flow Control Credit 0x0005 func (c *conn) handleSignal(a *aclData) error { - log.Printf("ignore l2cap signal:[ % X ]", a.b) - // FIXME: handle LE signaling channel (CID: 5) + // First 4 bytes are header - the code is at byte 4 + switch a.b[4] { + case 0x12: + return c.handleConnectionParameterUpdateReq(a) + default: + log.Printf("ignoring unimplemented l2cap signal:[ % X ]", a.b) + } + // FIXME: handle more LE signaling channel (CID: 5) return nil } + +func (c *conn) handleConnectionParameterUpdateReq(a *aclData) error { + log.Printf("processing connection parameter update") + if len(a.b) < 6 { + log.Printf("connection parameter update too short to reply, ignoring") + return nil + } + id := a.b[5] + res := byte(1) // Bluetooth for "rejected" + ok, intMin, intMax, slaveLatency, timeoutMult := c.checkConnectionParams(a) + if ok { + res = 0 // Bluetooth for "accepted" + + // This has to be done in a goroutine - here, we're on the same thread that is running + // the command loop. The send to HCI will wait for an ack to come back, which in turn + // will be processed by the command loop - except, if we do this without the goroutine, + // it'll never be processed, the send will never complete and we'll block forever. + go c.updateConnectionToHCI(intMin, intMax, slaveLatency, timeoutMult) + } + + // Reply to the other side + b := []byte{ + 0x13, // Code (Connection Param Update Response) + id, // ID + 0x02, // Length, byte 1 + 0x00, // Length, byte 2 + res, // Result + 0, // Result (the other byte that's always zero and makes you wonder why they used a 16-bit field) + } + _, err := c.write(0x05, b) + return err +} + +func (c *conn) updateConnectionToHCI(intMin uint16, intMax uint16, slaveLatency uint16, timeoutMult uint16) { + // Tell HCI to update + u := cmd.LEConnUpdate{ + c.attr, // Handle + intMin, + intMax, + slaveLatency, + timeoutMult, + 0, + 0, + } + if err, _ := c.hci.c.Send(u); err != nil { + log.Printf("ERR: updating HCI failed: %v", err) + } +} + +func (c *conn) checkConnectionParams(a *aclData) (bool, uint16, uint16, uint16, uint16) { + if len(a.b) < 16 { + log.Printf("connection parameter update actual length wrong: want 16, got %d", len(a.b)) + return false, 0, 0, 0, 0 + } + len := uint16(a.b[6]) | (uint16(a.b[7]) << 8) + if len != 8 { + log.Printf("connection parameter update len field: want 8, got %d", len) + return false, 0, 0, 0, 0 + } + intMin := uint16(a.b[8]) | (uint16(a.b[9]) << 8) + // Values from page 1070 of the Bluetooth 5.2 spec + if intMin < 6 || intMin > 3200 { + log.Printf("invalid interval minimum: %d", intMin) + return false, 0, 0, 0, 0 + } + intMax := uint16(a.b[10]) | (uint16(a.b[11]) << 8) + if intMax < 6 || intMax > 3200 { + log.Printf("invalid interval maximum: %d", intMax) + return false, 0, 0, 0, 0 + } + if intMax < intMin { + log.Printf("interval max (%d) less than min (%d)", intMax, intMin) + return false, 0, 0, 0, 0 + } + slaveLatency := uint16(a.b[12]) | (uint16(a.b[13]) << 8) + if slaveLatency >= 500 { + log.Printf("slave latency too large: %d", slaveLatency) + return false, 0, 0, 0, 0 + } + timeoutMult := uint16(a.b[14]) | (uint16(a.b[15]) << 8) + if timeoutMult < 10 || timeoutMult > 3200 { + log.Printf("invalid timeout multiplier: %d", timeoutMult) + return false, 0, 0, 0, 0 + } + maxSlaveLatency := (timeoutMult*10)/(intMax*2) - 1 + if slaveLatency > maxSlaveLatency { + log.Printf("invalid slave latency (%d) for timeout multiplier (%d)", slaveLatency, timeoutMult) + return false, 0, 0, 0, 0 + } + log.Printf("accepting, interval min %.2fms, max %.2fms, slave latency %d, supervision timeout %dms", float64(intMin)*1.25, float64(intMax)*1.25, slaveLatency, timeoutMult*10) + return true, intMin, intMax, slaveLatency, timeoutMult +} From 34cfe1aef091efa54fbb07dd0dee454cdc4869a9 Mon Sep 17 00:00:00 2001 From: Jon Bright Date: Fri, 2 Jul 2021 16:41:32 +0200 Subject: [PATCH 03/11] More fork changes --- device_linux.go | 4 ++-- go.mod | 1 + go.sum | 3 +++ linux/l2cap.go | 2 +- option_linux.go | 2 +- peripheral_linux.go | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/device_linux.go b/device_linux.go index 3e2fd99..cec10b3 100644 --- a/device_linux.go +++ b/device_linux.go @@ -4,8 +4,8 @@ import ( "encoding/binary" "net" - "github.com/bettercap/gatt/linux" - "github.com/bettercap/gatt/linux/cmd" + "github.com/Jon-Bright/gatt/linux" + "github.com/Jon-Bright/gatt/linux/cmd" ) type device struct { diff --git a/go.mod b/go.mod index 1c50d8a..70c110d 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/Jon-Bright/gatt go 1.13 require ( + github.com/bettercap/gatt v0.0.0-20210514133428-df6e615f2f67 github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.8 // indirect diff --git a/go.sum b/go.sum index bc88cd0..140cbe8 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/bettercap/gatt v0.0.0-20210514133428-df6e615f2f67 h1:xzN6806c01hWTz8gjGsRjhOPlYj5/dNoZIR8CN9+O1c= +github.com/bettercap/gatt v0.0.0-20210514133428-df6e615f2f67/go.mod h1:oafnPgaBI4gqJiYkueCyR4dqygiWGXTGOE0gmmAVeeQ= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -17,6 +19,7 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab h1:n8cgpHzJ5+EDyDri2s/GC7a9+qK3/YEGnBsd0uS/8PY= github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab/go.mod h1:y1pL58r5z2VvAjeG1VLGc8zOQgSOzbKN7kMHPvFXJ+8= diff --git a/linux/l2cap.go b/linux/l2cap.go index 946f7b8..a37c781 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -5,7 +5,7 @@ import ( "io" "log" - "github.com/bettercap/gatt/linux/cmd" + "github.com/Jon-Bright/gatt/linux/cmd" ) type aclData struct { diff --git a/option_linux.go b/option_linux.go index 1f59631..27ada13 100644 --- a/option_linux.go +++ b/option_linux.go @@ -4,7 +4,7 @@ import ( "errors" "io" - "github.com/bettercap/gatt/linux/cmd" + "github.com/Jon-Bright/gatt/linux/cmd" ) // LnxDeviceID specifies which HCI device to use. diff --git a/peripheral_linux.go b/peripheral_linux.go index b31cb9b..b162ae8 100644 --- a/peripheral_linux.go +++ b/peripheral_linux.go @@ -10,7 +10,7 @@ import ( "net" "strings" - "github.com/bettercap/gatt/linux" + "github.com/Jon-Bright/gatt/linux" ) type peripheral struct { From c8f9e414c6efbaac35a586f9f5b1eaecdfa51d36 Mon Sep 17 00:00:00 2001 From: Jon Bright Date: Sun, 4 Jul 2021 12:51:59 +0200 Subject: [PATCH 04/11] Fix concurrency bug: when unmarshalling an aclData package, we need to copy the data buffer. The bug that otherwise happens is: 1. HCI.mainLoop gets a byte buffer, reads into it, calls handlePacket 2. handlePacket calls handleL2CAP, which unmarshals into an aclData. This aclData references the original b slice 3. handleL2CAP adds the aclData to a channel 4. handlePacket returns the buffer to the pool 5. Repeat from 1, getting the same buffer _while the aclData referencing it is still in the channel_ Triggering this needs a relatively high data rate, but was possible repeatedly for me with a Polar H10. --- linux/l2cap.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linux/l2cap.go b/linux/l2cap.go index a37c781..ec64177 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -26,7 +26,10 @@ func (a *aclData) unmarshal(b []byte) error { return fmt.Errorf("malformed acl packet") } - *a = aclData{attr: attr, flags: flags, dlen: dlen, b: b[4:]} + *a = aclData{attr: attr, flags: flags, dlen: dlen, b: make([]byte, dlen)} + if c := copy(a.b, b[4:]); c != int(dlen) { + return fmt.Errorf("expected to copy %d bytes, copied %d", dlen, c) + } return nil } From b3e8270afce2c05aef145a92de6494f28b60d288 Mon Sep 17 00:00:00 2001 From: Jon Bright Date: Sun, 4 Jul 2021 13:26:32 +0200 Subject: [PATCH 05/11] Complete forking: import Jon-Bright/gatt everywhere rather than bettercap/gatt. NB: I still intend to drop this fork once I've got everything that I want working and any resulting pull requests to bettercap are merged. --- central_darwin.go | 2 +- device_darwin.go | 2 +- examples/discoverer.go | 4 ++-- examples/explorer.go | 4 ++-- examples/option/option_darwin.go | 2 +- examples/option/option_linux.go | 4 ++-- examples/server.go | 6 +++--- examples/server_lnx.go | 6 +++--- examples/service/battery.go | 2 +- examples/service/count.go | 2 +- examples/service/gap.go | 2 +- examples/service/gatt.go | 2 +- go.mod | 2 -- linux/cmd/cmd.go | 8 ++++---- linux/device.go | 4 ++-- linux/devices.go | 2 +- linux/evt/evt.go | 2 +- linux/hci.go | 6 +++--- option_linux_test.go | 2 +- peripheral_darwin.go | 2 +- 20 files changed, 32 insertions(+), 34 deletions(-) diff --git a/central_darwin.go b/central_darwin.go index 0c1408a..119bfe4 100644 --- a/central_darwin.go +++ b/central_darwin.go @@ -3,7 +3,7 @@ package gatt import ( "sync" - "github.com/bettercap/gatt/xpc" + "github.com/Jon-Bright/gatt/xpc" ) type central struct { diff --git a/device_darwin.go b/device_darwin.go index 0fb13ff..d583c37 100644 --- a/device_darwin.go +++ b/device_darwin.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/bettercap/gatt/xpc" + "github.com/Jon-Bright/gatt/xpc" ) const ( diff --git a/examples/discoverer.go b/examples/discoverer.go index deeb214..005b80e 100644 --- a/examples/discoverer.go +++ b/examples/discoverer.go @@ -6,8 +6,8 @@ import ( "fmt" "log" - "github.com/bettercap/gatt" - "github.com/bettercap/gatt/examples/option" + "github.com/Jon-Bright/gatt" + "github.com/Jon-Bright/gatt/examples/option" ) func onStateChanged(d gatt.Device, s gatt.State) { diff --git a/examples/explorer.go b/examples/explorer.go index 5a1b4a0..34187b3 100644 --- a/examples/explorer.go +++ b/examples/explorer.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/bettercap/gatt" - "github.com/bettercap/gatt/examples/option" + "github.com/Jon-Bright/gatt" + "github.com/Jon-Bright/gatt/examples/option" ) var done = make(chan struct{}) diff --git a/examples/option/option_darwin.go b/examples/option/option_darwin.go index 2905973..f766f0b 100644 --- a/examples/option/option_darwin.go +++ b/examples/option/option_darwin.go @@ -1,6 +1,6 @@ package option -import "github.com/bettercap/gatt" +import "github.com/Jon-Bright/gatt" var DefaultClientOptions = []gatt.Option{ gatt.MacDeviceRole(gatt.CentralManager), diff --git a/examples/option/option_linux.go b/examples/option/option_linux.go index 5710427..97a4370 100644 --- a/examples/option/option_linux.go +++ b/examples/option/option_linux.go @@ -1,8 +1,8 @@ package option import ( - "github.com/bettercap/gatt" - "github.com/bettercap/gatt/linux/cmd" + "github.com/Jon-Bright/gatt" + "github.com/Jon-Bright/gatt/linux/cmd" ) var DefaultClientOptions = []gatt.Option{ diff --git a/examples/server.go b/examples/server.go index cc105fe..6f5cf0e 100644 --- a/examples/server.go +++ b/examples/server.go @@ -6,9 +6,9 @@ import ( "fmt" "log" - "github.com/bettercap/gatt" - "github.com/bettercap/gatt/examples/option" - "github.com/bettercap/gatt/examples/service" + "github.com/Jon-Bright/gatt" + "github.com/Jon-Bright/gatt/examples/option" + "github.com/Jon-Bright/gatt/examples/service" ) func main() { diff --git a/examples/server_lnx.go b/examples/server_lnx.go index 0ab3ce8..c6d8248 100644 --- a/examples/server_lnx.go +++ b/examples/server_lnx.go @@ -9,9 +9,9 @@ import ( "log" "time" - "github.com/bettercap/gatt" - "github.com/bettercap/gatt/examples/service" - "github.com/bettercap/gatt/linux/cmd" + "github.com/Jon-Bright/gatt" + "github.com/Jon-Bright/gatt/examples/service" + "github.com/Jon-Bright/gatt/linux/cmd" ) // server_lnx implements a GATT server. diff --git a/examples/service/battery.go b/examples/service/battery.go index db2581b..62e8a57 100644 --- a/examples/service/battery.go +++ b/examples/service/battery.go @@ -1,6 +1,6 @@ package service -import "github.com/bettercap/gatt" +import "github.com/Jon-Bright/gatt" func NewBatteryService() *gatt.Service { lv := byte(100) diff --git a/examples/service/count.go b/examples/service/count.go index 1051dab..3d405a1 100644 --- a/examples/service/count.go +++ b/examples/service/count.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/bettercap/gatt" + "github.com/Jon-Bright/gatt" ) func NewCountService() *gatt.Service { diff --git a/examples/service/gap.go b/examples/service/gap.go index f856c9f..2ae8f8d 100644 --- a/examples/service/gap.go +++ b/examples/service/gap.go @@ -1,6 +1,6 @@ package service -import "github.com/bettercap/gatt" +import "github.com/Jon-Bright/gatt" var ( attrGAPUUID = gatt.UUID16(0x1800) diff --git a/examples/service/gatt.go b/examples/service/gatt.go index 467267c..0348fb8 100644 --- a/examples/service/gatt.go +++ b/examples/service/gatt.go @@ -3,7 +3,7 @@ package service import ( "log" - "github.com/bettercap/gatt" + "github.com/Jon-Bright/gatt" ) var ( diff --git a/go.mod b/go.mod index 70c110d..0589712 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,6 @@ module github.com/Jon-Bright/gatt go 1.13 require ( - github.com/bettercap/gatt v0.0.0-20210514133428-df6e615f2f67 - github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.8 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index d26df0f..0141341 100644 --- a/linux/cmd/cmd.go +++ b/linux/cmd/cmd.go @@ -7,8 +7,8 @@ import ( "io" "log" - "github.com/bettercap/gatt/linux/evt" - "github.com/bettercap/gatt/linux/util" + "github.com/Jon-Bright/gatt/linux/evt" + "github.com/Jon-Bright/gatt/linux/util" ) type CmdParam interface { @@ -140,9 +140,9 @@ const ( hostCtl = 0x03 infoParam = 0x04 statusParam = 0x05 - testingCmd = 0X3E + testingCmd = 0x3E leCtl = 0x08 - vendorCmd = 0X3F + vendorCmd = 0x3F ) const ( diff --git a/linux/device.go b/linux/device.go index b1c4a92..7afe078 100644 --- a/linux/device.go +++ b/linux/device.go @@ -7,8 +7,8 @@ import ( "syscall" "unsafe" - "github.com/bettercap/gatt/linux/gioctl" - "github.com/bettercap/gatt/linux/socket" + "github.com/Jon-Bright/gatt/linux/gioctl" + "github.com/Jon-Bright/gatt/linux/socket" "golang.org/x/sys/unix" ) diff --git a/linux/devices.go b/linux/devices.go index 776d39f..2af5392 100644 --- a/linux/devices.go +++ b/linux/devices.go @@ -1,6 +1,6 @@ package linux -import "github.com/bettercap/gatt/linux/gioctl" +import "github.com/Jon-Bright/gatt/linux/gioctl" const ( ioctlSize = uintptr(4) diff --git a/linux/evt/evt.go b/linux/evt/evt.go index 5f401f4..da614d6 100644 --- a/linux/evt/evt.go +++ b/linux/evt/evt.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - "github.com/bettercap/gatt/linux/util" + "github.com/Jon-Bright/gatt/linux/util" ) type EventHandler interface { diff --git a/linux/hci.go b/linux/hci.go index 6994efe..3038f09 100644 --- a/linux/hci.go +++ b/linux/hci.go @@ -6,9 +6,9 @@ import ( "log" "sync" - "github.com/bettercap/gatt/linux/cmd" - "github.com/bettercap/gatt/linux/evt" - "github.com/bettercap/gatt/linux/util" + "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/Jon-Bright/gatt/linux/evt" + "github.com/Jon-Bright/gatt/linux/util" "golang.org/x/sys/unix" ) diff --git a/option_linux_test.go b/option_linux_test.go index 6a155f9..5cbc5bd 100644 --- a/option_linux_test.go +++ b/option_linux_test.go @@ -3,7 +3,7 @@ package gatt import ( "bytes" - "github.com/bettercap/gatt/linux/cmd" + "github.com/Jon-Bright/gatt/linux/cmd" ) func ExampleLnxDeviceID() { diff --git a/peripheral_darwin.go b/peripheral_darwin.go index f145dec..bcc939c 100644 --- a/peripheral_darwin.go +++ b/peripheral_darwin.go @@ -4,7 +4,7 @@ import ( "errors" "log" - "github.com/bettercap/gatt/xpc" + "github.com/Jon-Bright/gatt/xpc" ) type peripheral struct { From 2b00d6e1b1eb3effa14b3d820eb1e438b1e0ccc1 Mon Sep 17 00:00:00 2001 From: Jon Bright Date: Mon, 5 Jul 2021 13:39:28 +0200 Subject: [PATCH 06/11] Add missing bounds check. The caller is checking for four bytes, the callee is checking for six bytes, but nobody was checking for 5 bytes :) --- linux/l2cap.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux/l2cap.go b/linux/l2cap.go index ec64177..a8b39dd 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -193,6 +193,9 @@ func (c *conn) Close() error { // 0x15 LE Credit Based Connection response 0x0005 // 0x16 LE Flow Control Credit 0x0005 func (c *conn) handleSignal(a *aclData) error { + if len(a.b) < 5 { + return fmt.Errorf("L2CAP signal without packet type") + } // First 4 bytes are header - the code is at byte 4 switch a.b[4] { case 0x12: From a7a36b976a7017dcb6f60c7df72515ac2ab7ecd8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Sep 2021 09:58:05 +0200 Subject: [PATCH 07/11] Replace log by logrus. --- device_darwin.go | 2 +- examples/discoverer.go | 3 ++- examples/server.go | 3 ++- examples/server_lnx.go | 3 ++- examples/service/count.go | 3 ++- go.mod | 1 + go.sum | 4 ++++ linux/cmd/cmd.go | 3 ++- linux/device.go | 3 ++- linux/hci.go | 3 ++- linux/l2cap.go | 2 +- peripheral_linux.go | 3 ++- 12 files changed, 23 insertions(+), 10 deletions(-) diff --git a/device_darwin.go b/device_darwin.go index d583c37..5b8741e 100644 --- a/device_darwin.go +++ b/device_darwin.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "errors" "fmt" - "log" + log "github.com/sirupsen/logrus" "sync" "time" diff --git a/examples/discoverer.go b/examples/discoverer.go index 005b80e..bc8246c 100644 --- a/examples/discoverer.go +++ b/examples/discoverer.go @@ -4,7 +4,8 @@ package main import ( "fmt" - "log" + + log "github.com/sirupsen/logrus" "github.com/Jon-Bright/gatt" "github.com/Jon-Bright/gatt/examples/option" diff --git a/examples/server.go b/examples/server.go index 6f5cf0e..ee0d847 100644 --- a/examples/server.go +++ b/examples/server.go @@ -4,7 +4,8 @@ package main import ( "fmt" - "log" + + log "github.com/sirupsen/logrus" "github.com/Jon-Bright/gatt" "github.com/Jon-Bright/gatt/examples/option" diff --git a/examples/server_lnx.go b/examples/server_lnx.go index c6d8248..17af8ad 100644 --- a/examples/server_lnx.go +++ b/examples/server_lnx.go @@ -6,9 +6,10 @@ import ( "bytes" "flag" "fmt" - "log" "time" + log "github.com/sirupsen/logrus" + "github.com/Jon-Bright/gatt" "github.com/Jon-Bright/gatt/examples/service" "github.com/Jon-Bright/gatt/linux/cmd" diff --git a/examples/service/count.go b/examples/service/count.go index 3d405a1..68e26cf 100644 --- a/examples/service/count.go +++ b/examples/service/count.go @@ -2,9 +2,10 @@ package service import ( "fmt" - "log" "time" + log "github.com/sirupsen/logrus" + "github.com/Jon-Bright/gatt" ) diff --git a/go.mod b/go.mod index 0589712..cc242b4 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/mattn/go-colorable v0.1.8 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab + github.com/sirupsen/logrus v1.8.1 // indirect github.com/stretchr/testify v1.7.0 // indirect golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 140cbe8..9062e01 100644 --- a/go.sum +++ b/go.sum @@ -25,9 +25,13 @@ github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab h1:n8cgpHzJ5+EDyDri2s/ github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab/go.mod h1:y1pL58r5z2VvAjeG1VLGc8zOQgSOzbKN7kMHPvFXJ+8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w= diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index 0141341..806d231 100644 --- a/linux/cmd/cmd.go +++ b/linux/cmd/cmd.go @@ -5,7 +5,8 @@ import ( "errors" "fmt" "io" - "log" + + log "github.com/sirupsen/logrus" "github.com/Jon-Bright/gatt/linux/evt" "github.com/Jon-Bright/gatt/linux/util" diff --git a/linux/device.go b/linux/device.go index 7afe078..c7fa7a8 100644 --- a/linux/device.go +++ b/linux/device.go @@ -2,11 +2,12 @@ package linux import ( "errors" - "log" "sync" "syscall" "unsafe" + log "github.com/sirupsen/logrus" + "github.com/Jon-Bright/gatt/linux/gioctl" "github.com/Jon-Bright/gatt/linux/socket" "golang.org/x/sys/unix" diff --git a/linux/hci.go b/linux/hci.go index 3038f09..51d00c7 100644 --- a/linux/hci.go +++ b/linux/hci.go @@ -3,9 +3,10 @@ package linux import ( "fmt" "io" - "log" "sync" + log "github.com/sirupsen/logrus" + "github.com/Jon-Bright/gatt/linux/cmd" "github.com/Jon-Bright/gatt/linux/evt" "github.com/Jon-Bright/gatt/linux/util" diff --git a/linux/l2cap.go b/linux/l2cap.go index a8b39dd..cda017b 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -3,9 +3,9 @@ package linux import ( "fmt" "io" - "log" "github.com/Jon-Bright/gatt/linux/cmd" + log "github.com/sirupsen/logrus" ) type aclData struct { diff --git a/peripheral_linux.go b/peripheral_linux.go index b162ae8..1d5a4e3 100644 --- a/peripheral_linux.go +++ b/peripheral_linux.go @@ -6,10 +6,11 @@ import ( "errors" "fmt" "io" - "log" "net" "strings" + log "github.com/sirupsen/logrus" + "github.com/Jon-Bright/gatt/linux" ) From eac68dd1d7568894278ad582b33b9c7cfa2bb9c1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Sep 2021 09:59:37 +0200 Subject: [PATCH 08/11] Fix go.mod to match repo. --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cc242b4..642e651 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Jon-Bright/gatt +module github.com/lightblox/gatt go 1.13 From 74a3e17cb34f735357293444151da84da2d525ef Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Sep 2021 10:02:40 +0200 Subject: [PATCH 09/11] Replace references. --- central_darwin.go | 2 +- device_darwin.go | 2 +- device_linux.go | 4 ++-- examples/discoverer.go | 4 ++-- examples/explorer.go | 4 ++-- examples/option/option_darwin.go | 2 +- examples/option/option_linux.go | 4 ++-- examples/server.go | 6 +++--- examples/server_lnx.go | 6 +++--- examples/service/battery.go | 2 +- examples/service/count.go | 2 +- examples/service/gap.go | 2 +- examples/service/gatt.go | 2 +- linux/cmd/cmd.go | 4 ++-- linux/device.go | 4 ++-- linux/devices.go | 2 +- linux/evt/evt.go | 2 +- linux/hci.go | 6 +++--- linux/l2cap.go | 2 +- option_linux.go | 2 +- option_linux_test.go | 2 +- peripheral_darwin.go | 2 +- peripheral_linux.go | 2 +- 23 files changed, 35 insertions(+), 35 deletions(-) diff --git a/central_darwin.go b/central_darwin.go index 119bfe4..71e16bb 100644 --- a/central_darwin.go +++ b/central_darwin.go @@ -3,7 +3,7 @@ package gatt import ( "sync" - "github.com/Jon-Bright/gatt/xpc" + "github.com/lightblox/gatt/xpc" ) type central struct { diff --git a/device_darwin.go b/device_darwin.go index 5b8741e..ef79793 100644 --- a/device_darwin.go +++ b/device_darwin.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/Jon-Bright/gatt/xpc" + "github.com/lightblox/gatt/xpc" ) const ( diff --git a/device_linux.go b/device_linux.go index cec10b3..087a187 100644 --- a/device_linux.go +++ b/device_linux.go @@ -4,8 +4,8 @@ import ( "encoding/binary" "net" - "github.com/Jon-Bright/gatt/linux" - "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/lightblox/gatt/linux" + "github.com/lightblox/gatt/linux/cmd" ) type device struct { diff --git a/examples/discoverer.go b/examples/discoverer.go index bc8246c..df840ec 100644 --- a/examples/discoverer.go +++ b/examples/discoverer.go @@ -7,8 +7,8 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt" - "github.com/Jon-Bright/gatt/examples/option" + "github.com/lightblox/gatt" + "github.com/lightblox/gatt/examples/option" ) func onStateChanged(d gatt.Device, s gatt.State) { diff --git a/examples/explorer.go b/examples/explorer.go index 34187b3..7871233 100644 --- a/examples/explorer.go +++ b/examples/explorer.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/Jon-Bright/gatt" - "github.com/Jon-Bright/gatt/examples/option" + "github.com/lightblox/gatt" + "github.com/lightblox/gatt/examples/option" ) var done = make(chan struct{}) diff --git a/examples/option/option_darwin.go b/examples/option/option_darwin.go index f766f0b..418599f 100644 --- a/examples/option/option_darwin.go +++ b/examples/option/option_darwin.go @@ -1,6 +1,6 @@ package option -import "github.com/Jon-Bright/gatt" +import "github.com/lightblox/gatt" var DefaultClientOptions = []gatt.Option{ gatt.MacDeviceRole(gatt.CentralManager), diff --git a/examples/option/option_linux.go b/examples/option/option_linux.go index 97a4370..94c82ac 100644 --- a/examples/option/option_linux.go +++ b/examples/option/option_linux.go @@ -1,8 +1,8 @@ package option import ( - "github.com/Jon-Bright/gatt" - "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/lightblox/gatt" + "github.com/lightblox/gatt/linux/cmd" ) var DefaultClientOptions = []gatt.Option{ diff --git a/examples/server.go b/examples/server.go index ee0d847..4b9354a 100644 --- a/examples/server.go +++ b/examples/server.go @@ -7,9 +7,9 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt" - "github.com/Jon-Bright/gatt/examples/option" - "github.com/Jon-Bright/gatt/examples/service" + "github.com/lightblox/gatt" + "github.com/lightblox/gatt/examples/option" + "github.com/lightblox/gatt/examples/service" ) func main() { diff --git a/examples/server_lnx.go b/examples/server_lnx.go index 17af8ad..00fb73f 100644 --- a/examples/server_lnx.go +++ b/examples/server_lnx.go @@ -10,9 +10,9 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt" - "github.com/Jon-Bright/gatt/examples/service" - "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/lightblox/gatt" + "github.com/lightblox/gatt/examples/service" + "github.com/lightblox/gatt/linux/cmd" ) // server_lnx implements a GATT server. diff --git a/examples/service/battery.go b/examples/service/battery.go index 62e8a57..6c65d44 100644 --- a/examples/service/battery.go +++ b/examples/service/battery.go @@ -1,6 +1,6 @@ package service -import "github.com/Jon-Bright/gatt" +import "github.com/lightblox/gatt" func NewBatteryService() *gatt.Service { lv := byte(100) diff --git a/examples/service/count.go b/examples/service/count.go index 68e26cf..7a0a382 100644 --- a/examples/service/count.go +++ b/examples/service/count.go @@ -6,7 +6,7 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt" + "github.com/lightblox/gatt" ) func NewCountService() *gatt.Service { diff --git a/examples/service/gap.go b/examples/service/gap.go index 2ae8f8d..f542fce 100644 --- a/examples/service/gap.go +++ b/examples/service/gap.go @@ -1,6 +1,6 @@ package service -import "github.com/Jon-Bright/gatt" +import "github.com/lightblox/gatt" var ( attrGAPUUID = gatt.UUID16(0x1800) diff --git a/examples/service/gatt.go b/examples/service/gatt.go index 0348fb8..f9eb8bf 100644 --- a/examples/service/gatt.go +++ b/examples/service/gatt.go @@ -3,7 +3,7 @@ package service import ( "log" - "github.com/Jon-Bright/gatt" + "github.com/lightblox/gatt" ) var ( diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index 806d231..0cdf995 100644 --- a/linux/cmd/cmd.go +++ b/linux/cmd/cmd.go @@ -8,8 +8,8 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt/linux/evt" - "github.com/Jon-Bright/gatt/linux/util" + "github.com/lightblox/gatt/linux/evt" + "github.com/lightblox/gatt/linux/util" ) type CmdParam interface { diff --git a/linux/device.go b/linux/device.go index c7fa7a8..7c88f68 100644 --- a/linux/device.go +++ b/linux/device.go @@ -8,8 +8,8 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt/linux/gioctl" - "github.com/Jon-Bright/gatt/linux/socket" + "github.com/lightblox/gatt/linux/gioctl" + "github.com/lightblox/gatt/linux/socket" "golang.org/x/sys/unix" ) diff --git a/linux/devices.go b/linux/devices.go index 2af5392..2d0c0e2 100644 --- a/linux/devices.go +++ b/linux/devices.go @@ -1,6 +1,6 @@ package linux -import "github.com/Jon-Bright/gatt/linux/gioctl" +import "github.com/lightblox/gatt/linux/gioctl" const ( ioctlSize = uintptr(4) diff --git a/linux/evt/evt.go b/linux/evt/evt.go index da614d6..4f8a1b9 100644 --- a/linux/evt/evt.go +++ b/linux/evt/evt.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - "github.com/Jon-Bright/gatt/linux/util" + "github.com/lightblox/gatt/linux/util" ) type EventHandler interface { diff --git a/linux/hci.go b/linux/hci.go index 51d00c7..9fc2be0 100644 --- a/linux/hci.go +++ b/linux/hci.go @@ -7,9 +7,9 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt/linux/cmd" - "github.com/Jon-Bright/gatt/linux/evt" - "github.com/Jon-Bright/gatt/linux/util" + "github.com/lightblox/gatt/linux/cmd" + "github.com/lightblox/gatt/linux/evt" + "github.com/lightblox/gatt/linux/util" "golang.org/x/sys/unix" ) diff --git a/linux/l2cap.go b/linux/l2cap.go index cda017b..dc4b2d3 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/lightblox/gatt/linux/cmd" log "github.com/sirupsen/logrus" ) diff --git a/option_linux.go b/option_linux.go index 27ada13..a4ff781 100644 --- a/option_linux.go +++ b/option_linux.go @@ -4,7 +4,7 @@ import ( "errors" "io" - "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/lightblox/gatt/linux/cmd" ) // LnxDeviceID specifies which HCI device to use. diff --git a/option_linux_test.go b/option_linux_test.go index 5cbc5bd..ffbd8c8 100644 --- a/option_linux_test.go +++ b/option_linux_test.go @@ -3,7 +3,7 @@ package gatt import ( "bytes" - "github.com/Jon-Bright/gatt/linux/cmd" + "github.com/lightblox/gatt/linux/cmd" ) func ExampleLnxDeviceID() { diff --git a/peripheral_darwin.go b/peripheral_darwin.go index bcc939c..f595d88 100644 --- a/peripheral_darwin.go +++ b/peripheral_darwin.go @@ -4,7 +4,7 @@ import ( "errors" "log" - "github.com/Jon-Bright/gatt/xpc" + "github.com/lightblox/gatt/xpc" ) type peripheral struct { diff --git a/peripheral_linux.go b/peripheral_linux.go index 1d5a4e3..e1d45cd 100644 --- a/peripheral_linux.go +++ b/peripheral_linux.go @@ -11,7 +11,7 @@ import ( log "github.com/sirupsen/logrus" - "github.com/Jon-Bright/gatt/linux" + "github.com/lightblox/gatt/linux" ) type peripheral struct { From 4684463605b5eb072c78613b32157dbd22063c9d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Sep 2021 10:04:58 +0200 Subject: [PATCH 10/11] Fix mods. --- go.mod | 2 +- go.sum | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 642e651..d2a49fc 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/mattn/go-colorable v0.1.8 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab - github.com/sirupsen/logrus v1.8.1 // indirect + github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.0 // indirect golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 9062e01..172195f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/bettercap/gatt v0.0.0-20210514133428-df6e615f2f67 h1:xzN6806c01hWTz8gjGsRjhOPlYj5/dNoZIR8CN9+O1c= -github.com/bettercap/gatt v0.0.0-20210514133428-df6e615f2f67/go.mod h1:oafnPgaBI4gqJiYkueCyR4dqygiWGXTGOE0gmmAVeeQ= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -7,18 +5,13 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= -github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab h1:n8cgpHzJ5+EDyDri2s/GC7a9+qK3/YEGnBsd0uS/8PY= @@ -34,15 +27,11 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w= -golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From edd7ec2591f2d47ce6112300313236a5bc426f66 Mon Sep 17 00:00:00 2001 From: David Alonso de la Torre Date: Wed, 20 Apr 2022 12:47:25 +0200 Subject: [PATCH 11/11] Fix l2cap segmentation error in concurrent subscription: Protect segment sending in l2cap.conn.write to avoid sending unordered segments for the same l2cap channel --- linux/l2cap.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux/l2cap.go b/linux/l2cap.go index dc4b2d3..5949a1d 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -3,6 +3,7 @@ package linux import ( "fmt" "io" + "sync" "github.com/lightblox/gatt/linux/cmd" log "github.com/sirupsen/logrus" @@ -38,6 +39,7 @@ type conn struct { attr uint16 aclc chan *aclData datac chan []byte + wmu *sync.Mutex } func newConn(hci *HCI, hh uint16) *conn { @@ -46,6 +48,7 @@ func newConn(hci *HCI, hh uint16) *conn { attr: hh, aclc: make(chan *aclData), datac: make(chan []byte, 32), + wmu: &sync.Mutex{}, } go c.loop() return c @@ -110,6 +113,7 @@ func (c *conn) write(cid int, b []byte) (int, error) { uint8(cid), uint8(cid >> 8), // l2cap header }, b...) + c.wmu.Lock() n := 4 + tlen // l2cap header + l2cap payload for n > 0 { dlen := n @@ -130,6 +134,7 @@ func (c *conn) write(cid int, b []byte) (int, error) { flag = 0x10 // the rest of iterations attr continued segments, if any. n -= dlen } + c.wmu.Unlock() return len(b), nil }