You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/12 18:59:32 UTC

[GitHub] ccollins476ad closed pull request #69: bll - Allow OwnAddrType to be specified in linux.

ccollins476ad closed pull request #69: bll - Allow OwnAddrType to be specified in linux.
URL: https://github.com/apache/mynewt-newtmgr/pull/69
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newtmgr/bll/bll_xport.go b/newtmgr/bll/bll_xport.go
index 6cecf28..06c9b33 100644
--- a/newtmgr/bll/bll_xport.go
+++ b/newtmgr/bll/bll_xport.go
@@ -27,11 +27,13 @@ import (
 	"github.com/go-ble/ble"
 	"github.com/go-ble/ble/examples/lib/dev"
 
+	"mynewt.apache.org/newtmgr/nmxact/bledefs"
 	"mynewt.apache.org/newtmgr/nmxact/sesn"
 )
 
 type XportCfg struct {
-	CtlrName string
+	CtlrName    string
+	OwnAddrType bledefs.BleAddrType
 }
 
 func NewXportCfg() XportCfg {
@@ -65,6 +67,11 @@ func (bx *BllXport) Start() error {
 		return err
 	}
 
+	// Set the connection parameters to use for all initiated connections.
+	if err := BllXportSetConnParams(d, bx.cfg.OwnAddrType); err != nil {
+		return err
+	}
+
 	ble.SetDefaultDevice(d)
 
 	return nil
diff --git a/newtmgr/bll/bll_xport_linux.go b/newtmgr/bll/bll_xport_linux.go
new file mode 100644
index 0000000..a4174ec
--- /dev/null
+++ b/newtmgr/bll/bll_xport_linux.go
@@ -0,0 +1,61 @@
+// +build linux
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package bll
+
+import (
+	"github.com/go-ble/ble"
+	"github.com/go-ble/ble/linux"
+	"github.com/go-ble/ble/linux/hci"
+	"github.com/go-ble/ble/linux/hci/cmd"
+
+	"mynewt.apache.org/newt/util"
+	"mynewt.apache.org/newtmgr/nmxact/bledefs"
+)
+
+func BllXportSetConnParams(dev ble.Device, ownAddrType bledefs.BleAddrType) error {
+	ldev := dev.(*linux.Device)
+
+	cc := cmd.LECreateConnection{
+		LEScanInterval:        0x0010, // 0x0004 - 0x4000; N * 0.625 msec
+		LEScanWindow:          0x0010, // 0x0004 - 0x4000; N * 0.625 msec
+		InitiatorFilterPolicy: 0x00,   // White list is not used
+		OwnAddressType:        uint8(ownAddrType),
+		ConnIntervalMin:       0x0006, // 0x0006 - 0x0C80; N * 1.25 msec
+		ConnIntervalMax:       0x0006, // 0x0006 - 0x0C80; N * 1.25 msec
+		ConnLatency:           0x0000, // 0x0000 - 0x01F3; N * 1.25 msec
+		SupervisionTimeout:    0x0048, // 0x000A - 0x0C80; N * 10 msec
+		MinimumCELength:       0x0000, // 0x0000 - 0xFFFF; N * 0.625 msec
+		MaximumCELength:       0x0000, // 0x0000 - 0xFFFF; N * 0.625 msec
+
+		// Specified at connect time.
+		PeerAddressType: 0x00,      // Public Device Address
+		PeerAddress:     [6]byte{}, //
+	}
+
+	opt := hci.OptConnParams(cc)
+	if err := ldev.HCI.Option(opt); err != nil {
+		return util.FmtNewtError("error setting connection parameters: %s",
+			err.Error())
+	}
+
+	return nil
+}
diff --git a/newtmgr/bll/bll_xport_nonlinux.go b/newtmgr/bll/bll_xport_nonlinux.go
new file mode 100644
index 0000000..cc88a51
--- /dev/null
+++ b/newtmgr/bll/bll_xport_nonlinux.go
@@ -0,0 +1,34 @@
+// +build !linux
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package bll
+
+import (
+	"github.com/go-ble/ble"
+
+	"mynewt.apache.org/newtmgr/nmxact/bledefs"
+)
+
+// macOS (CoreBluetooth) does not allow the connection parameters to be
+// configured, so this function is a no-op.
+func BllXportSetConnParams(dev ble.Device, ownAddrType bledefs.BleAddrType) error {
+	return nil
+}
diff --git a/newtmgr/cli/common.go b/newtmgr/cli/common.go
index b45c214..6e6ad49 100644
--- a/newtmgr/cli/common.go
+++ b/newtmgr/cli/common.go
@@ -130,6 +130,7 @@ func GetXport() (xport.Xport, error) {
 		if bc.CtlrName != "" {
 			cfg.CtlrName = bc.CtlrName
 		}
+		cfg.OwnAddrType = bc.OwnAddrType
 		globalXport = bll.NewBllXport(cfg)
 
 	case config.CONN_TYPE_BLE_PLAIN, config.CONN_TYPE_BLE_OIC:
diff --git a/newtmgr/config/bll_config.go b/newtmgr/config/bll_config.go
index 564a3d9..9235d02 100644
--- a/newtmgr/config/bll_config.go
+++ b/newtmgr/config/bll_config.go
@@ -30,12 +30,14 @@ import (
 	"mynewt.apache.org/newt/util"
 	"mynewt.apache.org/newtmgr/newtmgr/bll"
 	"mynewt.apache.org/newtmgr/newtmgr/nmutil"
+	"mynewt.apache.org/newtmgr/nmxact/bledefs"
 )
 
 type BllConfig struct {
-	CtlrName string
-	PeerId   string
-	PeerName string
+	CtlrName    string
+	OwnAddrType bledefs.BleAddrType
+	PeerId      string
+	PeerName    string
 }
 
 func NewBllConfig() *BllConfig {
@@ -68,6 +70,12 @@ func ParseBllConnString(cs string) (*BllConfig, error) {
 		switch k {
 		case "ctlr_name":
 			bc.CtlrName = v
+		case "own_addr_type":
+			var err error
+			bc.OwnAddrType, err = bledefs.BleAddrTypeFromString(v)
+			if err != nil {
+				return nil, einvalBleConnString("Invalid own_addr_type: %s", v)
+			}
 		case "peer_id":
 			bc.PeerId = v
 		case "peer_name":


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services