nmxact - reset ctlr on ble_xport shutdown.

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/commit/8c186383
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/8c186383
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/8c186383

Branch: refs/heads/master
Commit: 8c1863838b37abdc80d01fc09c294b453619c6a6
Parents: 97e9dfb
Author: Christopher Collins <[email protected]>
Authored: Wed May 10 17:33:50 2017 -0700
Committer: Christopher Collins <[email protected]>
Committed: Wed May 10 17:33:50 2017 -0700

----------------------------------------------------------------------
 nmxact/nmble/ble_act.go   | 32 ++++++++++++++++++++++++++++++++
 nmxact/nmble/ble_proto.go | 16 ++++++++++++++++
 nmxact/nmble/ble_util.go  | 27 +++++++++++++++++++++++++++
 nmxact/nmble/ble_xport.go |  7 ++++++-
 nmxact/nmble/dispatch.go  |  2 ++
 nmxact/nmxutil/nmxutil.go | 10 ++++++++++
 6 files changed, 93 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/8c186383/nmxact/nmble/ble_act.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_act.go b/nmxact/nmble/ble_act.go
index ad3a648..4c5eef0 100644
--- a/nmxact/nmble/ble_act.go
+++ b/nmxact/nmble/ble_act.go
@@ -411,6 +411,38 @@ func connFind(x *BleXport, bl *BleListener, r 
*BleConnFindReq) (
        }
 }
 
+// Tells the host to reset the controller.
+func reset(x *BleXport, bl *BleListener,
+       r *BleResetReq) error {
+
+       const rspType = MSG_TYPE_RESET
+
+       j, err := json.Marshal(r)
+       if err != nil {
+               return err
+       }
+
+       x.txNoSync(j)
+       for {
+               select {
+               case err := <-bl.ErrChan:
+                       return err
+
+               case bm := <-bl.BleChan:
+                       switch bm.(type) {
+                       case *BleResetRsp:
+                               bl.Acked = true
+                               return nil
+
+                       default:
+                       }
+
+               case <-bl.AfterTimeout(x.RspTimeout()):
+                       return BhdTimeoutError(rspType, r.Seq)
+               }
+       }
+}
+
 // Asks the controller to generate a random address.  This is done when the
 // transport is starting up, and therefore does not require the transport to be
 // synced.  Only the transport should call this function.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/8c186383/nmxact/nmble/ble_proto.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go
