Repository: incubator-mynewt-newtmgr
Updated Branches:
  refs/heads/master 41cf27469 -> 78d069c70


nmxact - Rollover seq at 0xffffff00

This bug could potentially cause NMP responses to get dropped if the BHD
sequence number were to exceed 0xffffff00.


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/83de4447
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/83de4447
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/83de4447

Branch: refs/heads/master
Commit: 83de4447d6d8946261fa1414d234e9ccdae865b1
Parents: 41cf274
Author: Christopher Collins <[email protected]>
Authored: Fri Apr 14 17:55:47 2017 -0700
Committer: Christopher Collins <[email protected]>
Committed: Fri Apr 14 17:55:47 2017 -0700

----------------------------------------------------------------------
 nmxact/nmble/ble_proto.go |  2 ++
 nmxact/nmble/ble_util.go  | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/83de4447/nmxact/nmble/ble_proto.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go
index a43348d..d2976d0 100644
--- a/nmxact/nmble/ble_proto.go
+++ b/nmxact/nmble/ble_proto.go
@@ -19,6 +19,8 @@ type BleBytes struct {
        Bytes []byte
 }
 
+const BLE_SEQ_MIN BleSeq = 0
+const BLE_SEQ_EVT_MIN BleSeq = 0xffffff00
 const BLE_SEQ_NONE BleSeq = 0xffffffff
 
 const ERR_CODE_ATT_BASE = 0x100

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/83de4447/nmxact/nmble/ble_util.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_util.go b/nmxact/nmble/ble_util.go
index 66c8c6b..eb24906 100644
--- a/nmxact/nmble/ble_util.go
+++ b/nmxact/nmble/ble_util.go
@@ -2,7 +2,7 @@ package nmble
 
 import (
        "fmt"
-       "sync/atomic"
+       "sync"
 
        log "github.com/Sirupsen/logrus"
 
@@ -19,10 +19,20 @@ const NmpOicRspChrUuid = 
"E9241982-4580-42C4-8831-95048216B256"
 const WRITE_CMD_BASE_SZ = 3
 const NOTIFY_CMD_BASE_SZ = 3
 
-var nextSeq uint32
+var nextSeq BleSeq = BLE_SEQ_MIN
+var seqMtx sync.Mutex
 
 func NextSeq() BleSeq {
-       return BleSeq(atomic.AddUint32(&nextSeq, 1))
+       seqMtx.Lock()
+       defer seqMtx.Unlock()
+
+       seq := nextSeq
+       nextSeq++
+       if nextSeq >= BLE_SEQ_EVT_MIN {
+               nextSeq = BLE_SEQ_MIN
+       }
+
+       return seq
 }
 
 func BhdTimeoutError(rspType MsgType) error {

Reply via email to