BrlAPI: BrlAPI's protocol

BrlAPI 0.8

Data Structures | Macros | Functions | Variables
BrlAPI's protocol

Instructions and constants for BrlAPI 's protocol. More...

## Data Structures
struct | brlapi_header_t
struct | brlapi_versionPacket_t
struct | brlapi_authClientPacket_t
struct | brlapi_authServerPacket_t
struct | brlapi_errorPacket_t
struct | brlapi_getDriverSpecificModePacket_t
struct | brlapi_writeArgumentsPacket_t
struct | brlapi_paramValuePacket_t
struct | brlapi_paramRequestPacket_t
union | brlapi_packet_t

## Macros
#define | BRLAPI_PROTOCOL_VERSION ((uint32_t) 8) /** Communication protocol version */
#define | BRLAPI_MAXPACKETSIZE 4096
#define | BRLAPI_PACKET_VERSION 'v'
#define | BRLAPI_PACKET_AUTH 'a'
#define | BRLAPI_PACKET_GETDRIVERNAME 'n'
#define | BRLAPI_PACKET_GETMODELID 'd'
#define | BRLAPI_PACKET_GETDISPLAYSIZE 's'
#define | BRLAPI_PACKET_ENTERTTYMODE 't'
#define | BRLAPI_PACKET_SETFOCUS 'F'
#define | BRLAPI_PACKET_LEAVETTYMODE 'L'
#define | BRLAPI_PACKET_KEY 'k'
#define | BRLAPI_PACKET_IGNOREKEYRANGES 'm'
#define | BRLAPI_PACKET_ACCEPTKEYRANGES 'u'
#define | BRLAPI_PACKET_WRITE 'w'
#define | BRLAPI_PACKET_ENTERRAWMODE '*'
#define | BRLAPI_PACKET_LEAVERAWMODE '#'
#define | BRLAPI_PACKET_PACKET 'p'
#define | BRLAPI_PACKET_ACK 'A'
#define | BRLAPI_PACKET_ERROR 'e'
#define | BRLAPI_PACKET_EXCEPTION 'E'
#define | BRLAPI_PACKET_SUSPENDDRIVER 'S'
#define | BRLAPI_PACKET_RESUMEDRIVER 'R'
#define | BRLAPI_PACKET_SYNCHRONIZE 'Z'
#define | BRLAPI_PACKET_PARAM_VALUE (('P'<<8) + 'V')
#define | BRLAPI_PACKET_PARAM_REQUEST (('P'<<8) + 'R')
#define | BRLAPI_PACKET_PARAM_UPDATE (('P'<<8) + 'U')
#define | BRLAPI_DEVICE_MAGIC (0xdeadbeefL)
#define | BRLAPI_HEADERSIZE sizeof(brlapi_header_t)
#define | BRLAPI_AUTH_NONE 'N'
#define | BRLAPI_AUTH_KEY 'K'
#define | BRLAPI_AUTH_CRED 'C'
#define | BRLAPI_WF_DISPLAYNUMBER 0X01
#define | BRLAPI_WF_REGION 0X02
#define | BRLAPI_WF_TEXT 0X04
#define | BRLAPI_WF_ATTR_AND 0X08
#define | BRLAPI_WF_ATTR_OR 0X10
#define | BRLAPI_WF_CURSOR 0X20
#define | BRLAPI_WF_CHARSET 0X40
#define | BRLAPI_PVF_GLOBAL 0X01 /** Value is the global value */
#define | BRLAPI_MAXPARAMSIZE (BRLAPI_MAXPACKETSIZE - (sizeof(uint32_t) + sizeof(brlapi_param_t) + 2*sizeof(uint32_t)))
#define | BRLAPI_PARAMF_GET 0X100 /** Get current parameter value */
#define | BRLAPI_PARAMF_SUBSCRIBE 0X200 /** Subscribe to parameter updates */
#define | BRLAPI_PARAMF_UNSUBSCRIBE 0X400 /** Unsubscribe from parameter updates */

## Functions
ssize_t | brlapi_writePacket (brlapi_fileDescriptor fd, brlapi_packetType_t type, const void *buf, size_t size)
ssize_t | brlapi_readPacketHeader (brlapi_fileDescriptor fd, brlapi_packetType_t *packetType)
ssize_t | brlapi_readPacketContent (brlapi_fileDescriptor fd, size_t packetSize, void *buf, size_t bufSize)
ssize_t | brlapi_readPacket (brlapi_fileDescriptor fd, brlapi_packetType_t *type, void *buf, size_t size)

## Variables
pthread_mutex_t | brlapi_fd_mutex

## Detailed Description

These are defines for the protocol between BrlAPI 's server and clients. Understanding is not needed to use the BrlAPI library, so reading this is not needed unless really wanting to connect to BrlAPI without BrlAPI 's library.

## Macro Definition Documentation

## ◆ BRLAPI_AUTH_CRED

#define BRLAPI_AUTH_CRED 'C'

Explicit socket credentials authorization

## ◆ BRLAPI_AUTH_KEY

#define BRLAPI_AUTH_KEY 'K'

Key authorization

