Update texinfo document with information about ACPI. * doc/guile-netlink.texi: Add ACPI concept in introduction. Add section on the ACPI API.
doc/guile-netlink.texi
| 7 | 7 | ||
| 8 | 8 | @copying | |
| 9 | 9 | Copyright @copyright{} 2020 Julien Lepiller | |
| 10 | + | Copyright @copyright{} 2025 Dale Mellor | |
| 10 | 11 | ||
| 11 | 12 | @quotation | |
| 12 | 13 | Permission is granted to copy, distribute and/or modify this document | |
… | |||
| 30 | 31 | implementation of the netlink protocol. | |
| 31 | 32 | ||
| 32 | 33 | @menu | |
| 33 | - | * Introduction:: What is netlink? | |
| 34 | - | * IP Library:: High-level functions for network devices. | |
| 35 | - | * API Reference:: Description of the library interface. | |
| 34 | + | * Introduction:: What is netlink? | |
| 35 | + | * IP Library:: High-level procedures for network devices. | |
| 36 | + | * ACPI API:: High-level procedures for receiving ACPI event notifications. | |
| 37 | + | * API Reference:: Low-level procedure reference. | |
| 36 | 38 | ||
| 37 | - | * Concept Index:: Concepts. | |
| 38 | - | * Programming Index:: Data types, procedures, and variables. | |
| 39 | + | * Concept Index:: Concepts. | |
| 40 | + | * Programming Index:: Data types, procedures, and variables. | |
| 39 | 41 | ||
| 40 | 42 | @detailmenu | |
| 41 | - | --- The Detailed Node Listing --- | |
| 43 | + | --- The Detailed Node Listing --- | |
| 42 | 44 | ||
| 43 | 45 | IP Library | |
| 44 | 46 | ||
| 45 | - | * Link:: Actions on network links. | |
| 46 | - | * Addr:: Actions on network addresses. | |
| 47 | - | * Route:: Actions on network routes. | |
| 47 | + | * Link:: | |
| 48 | + | * Addr:: | |
| 49 | + | * Route:: | |
| 48 | 50 | ||
| 49 | - | API Reference | |
| 51 | + | ACPI API | |
| 50 | 52 | ||
| 51 | - | * Common API:: Common functions and data types for defining netlink | |
| 52 | - | protocols. | |
| 53 | - | * Netlink API:: Common structures and data types for every protocols. | |
| 54 | - | * Rtnetlink API:: The ROUTE_NETLINK protocol. | |
| 53 | + | * ACPI example:: | |
| 54 | + | * ACPI reference:: | |
| 55 | + | ||
| 56 | + | Low-Level API Reference | |
| 57 | + | ||
| 58 | + | * Common API:: | |
| 59 | + | * Netlink API:: | |
| 60 | + | * Rtnetlink API:: | |
| 61 | + | ||
| 62 | + | Common API | |
| 63 | + | ||
| 64 | + | * Data Types:: | |
| 65 | + | * Constants:: | |
| 66 | + | * Netlink Connections:: | |
| 67 | + | ||
| 68 | + | Netlink API | |
| 69 | + | ||
| 70 | + | * Netlink Headers:: | |
| 71 | + | * Standard Message Types:: | |
| 72 | + | ||
| 73 | + | Rtnetlink API | |
| 74 | + | ||
| 75 | + | * Routing Attributes:: | |
| 76 | + | * Link Messages:: | |
| 77 | + | * Address Messages:: | |
| 55 | 78 | ||
| 56 | 79 | @end detailmenu | |
| 57 | 80 | @end menu | |
| 58 | 81 | ||
| 59 | 82 | @node Introduction | |
| 60 | 83 | @chapter Introduction | |
| 84 | + | @cindex netlink | |
| 85 | + | @cindex routing protocol | |
| 86 | + | @cindex ACPI protocol | |
| 87 | + | @cindex contributions | |
| 88 | + | @cindex high-level | |
| 89 | + | @cindex intermediate-level | |
| 90 | + | @cindex low-level | |
| 61 | 91 | ||
| 62 | 92 | Netlink is an inter-process communication protocol that can be used for | |
| 63 | 93 | communication between processes, or with the kernel. It is implemented by | |
| 64 | 94 | Linux. | |
| 65 | 95 | ||
| 66 | - | Many protocols exist on top of Netlink. The most famous are used to configure | |
| 67 | - | network-related functions in the kernel, such as firewall, route table or | |
| 68 | - | IP addresses of interfaces. | |
| 69 | - | ||
| 70 | - | This library implements the low-level bits of the code by providing data | |
| 71 | - | structures that are close to their C counterpart, and basic procedures to | |
| 72 | - | initiate communication. | |
| 96 | + | Many protocols exist on top of Netlink. For example, the @emph{routing} | |
| 97 | + | protocol is used to configure network-related functions in the kernel, such as | |
| 98 | + | firewall, route table or IP addresses of interfaces, and the @emph{ACPI} | |
| 99 | + | protocol is used by the Linux kernel to send notifications of changes in | |
| 100 | + | system power usage. (Deep down, these two protocols are very different beasts, | |
| 101 | + | with the former being regarded as a @emph{classical} protocol with very fixed | |
| 102 | + | message formats, and the latter being an example of a @emph{generic} protocol | |
| 103 | + | which entails subscribing to a broadcast channel and deeply introspecting the | |
| 104 | + | transmitted data.) | |
| 105 | + | ||
| 106 | + | Lots of other protocols, or families, are provided by Linux, but this library | |
| 107 | + | currently only services the two examples described above. Of course, | |
| 108 | + | contributions of code which implements others are always welcome! | |
| 109 | + | ||
| 110 | + | This library implements code at three levels: at high-level we have the | |
| 111 | + | @ref{IP Library} and @ref{ACPI API} which give immediate access to the | |
| 112 | + | protocols described above; at intermediate level there is the | |
| 113 | + | @ref{Rtnetlink API} which defines special structures and functions used in the | |
| 114 | + | routing protocol, and many of which are borrowed by the ACPI protocol; finally | |
| 115 | + | the low-level details are outlined in the @ref{API Reference}. | |
| 73 | 116 | ||
| 74 | 117 | @node IP Library | |
| 75 | 118 | @chapter IP Library | |
… | |||
| 77 | 120 | This library comes with higher-level procedures that let you access and modify | |
| 78 | 121 | the state of network on your computer. | |
| 79 | 122 | ||
| 123 | + | @menu | |
| 124 | + | * Link:: | |
| 125 | + | * Addr:: | |
| 126 | + | * Route:: | |
| 127 | + | @end menu | |
| 128 | + | ||
| 80 | 129 | @node Link | |
| 81 | 130 | @section Link | |
| 82 | 131 | ||
… | |||
| 381 | 430 | @end example | |
| 382 | 431 | @end deffn | |
| 383 | 432 | ||
| 433 | + | @node ACPI API | |
| 434 | + | @chapter ACPI API | |
| 435 | + | @cindex high-level | |
| 436 | + | @cindex read-selector procedure | |
| 437 | + | @cindex process-data procedure | |
| 438 | + | @cindex close-connection procedure | |
| 439 | + | ||
| 440 | + | This chapter describes the high-level procedures contained in the | |
| 441 | + | @code{(netlink acpi)} module that let you monitor the kernel for ACPI event | |
| 442 | + | notifications. At top level, the requirement is to connect to the kernel's | |
| 443 | + | netlink system, and then you receive three procedures for handling | |
| 444 | + | notifications on the connection. The first, nominally called | |
| 445 | + | @code{(read-selector)}, provides a file descriptor which you can use in a | |
| 446 | + | @code{select} read-list to wait for a notification to become available on the | |
| 447 | + | connection. | |
| 448 | + | ||
| 449 | + | Once you know that data are there waiting to be read, you use the second | |
| 450 | + | provided procedure: @code{(process-data @var{action})}, where the @var{action} | |
| 451 | + | you supply must be a procedure which takes in an @code{event} object, and does | |
| 452 | + | whatever the application needs to do. Data can be extracted from this object | |
| 453 | + | with @code{event-device-class}, @code{event-bus-id}, @code{event-kind} and | |
| 454 | + | @code{event-data}. | |
| 455 | + | ||
| 456 | + | When all is done, the connection should be closed with a call to the third | |
| 457 | + | provided function: @code{(close-connection)}. | |
| 458 | + | ||
| 459 | + | @menu | |
| 460 | + | * ACPI example:: | |
| 461 | + | * ACPI reference:: | |
| 462 | + | @end menu | |
| 463 | + | ||
| 464 | + | @node ACPI example | |
| 465 | + | @section acpi-listener example | |
| 466 | + | @cindex acpi-listener application | |
| 467 | + | @cindex ACPI example usage | |
| 468 | + | ||
| 469 | + | The following code snippet is the heart of the acpi-listener application | |
| 470 | + | distributed with guile-netlink. When you run the command at the command line | |
| 471 | + | (it takes no arguments), it will sit there silently and forever, waiting for | |
| 472 | + | an ACPI event to happen (perhaps you can put your computer to suspended sleep | |
| 473 | + | and then re-awaken it), at which time a message will be printed with the data | |
| 474 | + | of that event. | |
| 475 | + | ||
| 476 | + | @lisp | |
| 477 | + | ;; Use guile-netlink??s ACPI interface. The use of a prefix is discretionary; | |
| 478 | + | ;; it is useful to have in example code. | |
| 479 | + | (use-modules ((netlink acpi) #:prefix ACPI::)) | |
| 480 | + | ||
| 481 | + | ||
| 482 | + | (define (action event) ;; [1] | |
| 483 | + | ((@@ (ice-9 format) format) | |
| 484 | + | #t | |
| 485 | + | "device: ~20a, bus ID: ~15a, type: ~8,'0x, data: ~8,'0x\n" | |
| 486 | + | (ACPI::event-device-class event) | |
| 487 | + | (ACPI::event-bus-id event) | |
| 488 | + | (ACPI::event-kind event) | |
| 489 | + | (ACPI::event-data event))) | |
| 490 | + | ||
| 491 | + | ||
| 492 | + | ((@@ (ice-9 receive) receive) | |
| 493 | + | (ACPI::read-selector ACPI::process-events ACPI::close-connection) ;; [3] | |
| 494 | + | (ACPI::connect-events) ;; [2] | |
| 495 | + | ||
| 496 | + | (let loop () ;; [4] | |
| 497 | + | (select (list (ACPI::read-selector)) '() '()) | |
| 498 | + | (ACPI::process-events action) | |
| 499 | + | (loop)) | |
| 500 | + | ||
| 501 | + | (ACPI::close-connection)) ;; [5] | |
| 502 | + | @end lisp | |
| 503 | + | ||
| 504 | + | The action we take on receiving events is defined as @code{action} [1], and | |
| 505 | + | simply writes the data elements of the @var{event} to the command-line. | |
| 506 | + | ||
| 507 | + | The connection to the kernel is made with the @code{ACPI::connect-events} [2] | |
| 508 | + | procedure call, which gives us the @code{ACPI::read-selector}, | |
| 509 | + | @code{ACPI::process-events} and @code{ACPI::close-connection} [3] procedures | |
| 510 | + | for managing the connection. | |
| 511 | + | ||
| 512 | + | We then simply go into a tight loop [4] waiting for data, and processing that | |
| 513 | + | when it comes in. | |
| 514 | + | ||
| 515 | + | If, by some unattainable miracle, we get out of that loop and want to stop | |
| 516 | + | monitoring for kernel events, we can call the @code{ACPI::close-connection} | |
| 517 | + | procedure [5]. | |
| 518 | + | ||
| 519 | + | @node ACPI reference | |
| 520 | + | @section ACPI reference | |
| 521 | + | ||
| 522 | + | The following procedures are available in the @code{(netlink acpi)} module. | |
| 523 | + | ||
| 524 | + | @deffn {Scheme Procedure} connect-events | |
| 525 | + | Open a connection to the kernel, and set it up to listen for ACPI event | |
| 526 | + | notifications. The procedure returns three new procedures for managing this | |
| 527 | + | connection: @dfn{read-selector} which returns a file descriptor which can be | |
| 528 | + | passed to the @code{select} procedure to wait for data from the kernel, | |
| 529 | + | @dfn{process-data @var{action}} which reads and evaluates the data, and calls | |
| 530 | + | @code{ACTION @var{event}} on it, and finally @dfn{close-connection} which will | |
| 531 | + | terminate the connection with the kernel. | |
| 532 | + | @end deffn | |
| 533 | + | ||
| 534 | + | @deffn {Scheme Procedure} event-display-class @var{event} | |
| 535 | + | Extract the display class from the @var{event}. This will be a string. | |
| 536 | + | @end deffn | |
| 537 | + | ||
| 538 | + | @deffn {Scheme Procedure} event-bus-id @var{event} | |
| 539 | + | Extract the bus-id from the @var{event}, again a string. | |
| 540 | + | @end deffn | |
| 541 | + | ||
| 542 | + | @deffn {Scheme Procedure} event-kind @var{event} | |
| 543 | + | Extract the type of the @var{event}, a number, nominally unsigned 32 bit. | |
| 544 | + | @end deffn | |
| 545 | + | ||
| 546 | + | @deffn {Scheme Procedure} event-data @var{event} | |
| 547 | + | Extract the data from the @var{event}, a number, also nominally unsigned 32 | |
| 548 | + | bit. | |
| 549 | + | @end deffn | |
| 550 | + | ||
| 384 | 551 | @node API Reference | |
| 385 | - | @chapter API Reference | |
| 552 | + | @chapter Low-Level API Reference | |
| 553 | + | ||
| 554 | + | @menu | |
| 555 | + | * Common API:: | |
| 556 | + | * Netlink API:: | |
| 557 | + | * Rtnetlink API:: | |
| 558 | + | @end menu | |
| 386 | 559 | ||
| 387 | 560 | @node Common API | |
| 388 | 561 | @section Common API | |
… | |||
| 391 | 564 | section describes how to use this API to augment guile-netlink with additional | |
| 392 | 565 | protocols. | |
| 393 | 566 | ||
| 567 | + | @menu | |
| 568 | + | * Data Types:: | |
| 569 | + | * Constants:: | |
| 570 | + | * Netlink Connections:: | |
| 571 | + | @end menu | |
| 572 | + | ||
| 394 | 573 | @node Data Types | |
| 395 | 574 | @subsection Data Types | |
| 396 | 575 | ||
… | |||
| 625 | 804 | First, we introduce the structure of a netlink message, then we present the | |
| 626 | 805 | standard types of netlink messages, that can be used with every protocol. | |
| 627 | 806 | ||
| 807 | + | @menu | |
| 808 | + | * Netlink Headers:: | |
| 809 | + | * Standard Message Types:: | |
| 810 | + | @end menu | |
| 811 | + | ||
| 628 | 812 | @node Netlink Headers | |
| 629 | 813 | @subsection Netlink Headers | |
| 630 | 814 | ||
… | |||
| 694 | 878 | routing rules, queueing disciplines, traffic classes, traffic filters and | |
| 695 | 879 | more. | |
| 696 | 880 | ||
| 881 | + | @menu | |
| 882 | + | * Routing Attributes:: | |
| 883 | + | * Link Messages:: | |
| 884 | + | * Address Messages:: | |
| 885 | + | @end menu | |
| 886 | + | ||
| 697 | 887 | @node Routing Attributes | |
| 698 | 888 | @subsection Routing Attributes | |
| 699 | 889 | ||
… | |||
| 806 | 996 | @end table | |
| 807 | 997 | @end deffn | |
| 808 | 998 | ||
| 999 | + | ||
| 809 | 1000 | @c ********************************************************************* | |
| 810 | 1001 | @node Concept Index | |
| 811 | 1002 | @unnumbered Concept Index | |