/* $Id$ * $URL$ * * Wireless Extension plugin * * Copyright (C) 2004 Xavier Vello * Copyright (C) 2004 Martin Hejl * Copyright (C) 2004 The LCD4Linux Team * * Losts of code borrowed from Wireless Tools, which is * Copyright (C) 1997-2002 Jean Tourrilhes * (avaible at http://web.hpl.hp.com/personal/Jean_Tourrilhes/Linux/) * * This file is part of LCD4Linux. * * LCD4Linux is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * LCD4Linux is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ /* * Exported functions: wifi_level wifi_noise wifi_quality wifi_protocol wifi_frequency wifi_bitrate wifi_essid wifi_op_mode wifi_sensitivity wifi_sec_mode All Functions take one parameter (the name of the device, like "wlan0", "ath0" and so on) */ #include "config.h" #include #include #include #include #include #include #include #include #include #include "debug.h" #include "plugin.h" #include "cfg.h" #include "hash.h" #include "qprintf.h" #ifdef WITH_DMALLOC #include #endif #define HASH_TTL 100 /*#define KILO 1e3 */ /*#define MEGA 1e6 */ /*#define GIGA 1e9 */ #define KEY_LEVEL "level" #define KEY_QUALITY "quality" #define KEY_NOISE "noise" #define KEY_PROTO "proto" #define KEY_FREQUENCY "frequency" #define KEY_BIT_RATE "bit_rate" #define KEY_ESSID "essid" #define KEY_OP_MODE "op_mode" #define KEY_SENS "sens" #define KEY_SEC_MODE "sec_mode" #define FREQ2FLOAT(m,e) (((double) m) * pow(10,e)) #define MWATT2DBM(in) ((int) (ceil(10.0 * log10((double) in)))) static HASH wireless; static int sock = -2; static char *operation_mode[] = { "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Monitor", "n/a" }; static void ioctl_error(const int line) { error("IOCTL call to wireless extensions in line %d returned error", line); } int do_ioctl(const int sock, /* Socket to the kernel */ const char *ifname, /* Device name */ const int request, /* WE ID */ struct iwreq *pwrq) { /* Fixed part of the request */ /* Set device name */ strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); /* Do the request */ return (ioctl(sock, request, pwrq)); } int get_range_info(const int sock, const char *ifname, struct iw_range *range) { struct iwreq req; char buffer[sizeof(struct iw_range) * 2]; /* Large enough */ if (sock <= 0) { return (-1); } /* Cleanup */ memset(buffer, 0, sizeof(buffer)); req.u.data.pointer = (caddr_t) buffer; req.u.data.length = sizeof(buffer); req.u.data.flags = 0; if (do_ioctl(sock, ifname, SIOCGIWRANGE, &req) < 0) return (-1); /* Copy stuff at the right place, ignore extra */ memcpy((char *) range, buffer, sizeof(struct iw_range)); return (0); } static int get_ifname(struct iwreq *preq, const char *dev) { /* do not cache this call !!! */ struct iwreq req; char key_buffer[32]; if (sock <= 0) { return (-1); } qprintf(key_buffer, sizeof(key_buffer), "%s.%s", dev, KEY_PROTO); if (!preq) preq = &req; if (do_ioctl(sock, dev, SIOCGIWNAME, preq)) { debug("%s isn't a wirelesss interface !", dev); return -1; } hash_put(&wireless, key_buffer, preq->u.name); return (0); } static int get_frequency(const char *dev, const char *key) { /* Get frequency / channel */ struct iwreq req; char qprintf_buffer[1024]; char key_buffer[32]; double freq; int age; qprintf(key_buffer, sizeof(key_buffer), "%s.%s", dev, key); age = hash_age(&wireless, key); /* reread every HASH_TTL msec only */ if (age > 0 && age <= HASH_TTL) { return (0); } if (get_ifname(&req, dev) != 0) { return (-1); } req.u.data.length = 0; req.u.data.flags = 1; /* Clear updated flag */ if (do_ioctl(sock, dev, SIOCGIWFREQ, &req) < 0) { ioctl_error(__LINE__); return -1; } freq = FREQ2FLOAT(req.u.freq.m, req.u.freq.e); /*if( freq>= GIGA) snprintf(qprintf_buffer,sizeof(qprintf_buffer), "%g GHz", freq / GIGA); else if(freq>= MEGA) snprintf(qprintf_buffer,sizeof(qprintf_buffer), "%g MHz", freq / MEGA); else snprintf(qprintf_buffer,sizeof(qprintf_buffer), "%g kHz", freq / KILO); */ snprintf(qprintf_buffer, sizeof(qprintf_buffer), "%g", freq); hash_put(&wireless, key_buffer, qprintf_buffer); return (0); } static int get_essid(const char *dev, const char *key) { /* Get ESSID */ struct iwreq req; char key_buffer[32]; char essid_buffer[IW_ESSID_MAX_SIZE + 1]; int age; qprintf(key_buffer, sizeof(key_buffer), "%s.%s", dev, key); age = hash_age(&wireless, key); /* reread every HASH_TTL msec only */ if (age > 0 && age <= HASH_TTL) { return (0); } if (get_ifname(&req, dev) != 0) { return (-1); } memset(essid_buffer, 0, sizeof(essid_buffer
# Channel table for Fronteira - MG - Brazil
# Source: http://www.portalbsd.com.br/terrestres_channels.php?channels=1027

