@@ -12,6 +12,7 @@ import (
12
12
"time"
13
13
)
14
14
15
+ // List returns an accurate list of currently existing radio devices.
15
16
//nolint:funlen
16
17
func List (ctx context.Context ) ([]* Device , error ) {
17
18
fd , err := openEventDev ()
@@ -77,14 +78,17 @@ func List(ctx context.Context) ([]*Device, error) {
77
78
}
78
79
}
79
80
81
+ // Block blocks device(s) according to the given block option.
80
82
func Block (option BlockOption ) error {
81
83
return block (1 , option )
82
84
}
83
85
86
+ // Unblock unblocks device(s) according to the given block option.
84
87
func Unblock (option BlockOption ) error {
85
88
return block (0 , option )
86
89
}
87
90
91
+ // Events reports rfkill events until context is cancelled.
88
92
func Events (ctx context.Context , pollInterval time.Duration , callback func (ev * Event )) error {
89
93
fd , err := openEventDev ()
90
94
if err != nil {
@@ -163,6 +167,7 @@ func updateDevState(dev *Device, ev *rfkillEvent) {
163
167
dev .SoftBlock = ev .Soft > 0
164
168
}
165
169
170
+ // Device describes radio device.
166
171
type Device struct {
167
172
ID uint32
168
173
Type RadioType
@@ -171,6 +176,7 @@ type Device struct {
171
176
Name string
172
177
}
173
178
179
+ // Event describes rfkill event.
174
180
type Event struct {
175
181
ID uint32
176
182
Op EventOp
@@ -179,6 +185,7 @@ type Event struct {
179
185
SoftBlock bool
180
186
}
181
187
188
+ // RadioType is type for radio types.
182
189
type RadioType uint8
183
190
184
191
const (
@@ -193,6 +200,7 @@ const (
193
200
NFCRadio
194
201
)
195
202
203
+ // EventOp is type for event operations.
196
204
type EventOp uint8
197
205
198
206
const (
@@ -202,15 +210,18 @@ const (
202
210
ChangeAllOp
203
211
)
204
212
213
+ // BlockOption is type for block option.
205
214
type BlockOption func (ev * rfkillEvent )
206
215
216
+ // WithID option sets device to block or unblock by ID
207
217
func WithID (id uint ) BlockOption {
208
218
return func (ev * rfkillEvent ) {
209
219
ev .Op = uint8 (ChangeOp )
210
220
ev .ID = uint32 (id )
211
221
}
212
222
}
213
223
224
+ // WithType option sets devices to block or unblock by type
214
225
func WithType (typ RadioType ) BlockOption {
215
226
return func (ev * rfkillEvent ) {
216
227
ev .Op = uint8 (ChangeAllOp )
0 commit comments