pjbproto

Name

pjbproto -- PJB Protocol packet build routines

Synopsis



#define     PJB_PROTOCOL_VERSION
#define     DROP_PACKET
#define     KEEP_PACKET
#define     PJBPROTO_COMMAND_TIMEOUT
#define     PJBPROTO_POLL_INTERVAL
#define     PJBPROTO_RETRY_COUNT
#define     PJBPROTO_SOL_RETRY_COUNT
#define     PJB_FMT_NODATA
#define     PJB_FMT_BULKDATA
#define     PJB_FMT_ITEMLIST
#define     PJB_FMT_CONTINUE
#define     PJB_FMT_CONTINUE_ITEM
#define     PJB_PCLASS_CONFIG
#define     PJB_PCLASS_TOC
#define     PJB_PCLASS_STORAGE
#define     PJB_PCLASS_UPGRADE
#define     PJB_PCLASS_MAX
#define     MTC_CMDFLAG
#define     MTR_RESPFLAG
#define     DISPMAX                         (x)
#define     MTC_ECHO
#define     MTR_ECHO
#define     MTC_SOLICIT
#define     MTR_SOLICIT
#define     MTC_GETINFO
#define     MTR_GETINFO
#define     PJB_CONFIG_MAX
#define     MTC_READTOC
#define     MTR_READTOC
#define     MTC_WRITETOC
#define     MTR_WRITETOC
#define     MTC_COMMITTOC
#define     MTR_COMMITTOC
#define     PJB_TOC_MAX
#define     MTC_READBLOCKHDR
#define     MTR_READBLOCKHDR
#define     MTC_WRITEBLOCK
#define     MTR_WRITEBLOCK
#define     MTC_READBLOCK
#define     MTR_READBLOCK
#define     PJB_STORAGE_MAX
#define     MTC_OPENSOFT
#define     MTR_OPENSOFT
#define     MTC_WRITESOFT
#define     MTR_WRITESOFT
#define     MTC_COMMITSOFT
#define     MTR_COMMITSOFT
#define     MTC_REBOOT
#define     MTR_REBOOT
#define     PJB_UPGRADE_MAX
#define     BOOTMETHOD_MAIN
#define     BOOTMETHOD_RECOVERY
#define     IT_UINT
#define     IT_STRING
#define     IT_U32
#define     IT_U16
#define     IT_U8
#define     IT_4BREC
#define     IT_REC
#define     IT_END
#define     IT_TYPE                         (item)
#define     IT_DBGSTR
#define     IT_FSVERSION
#define     IT_CLICKSINTOC
#define     IT_TOTALBLOCKS
#define     IT_ERRORCOUNT
#define     IT_VALIDTOCS
#define     IT_CURTOCCLICKS
#define     IT_ISOLDTOC
#define     IT_HWVER
#define     IT_SWVER
#define     IT_FRIENDLYNAME
#define     IT_FEATURES
#define     IT_CHECKSUM
#define     IT_DEBUG1
#define     IT_DEBUG2
#define     IT_DEBUG3
#define     IT_SECTOR
#define     IT_SSN
#define     IT_DIAGPROG
#define     IT_DIAGARG
#define     PJBPROTO_HEADER_SIZE
int         pjbproto_build_header_from_record
                                            (EBUF *buf,
                                             PJBPKTHDR *hdr);
int         pjbproto_build_header           (EBUF *buf,
                                             u8 class,
                                             u8 cmd,
                                             u8 fmt,
                                             u8 status,
                                             u32 xid,
                                             u32 block,
                                             u16 click);
int         pjbproto_parse_header           (EBUF *buf,
                                             u8 *aclass,
                                             u8 *cmd,
                                             u8 *fmt,
                                             u8 *status,
                                             u32 *xid,
                                             u32 *block,
                                             u16 *click);
int         pjbproto_parse_header_to_record (EBUF *buf,
                                             PJBPKTHDR *rec);
int         pjbproto_get_header             (EBUF *buf,
                                             PJBPKTHDR *rec);