# Physical channel 23
[Rede Vida]
	DELIVERY_SYSTEM = ISDBT
	BANDWIDTH_HZ = 6000000
	FREQUENCY = 527142857
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	ISDBT_LAYER_ENABLED = 7
	ISDBT_SOUND_BROADCASTING = 0
	ISDBT_SB_SUBCHANNEL_ID = 0
	ISDBT_SB_SEGMENT_IDX = 0
	ISDBT_SB_SEGMENT_COUNT = 0
	ISDBT_LAYERA_FEC = AUTO
	ISDBT_LAYERA_MODULATION = QAM/AUTO
	ISDBT_LAYERA_SEGMENT_COUNT = 0
	ISDBT_LAYERA_TIME_INTERLEAVING = 0
	ISDBT_LAYERB_FEC = AUTO
	ISDBT_LAYERB_MODULATION = QAM/AUTO
	ISDBT_LAYERB_SEGMENT_COUNT = 0
	ISDBT_LAYERB_TIME_INTERLEAVING = 0
	ISDBT_LAYERC_FEC = AUTO
	ISDBT_LAYERC_MODULATION = QAM/AUTO
	ISDBT_LAYERC_SEGMENT_COUNT = 0
	ISDBT_LAYERC_TIME_INTERLEAVING = 0

# Physical channel 28
[TV Paranaíba]
	DELIVERY_SYSTEM = ISDBT
	BANDWIDTH_HZ = 6000000
	FREQUENCY = 557142857
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	ISDBT_LAYER_ENABLED = 7
	ISDBT_SOUND_BROADCASTING = 0
	ISDBT_SB_SUBCHANNEL_ID = 0
	ISDBT_SB_SEGMENT_IDX = 0
	ISDBT_SB_SEGMENT_COUNT = 0
	ISDBT_LAYERA_FEC = AUTO
	ISDBT_LAYERA_MODULATION = QAM/AUTO
	ISDBT_LAYERA_SEGMENT_COUNT = 0
	ISDBT_LAYERA_TIME_INTERLEAVING = 0
	ISDBT_LAYERB_FEC = AUTO
	ISDBT_LAYERB_MODULATION = QAM/AUTO
	ISDBT_LAYERB_SEGMENT_COUNT = 0
	ISDBT_LAYERB_TIME_INTERLEAVING = 0
	ISDBT_LAYERC_FEC = AUTO
	ISDBT_LAYERC_MODULATION = QAM/AUTO
	ISDBT_LAYERC_SEGMENT_COUNT = 0
	ISDBT_LAYERC_TIME_INTERLEAVING = 0

# Physical channel 31
[TV Integração Ituiutaba]
	DELIVERY_SYSTEM = ISDBT
	BANDWIDTH_HZ = 6000000
	FREQUENCY = 575142857
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	ISDBT_LAYER_ENABLED = 7
	ISDBT_SOUND_BROADCASTING = 0
	ISDBT_SB_SUBCHANNEL_ID = 0
	ISDBT_SB_SEGMENT_IDX = 0
	ISDBT_SB_SEGMENT_COUNT = 0
	ISDBT_LAYERA_FEC = AUTO
	ISDBT_LAYERA_MODULATION = QAM/AUTO
	ISDBT_LAYERA_SEGMENT_COUNT = 0
	ISDBT_LAYERA_TIME_INTERLEAVING = 0
	ISDBT_LAYERB_FEC = AUTO
	ISDBT_LAYERB_MODULATION = QAM/AUTO
	ISDBT_LAYERB_SEGMENT_COUNT = 0
	ISDBT_LAYERB_TIME_INTERLEAVING = 0
	ISDBT_LAYERC_FEC = AUTO
	ISDBT_LAYERC_MODULATION = QAM/AUTO
	ISDBT_LAYERC_SEGMENT_COUNT = 0
	ISDBT_LAYERC_TIME_INTERLEAVING = 0
result(result, dev, KEY_NOISE, get_stats(dev, KEY_NOISE)); } static void wireless_protocol(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_PROTO, get_ifname(NULL, dev)); } static void wireless_frequency(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_FREQUENCY, get_frequency(dev, KEY_FREQUENCY)); } static void wireless_bitrate(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_BIT_RATE, get_bitrate(dev, KEY_BIT_RATE)); } static void wireless_essid(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_ESSID, get_essid(dev, KEY_ESSID)); } static void wireless_op_mode(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_OP_MODE, get_op_mode(dev, KEY_OP_MODE)); } static void wireless_sensitivity(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_SENS, get_sens(dev, KEY_SENS)); } static void wireless_sec_mode(RESULT * result, RESULT * arg1) { char *dev = R2S(arg1); if (check_socket() != 0) return; save_result(result, dev, KEY_SEC_MODE, get_sec_mode(dev, KEY_SEC_MODE)); } /* init and cleanup */ int plugin_init_wireless(void) { hash_create(&wireless); AddFunction("wifi::level", 1, wireless_level); AddFunction("wifi::noise", 1, wireless_noise); AddFunction("wifi::quality", 1, wireless_quality); AddFunction("wifi::protocol", 1, wireless_protocol); AddFunction("wifi::frequency", 1, wireless_frequency); AddFunction("wifi::bitrate", 1, wireless_bitrate); AddFunction("wifi::essid", 1, wireless_essid); AddFunction("wifi::op_mode", 1, wireless_op_mode); AddFunction("wifi::sensitivity", 1, wireless_sensitivity); AddFunction("wifi::sec_mode", 1, wireless_sec_mode); return 0; } void plugin_exit_wireless(void) { if (sock > 0) close(sock); hash_destroy(&wireless); }