You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/03/03 03:19:44 UTC
[2/7] incubator-mynewt-newt git commit: MYNEWT-653 Use runtimeco gatt
fork.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/linux/util/util.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/linux/util/util.go b/newtmgr/vendor/github.com/runtimeinc/gatt/linux/util/util.go
deleted file mode 100644
index 4933008..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/linux/util/util.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package util
-
-import "encoding/binary"
-
-type order struct{ binary.ByteOrder }
-
-var Order = order{binary.LittleEndian}
-
-func (o order) Int8(b []byte) int8 { return int8(b[0]) }
-func (o order) Uint8(b []byte) uint8 { return b[0] }
-func (o order) MAC(b []byte) [6]byte { return [6]byte{b[5], b[4], b[3], b[2], b[1], b[0]} }
-
-func (o order) PutUint8(b []byte, v uint8) { b[0] = v }
-func (o order) PutMAC(b []byte, m [6]byte) {
- b[0], b[1], b[2], b[3], b[4], b[5] = m[5], m[4], m[3], m[2], m[1], m[0]
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/option_darwin.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/option_darwin.go b/newtmgr/vendor/github.com/runtimeinc/gatt/option_darwin.go
deleted file mode 100644
index 617db21..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/option_darwin.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package gatt
-
-const (
- CentralManager = 0 // Client functions (default)
- PeripheralManager = 1 // Server functions
-)
-
-// MacDeviceRole specify the XPC connection type to connect blued.
-// THis option can only be used with NewDevice on OS X implementation.
-func MacDeviceRole(r int) Option {
- return func(d Device) error {
- d.(*device).role = r
- return nil
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/option_linux.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/option_linux.go b/newtmgr/vendor/github.com/runtimeinc/gatt/option_linux.go
deleted file mode 100644
index fe8065b..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/option_linux.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package gatt
-
-import (
- "errors"
- "io"
-
- "github.com/runtimeinc/gatt/linux/cmd"
-)
-
-// LnxDeviceID specifies which HCI device to use.
-// If n is set to -1, all the available HCI devices will be probed.
-// If chk is set to true, LnxDeviceID checks the LE support in the feature list of the HCI device.
-// This is to filter devices that does not support LE. In case some LE driver that doesn't correctly
-// set the LE support in its feature list, user can turn off the check.
-// This option can only be used with NewDevice on Linux implementation.
-func LnxDeviceID(n int, chk bool) Option {
- return func(d Device) error {
- d.(*device).devID = n
- d.(*device).chkLE = chk
- return nil
- }
-}
-
-// LnxMaxConnections is an optional parameter.
-// If set, it overrides the default max connections supported.
-// This option can only be used with NewDevice on Linux implementation.
-func LnxMaxConnections(n int) Option {
- return func(d Device) error {
- d.(*device).maxConn = n
- return nil
- }
-}
-
-// LnxSetAdvertisingEnable sets the advertising data to the HCI device.
-// This option can be used with Option on Linux implementation.
-func LnxSetAdvertisingEnable(en bool) Option {
- return func(d Device) error {
- dd := d.(*device)
- if dd == nil {
- return errors.New("device is not initialized")
- }
- if err := dd.update(); err != nil {
- return err
- }
- return dd.hci.SetAdvertiseEnable(en)
- }
-}
-
-// LnxSetAdvertisingData sets the advertising data to the HCI device.
-// This option can be used with NewDevice or Option on Linux implementation.
-func LnxSetAdvertisingData(c *cmd.LESetAdvertisingData) Option {
- return func(d Device) error {
- d.(*device).advData = c
- return nil
- }
-}
-
-// LnxSetScanResponseData sets the scan response data to the HXI device.
-// This option can be used with NewDevice or Option on Linux implementation.
-func LnxSetScanResponseData(c *cmd.LESetScanResponseData) Option {
- return func(d Device) error {
- d.(*device).scanResp = c
- return nil
- }
-}
-
-// LnxSetAdvertisingParameters sets the advertising parameters to the HCI device.
-// This option can be used with NewDevice or Option on Linux implementation.
-func LnxSetAdvertisingParameters(c *cmd.LESetAdvertisingParameters) Option {
- return func(d Device) error {
- d.(*device).advParam = c
- return nil
- }
-}
-
-// LnxSendHCIRawCommand sends a raw command to the HCI device
-// This option can be used with NewDevice or Option on Linux implementation.
-func LnxSendHCIRawCommand(c cmd.CmdParam, rsp io.Writer) Option {
- return func(d Device) error {
- b, err := d.(*device).SendHCIRawCommand(c)
- if rsp == nil {
- return err
- }
- rsp.Write(b)
- return err
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral.go b/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral.go
deleted file mode 100644
index 36ad578..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral.go
+++ /dev/null
@@ -1,102 +0,0 @@
-package gatt
-
-import (
- "errors"
- "sync"
-)
-
-// Peripheral is the interface that represent a remote peripheral device.
-type Peripheral interface {
- // Device returns the underlying device.
- Device() Device
-
- // ID is the platform specific unique ID of the remote peripheral, e.g. MAC for Linux, Peripheral UUID for MacOS.
- ID() string
-
- // Name returns the name of the remote peripheral.
- // This can be the advertised name, if exists, or the GAP device name, which takes priority
- Name() string
-
- // Services returnns the services of the remote peripheral which has been discovered.
- Services() []*Service
-
- // DiscoverServices discover the specified services of the remote peripheral.
- // If the specified services is set to nil, all the available services of the remote peripheral are returned.
- DiscoverServices(s []UUID) ([]*Service, error)
-
- // DiscoverIncludedServices discovers the specified included services of a service.
- // If the specified services is set to nil, all the included services of the service are returned.
- DiscoverIncludedServices(ss []UUID, s *Service) ([]*Service, error)
-
- // DiscoverCharacteristics discovers the specified characteristics of a service.
- // If the specified characterstics is set to nil, all the characteristic of the service are returned.
- DiscoverCharacteristics(c []UUID, s *Service) ([]*Characteristic, error)
-
- // DiscoverDescriptors discovers the descriptors of a characteristic.
- // If the specified descriptors is set to nil, all the descriptors of the characteristic are returned.
- DiscoverDescriptors(d []UUID, c *Characteristic) ([]*Descriptor, error)
-
- // ReadCharacteristic retrieves the value of a specified characteristic.
- ReadCharacteristic(c *Characteristic) ([]byte, error)
-
- // ReadLongCharacteristic retrieves the value of a specified characteristic that is longer than the
- // MTU.
- ReadLongCharacteristic(c *Characteristic) ([]byte, error)
-
- // ReadDescriptor retrieves the value of a specified characteristic descriptor.
- ReadDescriptor(d *Descriptor) ([]byte, error)
-
- // WriteCharacteristic writes the value of a characteristic.
- WriteCharacteristic(c *Characteristic, b []byte, noRsp bool) error
-
- // WriteDescriptor writes the value of a characteristic descriptor.
- WriteDescriptor(d *Descriptor, b []byte) error
-
- // SetNotifyValue sets notifications for the value of a specified characteristic.
- SetNotifyValue(c *Characteristic, f func(*Characteristic, []byte, error)) error
-
- // SetIndicateValue sets indications for the value of a specified characteristic.
- SetIndicateValue(c *Characteristic, f func(*Characteristic, []byte, error)) error
-
- // ReadRSSI retrieves the current RSSI value for the remote peripheral.
- ReadRSSI() int
-
- // SetMTU sets the mtu for the remote peripheral.
- SetMTU(mtu uint16) error
-}
-
-type subscriber struct {
- sub map[uint16]subscribefn
- mu *sync.Mutex
-}
-
-type subscribefn func([]byte, error)
-
-func newSubscriber() *subscriber {
- return &subscriber{
- sub: make(map[uint16]subscribefn),
- mu: &sync.Mutex{},
- }
-}
-
-func (s *subscriber) subscribe(h uint16, f subscribefn) {
- s.mu.Lock()
- s.sub[h] = f
- s.mu.Unlock()
-}
-
-func (s *subscriber) unsubscribe(h uint16) {
- s.mu.Lock()
- delete(s.sub, h)
- s.mu.Unlock()
-}
-
-func (s *subscriber) fn(h uint16) subscribefn {
- s.mu.Lock()
- defer s.mu.Unlock()
- return s.sub[h]
-}
-
-var (
- ErrInvalidLength = errors.New("invalid length")
-)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_darwin.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_darwin.go b/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_darwin.go
deleted file mode 100644
index 69f9b36..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_darwin.go
+++ /dev/null
@@ -1,277 +0,0 @@
-package gatt
-
-import (
- "errors"
- "log"
-
- "github.com/runtimeinc/gatt/xpc"
-)
-
-type peripheral struct {
- // NameChanged is called whenever the peripheral GAP Device name has changed.
- NameChanged func(Peripheral)
-
- // ServicesModified is called when one or more service of a peripheral have changed.
- // A list of invalid service is provided in the parameter.
- ServicesModified func(Peripheral, []*Service)
-
- d *device
- svcs []*Service
-
- sub *subscriber
-
- id xpc.UUID
- name string
-
- reqc chan message
- rspc chan message
- quitc chan struct{}
-}
-
-func NewPeripheral(u UUID) Peripheral { return &peripheral{id: xpc.UUID(u.b)} }
-
-func (p *peripheral) Device() Device { return p.d }
-func (p *peripheral) ID() string { return p.id.String() }
-func (p *peripheral) Name() string { return p.name }
-func (p *peripheral) Services() []*Service { return p.svcs }
-
-func (p *peripheral) DiscoverServices(ss []UUID) ([]*Service, error) {
- rsp := p.sendReq(45, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgUUIDs": uuidSlice(ss),
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return nil, attEcode(res)
- }
- svcs := []*Service{}
- for _, xss := range rsp["kCBMsgArgServices"].(xpc.Array) {
- xs := xss.(xpc.Dict)
- u := MustParseUUID(xs.MustGetHexBytes("kCBMsgArgUUID"))
- h := uint16(xs.MustGetInt("kCBMsgArgServiceStartHandle"))
- endh := uint16(xs.MustGetInt("kCBMsgArgServiceEndHandle"))
- svcs = append(svcs, &Service{uuid: u, h: h, endh: endh})
- }
- p.svcs = svcs
- return svcs, nil
-}
-
-func (p *peripheral) DiscoverIncludedServices(ss []UUID, s *Service) ([]*Service, error) {
- rsp := p.sendReq(60, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgServiceStartHandle": s.h,
- "kCBMsgArgServiceEndHandle": s.endh,
- "kCBMsgArgUUIDs": uuidSlice(ss),
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return nil, attEcode(res)
- }
- // TODO
- return nil, notImplemented
-}
-
-func (p *peripheral) DiscoverCharacteristics(cs []UUID, s *Service) ([]*Characteristic, error) {
- rsp := p.sendReq(62, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgServiceStartHandle": s.h,
- "kCBMsgArgServiceEndHandle": s.endh,
- "kCBMsgArgUUIDs": uuidSlice(cs),
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return nil, attEcode(res)
- }
- for _, xcs := range rsp.MustGetArray("kCBMsgArgCharacteristics") {
- xc := xcs.(xpc.Dict)
- u := MustParseUUID(xc.MustGetHexBytes("kCBMsgArgUUID"))
- ch := uint16(xc.MustGetInt("kCBMsgArgCharacteristicHandle"))
- vh := uint16(xc.MustGetInt("kCBMsgArgCharacteristicValueHandle"))
- props := Property(xc.MustGetInt("kCBMsgArgCharacteristicProperties"))
- c := &Characteristic{uuid: u, svc: s, props: props, h: ch, vh: vh}
- s.chars = append(s.chars, c)
- }
- return s.chars, nil
-}
-
-func (p *peripheral) DiscoverDescriptors(ds []UUID, c *Characteristic) ([]*Descriptor, error) {
- rsp := p.sendReq(70, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgCharacteristicHandle": c.h,
- "kCBMsgArgCharacteristicValueHandle": c.vh,
- "kCBMsgArgUUIDs": uuidSlice(ds),
- })
- for _, xds := range rsp.MustGetArray("kCBMsgArgDescriptors") {
- xd := xds.(xpc.Dict)
- u := MustParseUUID(xd.MustGetHexBytes("kCBMsgArgUUID"))
- h := uint16(xd.MustGetInt("kCBMsgArgDescriptorHandle"))
- d := &Descriptor{uuid: u, char: c, h: h}
- c.descs = append(c.descs, d)
- }
- return c.descs, nil
-}
-
-func (p *peripheral) ReadCharacteristic(c *Characteristic) ([]byte, error) {
- rsp := p.sendReq(65, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgCharacteristicHandle": c.h,
- "kCBMsgArgCharacteristicValueHandle": c.vh,
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return nil, attEcode(res)
- }
- b := rsp.MustGetBytes("kCBMsgArgData")
- return b, nil
-}
-
-func (p *peripheral) ReadLongCharacteristic(c *Characteristic) ([]byte, error) {
- return nil, errors.New("Not implemented")
-}
-
-func (p *peripheral) WriteCharacteristic(c *Characteristic, b []byte, noRsp bool) error {
- args := xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgCharacteristicHandle": c.h,
- "kCBMsgArgCharacteristicValueHandle": c.vh,
- "kCBMsgArgData": b,
- "kCBMsgArgType": map[bool]int{false: 0, true: 1}[noRsp],
- }
- if noRsp {
- p.sendCmd(66, args)
- return nil
- }
- rsp := p.sendReq(65, args)
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return attEcode(res)
- }
- return nil
-}
-
-func (p *peripheral) ReadDescriptor(d *Descriptor) ([]byte, error) {
- rsp := p.sendReq(77, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgDescriptorHandle": d.h,
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return nil, attEcode(res)
- }
- b := rsp.MustGetBytes("kCBMsgArgData")
- return b, nil
-}
-
-func (p *peripheral) WriteDescriptor(d *Descriptor, b []byte) error {
- rsp := p.sendReq(78, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgDescriptorHandle": d.h,
- "kCBMsgArgData": b,
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return attEcode(res)
- }
- return nil
-}
-
-func (p *peripheral) SetNotifyValue(c *Characteristic, f func(*Characteristic, []byte, error)) error {
- set := 1
- if f == nil {
- set = 0
- }
- // To avoid race condition, registeration is handled before requesting the server.
- if f != nil {
- // Note: when notified, core bluetooth reports characteristic handle, not value's handle.
- p.sub.subscribe(c.h, func(b []byte, err error) { f(c, b, err) })
- }
- rsp := p.sendReq(68, xpc.Dict{
- "kCBMsgArgDeviceUUID": p.id,
- "kCBMsgArgCharacteristicHandle": c.h,
- "kCBMsgArgCharacteristicValueHandle": c.vh,
- "kCBMsgArgState": set,
- })
- if res := rsp.MustGetInt("kCBMsgArgResult"); res != 0 {
- return attEcode(res)
- }
- // To avoid race condition, unregisteration is handled after server responses.
- if f == nil {
- p.sub.unsubscribe(c.h)
- }
- return nil
-}
-
-func (p *peripheral) SetIndicateValue(c *Characteristic,
- f func(*Characteristic, []byte, error)) error {
- // TODO: Implement set indications logic for darwin (https://github.com/runtimeinc/gatt/issues/32)
- return nil
-}
-
-func (p *peripheral) ReadRSSI() int {
- rsp := p.sendReq(43, xpc.Dict{"kCBMsgArgDeviceUUID": p.id})
- return rsp.MustGetInt("kCBMsgArgData")
-}
-
-func (p *peripheral) SetMTU(mtu uint16) error {
- return errors.New("Not implemented")
-}
-
-func uuidSlice(uu []UUID) [][]byte {
- us := [][]byte{}
- for _, u := range uu {
- us = append(us, reverse(u.b))
- }
- return us
-}
-
-type message struct {
- id int
- args xpc.Dict
- rspc chan xpc.Dict
-}
-
-func (p *peripheral) sendCmd(id int, args xpc.Dict) {
- p.reqc <- message{id: id, args: args}
-}
-
-func (p *peripheral) sendReq(id int, args xpc.Dict) xpc.Dict {
- m := message{id: id, args: args, rspc: make(chan xpc.Dict)}
- p.reqc <- m
- return <-m.rspc
-}
-
-func (p *peripheral) loop() {
- rspc := make(chan message)
-
- go func() {
- for {
- select {
- case req := <-p.reqc:
- p.d.sendCBMsg(req.id, req.args)
- if req.rspc == nil {
- break
- }
- m := <-rspc
- req.rspc <- m.args
- case <-p.quitc:
- return
- }
- }
- }()
-
- for {
- select {
- case rsp := <-p.rspc:
- // Notification
- if rsp.id == 71 && rsp.args.GetInt("kCBMsgArgIsNotification", 0) != 0 {
- // While we're notified with the value's handle, blued reports the characteristic handle.
- ch := uint16(rsp.args.MustGetInt("kCBMsgArgCharacteristicHandle"))
- b := rsp.args.MustGetBytes("kCBMsgArgData")
- f := p.sub.fn(ch)
- if f == nil {
- log.Printf("notified by unsubscribed handle")
- // FIXME: should terminate the connection?
- } else {
- go f(b, nil)
- }
- break
- }
- rspc <- rsp
- case <-p.quitc:
- return
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_linux.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_linux.go b/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_linux.go
deleted file mode 100644
index a8a819c..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/peripheral_linux.go
+++ /dev/null
@@ -1,448 +0,0 @@
-package gatt
-
-import (
- "bytes"
- "encoding/binary"
- "fmt"
- "io"
- "log"
- "net"
- "strings"
-
- "github.com/runtimeinc/gatt/linux"
-)
-
-type peripheral struct {
- // NameChanged is called whenever the peripheral GAP device name has changed.
- NameChanged func(*peripheral)
-
- // ServicedModified is called when one or more service of a peripheral have changed.
- // A list of invalid service is provided in the parameter.
- ServicesModified func(*peripheral, []*Service)
-
- d *device
- svcs []*Service
-
- sub *subscriber
-
- mtu uint16
- l2c io.ReadWriteCloser
-
- reqc chan message
- quitc chan struct{}
-
- pd *linux.PlatData // platform specific data
-}
-
-func (p *peripheral) Device() Device { return p.d }
-func (p *peripheral) ID() string { return strings.ToUpper(net.HardwareAddr(p.pd.Address[:]).String()) }
-func (p *peripheral) Name() string { return p.pd.Name }
-func (p *peripheral) Services() []*Service { return p.svcs }
-
-func finish(op byte, h uint16, b []byte) bool {
- done := b[0] == attOpError && b[1] == op && b[2] == byte(h) && b[3] == byte(h>>8)
- e := attEcode(b[4])
- if e != attEcodeAttrNotFound {
- // log.Printf("unexpected protocol error: %s", e)
- // FIXME: terminate the connection
- }
- return done
-}
-
-func (p *peripheral) DiscoverServices(s []UUID) ([]*Service, error) {
- // TODO: implement the UUID filters
- // p.pd.Conn.Write([]byte{0x02, 0x87, 0x00}) // MTU
- done := false
- start := uint16(0x0001)
- for !done {
- op := byte(attOpReadByGroupReq)
- b := make([]byte, 7)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], start)
- binary.LittleEndian.PutUint16(b[3:5], 0xFFFF)
- binary.LittleEndian.PutUint16(b[5:7], 0x2800)
-
- b = p.sendReq(op, b)
- if finish(op, start, b) {
- break
- }
- b = b[1:]
- l, b := int(b[0]), b[1:]
- switch {
- case l == 6 && (len(b)%6 == 0):
- case l == 20 && (len(b)%20 == 0):
- default:
- return nil, ErrInvalidLength
- }
-
- for len(b) != 0 {
- h := binary.LittleEndian.Uint16(b[:2])
- endh := binary.LittleEndian.Uint16(b[2:4])
- s := &Service{
- uuid: UUID{b[4:l]},
- h: h,
- endh: endh,
- }
- p.svcs = append(p.svcs, s)
- b = b[l:]
- done = endh == 0xFFFF
- start = endh + 1
- }
- }
- return p.svcs, nil
-}
-
-func (p *peripheral) DiscoverIncludedServices(ss []UUID, s *Service) ([]*Service, error) {
- // TODO
- return nil, nil
-}
-
-func (p *peripheral) DiscoverCharacteristics(cs []UUID, s *Service) ([]*Characteristic, error) {
- // TODO: implement the UUID filters
- done := false
- start := s.h
- var prev *Characteristic
- for !done {
- op := byte(attOpReadByTypeReq)
- b := make([]byte, 7)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], start)
- binary.LittleEndian.PutUint16(b[3:5], s.endh)
- binary.LittleEndian.PutUint16(b[5:7], 0x2803)
-
- b = p.sendReq(op, b)
- if finish(op, start, b) {
- break
- }
- b = b[1:]
-
- l, b := int(b[0]), b[1:]
- switch {
- case l == 7 && (len(b)%7 == 0):
- case l == 21 && (len(b)%21 == 0):
- default:
- return nil, ErrInvalidLength
- }
-
- for len(b) != 0 {
- h := binary.LittleEndian.Uint16(b[:2])
- props := Property(b[2])
- vh := binary.LittleEndian.Uint16(b[3:5])
- u := UUID{b[5:l]}
- s := searchService(p.svcs, h, vh)
- if s == nil {
- log.Printf("Can't find service range that contains 0x%04X - 0x%04X", h, vh)
- return nil, fmt.Errorf("Can't find service range that contains 0x%04X - 0x%04X", h, vh)
- }
- c := &Characteristic{
- uuid: u,
- svc: s,
- props: props,
- h: h,
- vh: vh,
- }
- s.chars = append(s.chars, c)
- b = b[l:]
- done = vh == s.endh
- start = vh + 1
- if prev != nil {
- prev.endh = c.h - 1
- }
- prev = c
- }
- }
- if len(s.chars) > 1 {
- s.chars[len(s.chars)-1].endh = s.endh
- }
- return s.chars, nil
-}
-
-func (p *peripheral) DiscoverDescriptors(ds []UUID, c *Characteristic) ([]*Descriptor, error) {
- // TODO: implement the UUID filters
- done := false
- start := c.vh + 1
- for !done {
- if c.endh == 0 {
- c.endh = c.svc.endh
- }
- op := byte(attOpFindInfoReq)
- b := make([]byte, 5)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], start)
- binary.LittleEndian.PutUint16(b[3:5], c.endh)
-
- b = p.sendReq(op, b)
- if finish(attOpFindInfoReq, start, b) {
- break
- }
- b = b[1:]
-
- var l int
- f, b := int(b[0]), b[1:]
- switch {
- case f == 1 && (len(b)%4 == 0):
- l = 4
- case f == 2 && (len(b)%18 == 0):
- l = 18
- default:
- return nil, ErrInvalidLength
- }
-
- for len(b) != 0 {
- h := binary.LittleEndian.Uint16(b[:2])
- u := UUID{b[2:l]}
- d := &Descriptor{uuid: u, h: h, char: c}
- c.descs = append(c.descs, d)
- if u.Equal(attrClientCharacteristicConfigUUID) {
- c.cccd = d
- }
- b = b[l:]
- done = h == c.endh
- start = h + 1
- }
- }
- return c.descs, nil
-}
-
-func (p *peripheral) ReadCharacteristic(c *Characteristic) ([]byte, error) {
- b := make([]byte, 3)
- op := byte(attOpReadReq)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], c.vh)
-
- b = p.sendReq(op, b)
- b = b[1:]
- return b, nil
-}
-
-func (p *peripheral) ReadLongCharacteristic(c *Characteristic) ([]byte, error) {
- // The spec says that a read blob request should fail if the characteristic
- // is smaller than mtu - 1. To simplify the API, the first read is done
- // with a regular read request. If the buffer received is equal to mtu -1,
- // then we read the rest of the data using read blob.
- firstRead, err := p.ReadCharacteristic(c)
- if err != nil {
- return nil, err
- }
- if len(firstRead) < int(p.mtu)-1 {
- return firstRead, nil
- }
-
- var buf bytes.Buffer
- buf.Write(firstRead)
- off := uint16(len(firstRead))
- for {
- b := make([]byte, 5)
- op := byte(attOpReadBlobReq)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], c.vh)
- binary.LittleEndian.PutUint16(b[3:5], off)
-
- b = p.sendReq(op, b)
- b = b[1:]
- if len(b) == 0 {
- break
- }
- buf.Write(b)
- off += uint16(len(b))
- if len(b) < int(p.mtu)-1 {
- break
- }
- }
- return buf.Bytes(), nil
-}
-
-func (p *peripheral) WriteCharacteristic(c *Characteristic, value []byte, noRsp bool) error {
- b := make([]byte, 3+len(value))
- op := byte(attOpWriteReq)
- b[0] = op
- if noRsp {
- b[0] = attOpWriteCmd
- }
- binary.LittleEndian.PutUint16(b[1:3], c.vh)
- copy(b[3:], value)
-
- if noRsp {
- p.sendCmd(op, b)
- return nil
- }
- b = p.sendReq(op, b)
- // TODO: error handling
- b = b[1:]
- return nil
-}
-
-func (p *peripheral) ReadDescriptor(d *Descriptor) ([]byte, error) {
- b := make([]byte, 3)
- op := byte(attOpReadReq)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], d.h)
-
- b = p.sendReq(op, b)
- b = b[1:]
- // TODO: error handling
- return b, nil
-}
-
-func (p *peripheral) WriteDescriptor(d *Descriptor, value []byte) error {
- b := make([]byte, 3+len(value))
- op := byte(attOpWriteReq)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], d.h)
- copy(b[3:], value)
-
- b = p.sendReq(op, b)
- b = b[1:]
- // TODO: error handling
- return nil
-}
-
-func (p *peripheral) setNotifyValue(c *Characteristic, flag uint16,
- f func(*Characteristic, []byte, error)) error {
-/*
- if c.cccd == nil {
- return errors.New("no cccd") // FIXME
- }
- ccc := uint16(0)
- if f != nil {
- ccc = flag
-*/
- p.sub.subscribe(c.vh, func(b []byte, err error) { f(c, b, err) })
-/*
- }
- b := make([]byte, 5)
- op := byte(attOpWriteReq)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], c.cccd.h)
- binary.LittleEndian.PutUint16(b[3:5], ccc)
-
- b = p.sendReq(op, b)
- b = b[1:]
- // TODO: error handling
- if f == nil {
- p.sub.unsubscribe(c.vh)
- }
-*/
- return nil
-}
-
-func (p *peripheral) SetNotifyValue(c *Characteristic,
- f func(*Characteristic, []byte, error)) error {
- return p.setNotifyValue(c, gattCCCNotifyFlag, f)
-}
-
-func (p *peripheral) SetIndicateValue(c *Characteristic,
- f func(*Characteristic, []byte, error)) error {
- return p.setNotifyValue(c, gattCCCIndicateFlag, f)
-}
-
-func (p *peripheral) ReadRSSI() int {
- // TODO: implement
- return -1
-}
-
-func searchService(ss []*Service, start, end uint16) *Service {
- for _, s := range ss {
- if s.h < start && s.endh >= end {
- return s
- }
- }
- return nil
-}
-
-// TODO: unifiy the message with OS X pots and refactor
-type message struct {
- op byte
- b []byte
- rspc chan []byte
-}
-
-func (p *peripheral) sendCmd(op byte, b []byte) {
- p.reqc <- message{op: op, b: b}
-}
-
-func (p *peripheral) sendReq(op byte, b []byte) []byte {
- m := message{op: op, b: b, rspc: make(chan []byte)}
- p.reqc <- m
- return <-m.rspc
-}
-
-func (p *peripheral) loop() {
- // Serialize the request.
- rspc := make(chan []byte)
-
- // Dequeue request loop
- go func() {
- for {
- select {
- case req := <-p.reqc:
- p.l2c.Write(req.b)
- if req.rspc == nil {
- break
- }
- r := <-rspc
- switch reqOp, rspOp := req.b[0], r[0]; {
- case rspOp == attRspFor[reqOp]:
- case rspOp == attOpError && r[1] == reqOp:
- default:
- log.Printf("Request 0x%02x got a mismatched response: 0x%02x", reqOp, rspOp)
- // FIXME: terminate the connection?
- }
- req.rspc <- r
- case <-p.quitc:
- return
- }
- }
- }()
-
- // L2CAP implementations shall support a minimum MTU size of 48 bytes.
- // The default value is 672 bytes
- buf := make([]byte, 672)
-
- // Handling response or notification/indication
- for {
- n, err := p.l2c.Read(buf)
- if n == 0 || err != nil {
- close(p.quitc)
- return
- }
-
- b := make([]byte, n)
- copy(b, buf)
-
- if (b[0] != attOpHandleNotify) && (b[0] != attOpHandleInd) {
- rspc <- b
- continue
- }
-
- h := binary.LittleEndian.Uint16(b[1:3])
- f := p.sub.fn(h)
- if f == nil {
- log.Printf("notified by unsubscribed handle")
- // FIXME: terminate the connection?
- } else {
- go f(b[3:], nil)
- }
-
- if b[0] == attOpHandleInd {
- // write aknowledgement for indication
- p.l2c.Write([]byte{attOpHandleCnf})
- }
-
- }
-}
-
-func (p *peripheral) SetMTU(mtu uint16) error {
- b := make([]byte, 3)
- op := byte(attOpMtuReq)
- b[0] = op
- binary.LittleEndian.PutUint16(b[1:3], uint16(mtu))
-
- b = p.sendReq(op, b)
- serverMTU := binary.LittleEndian.Uint16(b[1:3])
- if serverMTU < mtu {
- mtu = serverMTU
- }
- p.mtu = mtu
- return nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/readme.md
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/readme.md b/newtmgr/vendor/github.com/runtimeinc/gatt/readme.md
deleted file mode 100644
index ea3a957..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/readme.md
+++ /dev/null
@@ -1,115 +0,0 @@
-# Package gatt provides a Bluetooth Low Energy GATT implementation.
-
-Gatt (Generic Attribute Profile) is the protocol used to write BLE peripherals (servers) and centrals (clients).
-
-As a peripheral, you can create services, characteristics, and descriptors,
-advertise, accept connections, and handle requests.
-
-As a central, you can scan, connect, discover services, and make requests.
-
-## SETUP
-
-### gatt supports both Linux and OS X.
-
-### On Linux:
-To gain complete and exclusive control of the HCI device, gatt uses
-HCI_CHANNEL_USER (introduced in Linux v3.14) instead of HCI_CHANNEL_RAW.
-Those who must use an older kernel may patch in these relevant commits
-from Marcel Holtmann:
-
- Bluetooth: Introduce new HCI socket channel for user operation
- Bluetooth: Introduce user channel flag for HCI devices
- Bluetooth: Refactor raw socket filter into more readable code
-
-Note that because gatt uses HCI_CHANNEL_USER, once gatt has opened the
-device no other program may access it.
-
-Before starting a gatt program, make sure that your BLE device is down:
-
- sudo hciconfig
- sudo hciconfig hci0 down # or whatever hci device you want to use
-
-If you have BlueZ 5.14+ (or aren't sure), stop the built-in
-bluetooth server, which interferes with gatt, e.g.:
-
- sudo service bluetooth stop
-
-Because gatt programs administer network devices, they must
-either be run as root, or be granted appropriate capabilities:
-
- sudo <executable>
- # OR
- sudo setcap 'cap_net_raw,cap_net_admin=eip' <executable>
- <executable>
-
-## Usage
-Please see [godoc.org](http://godoc.org/github.com/paypal/gatt) for documentation.
-
-## Examples
-
-### Build and run the examples on a native environment (Linux or OS X)
-
-Go is a compiled language, which means to run the examples you need to build them first.
-
- # Build the sample server.
- go build examples/server.go
- # Start the sample server.
- sudo ./server
-
-Alternatively, you can use "go run" to build and run the examples in a single step:
-
- # Build and run the sample server.
- sudo go run examples/server.go
-
-Discoverer and explorer demonstrates central (client) functions:
-
- # Discover surrounding peripherals.
- sudo go run examples/discoverer.go
-
- # Connect to and explorer a peripheral device.
- sudo go run examples/explorer.go <peripheral ID>
-
-### Cross-compile and deploy to a target device
-
- # Build and run the server example on a ARMv5 target device.
- GOARCH=arm GOARM=5 GOOS=linux go build examples/server.go
- cp server <target device>
- # Start the server on the target device
- sudo ./server
-
-See the server.go, discoverer.go, and explorer.go in the examples/
-directory for writing server or client programs that run on Linux
-and OS X.
-
-Users, especially on Linux platforms, seeking finer-grained control
-over the devices can see the examples/server_lnx.go for the usage
-of Option, which are platform specific.
-
-See the rest of the docs for other options and finer-grained control.
-
-## Note
-Note that some BLE central devices, particularly iOS, may aggressively
-cache results from previous connections. If you change your services or
-characteristics, you may need to reboot the other device to pick up the
-changes. This is a common source of confusion and apparent bugs. For an
-OS X central, see http://stackoverflow.com/questions/20553957.
-
-## Known Issues
-
-Currently OS X vesion does not support subscribing to indications.
-Please check [#32](https://github.com/paypal/gatt/issues/32) for the status of this issue.
-
-## REFERENCES
-
-gatt started life as a port of bleno, to which it is indebted:
-https://github.com/sandeepmistry/bleno. If you are having
-problems with gatt, particularly around installation, issues
-filed with bleno might also be helpful references.
-
-To try out your GATT server, it is useful to experiment with a
-generic BLE client. LightBlue is a good choice. It is available
-free for both iOS and OS X.
-
-gatt is similar to [bleno](https://github.com/sandeepmistry/bleno) and [noble](https://github.com/sandeepmistry/noble), which offer BLE GATT implementations for node.js.
-
-Gatt is released under a [BSD-style license](./LICENSE.md).
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/uuid.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/uuid.go b/newtmgr/vendor/github.com/runtimeinc/gatt/uuid.go
deleted file mode 100644
index 393e548..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/uuid.go
+++ /dev/null
@@ -1,86 +0,0 @@
-package gatt
-
-import (
- "bytes"
- "encoding/binary"
- "encoding/hex"
- "fmt"
- "strings"
-)
-
-// A UUID is a BLE UUID.
-type UUID struct {
- // Hide the bytes, so that we can enforce that they have length 2 or 16,
- // and that they are immutable. This simplifies the code and API.
- b []byte
-}
-
-// UUID16 converts a uint16 (such as 0x1800) to a UUID.
-func UUID16(i uint16) UUID {
- b := make([]byte, 2)
- binary.LittleEndian.PutUint16(b, i)
- return UUID{b}
-}
-
-// ParseUUID parses a standard-format UUID string, such
-// as "1800" or "34DA3AD1-7110-41A1-B1EF-4430F509CDE7".
-func ParseUUID(s string) (UUID, error) {
- s = strings.Replace(s, "-", "", -1)
- b, err := hex.DecodeString(s)
- if err != nil {
- return UUID{}, err
- }
- if err := lenErr(len(b)); err != nil {
- return UUID{}, err
- }
- return UUID{reverse(b)}, nil
-}
-
-// MustParseUUID parses a standard-format UUID string,
-// like ParseUUID, but panics in case of error.
-func MustParseUUID(s string) UUID {
- u, err := ParseUUID(s)
- if err != nil {
- panic(err)
- }
- return u
-}
-
-// lenErr returns an error if n is an invalid UUID length.
-func lenErr(n int) error {
- switch n {
- case 2, 16:
- return nil
- }
- return fmt.Errorf("UUIDs must have length 2 or 16, got %d", n)
-}
-
-// Len returns the length of the UUID, in bytes.
-// BLE UUIDs are either 2 or 16 bytes.
-func (u UUID) Len() int {
- return len(u.b)
-}
-
-// String hex-encodes a UUID.
-func (u UUID) String() string {
- return fmt.Sprintf("%x", reverse(u.b))
-}
-
-// Equal returns a boolean reporting whether v represent the same UUID as u.
-func (u UUID) Equal(v UUID) bool {
- return bytes.Equal(u.b, v.b)
-}
-
-// reverse returns a reversed copy of u.
-func reverse(u []byte) []byte {
- // Special-case 16 bit UUIDS for speed.
- l := len(u)
- if l == 2 {
- return []byte{u[1], u[0]}
- }
- b := make([]byte, l)
- for i := 0; i < l/2+1; i++ {
- b[i], b[l-i-1] = u[l-i-1], u[i]
- }
- return b
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/LICENSE b/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/LICENSE
deleted file mode 100644
index 766a0a5..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) {{{year}}} {{{fullname}}}
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/doc.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/doc.go b/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/doc.go
deleted file mode 100644
index d292249..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/doc.go
+++ /dev/null
@@ -1,8 +0,0 @@
-// Package xpc provides minimal OS X XPC support required for gatt
-//
-// This is adapted from [goble], by Raffaele Sena.
-//
-// http://godoc.org/github.com/raff/goble
-// https://github.com/raff/goble
-
-package xpc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_darwin.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_darwin.go b/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_darwin.go
deleted file mode 100644
index 2a85a99..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_darwin.go
+++ /dev/null
@@ -1,350 +0,0 @@
-package xpc
-
-/*
-#include "xpc_wrapper_darwin.h"
-#include "sys/utsname.h"
-*/
-import "C"
-
-import (
- "errors"
- "fmt"
- "log"
- r "reflect"
- "unsafe"
-)
-
-type XPC struct {
- conn C.xpc_connection_t
-}
-
-func (x *XPC) Send(msg interface{}, verbose bool) {
- // verbose == true converts the type from bool to C._Bool
- C.XpcSendMessage(x.conn, goToXpc(msg), true, verbose == true)
-}
-
-//
-// minimal XPC support required for BLE
-//
-
-// a dictionary of things
-type Dict map[string]interface{}
-
-func (d Dict) Contains(k string) bool {
- _, ok := d[k]
- return ok
-}
-
-func (d Dict) MustGetDict(k string) Dict {
- return d[k].(Dict)
-}
-
-func (d Dict) MustGetArray(k string) Array {
- return d[k].(Array)
-}
-
-func (d Dict) MustGetBytes(k string) []byte {
- return d[k].([]byte)
-}
-
-func (d Dict) MustGetHexBytes(k string) string {
- return fmt.Sprintf("%x", d[k].([]byte))
-}
-
-func (d Dict) MustGetInt(k string) int {
- return int(d[k].(int64))
-}
-
-func (d Dict) MustGetUUID(k string) []byte {
- u := d[k].(UUID)
- return u[:]
-}
-
-func (d Dict) GetString(k, defv string) string {
- if v := d[k]; v != nil {
- //log.Printf("GetString %s %#v\n", k, v)
- return v.(string)
- } else {
- //log.Printf("GetString %s default %#v\n", k, defv)
- return defv
- }
-}
-
-func (d Dict) GetBytes(k string, defv []byte) []byte {
- if v := d[k]; v != nil {
- //log.Printf("GetBytes %s %#v\n", k, v)
- return v.([]byte)
- } else {
- //log.Printf("GetBytes %s default %#v\n", k, defv)
- return defv
- }
-}
-
-func (d Dict) GetInt(k string, defv int) int {
- if v := d[k]; v != nil {
- //log.Printf("GetString %s %#v\n", k, v)
- return int(v.(int64))
- } else {
- //log.Printf("GetString %s default %#v\n", k, defv)
- return defv
- }
-}
-
-func (d Dict) GetUUID(k string) UUID {
- return GetUUID(d[k])
-}
-
-// an array of things
-type Array []interface{}
-
-func (a Array) GetUUID(k int) UUID {
- return GetUUID(a[k])
-}
-
-// a UUID
-type UUID []byte
-
-func MakeUUID(s string) UUID {
- var sl []byte
- fmt.Sscanf(s, "%32x", &sl)
-
- var uuid [16]byte
- copy(uuid[:], sl)
- return UUID(uuid[:])
-}
-
-func (uuid UUID) String() string {
- return fmt.Sprintf("%x", []byte(uuid))
-}
-
-func GetUUID(v interface{}) UUID {
- if v == nil {
- return UUID{}
- }
-
- if uuid, ok := v.(UUID); ok {
- return uuid
- }
-
- if bytes, ok := v.([]byte); ok {
- uuid := UUID{}
-
- for i, b := range bytes {
- uuid[i] = b
- }
-
- return uuid
- }
-
- if bytes, ok := v.([]uint8); ok {
- uuid := UUID{}
-
- for i, b := range bytes {
- uuid[i] = b
- }
-
- return uuid
- }
-
- log.Fatalf("invalid type for UUID: %#v", v)
- return UUID{}
-}
-
-var (
- CONNECTION_INVALID = errors.New("connection invalid")
- CONNECTION_INTERRUPTED = errors.New("connection interrupted")
- CONNECTION_TERMINATED = errors.New("connection terminated")
-
- TYPE_OF_UUID = r.TypeOf(UUID{})
- TYPE_OF_BYTES = r.TypeOf([]byte{})
-)
-
-type XpcEventHandler interface {
- HandleXpcEvent(event Dict, err error)
-}
-
-func XpcConnect(service string, eh XpcEventHandler) XPC {
- cservice := C.CString(service)
- defer C.free(unsafe.Pointer(cservice))
- return XPC{conn: C.XpcConnect(cservice, unsafe.Pointer(&eh))}
-}
-
-//export handleXpcEvent
-func handleXpcEvent(event C.xpc_object_t, p unsafe.Pointer) {
- //log.Printf("handleXpcEvent %#v %#v\n", event, p)
-
- t := C.xpc_get_type(event)
- eh := *((*XpcEventHandler)(p))
-
- if t == C.TYPE_ERROR {
- if event == C.ERROR_CONNECTION_INVALID {
- // The client process on the other end of the connection has either
- // crashed or cancelled the connection. After receiving this error,
- // the connection is in an invalid state, and you do not need to
- // call xpc_connection_cancel(). Just tear down any associated state
- // here.
- //log.Println("connection invalid")
- eh.HandleXpcEvent(nil, CONNECTION_INVALID)
- } else if event == C.ERROR_CONNECTION_INTERRUPTED {
- //log.Println("connection interrupted")
- eh.HandleXpcEvent(nil, CONNECTION_INTERRUPTED)
- } else if event == C.ERROR_CONNECTION_TERMINATED {
- // Handle per-connection termination cleanup.
- //log.Println("connection terminated")
- eh.HandleXpcEvent(nil, CONNECTION_TERMINATED)
- } else {
- //log.Println("got some error", event)
- eh.HandleXpcEvent(nil, fmt.Errorf("%v", event))
- }
- } else {
- eh.HandleXpcEvent(xpcToGo(event).(Dict), nil)
- }
-}
-
-// goToXpc converts a go object to an xpc object
-func goToXpc(o interface{}) C.xpc_object_t {
- return valueToXpc(r.ValueOf(o))
-}
-
-// valueToXpc converts a go Value to an xpc object
-//
-// note that not all the types are supported, but only the subset required for Blued
-func valueToXpc(val r.Value) C.xpc_object_t {
- if !val.IsValid() {
- return nil
- }
-
- var xv C.xpc_object_t
-
- switch val.Kind() {
- case r.Int, r.Int8, r.Int16, r.Int32, r.Int64:
- xv = C.xpc_int64_create(C.int64_t(val.Int()))
-
- case r.Uint, r.Uint8, r.Uint16, r.Uint32:
- xv = C.xpc_int64_create(C.int64_t(val.Uint()))
-
- case r.String:
- xv = C.xpc_string_create(C.CString(val.String()))
-
- case r.Map:
- xv = C.xpc_dictionary_create(nil, nil, 0)
- for _, k := range val.MapKeys() {
- v := valueToXpc(val.MapIndex(k))
- C.xpc_dictionary_set_value(xv, C.CString(k.String()), v)
- if v != nil {
- C.xpc_release(v)
- }
- }
-
- case r.Array, r.Slice:
- if val.Type() == TYPE_OF_UUID {
- // array of bytes
- var uuid [16]byte
- r.Copy(r.ValueOf(uuid[:]), val)
- xv = C.xpc_uuid_create(C.ptr_to_uuid(unsafe.Pointer(&uuid[0])))
- } else if val.Type() == TYPE_OF_BYTES {
- // slice of bytes
- xv = C.xpc_data_create(unsafe.Pointer(val.Pointer()), C.size_t(val.Len()))
- } else {
- xv = C.xpc_array_create(nil, 0)
- l := val.Len()
-
- for i := 0; i < l; i++ {
- v := valueToXpc(val.Index(i))
- C.xpc_array_append_value(xv, v)
- if v != nil {
- C.xpc_release(v)
- }
- }
- }
-
- case r.Interface, r.Ptr:
- xv = valueToXpc(val.Elem())
-
- default:
- log.Fatalf("unsupported %#v", val.String())
- }
-
- return xv
-}
-
-//export arraySet
-func arraySet(u unsafe.Pointer, i C.int, v C.xpc_object_t) {
- a := *(*Array)(u)
- a[i] = xpcToGo(v)
-}
-
-//export dictSet
-func dictSet(u unsafe.Pointer, k *C.char, v C.xpc_object_t) {
- d := *(*Dict)(u)
- d[C.GoString(k)] = xpcToGo(v)
-}
-
-// xpcToGo converts an xpc object to a go object
-//
-// note that not all the types are supported, but only the subset required for Blued
-func xpcToGo(v C.xpc_object_t) interface{} {
- t := C.xpc_get_type(v)
-
- switch t {
- case C.TYPE_ARRAY:
- a := make(Array, C.int(C.xpc_array_get_count(v)))
- C.XpcArrayApply(unsafe.Pointer(&a), v)
- return a
-
- case C.TYPE_DATA:
- return C.GoBytes(C.xpc_data_get_bytes_ptr(v), C.int(C.xpc_data_get_length(v)))
-
- case C.TYPE_DICT:
- d := make(Dict)
- C.XpcDictApply(unsafe.Pointer(&d), v)
- return d
-
- case C.TYPE_INT64:
- return int64(C.xpc_int64_get_value(v))
-
- case C.TYPE_STRING:
- return C.GoString(C.xpc_string_get_string_ptr(v))
-
- case C.TYPE_UUID:
- a := [16]byte{}
- C.XpcUUIDGetBytes(unsafe.Pointer(&a), v)
- return UUID(a[:])
-
- default:
- log.Fatalf("unexpected type %#v, value %#v", t, v)
- }
-
- return nil
-}
-
-// xpc_release is needed by tests, since they can't use CGO
-func xpc_release(xv C.xpc_object_t) {
- C.xpc_release(xv)
-}
-
-// this is used to check the OS version
-
-type Utsname struct {
- Sysname string
- Nodename string
- Release string
- Version string
- Machine string
-}
-
-func Uname(utsname *Utsname) error {
- var cstruct C.struct_utsname
- if err := C.uname(&cstruct); err != 0 {
- return errors.New("utsname error")
- }
-
- // XXX: this may crash if any value is exactly 256 characters (no 0 terminator)
- utsname.Sysname = C.GoString(&cstruct.sysname[0])
- utsname.Nodename = C.GoString(&cstruct.nodename[0])
- utsname.Release = C.GoString(&cstruct.release[0])
- utsname.Version = C.GoString(&cstruct.version[0])
- utsname.Machine = C.GoString(&cstruct.machine[0])
-
- return nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.c
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.c b/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.c
deleted file mode 100644
index 7bcb83d..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.c
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <dispatch/dispatch.h>
-#include <xpc/xpc.h>
-#include <xpc/connection.h>
-#include <Block.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "_cgo_export.h"
-
-//
-// types and errors are implemented as macros
-// create some real objects to make them accessible to Go
-//
-xpc_type_t TYPE_ERROR = XPC_TYPE_ERROR;
-
-xpc_type_t TYPE_ARRAY = XPC_TYPE_ARRAY;
-xpc_type_t TYPE_DATA = XPC_TYPE_DATA;
-xpc_type_t TYPE_DICT = XPC_TYPE_DICTIONARY;
-xpc_type_t TYPE_INT64 = XPC_TYPE_INT64;
-xpc_type_t TYPE_STRING = XPC_TYPE_STRING;
-xpc_type_t TYPE_UUID = XPC_TYPE_UUID;
-
-xpc_object_t ERROR_CONNECTION_INVALID = (xpc_object_t) XPC_ERROR_CONNECTION_INVALID;
-xpc_object_t ERROR_CONNECTION_INTERRUPTED = (xpc_object_t) XPC_ERROR_CONNECTION_INTERRUPTED;
-xpc_object_t ERROR_CONNECTION_TERMINATED = (xpc_object_t) XPC_ERROR_TERMINATION_IMMINENT;
-
-const ptr_to_uuid_t ptr_to_uuid(void *p) { return (ptr_to_uuid_t)p; }
-
-
-//
-// connect to XPC service
-//
-xpc_connection_t XpcConnect(char *service, void *ctx) {
- dispatch_queue_t queue = dispatch_queue_create(service, 0);
- xpc_connection_t conn = xpc_connection_create_mach_service(service, queue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);
-
- // making a local copy, that should be made "persistent" with the following Block_copy
- GoInterface ictx = *((GoInterface*)ctx);
-
- xpc_connection_set_event_handler(conn,
- Block_copy(^(xpc_object_t event) {
- handleXpcEvent(event, (void *)&ictx);
- })
- );
-
- xpc_connection_resume(conn);
- return conn;
-}
-
-void XpcSendMessage(xpc_connection_t conn, xpc_object_t message, bool release, bool reportDelivery) {
- xpc_connection_send_message(conn, message);
- xpc_connection_send_barrier(conn, ^{
- // Block is invoked on connection's target queue
- // when 'message' has been sent.
- if (reportDelivery) { // maybe this could be a callback
- puts("message delivered");
- }
- });
- if (release) {
- xpc_release(message);
- }
-}
-
-void XpcArrayApply(void *v, xpc_object_t arr) {
- xpc_array_apply(arr, ^bool(size_t index, xpc_object_t value) {
- arraySet(v, index, value);
- return true;
- });
-}
-
-void XpcDictApply(void *v, xpc_object_t dict) {
- xpc_dictionary_apply(dict, ^bool(const char *key, xpc_object_t value) {
- dictSet(v, (char *)key, value);
- return true;
- });
-}
-
-void XpcUUIDGetBytes(void *v, xpc_object_t uuid) {
- const uint8_t *src = xpc_uuid_get_bytes(uuid);
- uint8_t *dest = (uint8_t *)v;
-
- for (int i=0; i < sizeof(uuid_t); i++) {
- dest[i] = src[i];
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/abf65d3a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.h
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.h b/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.h
deleted file mode 100644
index e2cfb5c..0000000
--- a/newtmgr/vendor/github.com/runtimeinc/gatt/xpc/xpc_wrapper_darwin.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef _XPC_WRAPPER_H_
-#define _XPC_WRAPPER_H_
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <xpc/xpc.h>
-
-extern xpc_type_t TYPE_ERROR;
-
-extern xpc_type_t TYPE_ARRAY;
-extern xpc_type_t TYPE_DATA;
-extern xpc_type_t TYPE_DICT;
-extern xpc_type_t TYPE_INT64;
-extern xpc_type_t TYPE_STRING;
-extern xpc_type_t TYPE_UUID;
-
-extern xpc_object_t ERROR_CONNECTION_INVALID;
-extern xpc_object_t ERROR_CONNECTION_INTERRUPTED;
-extern xpc_object_t ERROR_CONNECTION_TERMINATED;
-
-extern xpc_connection_t XpcConnect(char *, void *);
-extern void XpcSendMessage(xpc_connection_t, xpc_object_t, bool, bool);
-extern void XpcArrayApply(void *, xpc_object_t);
-extern void XpcDictApply(void *, xpc_object_t);
-extern void XpcUUIDGetBytes(void *, xpc_object_t);
-
-// the input type for xpc_uuid_create should be uuid_t but CGO instists on unsigned char *
-// typedef uuid_t * ptr_to_uuid_t;
-typedef unsigned char * ptr_to_uuid_t;
-extern const ptr_to_uuid_t ptr_to_uuid(void *p);
-
-#endif