-
Notifications
You must be signed in to change notification settings - Fork 27
/
rgpiod.1
1058 lines (787 loc) · 17.2 KB
/
rgpiod.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Process this file with
.\" groff -man -Tascii lgd.1
.\"
.TH rgpiod 1 2020-2023 Linux "lg archive"
.SH NAME
rgpiod - a daemon to allow remote access to a SBC's GPIO.
.SH SYNOPSIS
rgpiod [OPTION]...&
.SH DESCRIPTION
.ad l
.nh
.br
.br
rgpiod is a daemon to allow remote access to a SBC's GPIO.
.br
.br
Once launched the daemon runs in the background accepting commands from the socket interface.
.br
.br
The daemon requires no special privileges and commands may be issued by normal users.
.br
.SH Features
.br
.br
The following features are available by issuing socket commands to the
daemon.
.br
.br
.br
o reading and writing GPIO singly and in groups
.br
o software timed PWM
.br
o GPIO callbacks
.br
o pipe notification of GPIO events
.br
o I2C wrapper
.br
o SPI wrapper
.br
o serial link wrapper
.br
o file handling
.br
o creating and running scripts
.br
.br
.SH Launch options
rgpiod [options] &
.br
.br
.SH OPTIONS
.IP "\fB-c dir \fP"
set the configuration directory (default current directory)
.br
.
.IP "\fB-l \fP"
disable remote socket interface (default enabled)
.br
.
.IP "\fB-n address \fP"
allow IP address to use the socket interface, name (e.g. paul) or dotted quad (e.g. 192.168.1.66). If the -n option is not used all addresses are allowed (unless overridden by the -l option). Multiple -n options are allowed. If -l has been used only -n localhost has any effect
.br
.
.IP "\fB-p value \fP"
set the socket port (1024-32000, default 8889)
.br
.
.IP "\fB-v \fP"
display rgpiod version and exit
.br
.
.IP "\fB-w dir \fP"
set working directory (default launch directory)
.br
.
.IP "\fB-x \fP"
enable access control (default off)
.
.SH Permissions
.br
.br
The rgpiod daemon has an optional access control system to control access to its functions.
.br
.br
See \fBPermits\fP.
.br
.br
.br
.br
.SH Scripts
.br
.br
Scripts are programs to be stored and executed by the rgpiod daemon.
They are intended to mitigate any performance problems associated with
the rgpiod daemon server/client model.
.br
.br
See \fBScripts\fP.
.br
.br
.SH Socket commands
.br
.br
Each socket command consists of a header and for commands with
parameters an extension.
.br
.br
The header is a lgCmd_t with the following structure.
.br
.br
.EX
typedef struct
.br
{
.br
union
.br
{
.br
uint32_t magic;
.br
int32_t status;
.br
};
.br
uint32_t size;
.br
uint16_t cmd;
.br
uint16_t doubles;
.br
uint16_t longs;
.br
uint16_t shorts;
.br
} lgCmd_t, *lgCmd_p;
.br
.EE
.br
.br
The magic value is 0x6c67646d (ASCII lgdm).
.br
.br
The size is the overall size in bytes of the optional extension.
.br
.br
The cmd is the command code. See the file lgSocketCommandCodes.h
for the command codes.
.br
.br
The doubles, longs, shorts is the number of 8-byte, 4-byte, and 2-byte
quantities in the extension. This information is used to
network order the bytes of the message. The extension should consist of
doubles 8-byte quantites, followed by longs 4-byte quantities, followed by
shorts 2-byte quantities, followed by as many 1-byte quantities needed to
make a total of size bytes.
.br
.br
If you wish to construct a client to talk to the rgpiod daemon the following
are a good source of information.
.br
o rpgio.py - a Python client
.br
o rgpio.c - a C client
.br
o rgs.c - a C command line client
.br
o lgCmd.c - a useful summary of the socket commands
.SH Daemon Access Control
.br
.br
The rpgpio daemon operates in two modes - with or without access control.
.br
.br
The default setting is without access control and the permissions
system does not apply (so the rest of this section may be ignored).
.br
.br
If the rgpiod daemon is started with the -x option it implements
an access control permissions system to its functions.
.br
.br
There are three parts to the permissions system.
.br
.br
.br
o An .lg_secret file in the users home directory.
.br
o An .lg_secret file in the daemon's configuration directory.
.br
o A permits file in the daemon's configuration directory.
.br
.br
The daemon client "logs in" to the daemon by choosing a user name. If the client and daemon copies of the password for the user match the user is "logged in".
.br
.br
The client program is then authorised to carry out any functions permitted to the user as specified in the permits file.
.br
.br
.SH User secret file
.br
.br
The user .lg_secret file contains a list of user names with an associated password.
.br
.br
These passwords have no relationship to the passwords used by Linux and should not be the same. The format is user=password.
.br
.br
An example .lg_secret file.
.br
.br
.EX
# user secrets file
.br
# user=password
.br
pete=t4pf4kvPOXjLfDnKBrMu
.br
.EE
.br
.br
The file should be readable/writable by the owner only.
.br
.br
chmod 600 .lg_secret
.SH Daemon secret file
.br
.br
The daemon .lg_secret file contains a list of user names with an associated password.
.br
.br
These passwords have no relationship to the passwords used by Linux and should not be the same. The format is user=password.
.br
.br
An example daemon .lg_secret file.
.br
.br
.EX
# rgpiod secrets file
.br
# user=password
.br
joan=kr6g89XmFQvLDWh6UcJH
.br
sally=fARrxSKqdHaPHBu6Vtet
.br
pete=t4pf4kvPOXjLfDnKBrMu
.br
fred=tugXUuRdPqGux6t7jhhv
.br
.EE
.br
.br
The file should be readable/writable by the owner only.
.br
.br
chmod 600 .lg_secret
.SH Daemon permits file
.br
.br
The permits file can contain the following sections. If a section is
absent it means that access to those features is forbidden.
.br
.br
.EX
[debug]
.br
[files]
.br
[gpio]
.br
[i2c]
.br
[notify]
.br
[scripts]
.br
[serial]
.br
[shell]
.br
[spi]
.br
.EE
.SH [debug]
Each entry in this section takes one of the following forms: \fBuser=y\fP or \fBuser=n\fP.
.br
.br
If the form \fBuser=y\fP is used that user is allowed to use the debug commands.
.br
.br
If the form \fBuser=n\fP is used, or there is no entry for the user, that user is
not allowed to use the debug command.
.br
.br
If the [debug] section is not present no user is allowed to use the
debug commands.
.br
.br
The debug commands are set and get sbc internals and reload configuration.
.SH [files]
Each entry in this section takes the form \fBuser=path x\fP where
\fBpath\fP indicates a file path and \fBx\fP refers to a permission. E.g.
\fB/home/peter/data.txt r\fP refers to Linux file\fB/home/peter/data.txt\fP
and read permission.
.br
.br
There may be more than one \fBpath\fP entry per user, each must be separated by a \fB:\fP character.
.br
.br
\fBpath\fP may contain the wild card characters \fB*\fP (matches any
characters) or \fB?\fP (matches a single character).
.br
.br
If the path entry starts with / it is relative to root (/) otherwise
it is relative to the daemons's working directory.
.br
.br
The permission may be R for read, W for write, U for read/write,
and N for no access. If a directory allows read/write access then
files may be created in that directory.
.br
.br
Where more than one entry matches a file the most specific rule
applies. If no entry matches a file then access is denied.
.br
.br
\fBExample\fP
.br
.EX
joan=/tmp/* u:* n:TEST/* r:TEST/TEST/* u
.br
.EE
.br
.br
User joan may create, read, and write files in the /tmp directory (\fB/tmp/* u\fP).
.br
.br
User joan has no access to files in the working directory (\fB* n\fP).
.br
.br
Overridden by user joan has read permission for files in the TEST directory
of the working directory (\fBTEST/* r\fP).
.br
.br
Overridden by user joan may create, read, and write files in the
TEST/TEST directory of the working directory (\fBTEST/TEST* u\fP).
.SH [gpio]
Each entry in this section takes the form \fBuser=x.y\fP where \fBx\fP indicates
a gpiochip device and \fBy\fP indicates a GPIO. E.g. \fB1.2\fP refers to Linux device \fB/dev/gpiochip1\fP GPIO 2.
.br
.br
There may be more than one \fBx.y\fP entry per user, each must be separated by a \fB:\fP character.
.br
.br
Both x and y may have the following forms.
.br
.br
\fB*\fP all gpiochips or all GPIO.
.br
\fBn\fP a single gpiochip or GPIO.
.br
\fBn,n\fP a list of gpiochips or GPIO.
.br
\fBn-n\fP a range of gpiochips or GPIO.
.br
.br
.br
\fBExample\fP
.br
.EX
fred=0.2-27 # user fred can access gpiochip 0 GPIO 2-27.
.br
peter=*.1,2 # user peter can access all gpiochips GPIO 1 and 2.
.br
jill=1,2.* # user jill can access all GPIO of gpiochips 1 and 2.
.br
boss=*.* # user boss can access all gpiochips and GPIO.
.br
sally=0.2-27:3.* # user sally can access gpiochip 0 GPIO 2-27 and
.br
# all GPIO of gpiochip 3.
.br
.EE
.br
.br
.SH [i2c]
Each entry in this section takes the form \fBuser=x.y\fP where \fBx\fP indicates
an I2C bus and \fBy\fP indicates a device on the bus. E.g. \fB1.27\fP refers to Linux device \fB/dev/i2c-1\fP device 27.
.br
.br
.br
There may be more than one \fBx.y\fP entry per user, each must be separated by a \fB:\fP character.
.br
.br
Both x and y may have the following forms.
.br
.br
\fB*\fP all I2C buses or all devices.
.br
\fBn\fP a single I2C bus or device.
.br
\fBn,n\fP a list of I2C buses or devices.
.br
\fBn-n\fP a range of I2C buses or devices.
.br
.br
.br
\fBExample\fP
.br
.EX
fred=0.3-127 # user fred can access I2C bus 0 devices 3-127.
.br
peter=*.83,89 # user peter can access all I2C buses devices 83 and 89.
.br
jill=1,2.* # user jill can access all devices on I2C buses 1 and 2.
.br
boss=*.* # user boss can access all I2C buses and devices.
.br
sally=0.80-99:3.* # user sally can access I2C bus 0 devices 80-99 and
.br
# all devices of I2C bus 3.
.br
.EE
.br
.br
.SH [notify]
Each entry in this section takes one of the following forms: \fBuser=y\fP or \fBuser=n\fP.
.br
.br
If the form \fBuser=y\fP is used that user is allowed to use the
notify commands.
.br
.br
If the form \fBuser=n\fP is used, or there is no entry for the user,
that user is not allowed to use the notifiy commands.
.br
.br
If the [notify] section is not present no user is allowed to use the
notify commands.
.SH [scripts]
Each entry in this section takes one of the following forms: \fBuser=y\fP or \fBuser=n\fP.
.br
.br
If the form \fBuser=y\fP is used that user is allowed to use the script commands.
.br
.br
If the form \fBuser=n\fP is used, or there is no entry for the user, that user is
not allowed to use the script command.
.br
.br
If the [debug] section is not present no user is allowed to use the
script commands.
.SH [serial]
Each entry in this section takes the form \fBuser=device\fP where
\fBdevice\fP indicates a serial device. E.g. \fB/dev/serial0\fP refers to
Linux device \fB/dev/serial0\fP
.br
.br
There may be more than one \fBdevice\fP entry per user, each must be separated by a \fB:\fP character.
.br
.br
\fBdevice\fP may contain the wild card characters \fB*\fP (matches any
characters) or \fB?\fP (matches a single character).
.br
.br
\fBExample\fP
.br
.EX
fred=/dev/serial0 # user fred can access /dev/serial0.
.br
peter=/dev/tty* # user peter can access /dev/tty*.
.br
boss=/dev/* # user boss can access /dev/*.
.br
sally=/dev/serial?:/dev/ttyS* # user sally can access /dev/serial?
.br
# and /dev/ttyS*.
.br
.EE
.br
.br
.SH [shell]
Each entry in this section takes one of the following forms: \fBuser=y\fP or \fBuser=n\fP.
.br
.br
If the form \fBuser=y\fP is used that user is allowed to use the shell commands.
.br
.br
If the form \fBuser=n\fP is used, or there is no entry for the user, that user is
not allowed to use the shell commands.
.br
.br
If the [shell] section is not present no user is allowed to use the
shell commands.
.SH [spi]
Each entry in this section takes the form \fBuser=x.y\fP where \fBx\fP
indicates a SPI bus and \fBy\fP indicates a slave select. E.g. \fB1.2\fP
refers to Linux device \fB/dev/spidev1.2\fP
.br
.br
There may be more than one \fBx.y\fP entry per user, each must be separated by a \fB:\fP character.
.br
.br
Both \fBx\fP and \fBy\fP may have the following forms.
.br
.br
\fB*\fP all SPI buses or all slaves.
.br
\fBn\fP a single SPI bus or slave.
.br
\fBn,n\fP a list of SPI buses or slaves.
.br
\fBn-n\fP a range of SPI buses or slaves.
.br
.br
.br
\fBExample\fP
.br
.EX
fred=0.0-2 # user fred can access SPI bus 0 slaves 0-2.
.br
peter=*.0 # user peter can access all SPI buses slave 0.
.br
jill=1,2.* # user jill can access all slaves on SPI buses 1 and 2.
.br
boss=*.* # user boss can access all SPI buses and slaves.
.br
sally=0.0-2:1.* # user sally can access SPI bus 0 slaves 0-2 and
.br
# all slaves of SPI bus 1.
.br
.EE
.br
.br
.SH Example permits file
.br
.br
.EX
# rgpiod test file for user access
.br
# user=permission
.br
.br
[files]
.br
default=:
.br
test1=/tmp/* u:* n:TEST/* r:TEST/TEST/* u:
.br
.br
[gpio]
.br
test1=*.2-27
.br
test2=0.2-27
.br
test3=0.5-10
.br
.br
[i2c]
.br
test1=1-999.*
.br
test2=1-2.*
.br
test3=2.5-20
.br
.br
[notify]
.br
test1=n
.br
test2=y
.br
test3=y
.br
.br
[scripts]
.br
test1=y
.br
test2=n
.br
test3=y
.br
.br
[serial]
.br
test1=/dev/serial*:/dev/ttyUSB*:/dev/ttyS*
.br
test2=/dev/ttyUSB1:/dev/tty0:/dev/ttyS0
.br
test3=/dev/null
.br
.br
[spi]
.br
test1=0.0:0.1:1.0:1.1:1.2:2.0:2.1
.br
test2=0.*
.br
test3=*.0
.br
.br
[debug]
.br
admin=y
.br
.br
[shell]
.br
test1=n
.br
test2=n
.br
test3=y
.br
.EE
.SH Scripts
.br
.br
Scripts are programs to be stored and executed by the rgpiod daemon.
They are intended to mitigate any performance problems associated with
the daemon server/client model.
.br
.br
Scripts are work in progress.
.br
.br
.SS Virtual machine
.br
.br
A script runs within a virtual machine with
.br
.br
a 32 bit accumulator A.
.br
a flags register F.
.br
a program counter PC.
.br
.br
Each script has
.br
.br
10 parameters named 0 through 9.
.br
150 variables named 0 through 149.
.br
50 labels which are named by any unique number.
.br
.br
.SS Commands
.br
.br
Many lg commands may be used within a script. However
some commands do not work within the script model as designed and
are not permitted.
.br
.br
The following commands are not permitted within a script:
.br
.br
.br
File - FL FO FR FW
.br
.br
I2C - I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ
.br
.br
Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU
.br
.br
Serial - SERO SERR SERW SLR
.br
.br
SPI - SPIR SPIW SPIX
.br
.br
The following commands are only permitted within a script:
.br
.br
.br
Command Description Definition
.br
ADD x Add x to accumulator A+=x; F=A
.br
AND x And x with accumulator A&=x; F=A
.br
CALL L Call subroutine at tag L push(PC+1); PC=L
.br
CMP x Compare x with accumulator F=A-x
.br
DCR y Decrement register --*y; F=*y
.br
DCRA Decrement accumulator --A; F=A
.br
DIV x Divide x into accumulator A/=x; F=A
.br
HALT Halt Halt
.br
INR y Increment register ++*y; F=*y
.br
INRA Increment accumulator ++A; F=A
.br
JGE L Jump if >= 0 to tag L if (F>=0) PC=L
.br
JGT L Jump if > 0 to tag L if (F>0) PC=L
.br
JLE L Jump if <= 0 to tag L if (F<=0) PC=L
.br
JLT L Jump if < 0 to tag L if (F<0) PC=L
.br
JMP L Jump to tag L PC=L
.br
JNZ L Jump if non-zero to tag L if (F) PC=L
.br
JZ L Jump if zero to tag L if (!F) PC=L
.br
LD y x Load register with x *y=x
.br
LDA x Load accumulator with x A=x
.br
MLT x Multiply x with accumulator A*=x; F=A
.br
MOD x Modulus x with accumulator A%=x; F=A
.br
OR x Or x with accumulator A|=x; F=A
.br
POP y Pop register y=pop()
.br
POPA Pop accumulator A=pop()
.br
PUSH y Push register push(y)
.br
PUSHA Push accumulator push(A)