int         pjbproto_build_itemlist         (EBUF *buf,
                                             ...);
int         pjbproto_parse_itemlist         (EBUF *buf,
                                             ...);

Description

This module builds and parses PJB packets and item lists.

Details

PJB_PROTOCOL_VERSION

#define PJB_PROTOCOL_VERSION	1


DROP_PACKET

#define DROP_PACKET	1


KEEP_PACKET

#define KEEP_PACKET	0


PJBPROTO_COMMAND_TIMEOUT

#define PJBPROTO_COMMAND_TIMEOUT	1000	/* msecs for command timeout */


PJBPROTO_POLL_INTERVAL

#define PJBPROTO_POLL_INTERVAL		10	/* msecs between polls */


PJBPROTO_RETRY_COUNT

#define PJBPROTO_RETRY_COUNT		4	/* number of retries */


PJBPROTO_SOL_RETRY_COUNT

#define PJBPROTO_SOL_RETRY_COUNT	2	/* solicit retries */


PJB_FMT_NODATA

#define PJB_FMT_NODATA		0	/* nothing follows */


PJB_FMT_BULKDATA

#define PJB_FMT_BULKDATA	1	/* raw data follows */


PJB_FMT_ITEMLIST

#define PJB_FMT_ITEMLIST	2	/* item list follows */


PJB_FMT_CONTINUE

#define PJB_FMT_CONTINUE	3	/* I'm still working, keep waiting */


PJB_FMT_CONTINUE_ITEM

#define PJB_FMT_CONTINUE_ITEM	4	/* Still working, with item list*/


PJB_PCLASS_CONFIG

#define PJB_PCLASS_CONFIG	0	/* config & status */


PJB_PCLASS_TOC

#define PJB_PCLASS_TOC		1	/* table of contents mgmt */


PJB_PCLASS_STORAGE

#define PJB_PCLASS_STORAGE	2	/* storage mgmt */


PJB_PCLASS_UPGRADE

#define PJB_PCLASS_UPGRADE	3	/* upgrade of software */


PJB_PCLASS_MAX

#define PJB_PCLASS_MAX		4


MTC_CMDFLAG

#define MTC_CMDFLAG		0x00	/* lack of bit indicates cmds */


MTR_RESPFLAG

#define MTR_RESPFLAG		0x01	/* this bit indicates responses */


DISPMAX()

#define DISPMAX(x)	((x+1)/2)

x : 


MTC_ECHO

#define MTC_ECHO		0x00	/* echo request */


MTR_ECHO

#define MTR_ECHO		0x01	/* echo reply */


MTC_SOLICIT

#define MTC_SOLICIT		0x02	/* solicit request */


MTR_SOLICIT

#define MTR_SOLICIT		0x03	/* solicit response */


MTC_GETINFO

#define MTC_GETINFO		0x04	/* get info */


MTR_GETINFO

#define MTR_GETINFO		0x05	/* get info response */


PJB_CONFIG_MAX

#define PJB_CONFIG_MAX		0x06	/* highest code */


MTC_READTOC

#define MTC_READTOC		0x00	/* read TOC */


MTR_READTOC

#define MTR_READTOC		0x01	/* read TOC response */


MTC_WRITETOC

#define MTC_WRITETOC		0x02	/* write TOC */


MTR_WRITETOC

#define MTR_WRITETOC		0x03	/* write TOC response */


MTC_COMMITTOC

#define MTC_COMMITTOC		0x04	/* commit TOC */


MTR_COMMITTOC

#define MTR_COMMITTOC		0x05 	/* commit TOC response */


PJB_TOC_MAX

#define PJB_TOC_MAX		0x06


MTC_READBLOCKHDR

#define MTC_READBLOCKHDR	0x00	/* read block header */


MTR_READBLOCKHDR

#define MTR_READBLOCKHDR	0x01	/* read block header response */


MTC_WRITEBLOCK

#define MTC_WRITEBLOCK		0x02	/* write block */