## ◆ BRLAPI_AUTH_NONE

#define BRLAPI_AUTH_NONE 'N'

No or implicit authorization

## ◆ BRLAPI_DEVICE_MAGIC

#define BRLAPI_DEVICE_MAGIC (0xdeadbeefL)

Magic number to give when sending a BRLPACKET_ENTERRAWMODE or BRLPACKET_SUSPEND packet

## ◆ BRLAPI_HEADERSIZE

#define BRLAPI_HEADERSIZE sizeof(brlapi_header_t)

Size of packet headers

## ◆ BRLAPI_MAXPACKETSIZE

#define BRLAPI_MAXPACKETSIZE 4096

Maximum packet size for packets exchanged on sockets and with braille terminal

## ◆ BRLAPI_MAXPARAMSIZE

#define BRLAPI_MAXPARAMSIZE (BRLAPI_MAXPACKETSIZE - (sizeof(uint32_t) + sizeof(brlapi_param_t) + 2*sizeof(uint32_t)))

## ◆ BRLAPI_PACKET_ACCEPTKEYRANGES

#define BRLAPI_PACKET_ACCEPTKEYRANGES 'u'

Unmask key ranges

## ◆ BRLAPI_PACKET_ACK

#define BRLAPI_PACKET_ACK 'A'

Acknowledgement

## ◆ BRLAPI_PACKET_AUTH

#define BRLAPI_PACKET_AUTH 'a'

Authorization

## ◆ BRLAPI_PACKET_ENTERRAWMODE

#define BRLAPI_PACKET_ENTERRAWMODE '*'

Enter in raw mode

## ◆ BRLAPI_PACKET_ENTERTTYMODE

#define BRLAPI_PACKET_ENTERTTYMODE 't'

Asks for a specified tty

## ◆ BRLAPI_PACKET_ERROR

#define BRLAPI_PACKET_ERROR 'e'

non-fatal error

## ◆ BRLAPI_PACKET_EXCEPTION

#define BRLAPI_PACKET_EXCEPTION 'E'

Exception

## ◆ BRLAPI_PACKET_GETDISPLAYSIZE

#define BRLAPI_PACKET_GETDISPLAYSIZE 's'

Dimensions of brl display

## ◆ BRLAPI_PACKET_GETDRIVERNAME

#define BRLAPI_PACKET_GETDRIVERNAME 'n'

Ask which driver is used

## ◆ BRLAPI_PACKET_GETMODELID

#define BRLAPI_PACKET_GETMODELID 'd'

Ask which model is used

## ◆ BRLAPI_PACKET_IGNOREKEYRANGES

#define BRLAPI_PACKET_IGNOREKEYRANGES 'm'

Mask key ranges

## ◆ BRLAPI_PACKET_KEY

#define BRLAPI_PACKET_KEY 'k'

Braille key

## ◆ BRLAPI_PACKET_LEAVERAWMODE

#define BRLAPI_PACKET_LEAVERAWMODE '#'

Leave raw mode

## ◆ BRLAPI_PACKET_LEAVETTYMODE

#define BRLAPI_PACKET_LEAVETTYMODE 'L'

Release the tty

## ◆ BRLAPI_PACKET_PACKET

#define BRLAPI_PACKET_PACKET 'p'

Raw packets

## ◆ BRLAPI_PACKET_PARAM_REQUEST

#define BRLAPI_PACKET_PARAM_REQUEST (('P'<<8) + 'R')

Parameter request

## ◆ BRLAPI_PACKET_PARAM_UPDATE

#define BRLAPI_PACKET_PARAM_UPDATE (('P'<<8) + 'U')

Parameter update

## ◆ BRLAPI_PACKET_PARAM_VALUE

#define BRLAPI_PACKET_PARAM_VALUE (('P'<<8) + 'V')

Parameter value

## ◆ BRLAPI_PACKET_RESUMEDRIVER

#define BRLAPI_PACKET_RESUMEDRIVER 'R'

Resume driver

## ◆ BRLAPI_PACKET_SETFOCUS

#define BRLAPI_PACKET_SETFOCUS 'F'

Set current tty focus

## ◆ BRLAPI_PACKET_SUSPENDDRIVER

#define BRLAPI_PACKET_SUSPENDDRIVER 'S'

Suspend driver

## ◆ BRLAPI_PACKET_SYNCHRONIZE

#define BRLAPI_PACKET_SYNCHRONIZE 'Z'

Synchronize exceptions

## ◆ BRLAPI_PACKET_VERSION

#define BRLAPI_PACKET_VERSION 'v'

Version

## ◆ BRLAPI_PACKET_WRITE

#define BRLAPI_PACKET_WRITE 'w'

Write

## ◆ BRLAPI_PARAMF_GET

#define BRLAPI_PARAMF_GET 0X100 /** Get current parameter value */

Flags for parameter requests

## ◆ BRLAPI_PARAMF_SUBSCRIBE

#define BRLAPI_PARAMF_SUBSCRIBE 0X200 /** Subscribe to parameter updates */

## ◆ BRLAPI_PARAMF_UNSUBSCRIBE

