This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git
commit badfa44761ef91da331ce91efe3525de9588edb4 Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Thu Aug 17 17:15:05 2017 -0700 newtmgr - revendor --- newtmgr/Godeps/Godeps.json | 72 +++++++-------- .../newtmgr/nmxact/bledefs/bledefs.go | 10 ++ .../newtmgr/nmxact/nmble/ble_sesn.go | 55 ++++++----- .../mynewt.apache.org/newtmgr/nmxact/nmble/conn.go | 40 ++++---- .../newtmgr/nmxact/nmble/profile.go | 4 + .../newtmgr/nmxact/sesn/sesn_util.go | 2 +- .../mynewt.apache.org/newtmgr/nmxact/xact/res.go | 101 +++++++++++++++++++-- 7 files changed, 199 insertions(+), 85 deletions(-) diff --git a/newtmgr/Godeps/Godeps.json b/newtmgr/Godeps/Godeps.json index 9f98425..bb0fef8 100644 --- a/newtmgr/Godeps/Godeps.json +++ b/newtmgr/Godeps/Godeps.json @@ -107,93 +107,93 @@ }, { "ImportPath": "mynewt.apache.org/newt/util", - "Comment": "mynewt_1_0_1_tag-26-gd70e83c", - "Rev": "d70e83caba3debbd8eff933308d619fe67c51dce" + "Comment": "mynewt_1_0_1_tag-32-g84f53dd", + "Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3" }, { "ImportPath": "mynewt.apache.org/newt/util/unixchild", - "Comment": "mynewt_1_0_1_tag-26-gd70e83c", - "Rev": "d70e83caba3debbd8eff933308d619fe67c51dce" + "Comment": "mynewt_1_0_1_tag-32-g84f53dd", + "Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3" }, { "ImportPath": "mynewt.apache.org/newt/viper", - "Comment": "mynewt_1_0_1_tag-26-gd70e83c", - "Rev": "d70e83caba3debbd8eff933308d619fe67c51dce" + "Comment": "mynewt_1_0_1_tag-32-g84f53dd", + "Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3" }, { "ImportPath": "mynewt.apache.org/newt/yaml", - "Comment": "mynewt_1_0_1_tag-26-gd70e83c", - "Rev": "d70e83caba3debbd8eff933308d619fe67c51dce" + "Comment": "mynewt_1_0_1_tag-32-g84f53dd", + "Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/adv", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/bledefs", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/mgmt", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmble", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmp", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmserial", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmxutil", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/oic", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/omp", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/scan", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/sesn", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/udp", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/xact", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/xport", - "Comment": "mynewt_1_1_0_tag-50-g9bffc58", - "Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29" + "Comment": "mynewt_1_1_0_tag-54-g96f7ef8", + "Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462" } ] } diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go index e6bb5b9..5538681 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go @@ -824,6 +824,16 @@ func (b *BleChrId) String() string { return fmt.Sprintf("s=%s c=%s", b.SvcUuid.String(), b.ChrUuid.String()) } +func CompareChrIds(a BleChrId, b BleChrId) int { + if rc := CompareUuids(a.SvcUuid, b.SvcUuid); rc != 0 { + return rc + } + if rc := CompareUuids(a.ChrUuid, b.ChrUuid); rc != 0 { + return rc + } + return 0 +} + type BleMgmtChrs struct { NmpReqChr *BleChrId NmpRspChr *BleChrId diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go index 31a8173..2355c30 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go @@ -110,6 +110,13 @@ func (s *BleSesn) disconnectListen() { }() } +func (s *BleSesn) errIfClosed() error { + if !s.IsOpen() { + return nmxutil.NewSesnClosedError("Attempt to use closed BLE session") + } + return nil +} + func (s *BleSesn) getChr(chrId *BleChrId) (*Characteristic, error) { if chrId == nil { return nil, fmt.Errorf("BLE session not configured with required " + @@ -133,7 +140,7 @@ func (s *BleSesn) createNotifyListener(chrId *BleChrId) ( return nil, err } - return s.conn.ListenForNotifications(chr), nil + return s.conn.ListenForNotifications(chr) } func (s *BleSesn) notifyListenOnce(chrId *BleChrId, @@ -168,19 +175,16 @@ func (s *BleSesn) notifyListenOnce(chrId *BleChrId, } func (s *BleSesn) notifyListen() { - s.notifyListenOnce(s.mgmtChrs.NmpRspChr, s.txvr.DispatchNmpRsp) s.notifyListenOnce(s.mgmtChrs.ResUnauthRspChr, s.txvr.DispatchCoap) s.notifyListenOnce(s.mgmtChrs.ResSecureRspChr, s.txvr.DispatchCoap) - - // XXX: Don't listen for public resource responses for now; characteristic - // may conflict with newtmgr. - //s.notifyListenOnce(s.mgmtChrs.ResPublicRspChr, s.txvr.DispatchCoap) + s.notifyListenOnce(s.mgmtChrs.ResPublicRspChr, s.txvr.DispatchCoap) + s.notifyListenOnce(s.mgmtChrs.NmpRspChr, s.txvr.DispatchNmpRsp) } func (s *BleSesn) openOnce() (bool, error) { if s.IsOpen() { return false, nmxutil.NewSesnAlreadyOpenError( - "Attempt to open an already-open bll session") + "Attempt to open an already-open BLE session") } if err := s.init(); err != nil { @@ -290,10 +294,27 @@ func (s *BleSesn) EncodeNmpMsg(m *nmp.NmpMsg) ([]byte, error) { return EncodeMgmtMsg(s.cfg.MgmtProto, m) } -// Blocking. +func (s *BleSesn) MtuIn() int { + mtu, _ := MtuIn(s.cfg.MgmtProto, s.conn.AttMtu()) + return mtu +} + +func (s *BleSesn) MtuOut() int { + mtu, _ := MtuOut(s.cfg.MgmtProto, s.conn.AttMtu()) + return mtu +} + +func (s *BleSesn) ConnInfo() (BleConnDesc, error) { + return s.conn.ConnInfo(), nil +} + func (s *BleSesn) TxNmpOnce(req *nmp.NmpMsg, opt sesn.TxOptions) ( nmp.NmpRsp, error) { + if err := s.errIfClosed(); err != nil { + return nil, err + } + chr, err := s.getChr(s.mgmtChrs.NmpReqChr) if err != nil { return nil, err @@ -306,24 +327,14 @@ func (s *BleSesn) TxNmpOnce(req *nmp.NmpMsg, opt sesn.TxOptions) ( return s.txvr.TxNmp(txRaw, req, opt.Timeout) } -func (s *BleSesn) MtuIn() int { - mtu, _ := MtuIn(s.cfg.MgmtProto, s.conn.AttMtu()) - return mtu -} - -func (s *BleSesn) MtuOut() int { - mtu, _ := MtuOut(s.cfg.MgmtProto, s.conn.AttMtu()) - return mtu -} - -func (s *BleSesn) ConnInfo() (BleConnDesc, error) { - return s.conn.ConnInfo(), nil -} - func (s *BleSesn) TxCoapOnce(m coap.Message, resType sesn.ResourceType, opt sesn.TxOptions) (coap.COAPCode, []byte, error) { + if err := s.errIfClosed(); err != nil { + return 0, nil, err + } + chrId := ResChrReqIdLookup(s.mgmtChrs, resType) chr, err := s.getChr(chrId) if err != nil { diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go index 5912d3d..40acaa0 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go @@ -46,7 +46,7 @@ type Conn struct { // Terminates all go routines. Gets set to null after disconnect. stopChan chan struct{} - notifyMap map[*Characteristic][](*NotifyListener) + notifyMap map[*Characteristic]*NotifyListener // Protects: // * connHandle @@ -64,7 +64,7 @@ func NewConn(bx *BleXport) *Conn { attMtu: BLE_ATT_MTU_DFLT, disconnectChan: make(chan error, 1), stopChan: make(chan struct{}), - notifyMap: map[*Characteristic][](*NotifyListener){}, + notifyMap: map[*Characteristic]*NotifyListener{}, } } @@ -88,12 +88,10 @@ func (c *Conn) initiateShutdown() bool { func (c *Conn) abortNotifyListeners(err error) { // No need to lock mutex; this should only be called after all go routines // have terminated. - for _, nls := range c.notifyMap { - for _, nl := range nls { - nl.ErrChan <- err - close(nl.NotifyChan) - close(nl.ErrChan) - } + for _, nl := range c.notifyMap { + nl.ErrChan <- err + close(nl.NotifyChan) + close(nl.ErrChan) } } @@ -201,19 +199,16 @@ func (c *Conn) rxNotify(msg *BleNotifyRxEvt) { return } - nls := c.notifyMap[chr] - if nls == nil { + nl := c.notifyMap[chr] + if nl == nil { return } - n := Notification{ + nl.NotifyChan <- Notification{ Chr: chr, Data: msg.Data.Bytes, Indication: msg.Indication, } - for _, nl := range nls { - nl.NotifyChan <- n - } } // Listens for incoming notifications and indications. @@ -662,17 +657,22 @@ func (c *Conn) Subscribe(chr *Characteristic) error { return c.WriteHandle(dsc.Handle, payload, "subscribe") } -func (c *Conn) ListenForNotifications(chr *Characteristic) *NotifyListener { +func (c *Conn) ListenForNotifications(chr *Characteristic) ( + *NotifyListener, error) { + c.mtx.Lock() defer c.mtx.Unlock() - nl := NewNotifyListener() - slice := c.notifyMap[chr] + if _, ok := c.notifyMap[chr]; ok { + return nil, fmt.Errorf( + "Already listening for notifications on characteristic %s", + chr.String()) + } - slice = append(slice, nl) - c.notifyMap[chr] = slice + nl := NewNotifyListener() + c.notifyMap[chr] = nl - return nl + return nl, nil } func (c *Conn) InitiateSecurity() error { diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go index 0e98740..9db78e9 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go @@ -31,6 +31,10 @@ type Profile struct { attrs map[uint16]*Characteristic } +func (c *Characteristic) String() string { + return c.Uuid.String() +} + func (c *Characteristic) SubscribeType() BleChrFlags { if c.Properties&BLE_GATT_F_NOTIFY != 0 { return BLE_GATT_F_NOTIFY diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go index f7b38c2..26eec86 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go @@ -128,7 +128,7 @@ func PostResource(s Sesn, resType ResourceType, uri string, } func DeleteResource(s Sesn, resType ResourceType, uri string, - value []byte, o TxOptions) (coap.COAPCode, []byte, error) { + o TxOptions) (coap.COAPCode, []byte, error) { return txCoap(func() (coap.COAPCode, []byte, error) { return deleteResourceOnce(s, resType, uri, o) diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go index c9fec2f..f54614a 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go @@ -27,8 +27,8 @@ import ( type GetResCmd struct { CmdBase - Uri string - Typ sesn.ResourceType + Path string + Typ sesn.ResourceType } func NewGetResCmd() *GetResCmd { @@ -55,7 +55,7 @@ func (r *GetResResult) Status() int { } func (c *GetResCmd) Run(s sesn.Sesn) (Result, error) { - status, val, err := sesn.GetResource(s, c.Typ, c.Uri, c.TxOptions()) + status, val, err := sesn.GetResource(s, c.Typ, c.Path, c.TxOptions()) if err != nil { return nil, err } @@ -68,7 +68,7 @@ func (c *GetResCmd) Run(s sesn.Sesn) (Result, error) { type PutResCmd struct { CmdBase - Uri string + Path string Typ sesn.ResourceType Value []byte } @@ -89,7 +89,10 @@ func newPutResResult() *PutResResult { } func (r *PutResResult) Status() int { - if r.Code == coap.Created || r.Code == coap.Changed || r.Code == coap.Content { + if r.Code == coap.Created || + r.Code == coap.Changed || + r.Code == coap.Content { + return 0 } else { return int(r.Code) @@ -97,7 +100,7 @@ func (r *PutResResult) Status() int { } func (c *PutResCmd) Run(s sesn.Sesn) (Result, error) { - status, r, err := sesn.PutResource(s, c.Typ, c.Uri, c.Value, c.TxOptions()) + status, r, err := sesn.PutResource(s, c.Typ, c.Path, c.Value, c.TxOptions()) if err != nil { return nil, err } @@ -107,3 +110,89 @@ func (c *PutResCmd) Run(s sesn.Sesn) (Result, error) { res.Value = r return res, nil } + +type PostResCmd struct { + CmdBase + Path string + Typ sesn.ResourceType + Value []byte +} + +func NewPostResCmd() *PostResCmd { + return &PostResCmd{ + CmdBase: NewCmdBase(), + } +} + +type PostResResult struct { + Code coap.COAPCode + Value []byte +} + +func newPostResResult() *PostResResult { + return &PostResResult{} +} + +func (r *PostResResult) Status() int { + if r.Code == coap.Created || + r.Code == coap.Changed || + r.Code == coap.Content { + + return 0 + } else { + return int(r.Code) + } +} + +func (c *PostResCmd) Run(s sesn.Sesn) (Result, error) { + status, r, err := sesn.PostResource(s, c.Typ, c.Path, c.Value, c.TxOptions()) + if err != nil { + return nil, err + } + + res := newPostResResult() + res.Code = status + res.Value = r + return res, nil +} + +type DeleteResCmd struct { + CmdBase + Path string + Typ sesn.ResourceType +} + +func NewDeleteResCmd() *DeleteResCmd { + return &DeleteResCmd{ + CmdBase: NewCmdBase(), + } +} + +type DeleteResResult struct { + Code coap.COAPCode + Value []byte +} + +func newDeleteResResult() *DeleteResResult { + return &DeleteResResult{} +} + +func (r *DeleteResResult) Status() int { + if r.Code == coap.Deleted { + return 0 + } else { + return int(r.Code) + } +} + +func (c *DeleteResCmd) Run(s sesn.Sesn) (Result, error) { + status, val, err := sesn.DeleteResource(s, c.Typ, c.Path, c.TxOptions()) + if err != nil { + return nil, err + } + + res := newDeleteResResult() + res.Code = status + res.Value = val + return res, nil +} -- To stop receiving notification emails like this one, please contact "commits@mynewt.apache.org" <commits@mynewt.apache.org>.