1.\" $OpenBSD: $ 2.\" 3.\" Jim Rees <rees@umich.edu> 4.\" CITI Smartcard development <smartcards@umich.edu> 5.\" 6.Dd August 3, 2001 7.Dt SECTOK 3 8.Os 9.Sh NAME 10.Nm sectok 11.Nd library for communicating with ISO 7816 smartcards 12.Sh SYNOPSIS 13.Fd #include \&"sectok.h\&" 14.Ft int 15.Fn sectok_open "int rn" "int flags" "int *swp" 16.Ft int 17.Fn sectok_friendly_open "const char *rn" "int flags" "int *swp" 18.Ft int 19.Fn sectok_xopen "int rn" "int flags" "char *config_path" "char *driver_path" "int *swp" 20.Ft int 21.Fn sectok_reset "int fd" "int flags" "unsigned char *atr" "int *swp" 22.Ft int 23.Fo sectok_apdu 24.Fa int fd 25.Fa int cla 26.Fa int ins 27.Fa int p1 28.Fa int p2 29.Fa int ilen 30.Fa unsigned char *ibuf 31.Fa int olen 32.Fa unsigned char *obuf 33.Fa int *swp 34.Fc 35.Ft int 36.Fn sectok_cardpresent "int fd" 37.Ft int 38.Fn sectok_close "int fd" 39.Ft int 40.Fn sectok_selectfile "int fd" "int cla" "unsigned char *fid" "int *swp" 41.Ft void 42.Fn sectok_fmt_fid "char *fname" "unsigned char *fid" 43.Ft int 44.Fn sectok_parse_atr "int fd" "int flags" "unsigned char *atr" "int len" "struct scparam *param" 45.Ft void 46.Fn sectok_parse_fname "char *buf" "unsigned char *fid" 47.Ft int 48.Fn sectok_parse_input "char *ibuf" "unsigned char *obuf" "int olen" 49.Ft int 50.Fn sectok_get_input "FILE *f" "unsigned char *obuf" "int omin" "int olen" 51.Ft int 52.Fn sectok_fdump_reply "FILE *f" "unsigned char *p" "int n" "int sw" 53.Ft int 54.Fn sectok_dump_reply "unsigned char *p" "int n" "int sw" 55.Ft void 56.Fn sectok_print_sw "int sw" 57.Ft "char *" 58.Fn sectok_get_sw "int sw" 59.Ft "char *" 60.Fn sectok_get_ins "int ins" 61.Ft int 62.Fn sectok_swOK "int sw" 63.Sh DESCRIPTION 64.Nm 65provides initialization, input, output, and other basic routines for ISO 667816 smart cards. 67Many of the routines return a status word. 68This will either be an error code as given in the include file, 69or a SW1/SW2 pair as specified in ISO 7816. 70.Pp 71.Fn sectok_scopen 72opens a connection to a smart card via serial port number 73.Fa ttyn . 74Ports are 75numbered from 0, which corresponds to /dev/tty00 on UNIX. 76If there is no card in the reader, 77.Fn sectok_scopen 78will either wait for card insertion, or if flag 79.Dv STONOWAIT 80is given, it will return immediately with error 81.Dv STENOCARD . 82.Fa swp 83points to a status word that will be set on return. 84.Pp 85.Fn sectok_reset 86resets the card and returns the ATR in the buffer pointed to by 87.Fa atr 88if it is not 89.Dv NULL . 90If the 91.Dv STRFORCE 92flag is given, a connection to the card will be established 93using default protocol parameters even if the card ATR is illegal. 94.Pp 95.Fn sectok_apdu 96sends an APDU to the card with optional IN and OUT data. 97.Bd -literal -offset xx 98cla - application class 99ins - instruction code 100p1, p2 - per ISO 7816-3 or application dependent 101ilen - length of IN data 102ibuf - pointer to IN data 103olen - length of OUT data 104obuf - pointer to OUT data 105swp - pointer to return status word 106.Ed 107.Pp 108.Fn sectok_cardpresent 109returns whether a card is present in the reader. 110.Pp 111.Fn sectok_close 112closes a connection to a smart card. 113.Pp 114.Fn sectok_selectfile 115selects a file given its FID by sending a "select" apdu to the card. 116.Pp 117.Fn sectok_fmt_fid 118returns a printable name for a FID. 119.Pp 120.Fn sectok_parse_atr 121parses a card ATR and returns the protocol parameters. 122If the 123.Dv STRV 124flag is given it will print the parameters to standard out. 125.Pp 126.Fn sectok_parse_fname 127translates a printable name to a FID. 128.Pp 129.Fn sectok_print_sw 130looks up the error message string affiliated with a status word 131and writes it to standard out. 132.Pp 133.Fn sectok_swOK 134returns 1 if 135.Dv sw 136indicates success, or 0 if it indicates failure. 137.Sh SEE ALSO 138.Xr sectok 1 139.Sh AUTHORS 140Jim Rees 141.Aq rees@umich.edu 142