#define BRLAPI_PARAMF_UNSUBSCRIBE 0X400 /** Unsubscribe from parameter updates */

## ◆ BRLAPI_PROTOCOL_VERSION

#define BRLAPI_PROTOCOL_VERSION ((uint32_t) 8) /** Communication protocol version */

## ◆ BRLAPI_PVF_GLOBAL

#define BRLAPI_PVF_GLOBAL 0X01 /** Value is the global value */

Flags for parameter values

## ◆ BRLAPI_WF_ATTR_AND

#define BRLAPI_WF_ATTR_AND 0X08

And attributes

## ◆ BRLAPI_WF_ATTR_OR

#define BRLAPI_WF_ATTR_OR 0X10

Or attributes

## ◆ BRLAPI_WF_CHARSET

#define BRLAPI_WF_CHARSET 0X40

Charset

## ◆ BRLAPI_WF_CURSOR

#define BRLAPI_WF_CURSOR 0X20

Cursor position

## ◆ BRLAPI_WF_DISPLAYNUMBER

#define BRLAPI_WF_DISPLAYNUMBER 0X01

Flags for writing Display number

## ◆ BRLAPI_WF_REGION

#define BRLAPI_WF_REGION 0X02

Region parameter

## ◆ BRLAPI_WF_TEXT

#define BRLAPI_WF_TEXT 0X04

Contains some text

## Function Documentation

## ◆ brlapi_readPacket()

ssize_t brlapi_readPacket | ( | brlapi_fileDescriptor | fd,
|  | brlapi_packetType_t * | type,
|  | void * | buf,
|  | size_t | size )

Read a packet from BrlAPI server

This function is for internal use, but one might use it if one really knows what one is doing...

type is where the function will store the packet type; it should always be one of the above defined BRLPACKET_* (or else something very nasty must have happened :/).

The syntax is the same as read()'s.

Returns
  packet's size, -2 if `EOF` occurred, -1 on error or signal interruption.

If the packet is larger than the supplied buffer, the buffer will be filled with the beginning of the packet, the rest of the packet being discarded. This follows the semantics of the recv system call when the MSG_TRUNC option is given.

See also
  brlapi_writePacket()

## ◆ brlapi_readPacketContent()

ssize_t brlapi_readPacketContent | ( | brlapi_fileDescriptor | fd,
|  | size_t | packetSize,
|  | void * | buf,
|  | size_t | bufSize )

Read the content of a packet from BrlAPI server

This function is for internal use, but one might use it if one really knows what one is doing...

packetSize is the size announced by brlapi_readPacketHeader()

bufSize is the size of buf

Returns
  packetSize, -2 if `EOF` occurred, -1 on error.

If the packet is larger than the supplied buffer, the buffer will be filled with the beginning of the packet, the rest of the packet being discarded. This follows the semantics of the recv system call when the MSG_TRUNC option is given.

See also
  brlapi_writePacket() brlapi_readPacketHeader() brlapi_readPacket()

## ◆ brlapi_readPacketHeader()

ssize_t brlapi_readPacketHeader | ( | brlapi_fileDescriptor | fd,
|  | brlapi_packetType_t * | packetType )

Read the header (type+size) of a packet from BrlAPI server

This function is for internal use, but one might use it if one really knows what one is doing...

type is where the function will store the packet type; it should always be one of the above defined BRLPACKET_* (or else something very nasty must have happened :/).

Returns
  packet's size, -2 if `EOF` occurred, -1 on error or signal interruption.

See also
  brlapi_writePacket() brlapi_readPacketContent brlapi_readPacket

## ◆ brlapi_writePacket()

ssize_t brlapi_writePacket | ( | brlapi_fileDescriptor | fd,
|  | brlapi_packetType_t | type,
|  | const void * | buf,
|  | size_t | size )

Send a packet to BrlAPI server

This function is for internal use, but one might use it if one really knows what one is doing...

type should only be one of the above defined BRLPACKET_*.

The syntax is the same as write()'s.

Returns
  0 on success, -1 on failure.

See also
  brlapi_readPacketHeader() brlapi_readPacketContent() brlapi_readPacket()

## Variable Documentation

## ◆ brlapi_fd_mutex

pthread_mutex_t brlapi_fd_mutex
| extern

Mutex for protecting concurrent fd access

In order to regulate concurrent access to the library's file descriptor and requests to / answers from BrlAPI server, every function of the library locks this mutex, namely

- brlapi_openConnection()
- brlapi_closeConnection()
- brlapi_enterRawMode()
- brlapi_leaveRawMode()
- brlapi_sendRaw()
- brlapi_recvRaw()
- brlapi_getDriverName()
- brlapi_getDisplaySize()
- brlapi_enterTtyMode()
- brlapi_enterTtyModeWithPath()
- brlapi_leaveTtyMode()
- brlapi_*write*()
- brlapi_(un)?ignorekey(Range|Set)()
- brlapi_readKey()

If both these functions and brlapi_writePacket() or brlapi_readPacket() are used in a multithreaded application, this mutex must be locked before calling brlapi_writePacket() or brlapi_readPacket(), and unlocked afterwards.