Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions gatts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ type Service struct {

type WriteEvent = func(client Connection, offset int, value []byte)

// SecurityLevel specifies the security required for a characteristic operation.
// Settings other than the default (SecurityNone) may result in the peer initiating a pairing operation.
type SecurityLevel uint8

const (
SecurityNone SecurityLevel = iota // encryption not required
SecurityEncrypted // encryption required
SecurityEncryptedAuthenticated // encryption and authentication (MITM protection) required
)

// CharacteristicConfig contains some parameters for the configuration of a
// single characteristic.
//
Expand All @@ -18,9 +28,13 @@ type WriteEvent = func(client Connection, offset int, value []byte)
type CharacteristicConfig struct {
Handle *Characteristic
UUID
Value []byte
Flags CharacteristicPermissions
WriteEvent WriteEvent
Value []byte
Flags CharacteristicPermissions
WriteEvent WriteEvent
ReadSecurity SecurityLevel
WriteSecurity SecurityLevel
NotifySecurity SecurityLevel
IndicateSecurity SecurityLevel
}

// CharacteristicPermissions lists a number of basic permissions/capabilities
Expand Down
20 changes: 20 additions & 0 deletions gatts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ func (a *Adapter) AddService(s *Service) error {
flags = append(flags, bluezCharFlags[i])
}
}
if char.ReadSecurity == SecurityEncrypted {
flags = append(flags, "encrypt-read")
} else if char.ReadSecurity == SecurityEncryptedAuthenticated {
flags = append(flags, "encrypt-authenticated-read")
}
if char.WriteSecurity == SecurityEncrypted {
flags = append(flags, "encrypt-write")
} else if char.WriteSecurity == SecurityEncryptedAuthenticated {
flags = append(flags, "encrypt-authenticated-write")
}
if char.NotifySecurity == SecurityEncrypted {
flags = append(flags, "encrypt-notify")
} else if char.NotifySecurity == SecurityEncryptedAuthenticated {
flags = append(flags, "encrypt-authenticated-notify")
}
if char.IndicateSecurity == SecurityEncrypted {
flags = append(flags, "encrypt-indicate")
} else if char.IndicateSecurity == SecurityEncryptedAuthenticated {
flags = append(flags, "encrypt-authenticated-indicate")
}

// Export the properties of this characteristic.
charPath := path + dbus.ObjectPath("/char"+strconv.Itoa(i))
Expand Down
Loading