^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) .. include:: <isonum.txt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) Using Linux CAIF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) :Copyright: |copy| ST-Ericsson AB 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) :Author: Sjur Brendeland/ sjur.brandeland@stericsson.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) Start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) =====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) If you have compiled CAIF for modules do::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) $modprobe crc_ccitt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) $modprobe caif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) $modprobe caif_socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) $modprobe chnl_net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) Preparing the setup with a STE modem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) ====================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) If you are working on integration of CAIF you should make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) that the kernel is built with module support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) There are some things that need to be tweaked to get the host TTY correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) set up to talk to the modem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Since the CAIF stack is running in the kernel and we want to use the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) TTY, we are installing our physical serial driver as a line discipline above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) the TTY device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) To achieve this we need to install the N_CAIF ldisc from user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) The benefit is that we can hook up to any TTY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) The use of Start-of-frame-extension (STX) must also be set as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) module parameter "ser_use_stx".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Normally Frame Checksum is always used on UART, but this is also provided as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) module parameter "ser_use_fcs".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) $ modprobe caif_serial ser_ttyname=/dev/ttyS0 ser_use_stx=yes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) $ ifconfig caif_ttyS0 up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) PLEASE NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) There is a limitation in Android shell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) It only accepts one argument to insmod/modprobe!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) Trouble shooting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) There are debugfs parameters provided for serial communication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /sys/kernel/debug/caif_serial/<tty-name>/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * ser_state: Prints the bit-mask status where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) - 0x02 means SENDING, this is a transient state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) - 0x10 means FLOW_OFF_SENT, i.e. the previous frame has not been sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) and is blocking further send operation. Flow OFF has been propagated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) to all CAIF Channels using this TTY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * tty_status: Prints the bit-mask tty status information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) - 0x01 - tty->warned is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) - 0x02 - tty->low_latency is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) - 0x04 - tty->packed is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) - 0x08 - tty->flow_stopped is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) - 0x10 - tty->hw_stopped is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) - 0x20 - tty->stopped is on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * last_tx_msg: Binary blob Prints the last transmitted frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) This can be printed with::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) $od --format=x1 /sys/kernel/debug/caif_serial/<tty>/last_rx_msg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) The first two tx messages sent look like this. Note: The initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) byte 02 is start of frame extension (STX) used for re-syncing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) upon errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) - Enumeration::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 0000000 02 05 00 00 03 01 d2 02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) STX(1) | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) Length(2)| | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) Control Channel(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) Command:Enumeration(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) Link-ID(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) Checksum(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) - Channel Setup::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 0000000 02 07 00 00 00 21 a1 00 48 df
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) | | | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) STX(1) | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) Length(2)| | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) Control Channel(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) Command:Channel Setup(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) Channel Type(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) Priority and Link-ID(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) Endpoint(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) Checksum(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * last_rx_msg: Prints the last transmitted frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) The RX messages for LinkSetup look almost identical but they have the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) bit 0x20 set in the command bit, and Channel Setup has added one byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) before Checksum containing Channel ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) Several CAIF Messages might be concatenated. The maximum debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) buffer size is 128 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) Error Scenarios
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ===============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) - last_tx_msg contains channel setup message and last_rx_msg is empty ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) The host seems to be able to send over the UART, at least the CAIF ldisc get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) notified that sending is completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) - last_tx_msg contains enumeration message and last_rx_msg is empty ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) The host is not able to send the message from UART, the tty has not been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) able to complete the transmit operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) - if /sys/kernel/debug/caif_serial/<tty>/tty_status is non-zero there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) might be problems transmitting over UART.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) E.g. host and modem wiring is not correct you will typically see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) tty_status = 0x10 (hw_stopped) and ser_state = 0x10 (FLOW_OFF_SENT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) You will probably see the enumeration message in last_tx_message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) and empty last_rx_message.