globalplatform
util.h
Go to the documentation of this file.
1 /* Copyright (c) 2009, Karsten Ohme
2  * This file is part of GlobalPlatform.
3  *
4  * GlobalPlatform is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * GlobalPlatform is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with GlobalPlatform. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
22 #ifndef OPGP_UTIL_H
23 #define OPGP_UTIL_H
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30 #ifdef WIN32
31 #include "stdafx.h"
32 #endif
33 
34 #include "globalplatform/types.h"
35 #include "globalplatform/library.h"
36 
40 typedef struct {
41  USHORT tag;
43  BYTE value[256];
45 } TLV;
46 
48 OPGP_NO_API
49 LONG read_TLV(PBYTE buffer, DWORD length, TLV *tlv);
50 
52 OPGP_NO_API
54 
56 OPGP_NO_API
57 DWORD get_short(PBYTE buf, DWORD offset);
58 
60 OPGP_NO_API
61 DWORD get_int(PBYTE buf, DWORD offset);
62 
64 DWORD get_number(PBYTE buf, DWORD offset, BYTE numLength);
65 
67 OPGP_NO_API
68 LONG parse_apdu_case(PBYTE apduCommand, DWORD apduCommandLength, PBYTE caseAPDU, PBYTE lc, PBYTE le);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif
get_short
OPGP_NO_API DWORD get_short(PBYTE buf, DWORD offset)
Returns an unsigned short int from the given position.
Definition: util.c:65
PBYTE
unsigned char * PBYTE
A Microsoft/Muscle LPBYTE, pointer to unsigned char.
Definition: types.h:48
TLV
Definition: util.h:40
read_TLV
OPGP_NO_API LONG read_TLV(PBYTE buffer, DWORD length, TLV *tlv)
Reads a TLV struct from the given buffer.
Definition: util.c:76
types.h
BYTE
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:51
LONG
long LONG
A long value.
Definition: types.h:53
TLV::tag
USHORT tag
The Tag.
Definition: util.h:41
convert_byte
OPGP_NO_API DWORD convert_byte(BYTE b)
Converts a ISO 7816-4 Le Byte into its value.
Definition: util.c:25
DWORD
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:52
get_number
DWORD get_number(PBYTE buf, DWORD offset, BYTE numLength)
Returns an unsigned int from the given position by taking just numLength bytes starting at offset int...
Definition: util.c:44
get_int
OPGP_NO_API DWORD get_int(PBYTE buf, DWORD offset)
Returns an unsigned int from the given position.
Definition: util.c:34
library.h
TLV::length
DWORD length
The length of the value.
Definition: util.h:42
parse_apdu_case
OPGP_NO_API LONG parse_apdu_case(PBYTE apduCommand, DWORD apduCommandLength, PBYTE caseAPDU, PBYTE lc, PBYTE le)
Parse the APDU case.
Definition: util.c:135
TLV::tlvLength
DWORD tlvLength
The length of the whole TLV.
Definition: util.h:44