newtmgr - revendor
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/3b818c38 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/3b818c38 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/3b818c38 Branch: refs/heads/master Commit: 3b818c3855ec1e29564e7c2070120db0798686d5 Parents: 2f603ea Author: Christopher Collins <[email protected]> Authored: Tue Apr 4 12:23:34 2017 -0700 Committer: Christopher Collins <[email protected]> Committed: Tue Apr 4 18:10:25 2017 -0700 ---------------------------------------------------------------------- newtmgr/Godeps/Godeps.json | 36 +++++----- .../newtmgr/nmxact/nmble/ble_fsm.go | 69 +++++++++++--------- .../newtmgr/nmxact/nmble/ble_oic_sesn.go | 29 +++++--- .../newtmgr/nmxact/nmble/ble_plain_sesn.go | 29 +++++--- .../newtmgr/nmxact/nmble/ble_proto.go | 67 ++++++++++--------- .../newtmgr/nmxact/nmble/ble_util.go | 4 +- .../newtmgr/nmxact/nmble/ble_xport.go | 9 +-- .../newtmgr/nmxact/nmble/dispatch.go | 22 +++---- 8 files changed, 145 insertions(+), 120 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/Godeps/Godeps.json ---------------------------------------------------------------------- diff --git a/newtmgr/Godeps/Godeps.json b/newtmgr/Godeps/Godeps.json index dec9341..a1a8585 100644 --- a/newtmgr/Godeps/Godeps.json +++ b/newtmgr/Godeps/Godeps.json @@ -96,48 +96,48 @@ }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/bledefs", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmble", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmp", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmserial", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmxutil", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/omp", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/sesn", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/xact", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" }, { "ImportPath": "mynewt.apache.org/newtmgr/nmxact/xport", - "Comment": "mynewt_0_9_0_tag-456-gb056251", - "Rev": "b05625178026773b707953f73d54a1963d186959" + "Comment": "mynewt_0_9_0_tag-464-gf662168", + "Rev": "f662168755e02e16a9f0eab99683560707e9cf79" } ] } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_fsm.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_fsm.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_fsm.go index 39bfdfc..dc94ca9 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_fsm.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_fsm.go @@ -59,14 +59,13 @@ type BleFsmParams struct { type BleFsm struct { params BleFsmParams - peerDev *BleDev - connHandle int - nmpSvc *BleSvc - nmpReqChr *BleChr - nmpRspChr *BleChr - attMtu int - connChan chan error - + peerDev *BleDev + connHandle int + nmpSvc *BleSvc + nmpReqChr *BleChr + nmpRspChr *BleChr + attMtu int + connChan chan error mtx sync.Mutex lastStateChange time.Time @@ -106,12 +105,16 @@ func (bf *BleFsm) getState() BleSesnState { return bf.state } +func (bf *BleFsm) setStateNoLock(toState BleSesnState) { + bf.state = toState + bf.lastStateChange = time.Now() +} + func (bf *BleFsm) setState(toState BleSesnState) { bf.mtx.Lock() defer bf.mtx.Unlock() - bf.state = toState - bf.lastStateChange = time.Now() + bf.setStateNoLock(toState) } func (bf *BleFsm) transitionState(fromState BleSesnState, @@ -127,7 +130,7 @@ func (bf *BleFsm) transitionState(fromState BleSesnState, toState, fromState) } - bf.state = toState + bf.setStateNoLock(toState) return nil } @@ -135,18 +138,17 @@ func (bf *BleFsm) addBleListener(base BleMsgBase) (*BleListener, error) { bl := NewBleListener() bf.mtx.Lock() - bf.bls[bl] = struct{}{} - bf.mtx.Unlock() + defer bf.mtx.Unlock() if err := bf.params.Bx.Bd.AddListener(base, bl); err != nil { - delete(bf.bls, bl) return nil, err } + bf.bls[bl] = struct{}{} return bl, nil } -func (bf *BleFsm) addBleSeqListener(seq int) (*BleListener, error) { +func (bf *BleFsm) addBleSeqListener(seq BleSeq) (*BleListener, error) { base := BleMsgBase{ Op: -1, Type: -1, @@ -162,15 +164,16 @@ func (bf *BleFsm) addBleSeqListener(seq int) (*BleListener, error) { } func (bf *BleFsm) removeBleListener(base BleMsgBase) { + bf.mtx.Lock() + defer bf.mtx.Unlock() + bl := bf.params.Bx.Bd.RemoveListener(base) if bl != nil { - bf.mtx.Lock() delete(bf.bls, bl) - bf.mtx.Unlock() } } -func (bf *BleFsm) removeBleSeqListener(seq int) { +func (bf *BleFsm) removeBleSeqListener(seq BleSeq) { base := BleMsgBase{ Op: -1, Type: -1, @@ -200,8 +203,8 @@ func (bf *BleFsm) action( return nil } -func (bf *BleFsm) calcDisconnectType() BleFsmDisconnectType { - switch bf.getState() { +func calcDisconnectType(state BleSesnState) BleFsmDisconnectType { + switch state { case SESN_STATE_EXCHANGING_MTU: return FSM_DISCONNECT_TYPE_IMMEDIATE_TIMEOUT @@ -220,19 +223,23 @@ func (bf *BleFsm) onDisconnect(err error) { log.Debugf(err.Error()) bf.mtx.Lock() - bls := make([]*BleListener, 0, len(bf.bls)) - for bl, _ := range bf.bls { - bls = append(bls, bl) - } - bf.mtx.Unlock() // Remember some fields before we clear them. - dt := bf.calcDisconnectType() + dt := calcDisconnectType(bf.state) peer := *bf.peerDev - bf.setState(SESN_STATE_UNCONNECTED) + bf.setStateNoLock(SESN_STATE_UNCONNECTED) bf.peerDev = nil + // Make a copy of all the listeners so we don't have to keep the mutex + // locked while we send error signals to them. + bls := make([]*BleListener, 0, len(bf.bls)) + for bl, _ := range bf.bls { + bls = append(bls, bl) + } + + bf.mtx.Unlock() + for _, bl := range bls { bl.ErrChan <- err } @@ -240,7 +247,7 @@ func (bf *BleFsm) onDisconnect(err error) { bf.params.DisconnectCb(dt, peer, err) } -func (bf *BleFsm) connectListen(seq int) error { +func (bf *BleFsm) connectListen(seq BleSeq) error { bf.connChan = make(chan error, 1) bl, err := bf.addBleSeqListener(seq) @@ -253,7 +260,7 @@ func (bf *BleFsm) connectListen(seq int) error { for { select { case err := <-bl.ErrChan: - // Transport reported error. Assume all connections have + // Transport reported error. Assume the connection has // dropped. bf.onDisconnect(err) return @@ -326,7 +333,7 @@ func (bf *BleFsm) nmpRspListen() error { base := BleMsgBase{ Op: MSG_OP_EVT, Type: MSG_TYPE_NOTIFY_RX_EVT, - Seq: -1, + Seq: BLE_SEQ_NONE, ConnHandle: bf.connHandle, } @@ -453,7 +460,7 @@ func (bf *BleFsm) terminateSetState() error { return fmt.Errorf( "BLE terminate failed; session already being closed") default: - bf.state = SESN_STATE_TERMINATING + bf.setStateNoLock(SESN_STATE_TERMINATING) } return nil http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_oic_sesn.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_oic_sesn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_oic_sesn.go index 5fa9291..e5139be 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_oic_sesn.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_oic_sesn.go @@ -23,7 +23,7 @@ type BleOicSesn struct { onCloseCb sesn.BleOnCloseFn closeChan chan error - mx sync.Mutex + mtx sync.Mutex } func NewBleOicSesn(bx *BleXport, cfg sesn.SesnCfg) *BleOicSesn { @@ -67,18 +67,22 @@ func NewBleOicSesn(bx *BleXport, cfg sesn.SesnCfg) *BleOicSesn { } func (bos *BleOicSesn) addNmpListener(seq uint8) (*nmp.NmpListener, error) { - nl := nmp.NewNmpListener() - bos.nls[nl] = struct{}{} + bos.mtx.Lock() + defer bos.mtx.Unlock() + nl := nmp.NewNmpListener() if err := bos.od.AddListener(seq, nl); err != nil { - delete(bos.nls, nl) return nil, err } + bos.nls[nl] = struct{}{} return nl, nil } func (bos *BleOicSesn) removeNmpListener(seq uint8) { + bos.mtx.Lock() + defer bos.mtx.Unlock() + listener := bos.od.RemoveListener(seq) if listener != nil { delete(bos.nls, listener) @@ -87,8 +91,8 @@ func (bos *BleOicSesn) removeNmpListener(seq uint8) { // Returns true if a new channel was assigned. func (bos *BleOicSesn) setCloseChan() error { - bos.mx.Lock() - defer bos.mx.Unlock() + bos.mtx.Lock() + defer bos.mtx.Unlock() if bos.closeChan != nil { return fmt.Errorf("Multiple listeners waiting for session to close") @@ -99,8 +103,8 @@ func (bos *BleOicSesn) setCloseChan() error { } func (bos *BleOicSesn) clearCloseChan() { - bos.mx.Lock() - defer bos.mx.Unlock() + bos.mtx.Lock() + defer bos.mtx.Unlock() bos.closeChan = nil } @@ -126,7 +130,7 @@ func (bos *BleOicSesn) blockUntilClosed(timeout time.Duration) error { return nil } - // Block until close completes or timeout. + // Block until close completes or times out. return bos.listenForClose(timeout) } @@ -173,7 +177,7 @@ func (bos *BleOicSesn) Close() error { return nil } - // Block until close completes or timeout. + // Block until close completes or times out. return bos.listenForClose(bos.closeTimeout) } @@ -185,9 +189,12 @@ func (bos *BleOicSesn) onRxNmp(data []byte) { bos.od.Dispatch(data) } +// Called by the FSM when a blehostd disconnect event is received. func (bos *BleOicSesn) onDisconnect(dt BleFsmDisconnectType, peer BleDev, err error) { + bos.mtx.Lock() + for nl, _ := range bos.nls { nl.ErrChan <- err } @@ -197,6 +204,8 @@ func (bos *BleOicSesn) onDisconnect(dt BleFsmDisconnectType, peer BleDev, bos.closeChan <- err } + bos.mtx.Unlock() + // Only execute client's disconnect callback if the disconnect was // unsolicited and the session was fully open. if dt == FSM_DISCONNECT_TYPE_OPENED && bos.onCloseCb != nil { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_plain_sesn.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_plain_sesn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_plain_sesn.go index 15419a9..803eb45 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_plain_sesn.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_plain_sesn.go @@ -22,7 +22,7 @@ type BlePlainSesn struct { onCloseCb sesn.BleOnCloseFn closeChan chan error - mx sync.Mutex + mtx sync.Mutex } func NewBlePlainSesn(bx *BleXport, cfg sesn.SesnCfg) *BlePlainSesn { @@ -61,18 +61,22 @@ func NewBlePlainSesn(bx *BleXport, cfg sesn.SesnCfg) *BlePlainSesn { } func (bps *BlePlainSesn) addNmpListener(seq uint8) (*nmp.NmpListener, error) { - nl := nmp.NewNmpListener() - bps.nls[nl] = struct{}{} + bps.mtx.Lock() + defer bps.mtx.Unlock() + nl := nmp.NewNmpListener() if err := bps.nd.AddListener(seq, nl); err != nil { - delete(bps.nls, nl) return nil, err } + bps.nls[nl] = struct{}{} return nl, nil } func (bps *BlePlainSesn) removeNmpListener(seq uint8) { + bps.mtx.Lock() + defer bps.mtx.Unlock() + listener := bps.nd.RemoveListener(seq) if listener != nil { delete(bps.nls, listener) @@ -80,8 +84,8 @@ func (bps *BlePlainSesn) removeNmpListener(seq uint8) { } func (bps *BlePlainSesn) setCloseChan() error { - bps.mx.Lock() - defer bps.mx.Unlock() + bps.mtx.Lock() + defer bps.mtx.Unlock() if bps.closeChan != nil { return fmt.Errorf("Multiple listeners waiting for session to close") @@ -92,8 +96,8 @@ func (bps *BlePlainSesn) setCloseChan() error { } func (bps *BlePlainSesn) clearCloseChan() { - bps.mx.Lock() - defer bps.mx.Unlock() + bps.mtx.Lock() + defer bps.mtx.Unlock() bps.closeChan = nil } @@ -119,7 +123,7 @@ func (bps *BlePlainSesn) blockUntilClosed(timeout time.Duration) error { return nil } - // Block until close completes or timeout. + // Block until close completes or times out. return bps.listenForClose(timeout) } @@ -166,7 +170,7 @@ func (bps *BlePlainSesn) Close() error { return nil } - // Block until close completes or timeout. + // Block until close completes or times out. return bps.listenForClose(bps.closeTimeout) } @@ -178,9 +182,12 @@ func (bps *BlePlainSesn) onRxNmp(data []byte) { bps.nd.Dispatch(data) } +// Called by the FSM when a blehostd disconnect event is received. func (bps *BlePlainSesn) onDisconnect(dt BleFsmDisconnectType, peer BleDev, err error) { + bps.mtx.Lock() + for nl, _ := range bps.nls { nl.ErrChan <- err } @@ -190,6 +197,8 @@ func (bps *BlePlainSesn) onDisconnect(dt BleFsmDisconnectType, peer BleDev, bps.closeChan <- err } + bps.mtx.Unlock() + // Only execute client's disconnect callback if the disconnect was // unsolicited and the session was fully open. if dt == FSM_DISCONNECT_TYPE_OPENED && bps.onCloseCb != nil { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_proto.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_proto.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_proto.go index fe9112d..8545335 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_proto.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_proto.go @@ -13,6 +13,7 @@ import ( type MsgOp int type MsgType int +type BleSeq uint32 type BleBytes struct { Bytes []byte @@ -22,6 +23,8 @@ type BleUuid struct { Bytes [16]byte } +const BLE_SEQ_NONE BleSeq = 0xffffffff + const ERR_CODE_ATT_BASE = 0x100 const ERR_CODE_HCI_BASE = 0x200 const ERR_CODE_L2C_BASE = 0x300 @@ -274,7 +277,7 @@ var MsgTypeStringMap = map[MsgType]string{ type BleHdr struct { Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` } type BleMsg interface{} @@ -296,14 +299,14 @@ type BleSyncReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` } type BleConnectReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory OwnAddrType BleAddrType `json:"own_addr_type"` @@ -326,7 +329,7 @@ type BleConnectRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -336,7 +339,7 @@ type BleConnectEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -355,7 +358,7 @@ type BleTerminateReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` ConnHandle int `json:"conn_handle"` HciReason int `json:"hci_reason"` @@ -365,7 +368,7 @@ type BleTerminateRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -375,14 +378,14 @@ type BleConnCancelReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` } type BleConnCancelRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -392,7 +395,7 @@ type BleDisconnectEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Reason int `json:"reason"` @@ -403,7 +406,7 @@ type BleDiscSvcUuidReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory ConnHandle int `json:"conn_handle"` @@ -414,7 +417,7 @@ type BleDiscSvcUuidRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -424,7 +427,7 @@ type BleDiscSvcEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -435,7 +438,7 @@ type BleDiscChrUuidReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory ConnHandle int `json:"conn_handle"` @@ -448,7 +451,7 @@ type BleDiscAllChrsReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory ConnHandle int `json:"conn_handle"` @@ -460,7 +463,7 @@ type BleDiscAllChrsRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -470,7 +473,7 @@ type BleErrRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -481,7 +484,7 @@ type BleSyncRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Synced bool `json:"synced"` @@ -491,7 +494,7 @@ type BleDiscChrUuidRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -501,7 +504,7 @@ type BleDiscChrEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -512,7 +515,7 @@ type BleWriteCmdReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory ConnHandle int `json:"conn_handle"` @@ -524,7 +527,7 @@ type BleWriteCmdRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -534,7 +537,7 @@ type BleSyncEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Synced bool `json:"synced"` @@ -544,7 +547,7 @@ type BleNotifyRxEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory ConnHandle int `json:"conn_handle"` @@ -557,7 +560,7 @@ type BleExchangeMtuReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory ConnHandle int `json:"conn_handle"` @@ -567,7 +570,7 @@ type BleExchangeMtuRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -577,7 +580,7 @@ type BleMtuChangeEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -589,7 +592,7 @@ type BleScanReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory OwnAddrType BleAddrType `json:"own_addr_type"` @@ -606,7 +609,7 @@ type BleScanRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` @@ -616,7 +619,7 @@ type BleScanEvt struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory EventType BleAdvEventType `json:"event_type"` @@ -635,14 +638,14 @@ type BleScanCancelReq struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` } type BleScanCancelRsp struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Mandatory Status int `json:"status"` http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_util.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_util.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_util.go index 31f0e62..07cd8c3 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_util.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_util.go @@ -22,8 +22,8 @@ const NOTIFY_CMD_BASE_SZ = 3 var nextSeq uint32 -func NextSeq() int { - return int(atomic.AddUint32(&nextSeq, 1)) +func NextSeq() BleSeq { + return BleSeq(atomic.AddUint32(&nextSeq, 1)) } func ParseUuid(uuidStr string) (BleUuid, error) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_xport.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_xport.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_xport.go index 02854c6..f957341 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_xport.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_xport.go @@ -76,6 +76,7 @@ func NewBleXport(cfg XportCfg) (*BleXport, error) { bx := &BleXport{ Bd: NewBleDispatcher(), shutdownChan: make(chan bool), + readyChan: make(chan error), cfg: cfg, } @@ -113,7 +114,7 @@ func (bx *BleXport) addSyncListener() (*BleListener, error) { base := BleMsgBase{ Op: MSG_OP_EVT, Type: MSG_TYPE_SYNC_EVT, - Seq: -1, + Seq: BLE_SEQ_NONE, ConnHandle: -1, } if err := bx.Bd.AddListener(base, bl); err != nil { @@ -127,7 +128,7 @@ func (bx *BleXport) removeSyncListener() { base := BleMsgBase{ Op: MSG_OP_EVT, Type: MSG_TYPE_SYNC_EVT, - Seq: -1, + Seq: BLE_SEQ_NONE, ConnHandle: -1, } bx.Bd.RemoveListener(base) @@ -205,9 +206,6 @@ func (bx *BleXport) shutdown(restart bool, err error) { // Stop the unixchild instance (blehostd + socket). if bx.client != nil { bx.client.Stop() - - // Unblock the unixchild instance. - bx.client.FromChild <- nil } // Indicate an error to all of this transport's listeners. This prevents @@ -289,7 +287,6 @@ func (bx *BleXport) startOnce() error { bx.stopChan = make(chan struct{}) bx.numStopListeners = 0 - bx.Bd.Clear() bx.createUnixChild() if err := bx.client.Start(); err != nil { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/3b818c38/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/dispatch.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/dispatch.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/dispatch.go index c9ef39e..583f3a4 100644 --- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/dispatch.go +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/dispatch.go @@ -37,7 +37,7 @@ type BleMsgBase struct { // Header Op MsgOp `json:"op"` Type MsgType `json:"type"` - Seq int `json:"seq"` + Seq BleSeq `json:"seq"` // Optional ConnHandle int `json:"conn_handle" json:",omitempty"` @@ -77,7 +77,7 @@ func (bl *BleListener) Stop() { } type BleDispatcher struct { - seqMap map[int]*BleListener + seqMap map[BleSeq]*BleListener baseMap map[BleMsgBase]*BleListener mutex sync.Mutex } @@ -132,7 +132,7 @@ var msgCtorMap = map[OpTypePair]msgCtor{ func NewBleDispatcher() *BleDispatcher { return &BleDispatcher{ - seqMap: map[int]*BleListener{}, + seqMap: map[BleSeq]*BleListener{}, baseMap: map[BleMsgBase]*BleListener{}, } } @@ -162,7 +162,7 @@ func (bd *BleDispatcher) findBaseListener(base BleMsgBase) ( func (bd *BleDispatcher) findDupListener(base BleMsgBase) ( BleMsgBase, *BleListener) { - if base.Seq != -1 { + if base.Seq != BLE_SEQ_NONE { return base, bd.seqMap[base.Seq] } @@ -172,7 +172,7 @@ func (bd *BleDispatcher) findDupListener(base BleMsgBase) ( func (bd *BleDispatcher) findListener(base BleMsgBase) ( BleMsgBase, *BleListener) { - if base.Seq != -1 { + if base.Seq != BLE_SEQ_NONE { if bl := bd.seqMap[base.Seq]; bl != nil { return base, bl } @@ -196,7 +196,7 @@ func (bd *BleDispatcher) AddListener(base BleMsgBase, base.Op, base.Type, base.Seq, base.ConnHandle) } - if base.Seq != -1 { + if base.Seq != BLE_SEQ_NONE { if base.Op != -1 || base.Type != -1 || base.ConnHandle != -1 { @@ -219,7 +219,7 @@ func (bd *BleDispatcher) RemoveListener(base BleMsgBase) *BleListener { base, bl := bd.findListener(base) if bl != nil { bl.Stop() - if base.Seq != -1 { + if base.Seq != BLE_SEQ_NONE { delete(bd.seqMap, base.Seq) } else { delete(bd.baseMap, base) @@ -292,6 +292,8 @@ func (bd *BleDispatcher) ErrorAll(err error) { listeners = append(listeners, v) } + bd.clear() + bd.mutex.Unlock() for _, listener := range listeners { @@ -299,10 +301,8 @@ func (bd *BleDispatcher) ErrorAll(err error) { } } -func (bd *BleDispatcher) Clear() { - bd.mutex.Lock() - defer bd.mutex.Unlock() - +// The caller must lock the mutex. +func (bd *BleDispatcher) clear() { for s, _ := range bd.seqMap { delete(bd.seqMap, s) }
