Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APP-7651]: Implement methods for start/stop advertising a BLE connection. #66

Open
wants to merge 2 commits into
base: APP-7654
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions subsystems/provisioning/bluetooth/bluetooth_wifi_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
currentValue T
}

// bluetoothWiFiProvisioner provides an interface for managing BLE (bluetooth-low-energy) peripheral advertisement on Linux.

Check failure on line 49 in subsystems/provisioning/bluetooth/bluetooth_wifi_provisioner.go

View workflow job for this annotation

GitHub Actions / Test lint and build

ST1021: comment on exported type BluetoothWiFiProvisioner should be of the form "BluetoothWiFiProvisioner ..." (with optional leading article) (stylecheck)
type BluetoothWiFiProvisioner struct {
logger logging.Logger
mu sync.Mutex
Expand Down Expand Up @@ -77,7 +77,7 @@
return bwp.stopAdvertisingBLE()
}

// Update updates the list of networks that are advertised via bluetooth as available.

Check failure on line 80 in subsystems/provisioning/bluetooth/bluetooth_wifi_provisioner.go

View workflow job for this annotation

GitHub Actions / Test lint and build

ST1020: comment on exported method RefreshAvailableNetworks should be of the form "RefreshAvailableNetworks ..." (stylecheck)
func (bwp *BluetoothWiFiProvisioner) RefreshAvailableNetworks(ctx context.Context, awns *AvailableWiFiNetworks) error {
return bwp.writeAvailableNetworks(ctx, awns)
}
Expand Down Expand Up @@ -128,12 +128,40 @@

/** Unexported helper methods for low-level system calls and read/write requests to/from bluetooth characteristics **/

func (bwp *BluetoothWiFiProvisioner) startAdvertisingBLE(ctx context.Context) error {

Check failure on line 131 in subsystems/provisioning/bluetooth/bluetooth_wifi_provisioner.go

View workflow job for this annotation

GitHub Actions / Test lint and build

`(*BluetoothWiFiProvisioner).startAdvertisingBLE` - `ctx` is unused (unparam)
return errors.New("TODO APP-7644: Add Linux-specific bluetooth calls for automatic pairing and read/write to BLE characteristics")
bwp.mu.Lock()
defer bwp.mu.Unlock()

if bwp.adv == nil {
return errors.New("advertisement is nil")
}
if bwp.advActive {
return errors.New("invalid request, advertising already active")
}
if err := bwp.adv.Start(); err != nil {
return errw.WithMessage(err, "failed to start advertising")
}
bwp.advActive = true
bwp.logger.Info("started advertising a BLE connection...")
return nil
}

func (bwp *BluetoothWiFiProvisioner) stopAdvertisingBLE() error {
return errors.New("TODO APP-7644: Add Linux-specific bluetooth calls for automatic pairing and read/write to BLE characteristics")
bwp.mu.Lock()
defer bwp.mu.Unlock()

if bwp.adv == nil {
return errors.New("advertisement is nil")
}
if !bwp.advActive {
return errors.New("invalid request, advertising already inactive")
}
if err := bwp.adv.Stop(); err != nil {
return errw.WithMessage(err, "failed to stop advertising")
}
bwp.advActive = false
bwp.logger.Info("stopped advertising a BLE connection")
return nil
}

func (bwp *BluetoothWiFiProvisioner) enableAutoAcceptPairRequest() {}
Expand Down
Loading