aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gud/MobiCoreKernelApi/connection.h
blob: ba7f5091c2a4500da84ce70395243ff1208c429e (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/** @addtogroup MCD_MCDIMPL_DAEMON_SRV
 * @{
 * @file
 *
 * Connection data.
 *
 * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2011 -->
 */
#ifndef CONNECTION_H_
#define CONNECTION_H_

#include <linux/semaphore.h>

#include <stddef.h>
#include <stdbool.h>

#define MAX_PAYLOAD_SIZE 128

typedef struct {
	struct sock *socketDescriptor; /**< Netlink socket */
    uint32_t sequenceMagic; /**< Random? magic to match requests/answers */

	struct nlmsghdr *dataMsg;
    uint32_t dataLen; /**< How much connection data is left */
    void *dataStart; /**< Start pointer of remaining data */
    struct sk_buff *skb;

	struct semaphore dataSem; /**< Data protection semaphore */
	struct semaphore dataAvailableSem; /**< Data protection semaphore */

    pid_t selfPid; /**< PID address used for local connection */
    pid_t peerPid; /**< Remote PID for connection */

    struct list_head list; /**< The list param for using the kernel lists*/
} connection_t;

connection_t* connection_new(
	void
);

connection_t* connection_create(
    int          socketDescriptor,
    pid_t        dest
);

void connection_cleanup(
	connection_t *conn
);

/**
  * Connect to destination.
  *
  * @param Destination pointer.
  * @return true on success.
  */
bool connection_connect(
    connection_t *conn,
    pid_t        dest
);


/**
  * Read bytes from the connection.
  *
  * @param buffer    Pointer to destination buffer.
  * @param len       Number of bytes to read.
  * @return Number of bytes read.
  */
size_t connection_readDataBlock(
    connection_t *conn,
    void         *buffer,
    uint32_t     len
);
/**
  * Read bytes from the connection.
  *
  * @param buffer	Pointer to destination buffer.
  * @param len       Number of bytes to read.
  * @param timeout   Timeout in milliseconds
  * @return Number of bytes read.
  * @return -1 if select() failed (returned -1)
  * @return -2 if no data available, i.e. timeout
  */
size_t connection_readData(
    connection_t *conn,
    void         *buffer,
    uint32_t     len,
    int32_t      timeout
);

/**
  * Write bytes to the connection.
  *
  * @param buffer	Pointer to source buffer.
  * @param len		Number of bytes to read.
  * @return Number of bytes written.
  */
size_t connection_writeData(
    connection_t *conn,
    void         *buffer,
    uint32_t      len
);

/**
 * Write bytes to the connection.
 *
 * @param buffer	Pointer to source buffer.
 * @param len		Number of bytes to read.
 * @return Number of bytes written.
 */
int connection_process(
	connection_t *conn,
	struct sk_buff *skb
);

typedef struct list_head connectionVector_t;

#endif /* CONNECTION_H_ */

/** @} */