summaryrefslogtreecommitdiff
path: root/interface/sniffer/sniffer.h
blob: d1fb0be2ba533350361c4735880b5082c023b117 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#ifndef interface_sniffer_sniffer_h
#define interface_sniffer_sniffer_h
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    interface/sniffer/sniffer.h
 * \brief   Sniffer public functions. 
 * \ingroup interface_sniffer
 *
 */
#include "common/defs/ethernet.h"
#include "common/defs/homeplugAV.h"

#include "lib/bitstream.h"
#include "hal/hle/defs.h"
#include "string.h"

#include "mac/pbproc/pbproc.h"
#include "mac/common/pb.h"


/** Send a message to the interface. This message shall be send to the linux driver.
 * \param  user_data  the data provided in the function registration
 * \param  message  the message to send.
 * \param  length  the message length
 */
typedef void (*interface_sniffer_send_message_cb_t) (void *user_data,
                                                     uint *message, uint length);


/** Forward declaration. */
typedef struct interface_sniffer_t interface_sniffer_t; 


/** Initialise the sniffer and all the callback of the sniffer.
 * \param  cb the function to call when the sniffer needs to send a message.
 * \param  user_data the data to provide on each function callback provided.
 */
interface_sniffer_t*
interface_sniffer_init (interface_sniffer_send_message_cb_t cb, void *user_data);


/** Uninitalise the sniffer.
 * \param  ctx the sniffer context.
 */
void
interface_sniffer_uninit (interface_sniffer_t *ctx);

/** Configure the sniffer.
 * \param  ctx the sniffer context
 * \param  data the data to configure the sniffer.
 */
void
interface_sniffer_configure (interface_sniffer_t *ctx, uint data);


/** Copy a MME to the buffer and request the interface to send the MME.
 * \param  ctx the sniffer context.
 * \param  mme the MME buffer
 * \param  length the MME length
 * \param  buffer the destination buffer.
 * \param  tx the MME way (TX/RX)
 * \param  encrypted  if the MME has been encrypted or not.
 */
void
interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
                            u8 *buffer, bool tx, bool encrypted);

/** Copy a MME to the buffer and request the interface to send the MME.
 * \param  ctx the sniffer context.
 * \param  mme the MME buffer
 * \param  length the MME length
 * \param  buffer the destination buffer.
 * \param  encrypted  if the MME has been encrypted or not.
 */
extern inline void
interface_sniffer_copy_mme_tx (interface_sniffer_t *ctx, u8 *mme, uint length,
                            u8 *buffer, bool encrypted)
{
    interface_sniffer_copy_mme (ctx, mme, length, buffer, true, encrypted);
}

/** Copy a MME to the buffer and request the interface to send the MME.
 * \param  ctx the sniffer context.
 * \param  mme the MME buffer
 * \param  length the MME length
 * \param  buffer the destination buffer.
 * \param  encrypted  if the MME has been encrypted or not.
 */
extern inline void
interface_sniffer_copy_mme_rx (interface_sniffer_t *ctx, u8 *mme, uint length,
                            u8 *buffer, bool encrypted)
{
    interface_sniffer_copy_mme (ctx, mme, length, buffer, false, encrypted);
}

/** Copy a beacon to the buffer and request the interface to send the copied beacon.
 * Encapsulate the beacon in a MME.
 * \param  ctx the sniffer context.
 * \param  beacon the beacon
 * \param  buffer the destination buffer.
 * \param  tx the beacon way (TX/RX)
 * \param  mac_address  the station mac address to fill the OSA ODA in the
 * MME.
 */
void
interface_sniffer_copy_beacon (interface_sniffer_t *ctx, pb_beacon_t *beacon,
                               u8 *buffer, bool tx, mac_t mac_address);

/** Copy a beacon to the buffer and request the interface to send the copied beacon.
 * Encapsulate the beacon in a MME.
 * \param  ctx the sniffer context.
 * \param  beacon the beacon
 * \param  buffer the destination buffer.
 * \param  mac_address  the station mac address to fill the OSA ODA in the
 * MME.
 */
extern inline void
interface_sniffer_copy_beacon_tx (interface_sniffer_t *ctx, pb_beacon_t *beacon,
                               u8 *buffer, mac_t mac_address)
{
    interface_sniffer_copy_beacon (ctx, beacon, buffer, true, mac_address);
}

/** Copy a beacon to the buffer and request the interface to send the copied beacon.
 * Encapsulate the beacon in a MME.
 * \param  ctx the sniffer context.
 * \param  beacon the beacon
 * \param  buffer the destination buffer.
 * \param  mac_address  the station mac address to fill the OSA ODA in the
 * MME.
 */
extern inline void
interface_sniffer_copy_beacon_rx (interface_sniffer_t *ctx, pb_beacon_t *beacon,
                               u8 *buffer, mac_t mac_address)
{
    interface_sniffer_copy_beacon (ctx, beacon, buffer, false, mac_address);
}

/** Provides the MME sniff status.
 * \param  ctx the sniffer context.
 * \param  tx the way.
 * \return  the MME sniff status.
 */
bool
interface_sniffer_mme_status (interface_sniffer_t *ctx, bool tx);


/** Provides the MME sniff status.
 * \param  ctx the sniffer context.
 * \return  the MME sniff status.
 */
extern inline bool
interface_sniffer_mme_status_tx (interface_sniffer_t *ctx)
{
    return interface_sniffer_mme_status(ctx, true);
}

/** Provides the MME sniff status.
 * \param  ctx the sniffer context.
 * \return  the MME sniff status.
 */
extern inline bool
interface_sniffer_mme_status_rx (interface_sniffer_t *ctx)
{
    return interface_sniffer_mme_status(ctx, false);
}

/** Provides the beacon sniff status.
 * \param  ctx the sniffer context.
 * \param  tx  the way.
 * \return  the beacon sniff status.
 */
bool
interface_sniffer_beacon_status (interface_sniffer_t *ctx, bool tx);

/** Provides the beacon sniff status.
 * \param  ctx the sniffer context.
 * \return  the beacon sniff status.
 */
extern inline bool
interface_sniffer_beacon_status_tx (interface_sniffer_t *ctx)
{
   return interface_sniffer_beacon_status (ctx, true); 
}

/** Provides the beacon sniff status.
 * \param  ctx the sniffer context.
 * \return  the beacon sniff status.
 */
extern inline bool
interface_sniffer_beacon_status_rx (interface_sniffer_t *ctx)
{
    return interface_sniffer_beacon_status (ctx, false); 
}

#endif /* interface_sniffer_sniffer_h */