View | Details | Raw Unified | Return to bug 140475
Collapse All | Expand All

(-)panel-plugin/wi_bsd.c (-13 / +114 lines)
Lines 1-6 Link Here
1
/* $Id: wi_bsd.c 562 2004-12-03 18:29:41Z benny $ */
1
/* $Id: wi_bsd.c 562 2004-12-03 18:29:41Z benny $ */
2
/*-
2
/*-
3
 * Copyright (c) 2003 Benedikt Meurer <benny@xfce.org>
3
 * Copyright (c) 2003 Benedikt Meurer <benny@xfce.org>
4
 *               2008 Pietro Cerutti <gahr@gahr.ch>
5
 *                    (FreeBSD > 700000 adaptation)
4
 *
6
 *
5
 * Redistribution and use in source and binary forms, with or without
7
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
8
 * modification, are permitted provided that the following conditions
Lines 36-51 Link Here
36
#include <net/if.h>
38
#include <net/if.h>
37
#include <net/if_media.h>
39
#include <net/if_media.h>
38
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
40
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
41
#include <netinet/in.h>
42
#include <netinet/if_ether.h>
43
#include <sys/endian.h>
44
#if __FreeBSD_version >= 700000
45
#include <sys/types.h>
46
#include <sys/sysctl.h>
47
#include <net80211/ieee80211_ioctl.h>
48
#else
39
#include <net/if_var.h>
49
#include <net/if_var.h>
40
#include <net/ethernet.h>
50
#include <net/ethernet.h>
41
42
#include <dev/wi/if_wavelan_ieee.h>
51
#include <dev/wi/if_wavelan_ieee.h>
43
#if __FreeBSD_version >= 500033
44
#include <sys/endian.h>
45
#endif
52
#endif
46
#else
53
#else
47
#include <netinet/in.h>
48
#include <netinet/if_ether.h>
49
#ifdef __NetBSD__
54
#ifdef __NetBSD__
50
#include <net80211/ieee80211.h>
55
#include <net80211/ieee80211.h>
51
#include <net80211/ieee80211_ioctl.h>
56
#include <net80211/ieee80211_ioctl.h>
Lines 95-101 Link Here
95
};
100
};
96
101
97
static int _wi_carrier(const struct wi_device *);
102
static int _wi_carrier(const struct wi_device *);
103
#if defined(__FreeBSD__) && __FreeBSD_version > 700000
104
static int _wi_getval(const struct wi_device *, struct ieee80211req_scan_result *);
105
#else
98
static int _wi_getval(const struct wi_device *, struct wi_req *);
106
static int _wi_getval(const struct wi_device *, struct wi_req *);
107
#endif
99
static int _wi_vendor(const struct wi_device *, char *, size_t);
108
static int _wi_vendor(const struct wi_device *, char *, size_t);
100
static int _wi_netname(const struct wi_device *, char *, size_t);
109
static int _wi_netname(const struct wi_device *, char *, size_t);
101
static int _wi_quality(const struct wi_device *, int *);
110
static int _wi_quality(const struct wi_device *, int *);
Lines 193-216 Link Here
193
	return((ifmr.ifm_status & IFM_ACTIVE) != 0 ? WI_OK : WI_NOCARRIER);
202
	return((ifmr.ifm_status & IFM_ACTIVE) != 0 ? WI_OK : WI_NOCARRIER);
194
}
203
}
195
204
205
#if defined(__FreeBSD__) && __FreeBSD_version >= 700000
196
static int
206
static int
197
_wi_getval(const struct wi_device *device, struct wi_req *wr)
207
_wi_getval(const struct wi_device *device, struct ieee80211req_scan_result *scan)
198
{
208
{
199
  struct ifreq ifr;
209
   char buffer[24 * 1024];
210
   const uint8_t *bp;
211
   struct ieee80211req ireq;
212
   size_t len;
213
   bzero(&ireq, sizeof(ireq));
214
   strlcpy(ireq.i_name, device->interface, sizeof(ireq.i_name));
215
216
   ireq.i_type = IEEE80211_IOC_SCAN_RESULTS;
217
   ireq.i_data = buffer;
218
   ireq.i_len = sizeof(buffer);
219
220
   if(ioctl(device->socket, SIOCG80211, &ireq) < 0)
221
      return(WI_NOSUCHDEV);
200
222
201
  bzero((void*)&ifr, sizeof(ifr));
223
   if(ireq.i_len < sizeof(struct ieee80211req_scan_result))
202
  strlcpy(ifr.ifr_name, device->interface, sizeof(ifr.ifr_name));
224
      return(WI_NOSUCHDEV);
203
  ifr.ifr_data = (void*)wr;
204
225
205
  if (ioctl(device->socket, SIOCGWAVELAN, &ifr) < 0)
226
   memcpy(scan, buffer, sizeof(struct ieee80211req_scan_result));
206
    return(WI_NOSUCHDEV);
207
227
208
  return(WI_OK);
228
   return(WI_OK);
209
}
229
}
230
#else
231
static int
232
_wi_getval(const struct wi_device *device, struct wi_req *wr)
233
{
234
   struct ifreq ifr;
235
236
   bzero((void*)&ifr, sizeof(ifr));
237
   strlcpy(ifr.ifr_name, device->interface, sizeof(ifr.ifr_name));
238
   ifr.ifr_data = (void*)wr;
239
240
   if (ioctl(device->socket, SIOCGWAVELAN, &ifr) < 0)
241
      return(WI_NOSUCHDEV);
242
   
243
   return (WI_OK);
244
}
245
#endif
210
246
211
static int
247
static int
212
_wi_vendor(const struct wi_device *device, char *buffer, size_t len)
248
_wi_vendor(const struct wi_device *device, char *buffer, size_t len)
213
{
249
{
250
#if defined(__FreeBSD__) && __FreeBSD_version >= 700000
251
   /*
252
    * We use sysctl to get a device description
253
    */
