summaryrefslogtreecommitdiff
path: root/test/tpm_test/ftdi_spi_tpm.i
blob: 2bbcded64bf9d3efb57393984599884300d1ea38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

%module ftdi_spi_tpm
typedef unsigned uint32_t;
typedef unsigned char uint8_t;

%{
typedef struct swig_string_data
{
  int size;
  char *data;
} swig_string_data;

extern int FtdiSpiInit(uint32_t freq, int enable_debug);
extern void FtdiStop(void);
extern swig_string_data FtdiSendCommandAndWait(char *tpm_command,
					       int command_size);
%}

%typemap(in) (char *tpm_command, int command_size)
{
        if(!PyString_Check($input))
        {
                PyErr_SetString(PyExc_ValueError, "String value required");
                return NULL;
        }

        $1 = PyString_AsString($input);
        $2 = PyString_Size($input);
}

%typemap(out) swig_string_data
{
        $result = PyBytes_FromStringAndSize($1.data, $1.size);
        free($1.data);
}

typedef struct swig_string_data
{
  int size;
  char *data;
} swig_string_data;

extern int FtdiSpiInit(uint32_t freq, int enable_debug);
extern void FtdiStop(void);
extern swig_string_data FtdiSendCommandAndWait(char *tpm_command,
					       int command_size);