index d2976d0..0bb4d01 100644
--- a/nmxact/nmble/ble_proto.go
+++ b/nmxact/nmble/ble_proto.go
@@ -233,6 +233,7 @@ const (
        MSG_TYPE_SET_PREFERRED_MTU         = 17
        MSG_TYPE_SECURITY_INITIATE         = 18
        MSG_TYPE_CONN_FIND                 = 19
+       MSG_TYPE_RESET                     = 20
 
        MSG_TYPE_SYNC_EVT       = 2049
        MSG_TYPE_CONNECT_EVT    = 2050
@@ -270,6 +271,7 @@ var MsgTypeStringMap = map[MsgType]string{
        MSG_TYPE_SCAN_CANCEL:       "scan_cancel",
        MSG_TYPE_SET_PREFERRED_MTU: "set_preferred_mtu",
        MSG_TYPE_CONN_FIND:         "conn_find",
+       MSG_TYPE_RESET:             "reset",
 
        MSG_TYPE_SYNC_EVT:       "sync_evt",
        MSG_TYPE_CONNECT_EVT:    "connect_evt",
@@ -770,6 +772,20 @@ type BleConnFindRsp struct {
        PeerOtaAddr     BleAddr     `json:"peer_ota_addr"`
 }
 
+type BleResetReq struct {
+       // Header
+       Op   MsgOp   `json:"op"`
+       Type MsgType `json:"type"`
+       Seq  BleSeq  `json:"seq"`
+}
+
+type BleResetRsp struct {
+       // Header
+       Op   MsgOp   `json:"op"`
+       Type MsgType `json:"type"`
+       Seq  BleSeq  `json:"seq"`
+}
+
 func ErrCodeToString(e int) string {
        var s string
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/8c186383/nmxact/nmble/ble_util.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_util.go b/nmxact/nmble/ble_util.go
index cc9409b..13a2b8c 100644
--- a/nmxact/nmble/ble_util.go
+++ b/nmxact/nmble/ble_util.go
@@ -243,6 +243,14 @@ func NewBleConnFindReq() *BleConnFindReq {
        }
 }
 
+func NewResetReq() *BleResetReq {
+       return &BleResetReq{
+               Op:   MSG_OP_REQ,
+               Type: MSG_TYPE_RESET,
+               Seq:  NextSeq(),
+       }
+}
+
 func ConnFindXact(x *BleXport, connHandle uint16) (BleConnDesc, error) {
        r := NewBleConnFindReq()
        r.ConnHandle = connHandle
@@ -320,3 +328,22 @@ func SetPreferredMtuXact(x *BleXport, mtu uint16) error {
 
        return setPreferredMtu(x, bl, r)
 }
+
+func ResetXact(x *BleXport) error {
+       r := NewResetReq()
+
+       base := BleMsgBase{
+               Op:         -1,
+               Type:       -1,
+               Seq:        r.Seq,
+               ConnHandle: -1,
+       }
+
+       bl := NewBleListener()
+       if err := x.Bd.AddListener(base, bl); err != nil {
+               return err
+       }
+       defer x.Bd.RemoveListener(base)
+
+       return reset(x, bl, r)
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/8c186383/nmxact/nmble/ble_xport.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_xport.go b/nmxact/nmble/ble_xport.go
index e7a495f..091b607 100644
--- a/nmxact/nmble/ble_xport.go
+++ b/nmxact/nmble/ble_xport.go
@@ -322,7 +322,12 @@ func (bx *BleXport) setStateFrom(from BleXportState, to 
BleXportState) bool {
 }
 
 func (bx *BleXport) Stop() error {
-       // XXX: Reset controller to terminate all connections.
+       synced, err := bx.querySyncStatus()
+       if err == nil && synced {
+               // Reset controller so that all outstanding connections 
terminate.
+               ResetXact(bx)
+       }
+
        bx.shutdown(false, nmxutil.NewXportError("xport stopped"))
        return nil
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/8c186383/nmxact/nmble/dispatch.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/dispatch.go b/nmxact/nmble/dispatch.go
index 83f1f0f..c9f17ec 100644
--- a/nmxact/nmble/dispatch.go
+++ b/nmxact/nmble/dispatch.go
@@ -100,6 +100,7 @@ func scanRspCtor() BleMsg            { return &BleScanRsp{} 
}
 func scanCancelRspCtor() BleMsg      { return &BleScanCancelRsp{} }
 func setPreferredMtuRspCtor() BleMsg { return &BleSetPreferredMtuRsp{} }
 func connFindRspCtor() BleMsg        { return &BleConnFindRsp{} }
+func resetRspCtor() BleMsg           { return &BleResetRsp{} }
 
 func syncEvtCtor() BleMsg       { return &BleSyncEvt{} }
 func connectEvtCtor() BleMsg    { return &BleConnectEvt{} }
@@ -128,6 +129,7 @@ var msgCtorMap = map[OpTypePair]msgCtor{
        {MSG_OP_RSP, MSG_TYPE_SCAN_CANCEL}:       scanCancelRspCtor,
        {MSG_OP_RSP, MSG_TYPE_SET_PREFERRED_MTU}: setPreferredMtuRspCtor,
        {MSG_OP_RSP, MSG_TYPE_CONN_FIND}:         connFindRspCtor,
+       {MSG_OP_RSP, MSG_TYPE_RESET}:             resetRspCtor,
 
        {MSG_OP_EVT, MSG_TYPE_SYNC_EVT}:       syncEvtCtor,
        {MSG_OP_EVT, MSG_TYPE_CONNECT_EVT}:    connectEvtCtor,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/8c186383/nmxact/nmxutil/nmxutil.go
----------------------------------------------------------------------
diff --git a/nmxact/nmxutil/nmxutil.go b/nmxact/nmxutil/nmxutil.go
index 707b1bc..75ce988 100644
--- a/nmxact/nmxutil/nmxutil.go
+++ b/nmxact/nmxutil/nmxutil.go
@@ -173,6 +173,16 @@ func (f *ErrFunnel) Reset() {
        }
 }
 
+func (f *ErrFunnel) BlockUntilExp() {
+       f.mtx.Lock()
+       defer f.mtx.Unlock()
+
+       if f.started {
+               f.resetMtx.Lock()
+               f.resetMtx.Unlock()
+       }
+}
+
 func (f *ErrFunnel) timerExp() {
        f.mtx.Lock()
        err := f.curErr

Reply via email to