254
   char mib[WI_MAXSTRLEN];
255
   char dev_name[WI_MAXSTRLEN];
256
   char *c = dev_name;
257
   int  dev_number;
258
259
   /*
260
    * Dirty hack to split the device name into name and number
261
    */
262
   strncpy(dev_name, device->interface, WI_MAXSTRLEN);
263
   while(!isdigit(*c)) c++;
264
   dev_number = (int)strtol(c, NULL, 10);
265
   *c = '\0';
266
267
   snprintf(mib, sizeof(mib), "dev.%s.%d.%%desc", dev_name, dev_number);
268
   if(sysctlbyname(mib, buffer, &len, NULL, 0) == -1) {
269
      /* check for wlan device instead */
270
      snprintf(mib, sizeof(mib), "net.%s.%d.%%parent", dev_name, dev_number);
271
      if(sysctlbyname(mib, buffer, &len, NULL, 0) == -1)
272
         return (WI_NOSUCHDEV);
273
   }
274
#else
214
#define WI_RID_STA_IDENTITY_LUCENT	0x1
275
#define WI_RID_STA_IDENTITY_LUCENT	0x1
215
#define WI_RID_STA_IDENTITY_PRISMII	0x2
276
#define WI_RID_STA_IDENTITY_PRISMII	0x2
216
#define WI_RID_STA_IDENTITY_SAMSUNG	0x3
277
#define WI_RID_STA_IDENTITY_SAMSUNG	0x3
Lines 250-255 Link Here
250
311
251
  snprintf(buffer, len, "%s (ID %d, version %d.%d)", vendor,
312
  snprintf(buffer, len, "%s (ID %d, version %d.%d)", vendor,
252
      wr.wi_val[0], wr.wi_val[2], wr.wi_val[3]);
313
      wr.wi_val[0], wr.wi_val[2], wr.wi_val[3]);