MTR_WRITEBLOCK

#define MTR_WRITEBLOCK		0x03	/* write block response */


MTC_READBLOCK

#define MTC_READBLOCK		0x04    /* read block */ 


MTR_READBLOCK

#define MTR_READBLOCK		0x05    /* read block response */


PJB_STORAGE_MAX

#define PJB_STORAGE_MAX		0x06


MTC_OPENSOFT

#define MTC_OPENSOFT		0x00	/* open software upgrade */


MTR_OPENSOFT

#define MTR_OPENSOFT		0x01	/* open software upgrade response */


MTC_WRITESOFT

#define MTC_WRITESOFT		0x02	/* write software */


MTR_WRITESOFT

#define MTR_WRITESOFT		0x03	/* write software response */


MTC_COMMITSOFT

#define MTC_COMMITSOFT		0x04	/* commit software */


MTR_COMMITSOFT

#define MTR_COMMITSOFT		0x05	/* commit software response */


MTC_REBOOT

#define MTC_REBOOT		0x06	/* reboot PJB */


MTR_REBOOT

#define MTR_REBOOT		0x07	/* reboot response */


PJB_UPGRADE_MAX

#define PJB_UPGRADE_MAX		0x08


BOOTMETHOD_MAIN

#define     BOOTMETHOD_MAIN


BOOTMETHOD_RECOVERY

#define     BOOTMETHOD_RECOVERY


IT_UINT

#define IT_UINT		0x1000		/* int (32 bits on wire, machine


IT_STRING

#define IT_STRING	0x2000		/* ASCII string, null terminated */


IT_U32

#define IT_U32		0x3000		/* always 32 bits */


IT_U16

#define IT_U16		0x4000		/* always 16 bits */


IT_U8

#define IT_U8		0x5000		/* always 8 bits */


IT_4BREC

#define IT_4BREC	0x6000		/* 4 bytes */


IT_REC

#define IT_REC		0x7000		/* record (bytes) */


IT_END

#define IT_END		(0)		/* last item */


IT_TYPE()

#define IT_TYPE(item)   ((item)&0xF000) /* get item type from item */

item : 


IT_DBGSTR

#define IT_DBGSTR	(IT_STRING | 1)	/* debug message */


IT_FSVERSION

#define IT_FSVERSION	(IT_UINT  | 2)  /* filesystem version */


IT_CLICKSINTOC

#define IT_CLICKSINTOC  (IT_UINT  | 3)  /* clicks in the TOC */


IT_TOTALBLOCKS

#define IT_TOTALBLOCKS  (IT_UINT  | 4)  /* total allocation blocks in disk */


IT_ERRORCOUNT

#define IT_ERRORCOUNT   (IT_UINT  | 5)  /* cumulative errors on disk */


IT_VALIDTOCS

#define IT_VALIDTOCS    (IT_UINT  | 6)  /* number of valid TOCs */


IT_CURTOCCLICKS

#define IT_CURTOCCLICKS (IT_UINT  | 7)  /* # of clicks in the TOC */


IT_ISOLDTOC

#define IT_ISOLDTOC     (IT_UINT  | 8)  /* nonzero if it's an old TOC */


IT_HWVER

#define IT_HWVER        (IT_UINT  | 9)  /* hardware version */


IT_SWVER

#define IT_SWVER        (IT_UINT  | 10) /* software version */


IT_FRIENDLYNAME

#define IT_FRIENDLYNAME (IT_STRING | 11) /* friendly PJB name */


IT_FEATURES

#define IT_FEATURES     (IT_UINT  | 12)  /* feature bits */


IT_CHECKSUM

#define IT_CHECKSUM     (IT_4BREC | 13)  /* checksum field */


IT_DEBUG1

#define IT_DEBUG1	(IT_UINT  | 14)


IT_DEBUG2

#define IT_DEBUG2       (IT_UINT  | 15)


IT_DEBUG3

#define IT_DEBUG3       (IT_UINT  | 16)


IT_SECTOR

