Harald Welte | 619b2a6 | 2019-11-22 00:35:52 +0100 | [diff] [blame] | 1 | module VPCD_Types { |
| 2 | |
| 3 | /* VPCD/VPICC Types, implementing the protocol used by vpcd/vpicc of |
| 4 | * vsmartcard.git by Frank Morgner. |
| 5 | */ |
| 6 | |
| 7 | import from General_Types all; |
| 8 | import from Osmocom_Types all; |
| 9 | |
| 10 | type enumerated VPCD_CtrlCmd { |
| 11 | VPCD_CTRL_OFF (0), |
| 12 | VPCD_CTRL_ON (1), |
| 13 | VPCD_CTRL_RESET (2), |
| 14 | VPCD_CTRL_ATR (4) |
| 15 | } with { variant "FIELDLENGTH(8)" }; |
| 16 | |
| 17 | type union VPCD_MsgUnion { |
| 18 | VPCD_CtrlCmd ctrl, |
| 19 | octetstring data |
| 20 | }; |
| 21 | |
| 22 | type record VPCD_PDU { |
| 23 | uint16_t len, |
| 24 | VPCD_MsgUnion u |
| 25 | } with { |
| 26 | variant (len) "LENGTHTO(u)" |
| 27 | variant (u) "CROSSTAG( |
| 28 | ctrl, len = 1; |
| 29 | data, OTHERWISE)" |
| 30 | }; |
| 31 | |
| 32 | |
| 33 | template (value) VPCD_PDU ts_VPCD_CTRL(template (value) VPCD_CtrlCmd cmd) := { |
| 34 | len := 0, // overwritten |
| 35 | u := { |
| 36 | ctrl := cmd |
| 37 | } |
| 38 | } |
| 39 | template (value) VPCD_PDU ts_VPCD_CTRL_OFF := ts_VPCD_CTRL(VPCD_CTRL_OFF); |
| 40 | template (value) VPCD_PDU ts_VPCD_CTRL_ON := ts_VPCD_CTRL(VPCD_CTRL_ON); |
| 41 | template (value) VPCD_PDU ts_VPCD_CTRL_RESET := ts_VPCD_CTRL(VPCD_CTRL_RESET); |
| 42 | template (value) VPCD_PDU ts_VPCD_CTRL_ATR := ts_VPCD_CTRL(VPCD_CTRL_ATR); |
| 43 | template (value) VPCD_PDU ts_VPCD_DATA(template (value) octetstring data) := { |
| 44 | len := 0, //overwritten |
| 45 | u := { |
| 46 | data := data |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | template (present) VPCD_PDU tr_VPCD_CTRL(template (present) VPCD_CtrlCmd cmd) := { |
| 51 | len := ?, |
| 52 | u := { |
| 53 | ctrl := cmd |
| 54 | } |
| 55 | } |
| 56 | template (present) VPCD_PDU tr_VPCD_CTRL_OFF := tr_VPCD_CTRL(VPCD_CTRL_OFF); |
| 57 | template (present) VPCD_PDU tr_VPCD_CTRL_ON := tr_VPCD_CTRL(VPCD_CTRL_ON); |
| 58 | template (present) VPCD_PDU tr_VPCD_CTRL_RESET := tr_VPCD_CTRL(VPCD_CTRL_RESET); |
| 59 | template (present) VPCD_PDU tr_VPCD_CTRL_ATR := tr_VPCD_CTRL(VPCD_CTRL_ATR); |
| 60 | template (present) VPCD_PDU tr_VPCD_DATA(template (present) octetstring data) := { |
| 61 | len := ?, |
| 62 | u := { |
| 63 | data := data |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | external function enc_VPCD_PDU(in VPCD_PDU msg) return octetstring |
| 68 | with { extension "prototype(convert) encode(RAW)" }; |
| 69 | |
| 70 | external function dec_VPCD_PDU(in octetstring msg) return VPCD_PDU |
| 71 | with { extension "prototype(convert) decode(RAW)" }; |
| 72 | |
| 73 | |
| 74 | |
| 75 | } with { encode "RAW" }; |