314
#endif
253
315
254
  return(WI_OK);
316
  return(WI_OK);
255
}
317
}
Lines 257-262 Link Here
257
static int
319
static int
258
_wi_netname(const struct wi_device *device, char *buffer, size_t len)
320
_wi_netname(const struct wi_device *device, char *buffer, size_t len)
259
{
321
{
322
#if defined(__FreeBSD__) && __FreeBSD_version >= 700000
323
   struct ieee80211req ireq;
324
325
   memset(&ireq, 0, sizeof(ireq));
326
   strncpy(ireq.i_name, device->interface, sizeof(ireq.i_name));
327
   ireq.i_type = IEEE80211_IOC_SSID;
328
   ireq.i_val = -1;
329
   ireq.i_data = buffer;
330
   ireq.i_len = len; 
331
   if (ioctl(device->socket, SIOCG80211, &ireq) < 0) 
332
      return WI_NOSUCHDEV;
333
#else
260
  struct wi_req wr;
334
  struct wi_req wr;
261
  int result;
335
  int result;
262
336
Lines 268-273 Link Here
268
    return(result);
342
    return(result);
269
343
270
  strlcpy(buffer, (char *)&wr.wi_val[1], MIN(len, le16toh(wr.wi_val[0]) + 1));
344
  strlcpy(buffer, (char *)&wr.wi_val[1], MIN(len, le16toh(wr.wi_val[0]) + 1));
345
#endif
271
346
272
  return(WI_OK);
347
  return(WI_OK);
273
}
348
}
Lines 275-280 Link Here
275
static int
350
static int
276
_wi_quality(const struct wi_device *device, int *quality)
351
_wi_quality(const struct wi_device *device, int *quality)
277
{
352
{
353
#if defined(__FreeBSD__) && __FreeBSD_version >= 700000
354
   struct ieee80211req_scan_result req;
355
   int result;
356
   bzero(&req, sizeof(req));
357
358
   if((result = _wi_getval(device, &req)) != WI_OK)
359
      return (result);
360
361
   *quality = req.isr_rssi * 2;
362
#else
278
  struct wi_req wr;
363
  struct wi_req wr;
279
  int result;
364
  int result;
280
365
Lines 289-294 Link Here
289
    *quality = le16toh(wr.wi_val[1]);
374
    *quality = le16toh(wr.wi_val[1]);
290
  else
375
  else
291
    *quality = le16toh(wr.wi_val[0]);
376
    *quality = le16toh(wr.wi_val[0]);
377
#endif
292
378
293
  return(WI_OK);
379
  return(WI_OK);
294
}
380
}
Lines 296-301 Link Here
296
static int
382
static int
297
_wi_rate(const struct wi_device *device, int *rate)
383
_wi_rate(const struct wi_device *device, int *rate)
298
{
384
{
385
#if defined(__FreeBSD__) && __FreeBSD_version >= 700000
386
   struct ieee80211req_scan_result req;
387
   int result, i, high;
388
   bzero(&req, sizeof(req));
389
390
   if((result = _wi_getval(device, &req)) != WI_OK)
391
      return (result);
392
393
   for(i=0, high=-1; i<req.isr_nrates; i++)
394
      if((req.isr_rates[i] & IEEE80211_RATE_VAL) > high)
395
         high = req.isr_rates[i] & IEEE80211_RATE_VAL;
396
   
397
   *rate = high / 2;
398
#else
299
  struct wi_req wr;
399
  struct wi_req wr;
300
  int result;
400
  int result;
301
401
Lines 307-312 Link Here
307
    return(result);
407
    return(result);
308
408
309
  *rate = le16toh(wr.wi_val[0]);
409
  *rate = le16toh(wr.wi_val[0]);
410
#endif
310
411
311
  return(WI_OK);
412
  return(WI_OK);
312
}
413
}

Return to bug 140475