rb-lorcon 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +15 -0
- data/ext/Lorcon.c +525 -0
- data/ext/Lorcon.h +19 -0
- data/ext/extconf.rb +10 -0
- data/lib/rb-lorcon.rb +1 -0
- metadata +60 -0
data/README.markdown
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
rb-lorcon
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
A simple ruby wrapper for the lorcon library. Note that this is a fork of ruby-lorcon from the Metasploit framework.
|
|
5
|
+
|
|
6
|
+
Compiling
|
|
7
|
+
---------
|
|
8
|
+
|
|
9
|
+
ruby extconf.rb
|
|
10
|
+
make
|
|
11
|
+
|
|
12
|
+
Installing
|
|
13
|
+
----------
|
|
14
|
+
|
|
15
|
+
gem install dxoigmn-rb-lorcon
|
data/ext/Lorcon.c
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
#include "Lorcon.h"
|
|
2
|
+
#include "ruby.h"
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
self.license = GPLv2;
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
This is a derivative of the tx.c sample included with lorcon:
|
|
10
|
+
http://802.11ninja.net/lorcon/
|
|
11
|
+
|
|
12
|
+
lorcon is free software; you can redistribute it and/or modify
|
|
13
|
+
it under the terms of the GNU General Public License as published by
|
|
14
|
+
the Free Software Foundation; either version 2 of the License, or
|
|
15
|
+
(at your option) any later version.
|
|
16
|
+
|
|
17
|
+
lorcon is distributed in the hope that it will be useful,
|
|
18
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
GNU General Public License for more details.
|
|
21
|
+
|
|
22
|
+
You should have received a copy of the GNU General Public License
|
|
23
|
+
along with lorcon; if not, write to the Free Software
|
|
24
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
25
|
+
|
|
26
|
+
Copyright (c) 2005 dragorn and Joshua Wright
|
|
27
|
+
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
Lots of code borrowed from Tom Wambold's pylorcon:
|
|
32
|
+
http://pylorcon.googlecode.com/ - tom5760[at]gmail.com
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
All ruby-lorcon/rubyisms are by Metasploit LLC (C) 2006-2007
|
|
37
|
+
http://metasploit.com/ - msfdev[at]metasploit.com
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
VALUE mLorcon;
|
|
41
|
+
VALUE cDevice;
|
|
42
|
+
|
|
43
|
+
VALUE lorcon_get_version(VALUE self) {
|
|
44
|
+
return INT2NUM(tx80211_getversion());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
VALUE lorcon_cap_to_list(int cap) {
|
|
48
|
+
VALUE list;
|
|
49
|
+
list = rb_ary_new();
|
|
50
|
+
|
|
51
|
+
if ((cap & TX80211_CAP_SNIFF) != 0)
|
|
52
|
+
rb_ary_push(list, rb_str_new2("SNIFF"));
|
|
53
|
+
|
|
54
|
+
if ((cap & TX80211_CAP_TRANSMIT) != 0)
|
|
55
|
+
rb_ary_push(list, rb_str_new2("TRANSMIT"));
|
|
56
|
+
|
|
57
|
+
if ((cap & TX80211_CAP_SEQ) != 0)
|
|
58
|
+
rb_ary_push(list, rb_str_new2("SEQ"));
|
|
59
|
+
|
|
60
|
+
if ((cap & TX80211_CAP_BSSTIME) != 0)
|
|
61
|
+
rb_ary_push(list, rb_str_new2("BSSTIME"));
|
|
62
|
+
|
|
63
|
+
if ((cap & TX80211_CAP_FRAG) != 0)
|
|
64
|
+
rb_ary_push(list, rb_str_new2("FRAG"));
|
|
65
|
+
|
|
66
|
+
if ((cap & TX80211_CAP_CTRL) != 0)
|
|
67
|
+
rb_ary_push(list, rb_str_new2("CTRL"));
|
|
68
|
+
|
|
69
|
+
if ((cap & TX80211_CAP_DURID) != 0)
|
|
70
|
+
rb_ary_push(list, rb_str_new2("DURID"));
|
|
71
|
+
|
|
72
|
+
if ((cap & TX80211_CAP_SNIFFACK) != 0)
|
|
73
|
+
rb_ary_push(list, rb_str_new2("SNIFFACK"));
|
|
74
|
+
|
|
75
|
+
if ((cap & TX80211_CAP_SELFACK) != 0)
|
|
76
|
+
rb_ary_push(list, rb_str_new2("SELFACK"));
|
|
77
|
+
|
|
78
|
+
if ((cap & TX80211_CAP_TXNOWAIT) != 0)
|
|
79
|
+
rb_ary_push(list, rb_str_new2("TXNOWAIT"));
|
|
80
|
+
|
|
81
|
+
if ((cap & TX80211_CAP_DSSSTX) != 0)
|
|
82
|
+
rb_ary_push(list, rb_str_new2("DSSSTX"));
|
|
83
|
+
|
|
84
|
+
if ((cap & TX80211_CAP_OFDMTX) != 0)
|
|
85
|
+
rb_ary_push(list, rb_str_new2("OFDMTX"));
|
|
86
|
+
|
|
87
|
+
if ((cap & TX80211_CAP_MIMOTX) != 0)
|
|
88
|
+
rb_ary_push(list, rb_str_new2("MIMOTX"));
|
|
89
|
+
|
|
90
|
+
if ((cap & TX80211_CAP_SETRATE) != 0)
|
|
91
|
+
rb_ary_push(list, rb_str_new2("SETRATE"));
|
|
92
|
+
|
|
93
|
+
if ((cap & TX80211_CAP_SETMODULATION) != 0)
|
|
94
|
+
rb_ary_push(list, rb_str_new2("SETMODULATION"));
|
|
95
|
+
|
|
96
|
+
if ((cap & TX80211_CAP_NONE) != 0)
|
|
97
|
+
rb_ary_push(list, rb_str_new2("NONE"));
|
|
98
|
+
|
|
99
|
+
return list;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
static VALUE lorcon_driver_list(VALUE self) {
|
|
104
|
+
VALUE list;
|
|
105
|
+
VALUE hash;
|
|
106
|
+
|
|
107
|
+
struct tx80211_cardlist *cards = NULL;
|
|
108
|
+
int i;
|
|
109
|
+
|
|
110
|
+
list = rb_hash_new();
|
|
111
|
+
cards = tx80211_getcardlist();
|
|
112
|
+
if (cards == NULL) {
|
|
113
|
+
return(Qnil);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (i = 1; i < cards->num_cards; i++) {
|
|
117
|
+
hash = rb_hash_new();
|
|
118
|
+
rb_hash_aset(hash, rb_str_new2("name"), rb_str_new2(cards->cardnames[i]));
|
|
119
|
+
rb_hash_aset(hash, rb_str_new2("description"), rb_str_new2(cards->descriptions[i]));
|
|
120
|
+
rb_hash_aset(hash, rb_str_new2("capabilities"), lorcon_cap_to_list(cards->capabilities[i]));
|
|
121
|
+
rb_hash_aset(list, rb_str_new2(cards->cardnames[i]), hash);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
tx80211_freecardlist(cards);
|
|
125
|
+
return(list);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static VALUE lorcon_device_get_channel(VALUE self) {
|
|
129
|
+
struct rldev *rld;
|
|
130
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
131
|
+
return INT2NUM(tx80211_getchannel(&rld->in_tx));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static VALUE lorcon_device_set_channel(VALUE self, VALUE channel) {
|
|
135
|
+
struct rldev *rld;
|
|
136
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
137
|
+
tx80211_setchannel(&rld->in_tx, NUM2INT(channel));
|
|
138
|
+
return INT2NUM(tx80211_getchannel(&rld->in_tx));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void lorcon_device_free(struct rldev *rld) {
|
|
142
|
+
if (tx80211_getmode(&rld->in_tx) >= 0) {
|
|
143
|
+
tx80211_close(&rld->in_tx);
|
|
144
|
+
}
|
|
145
|
+
free(&rld->in_tx);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
static VALUE lorcon_device_get_mode(VALUE self) {
|
|
150
|
+
struct rldev *rld;
|
|
151
|
+
int mode;
|
|
152
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
mode = tx80211_getmode(&rld->in_tx);
|
|
156
|
+
if (mode < 0) {
|
|
157
|
+
rb_raise(rb_eArgError, "Lorcon could not determine the mode of this device: %s", tx80211_geterrstr(&rld->in_tx));
|
|
158
|
+
return(Qnil);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
switch (mode) {
|
|
162
|
+
case TX80211_MODE_AUTO:
|
|
163
|
+
return rb_str_new2("AUTO");
|
|
164
|
+
break;
|
|
165
|
+
case TX80211_MODE_ADHOC:
|
|
166
|
+
return rb_str_new2("ADHOC");
|
|
167
|
+
break;
|
|
168
|
+
case TX80211_MODE_INFRA:
|
|
169
|
+
return rb_str_new2("INFRA");
|
|
170
|
+
break;
|
|
171
|
+
case TX80211_MODE_MASTER:
|
|
172
|
+
return rb_str_new2("MASTER");
|
|
173
|
+
break;
|
|
174
|
+
case TX80211_MODE_REPEAT:
|
|
175
|
+
return rb_str_new2("REPEAT");
|
|
176
|
+
break;
|
|
177
|
+
case TX80211_MODE_SECOND:
|
|
178
|
+
return rb_str_new2("SECOND");
|
|
179
|
+
break;
|
|
180
|
+
case TX80211_MODE_MONITOR:
|
|
181
|
+
return rb_str_new2("MONITOR");
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
return Qnil;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static VALUE lorcon_device_set_mode(VALUE self, VALUE rmode) {
|
|
190
|
+
struct rldev *rld;
|
|
191
|
+
char *setmode = StringValuePtr(rmode);
|
|
192
|
+
int mode = -1;
|
|
193
|
+
|
|
194
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
195
|
+
|
|
196
|
+
if (strcmp(setmode, "AUTO") == 0) {
|
|
197
|
+
mode = TX80211_MODE_AUTO;
|
|
198
|
+
} else if (strcmp(setmode, "ADHOC") == 0) {
|
|
199
|
+
mode = TX80211_MODE_ADHOC;
|
|
200
|
+
} else if (strcmp(setmode, "INFRA") == 0) {
|
|
201
|
+
mode = TX80211_MODE_INFRA;
|
|
202
|
+
} else if (strcmp(setmode, "MASTER") == 0) {
|
|
203
|
+
mode = TX80211_MODE_MASTER;
|
|
204
|
+
} else if (strcmp(setmode, "REPEAT") == 0) {
|
|
205
|
+
mode = TX80211_MODE_REPEAT;
|
|
206
|
+
} else if (strcmp(setmode, "SECOND") == 0) {
|
|
207
|
+
mode = TX80211_MODE_SECOND;
|
|
208
|
+
} else if (strcmp(setmode, "MONITOR") == 0) {
|
|
209
|
+
mode = TX80211_MODE_MONITOR;
|
|
210
|
+
} else {
|
|
211
|
+
rb_raise(rb_eArgError, "Invalid mode specified: %s", tx80211_geterrstr(&rld->in_tx));
|
|
212
|
+
return(Qnil);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return INT2NUM(tx80211_setmode(&rld->in_tx, mode));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
static VALUE lorcon_device_set_functional_mode(VALUE self, VALUE rmode) {
|
|
220
|
+
struct rldev *rld;
|
|
221
|
+
char *funcmode = StringValuePtr(rmode);
|
|
222
|
+
int mode = -1;
|
|
223
|
+
|
|
224
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
225
|
+
|
|
226
|
+
if (strcmp(funcmode, "RFMON") == 0) {
|
|
227
|
+
mode = TX80211_FUNCMODE_RFMON;
|
|
228
|
+
} else if (strcmp(funcmode, "INJECT") == 0) {
|
|
229
|
+
mode = TX80211_FUNCMODE_INJECT;
|
|
230
|
+
} else if (strcmp(funcmode, "INJMON") == 0) {
|
|
231
|
+
mode = TX80211_FUNCMODE_INJMON;
|
|
232
|
+
} else {
|
|
233
|
+
rb_raise(rb_eArgError, "Invalid mode specified: %s", tx80211_geterrstr(&rld->in_tx));
|
|
234
|
+
return(Qnil);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (tx80211_setfunctionalmode(&rld->in_tx, mode) != 0) {
|
|
238
|
+
rb_raise(rb_eArgError, "Lorcon could not set the functional mode: %s", tx80211_geterrstr(&rld->in_tx));
|
|
239
|
+
return(Qnil);
|
|
240
|
+
}
|
|
241
|
+
return Qtrue;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
static VALUE lorcon_device_get_txrate(VALUE self) {
|
|
246
|
+
struct rldev *rld;
|
|
247
|
+
int txrate;
|
|
248
|
+
|
|
249
|
+
txrate = tx80211_gettxrate(&rld->in_packet);
|
|
250
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
251
|
+
|
|
252
|
+
switch (txrate) {
|
|
253
|
+
case TX80211_RATE_DEFAULT:
|
|
254
|
+
return UINT2NUM(0);
|
|
255
|
+
break;
|
|
256
|
+
case TX80211_RATE_1MB:
|
|
257
|
+
return UINT2NUM(1);
|
|
258
|
+
break;
|
|
259
|
+
case TX80211_RATE_2MB:
|
|
260
|
+
return UINT2NUM(2);
|
|
261
|
+
break;
|
|
262
|
+
case TX80211_RATE_5_5MB:
|
|
263
|
+
return UINT2NUM(5);
|
|
264
|
+
break;
|
|
265
|
+
case TX80211_RATE_6MB:
|
|
266
|
+
return UINT2NUM(6);
|
|
267
|
+
break;
|
|
268
|
+
case TX80211_RATE_9MB:
|
|
269
|
+
return UINT2NUM(9);
|
|
270
|
+
break;
|
|
271
|
+
case TX80211_RATE_11MB:
|
|
272
|
+
return UINT2NUM(11);
|
|
273
|
+
break;
|
|
274
|
+
case TX80211_RATE_24MB:
|
|
275
|
+
return UINT2NUM(24);
|
|
276
|
+
break;
|
|
277
|
+
case TX80211_RATE_36MB:
|
|
278
|
+
return UINT2NUM(36);
|
|
279
|
+
break;
|
|
280
|
+
case TX80211_RATE_48MB:
|
|
281
|
+
return UINT2NUM(48);
|
|
282
|
+
break;
|
|
283
|
+
case TX80211_RATE_108MB:
|
|
284
|
+
return UINT2NUM(108);
|
|
285
|
+
break;
|
|
286
|
+
default:
|
|
287
|
+
rb_raise(rb_eArgError, "Lorcon could not determine the tx rate: %s", tx80211_geterrstr(&rld->in_tx));
|
|
288
|
+
return(Qnil);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return Qnil;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
static VALUE lorcon_device_set_txrate(VALUE self, VALUE rrate) {
|
|
296
|
+
struct rldev *rld;
|
|
297
|
+
float settxrate = -1;
|
|
298
|
+
int txrate = -1;
|
|
299
|
+
|
|
300
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
if ((tx80211_getcapabilities(&rld->in_tx) & TX80211_CAP_SETRATE) == 0) {
|
|
304
|
+
rb_raise(rb_eArgError, "Lorcon does not support setting the tx rate for this card");
|
|
305
|
+
return(Qnil);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
settxrate = NUM2DBL(rrate);
|
|
309
|
+
|
|
310
|
+
if (settxrate == -1) {
|
|
311
|
+
txrate = TX80211_RATE_DEFAULT;
|
|
312
|
+
} else if (settxrate == 1) {
|
|
313
|
+
txrate = TX80211_RATE_1MB;
|
|
314
|
+
} else if (settxrate == 2) {
|
|
315
|
+
txrate = TX80211_RATE_2MB;
|
|
316
|
+
} else if (settxrate == 5.5) {
|
|
317
|
+
txrate = TX80211_RATE_5_5MB;
|
|
318
|
+
} else if (settxrate == 6) {
|
|
319
|
+
txrate = TX80211_RATE_6MB;
|
|
320
|
+
} else if (settxrate == 9) {
|
|
321
|
+
txrate = TX80211_RATE_9MB;
|
|
322
|
+
} else if (settxrate == 11) {
|
|
323
|
+
txrate = TX80211_RATE_11MB;
|
|
324
|
+
} else if (settxrate == 24) {
|
|
325
|
+
txrate = TX80211_RATE_24MB;
|
|
326
|
+
} else if (settxrate == 36) {
|
|
327
|
+
txrate = TX80211_RATE_36MB;
|
|
328
|
+
} else if (settxrate == 48) {
|
|
329
|
+
txrate = TX80211_RATE_48MB;
|
|
330
|
+
} else if (settxrate == 108) {
|
|
331
|
+
txrate = TX80211_RATE_108MB;
|
|
332
|
+
} else {
|
|
333
|
+
rb_raise(rb_eArgError, "Lorcon does not support this rate setting");
|
|
334
|
+
return(Qnil);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (tx80211_settxrate(&rld->in_tx, &rld->in_packet, txrate) < 0) {
|
|
338
|
+
rb_raise(rb_eArgError, "Lorcon could not set the tx rate: %s", tx80211_geterrstr(&rld->in_tx));
|
|
339
|
+
return(Qnil);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return INT2NUM(txrate);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
static VALUE lorcon_device_get_modulation(VALUE self) {
|
|
346
|
+
struct rldev *rld;
|
|
347
|
+
int mod;
|
|
348
|
+
|
|
349
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
350
|
+
|
|
351
|
+
mod = tx80211_getmodulation(&rld->in_packet);
|
|
352
|
+
switch (mod) {
|
|
353
|
+
case TX80211_MOD_DEFAULT:
|
|
354
|
+
return rb_str_new2("DEFAULT");
|
|
355
|
+
break;
|
|
356
|
+
case TX80211_MOD_FHSS:
|
|
357
|
+
return rb_str_new2("FHSS");
|
|
358
|
+
break;
|
|
359
|
+
case TX80211_MOD_DSSS:
|
|
360
|
+
return rb_str_new2("DSSS");
|
|
361
|
+
break;
|
|
362
|
+
case TX80211_MOD_OFDM:
|
|
363
|
+
return rb_str_new2("OFDM");
|
|
364
|
+
break;
|
|
365
|
+
case TX80211_MOD_TURBO:
|
|
366
|
+
return rb_str_new2("TURBO");
|
|
367
|
+
break;
|
|
368
|
+
case TX80211_MOD_MIMO:
|
|
369
|
+
return rb_str_new2("MIMO");
|
|
370
|
+
break;
|
|
371
|
+
case TX80211_MOD_MIMOGF:
|
|
372
|
+
return rb_str_new2("MIMOGF");
|
|
373
|
+
break;
|
|
374
|
+
default:
|
|
375
|
+
rb_raise(rb_eArgError, "Lorcon could not get the modulation value");
|
|
376
|
+
return(Qnil);
|
|
377
|
+
}
|
|
378
|
+
return(Qnil);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
static VALUE lorcon_device_set_modulation(VALUE self, VALUE rmod) {
|
|
382
|
+
struct rldev *rld;
|
|
383
|
+
char *setmod = NULL;
|
|
384
|
+
int mod;
|
|
385
|
+
|
|
386
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
387
|
+
|
|
388
|
+
if ((tx80211_getcapabilities(&rld->in_tx) & TX80211_CAP_SETMODULATION) == 0) {
|
|
389
|
+
rb_raise(rb_eArgError, "Lorcon does not support setting the modulation for this card");
|
|
390
|
+
return(Qnil);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
setmod = StringValuePtr(rmod);
|
|
394
|
+
|
|
395
|
+
if (strcmp(setmod, "DEFAULT") == 0) {
|
|
396
|
+
mod = TX80211_MOD_DEFAULT;
|
|
397
|
+
} else if (strcmp(setmod, "FHSS") == 0) {
|
|
398
|
+
mod = TX80211_MOD_FHSS;
|
|
399
|
+
} else if (strcmp(setmod, "DSSS") == 0) {
|
|
400
|
+
mod = TX80211_MOD_DSSS;
|
|
401
|
+
} else if (strcmp(setmod, "OFDM") == 0) {
|
|
402
|
+
mod = TX80211_MOD_OFDM;
|
|
403
|
+
} else if (strcmp(setmod, "TURBO") == 0) {
|
|
404
|
+
mod = TX80211_MOD_TURBO;
|
|
405
|
+
} else if (strcmp(setmod, "MIMO") == 0) {
|
|
406
|
+
mod = TX80211_MOD_MIMO;
|
|
407
|
+
} else if (strcmp(setmod, "MIMOGF") == 0) {
|
|
408
|
+
mod = TX80211_MOD_MIMOGF;
|
|
409
|
+
} else {
|
|
410
|
+
rb_raise(rb_eArgError, "Lorcon does not support this modulation setting");
|
|
411
|
+
return(Qnil);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (tx80211_setmodulation(&rld->in_tx, &rld->in_packet, mod) < 0) {
|
|
415
|
+
rb_raise(rb_eArgError, "Lorcon could not set the modulation: %s", tx80211_geterrstr(&rld->in_tx));
|
|
416
|
+
return(Qnil);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return INT2NUM(mod);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
static VALUE lorcon_device_get_capabilities(VALUE self) {
|
|
423
|
+
struct rldev *rld;
|
|
424
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
425
|
+
return(lorcon_cap_to_list(tx80211_getcapabilities(&rld->in_tx)));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
static VALUE lorcon_device_open(int argc, VALUE *argv, VALUE self) {
|
|
429
|
+
struct rldev *rld;
|
|
430
|
+
int ret = 0;
|
|
431
|
+
int drivertype = INJ_NODRIVER;
|
|
432
|
+
char *driver, *intf;
|
|
433
|
+
VALUE rbdriver, rbintf;
|
|
434
|
+
VALUE obj;
|
|
435
|
+
|
|
436
|
+
rb_scan_args(argc, argv, "2", &rbintf, &rbdriver);
|
|
437
|
+
|
|
438
|
+
driver = STR2CSTR(rbdriver);
|
|
439
|
+
intf = STR2CSTR(rbintf);
|
|
440
|
+
|
|
441
|
+
obj = Data_Make_Struct(cDevice, struct rldev, 0, lorcon_device_free, rld);
|
|
442
|
+
|
|
443
|
+
drivertype = tx80211_resolvecard(driver);
|
|
444
|
+
if (drivertype == INJ_NODRIVER) {
|
|
445
|
+
rb_raise(rb_eArgError, "Lorcon did not recognize the specified driver");
|
|
446
|
+
return(Qnil);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (tx80211_init(&rld->in_tx, intf, drivertype) < 0) {
|
|
450
|
+
rb_raise(rb_eRuntimeError, "Lorcon could not initialize the interface: %s", tx80211_geterrstr(&rld->in_tx));
|
|
451
|
+
return(Qnil);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/* Open the interface to get a socket */
|
|
455
|
+
ret = tx80211_open(&rld->in_tx);
|
|
456
|
+
if (ret < 0) {
|
|
457
|
+
rb_raise(rb_eRuntimeError, "Lorcon could not open the interface: %s", tx80211_geterrstr(&rld->in_tx));
|
|
458
|
+
return(Qnil);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
rb_obj_call_init(obj, 0, 0);
|
|
462
|
+
return(obj);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
static VALUE lorcon_device_write(int argc, VALUE *argv, VALUE self) {
|
|
466
|
+
struct rldev *rld;
|
|
467
|
+
int ret = 0;
|
|
468
|
+
int cnt = 0;
|
|
469
|
+
int dly = 0;
|
|
470
|
+
|
|
471
|
+
VALUE rbbuff, rbcnt, rbdelay;
|
|
472
|
+
|
|
473
|
+
Data_Get_Struct(self, struct rldev, rld);
|
|
474
|
+
|
|
475
|
+
switch(rb_scan_args(argc, argv, "12", &rbbuff, &rbcnt, &rbdelay)) {
|
|
476
|
+
case 1:
|
|
477
|
+
rbdelay = INT2NUM(0);
|
|
478
|
+
case 2:
|
|
479
|
+
rbcnt = INT2NUM(1);
|
|
480
|
+
default:
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
cnt = NUM2INT(rbcnt);
|
|
485
|
+
dly = NUM2INT(rbdelay);
|
|
486
|
+
|
|
487
|
+
rld->in_packet.packet = StringValuePtr(rbbuff);
|
|
488
|
+
rld->in_packet.plen = RSTRING(rbbuff)->len;
|
|
489
|
+
|
|
490
|
+
for (; cnt > 0; cnt--) {
|
|
491
|
+
ret = tx80211_txpacket(&rld->in_tx, &rld->in_packet);
|
|
492
|
+
if (ret < 0) {
|
|
493
|
+
rb_raise(rb_eRuntimeError, "Lorcon could not transmit packet: %s", tx80211_geterrstr(&rld->in_tx));
|
|
494
|
+
return(INT2NUM(ret));
|
|
495
|
+
}
|
|
496
|
+
if (dly > 0)
|
|
497
|
+
#ifdef _MSC_VER
|
|
498
|
+
Sleep(dly);
|
|
499
|
+
#else
|
|
500
|
+
usleep(dly);
|
|
501
|
+
#endif
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return (rbcnt);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
void Init_Lorcon() {
|
|
508
|
+
mLorcon = rb_define_module("Lorcon");
|
|
509
|
+
rb_define_module_function(mLorcon, "drivers", lorcon_driver_list, 0);
|
|
510
|
+
rb_define_module_function(mLorcon, "version", lorcon_get_version, 0);
|
|
511
|
+
|
|
512
|
+
cDevice = rb_define_class_under(mLorcon, "Device", rb_cObject);
|
|
513
|
+
rb_define_singleton_method(cDevice, "new", lorcon_device_open, -1);
|
|
514
|
+
rb_define_method(cDevice, "channel", lorcon_device_get_channel, 0);
|
|
515
|
+
rb_define_method(cDevice, "channel=", lorcon_device_set_channel, 1);
|
|
516
|
+
rb_define_method(cDevice, "write", lorcon_device_write, -1);
|
|
517
|
+
rb_define_method(cDevice, "mode", lorcon_device_get_mode, 0);
|
|
518
|
+
rb_define_method(cDevice, "mode=", lorcon_device_set_mode, 1);
|
|
519
|
+
rb_define_method(cDevice, "fmode=", lorcon_device_set_functional_mode, 1);
|
|
520
|
+
rb_define_method(cDevice, "txrate", lorcon_device_get_txrate, 0);
|
|
521
|
+
rb_define_method(cDevice, "txrate=", lorcon_device_set_txrate, 1);
|
|
522
|
+
rb_define_method(cDevice, "modulation", lorcon_device_get_modulation, 0);
|
|
523
|
+
rb_define_method(cDevice, "modulation=", lorcon_device_set_modulation, 1);
|
|
524
|
+
rb_define_method(cDevice, "capabilities", lorcon_device_get_capabilities, 0);
|
|
525
|
+
}
|
data/ext/Lorcon.h
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#ifndef _MSFLORCON_H
|
|
2
|
+
#define _MSFLORCON_H
|
|
3
|
+
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <errno.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
#include <stdio.h>
|
|
8
|
+
#include <sys/socket.h>
|
|
9
|
+
#include <tx80211.h>
|
|
10
|
+
#include <tx80211_packet.h>
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
struct rldev {
|
|
14
|
+
struct tx80211 in_tx;
|
|
15
|
+
struct tx80211_packet in_packet;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
#endif
|
data/ext/extconf.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'mkmf'
|
|
3
|
+
|
|
4
|
+
dir_config("orcon")
|
|
5
|
+
|
|
6
|
+
if (have_library("orcon", "tx80211_txpacket", "tx80211.h") or find_library("orcon", "tx80211_txpacket", "tx80211.h"))
|
|
7
|
+
create_makefile("Lorcon")
|
|
8
|
+
else
|
|
9
|
+
puts "Error: the lorcon library was not found, please see the README"
|
|
10
|
+
end
|
data/lib/rb-lorcon.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'Lorcon'
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rb-lorcon
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Cory T. Cornelius
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-08-02 00:00:00 -04:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: A simple lorcon wrapper.
|
|
17
|
+
email:
|
|
18
|
+
- cory.t.cornelius@dartmouth.edu
|
|
19
|
+
executables: []
|
|
20
|
+
|
|
21
|
+
extensions:
|
|
22
|
+
- ext/extconf.rb
|
|
23
|
+
extra_rdoc_files: []
|
|
24
|
+
|
|
25
|
+
files:
|
|
26
|
+
- README.markdown
|
|
27
|
+
- lib/rb-lorcon.rb
|
|
28
|
+
- ext/extconf.rb
|
|
29
|
+
- ext/Lorcon.c
|
|
30
|
+
- ext/Lorcon.h
|
|
31
|
+
has_rdoc: true
|
|
32
|
+
homepage: http://github.com/dxoigmn/rb-lorcon
|
|
33
|
+
licenses: []
|
|
34
|
+
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: "0"
|
|
45
|
+
version:
|
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: "0"
|
|
51
|
+
version:
|
|
52
|
+
requirements: []
|
|
53
|
+
|
|
54
|
+
rubyforge_project:
|
|
55
|
+
rubygems_version: 1.3.5
|
|
56
|
+
signing_key:
|
|
57
|
+
specification_version: 3
|
|
58
|
+
summary: Simple lorcon wrapper.
|
|
59
|
+
test_files: []
|
|
60
|
+
|