#define IT_SECTOR       (IT_UINT  | 17)


IT_SSN

#define IT_SSN		(IT_REC   | 18)


IT_DIAGPROG

#define	IT_DIAGPROG	(IT_UINT  | 19)	/* diagnostic to run */


IT_DIAGARG

#define	IT_DIAGARG	(IT_UINT  | 20)	/* argument to diagnostic */


PJBPROTO_HEADER_SIZE

#define PJBPROTO_HEADER_SIZE	15


pjbproto_build_header_from_record ()

int         pjbproto_build_header_from_record
                                            (EBUF *buf,
                                             PJBPKTHDR *hdr);

This routine builds the fixed portion of a PJB packet. We use this function call instead of a structure copy to work around the different representations of data between the 56309 and the X86

buf : an EBUF structure
hdr : record containing header fields
Returns : number of bytes copied to the structure


pjbproto_build_header ()

int         pjbproto_build_header           (EBUF *buf,
                                             u8 class,
                                             u8 cmd,
                                             u8 fmt,
                                             u8 status,
                                             u32 xid,
                                             u32 block,
                                             u16 click);

This routine builds the fixed portion of a PJB packet. We use this function call instead of a structure copy to work around the different representations of data between the 56309 and the X86

buf : an EBUF structure
class : Header field
cmd : Header field
fmt : Header field
status : Header field
xid : Header field
block : Header field
click : Header field
Returns : number of bytes copied to the structure


pjbproto_parse_header ()

int         pjbproto_parse_header           (EBUF *buf,
                                             u8 *aclass,
                                             u8 *cmd,
                                             u8 *fmt,
                                             u8 *status,
                                             u32 *xid,
                                             u32 *block,
                                             u16 *click);

This routine parses the fixed portion of a PJB packet, unpacking the data into a record. We use this function call instead of a structure copy to work around the different representations of data between the 56309 and the X86

buf : an EBUF structure
aclass : Pointer to header field - NULL indicates don't copy this field
cmd : Pointer to header field - NULL indicates don't copy this field
fmt : Pointer to header field - NULL indicates don't copy this field
status : Pointer to header field - NULL indicates don't copy this field
xid : Pointer to header field - NULL indicates don't copy this field
block : Pointer to header field - NULL indicates don't copy this field
click : Pointer to header field - NULL indicates don't copy this field
Returns : >=0 = ok, <0 means the packet has problems.


pjbproto_parse_header_to_record ()

int         pjbproto_parse_header_to_record (EBUF *buf,
                                             PJBPKTHDR *rec);

This routine parses the fixed portion of a PJB packet, unpacking the data into a record. We use this function call instead of a structure copy to work around the different representations of data between the 56309 and the X86

buf : an EBUF structure
rec : a PJBPKTHDR record
Returns : >=0 = ok, <0 means the packet has problems.


pjbproto_get_header ()

int         pjbproto_get_header             (EBUF *buf,
                                             PJBPKTHDR *rec);

Retrieve the header information from a packet, without disturbing the packet's data pointer and length. This is used in the receive routines to verify headres before passing the data to a handler.

buf : an EBUF structure
rec : a PJBPKTHDR record
Returns : >=0 = ok, <0 means the packet has problems.


pjbproto_build_itemlist ()

int         pjbproto_build_itemlist         (EBUF *buf,
                                             ...);

Builds an item list in the specified buffer. the arg list is a variable-argument list, in the form of itemcode,value,itemcode,value,...,0

buf : an EBUF structure
... : items to add
Returns : number of bytes added


pjbproto_parse_itemlist ()

int         pjbproto_parse_itemlist         (EBUF *buf,
                                             ...);

Parse an item list. The input parameter is a variable-length arglist, in the form itemcode,ptr,itemcode,ptr,...,0 where ptr is a pointer to where to put the item's data. For strings and records, ptr is actually a pointer to the pointer to the data (the data is not copied).

buf : an EBUF structure
... : items to add
Returns : number of fields extracted