You are on page 1of 52

Masters thesis in Computer Science and Engineering

Evaluation of path cost algorithms for a bridged wireless (wireless distribution


system) mobile network using the Spanning Tree Protocol







Stockholm, 2004

Allan Nadhmi Faraj

Royal Institute of Technology, Sweden











Swedish title: Evaluering av en vgkostnadsalgoritm fr Spanning Tree-protokollet i ett bryggat
trdlst mobilt ntverk genom anvndandet utav ett trdlst distributionssystem


Supervisors: Johan Moberg, Possio AB
Fredrik Widell, KTH NOC
Stefan Nilsson, NADA KTH

Examiner: Prof. Stefan Arnborg
Department of Numerical Analysis and Computing Science
Royal Institute of Technology

Master Thesis Project 2004-12-08 2(52)
Allan Nadhmi Faraj




















For my Mom and Dad, who made it all possible






























Master Thesis Project 2004-12-08 3(52)
Allan Nadhmi Faraj




Abstract


The aim of this Thesis was to evaluate a path cost algorithm for the Spanning Tree Protocol (STP) in a
wireless mobile network, using the Wireless Distribution System (WDS). For this task we have limited
ourselves to researching and experimentally verifying a cost based upon the signal and noise qualities
of the links. To provide layer two connectivity the Spanning Tree Protocol was used. This is to define
a loop-free topology that spans all bridges in the network. Each link in the topology represents a
cost/value.

Modified software was used to analyse the signal and noise values in order to calculate a proper
cost. This cost is inserted into the spanning tree protocol. The mathematical model, describing the
transition between given SNR values to a cost into STP, is roughly estimated through experiments.
The experiments were performed on five Possios wireless PX30 gateways. In short, the results of the
simulations have shown an improved performance of the wireless network when using the path cost
algorithm as compared to without.



Sammanfattning


Mlet med denna examensrapport r att utvrdera en kostnadsalgoritm fr Spanning Tree-protokollet i
ett trdlst mobilt ntverk, genom anvndandet utav ett trdlst distributionssystem. Fr denna uppgift
har vi begrnsat oss till att utforska och experimentellt verifiera en kostnad baserad p signal- och
brus- egenskaperna hos en lnk. Fr att tillgodose en lnklagersammankoppling s har Spanning Tree-
protokollet anvnts. Detta fr att definiera en loop-fri topologi som spnner ver alla bryggor i ett
ntverk. Varje lnk i topologin representerar en kostnad.

Modifierad mjukvara anvndes fr att analysera signal- och brusvrdena fr att p s stt kunna
rkna ut en kostnad. Denna kostnad stts in i Spanning Tree-protokollet. Den matematiska modellen
som beskriver verfringen mellan ett givet SNR (signal brus frhllande) vrde till en kostnad i STP
kommer att genom experiment grovt estimeras. Experimenten utfrdes p fem utav Possios trdlsa
PX30 bryggor. Sammanfattningsvis s visade resultaten av experimenten en frbttrad prestanda hos
det trdlsa ntverket nr man anvnde kostnadsalgoritmen till skillnad mot utan.


















Master Thesis Project 2004-12-08 4(52)
Allan Nadhmi Faraj




Preface


This report is the result of my masters project carried out at Possio AB in Stockholm during spring
2004. It is therefore the last part of my Master of Science degree at the Royal Institute of Technology.
Possio AB is an engineering company within tele-/data communication with more than 20 years of
experience. In short my thesis consisted of experimenting and programming Possios programmable
wireless router, PX30. It is to evaluate a path cost algorithm for obtaining a better use of bandwidth to
maintain a higher performance.

I would like to thank the following persons: Johan Moberg for being my supervisor and for giving
me great support at Possio AB. Thanks to Stefan Nilsson at the department of Numerical Analysis and
Computing Science for helping me getting started with this thesis. Thanks to Stefan Arnborg for being
my examiner at the Royal Institute of Technology. Great thanks to everybody at Possio AB for being
nice and helpful to me during my time there. Last but not least I also would like to thank Kambiz
Behrooz for his help, time and advice.





































Master Thesis Project 2004-12-08 5(52)
Allan Nadhmi Faraj




Table of Contents


1. Introduction............................................................................................................................. 7
1.1. Background....................................................................................................................... 7
1.2. Problem description .......................................................................................................... 7
1.3. Equipment and software.................................................................................................... 8
1.4. Possio AB.......................................................................................................................... 8
1.5. Project organization .......................................................................................................... 8
1.6. Outline............................................................................................................................... 9

2. WLAN - 802.11b ..................................................................................................................... 10
2.1. 802.11 Overview............................................................................................................... 10
2.2. Basic 802.11 definitions.................................................................................................... 12

3. WDS - Wireless Distribution System.................................................................................... 13
3.1. The 802.11 Distribution System....................................................................................... 13
3.2. What is the WDS?............................................................................................................. 13

4. STP Spanning Tree Protocol............................................................................................... 14
4.1. Spanning Tree Protocol Concepts..................................................................................... 14
4.2. Quality of Service in routing protocols............................................................................. 17

5. Bridges and Experimental Setup........................................................................................... 18

6. Algorithms and method discussion........................................................................................ 19
6.1. Costs from SNR 1
st
algorithm........................................................................................ 19
6.2. Additional algorithm 2
nd
algorithm................................................................................ 21

7. Results and evaluations .......................................................................................................... 23
7.1. Results with the 1
st
algorithm............................................................................................ 23
7.2. Results with the 2
nd
algorithm........................................................................................... 24

8. Conclusions.............................................................................................................................. 25
8.1. Discussion of the obtained results..................................................................................... 25
8.2. Future work....................................................................................................................... 25

9. References................................................................................................................................ 26

APPENDIX A PX30 pictures .................................................................................................... 27
A.1 Front picture with shell .................................................................................................... 27
A.2 Front picture without shell ............................................................................................... 27
A.3 Rear picture...................................................................................................................... 27

APPENDIX B Manual Reference page for Iwlist.................................................................... 28

APPENDIX C Iw_own source code .......................................................................................... 29

APPENDIX D Bridge Init script............................................................................................... 52




Master Thesis Project 2004-12-08 6(52)
Allan Nadhmi Faraj




List of Acronyms


AODV Ad hoc on-demand Distance Vector
AP Access Point
BPDU Bridge Protocol Data Unit
BSS Basic Service Set
CSMA/CA Carrier Sense Multiple Access with Collision Avoidance
DS Distribution System
DSSS Direct Sequence Spread Spectrum
ESS Extended Service Set
IBSS Independent Basic Server Set
IEEE Institute of Electrical and Electronics Engineers
IETF Internet Engineering Task Force
ISM band Industrial, Scientific and Medical band
KTH Royal Institute of Technology, (Swedish term is Kungliga Tekniska Hgskolan)
LAN Local Area Network
MAC Medium Access Control
MANET Mobile Ad hoc NETworking
NADA Department of Numerical Analysis and Computing Science, (Swedish term is
Numerisk Analys och Datalogi)
NIC Network Interface Card
OLSR Optimized Link State Routing
RFC Request for Comments
SNR Signal to Noise Ratio
SS Spread Spectrum
SSH Secure SHell
STA Spanning Tree Algorithm
STP Spanning Tree Protocol
WDS Wireless Distribution System
WLAN Wireless Local Area Network






















Master Thesis Project 2004-12-08 7(52)
Allan Nadhmi Faraj




1 Introduction


1.1 Background

This work has been carried out at Possio AB premises during spring 2004 in cooperation with NADA
1

at KTH
2
. Possio AB has developed among other things a wireless gateway called PX30, which acts as
an application server and as a bridge to wireless technologies. This development is due to the rapid
growth of wireless LANs. The PX30 can be used as an enhancement of existing networks or used in
full scale for deployment of wireless networks.

The 802.1D Spanning Tree Protocol (STP) standard is a link management protocol that prevents
undesirable bridging loops in a network while provides path redundancy in case one link fails. When
loops occur it confuses the forwarding process and allows duplicate frames to be forwarded. For a
proper functioning network we apply the spanning tree protocol so only one active path exists for data
in the network. Each link in the path represents a cost/value, but the algorithm for assigning the path
cost based upon the signal and noise qualities of the link is not subject to standardization. We might
allow for a better use of bandwidth by inserting different path cost.

If we want to enable transparent bridging in our wireless network such that it creates a wireless
backbone then the Wireless Distribution System (WDS) has to be used. This mode allows the wireless
nodes to only communicate with/through each others. A node might send data packets bound for a
station on another node over the wireless network. Transparent bridges get their name because they are
invisible to all the network nodes for which they provide services.


1.2 Problem description

Wireless networks have certain unique characteristics where the most important one is the
dynamically changing network of mobile devices. This imposes new demands on the protocol that is
being used. Link conditions and surrounding circumstances between wireless nodes can change quite
frequently. The wireless network needs thus to adapt to these changes in order to maintain a high
performance. This arrangement requires some support from the lower layer.

This final thesis discusses and evaluates two methods for assigning STP path costs using a
bridged, wireless (using WDS) and mobile network. A test-bed of Possios wireless routers (PX30)
will be used where the methods will be tested and experimental data will be obtained. For this task we
have limited ourselves to researching and experimentally verifying a cost based upon the signal and
noise qualities of the links. It was also desirable to compare the path cost assignment (i.e. in terms of
Quality of Service) with some proposed routing protocols for wireless Ad-Hoc Networks.

Since link conditions and surrounding circumstances between wireless nodes can change quite
frequently we should take this into account when evaluating the path cost algorithm. The topology in
the test-bed is mobile, and the changes are slow. The path cost assignment will be based upon which
of the presented methods to use, so that afterwards one could decide which of them given these
conditions should be choosed as the best one. What we define as best was that the percentage amount
of arrived data packets should be large. For the main part of the experiments the PING utility has been
used to gather the packet loss statistics.


1
NADA stands for Numerisk Analys och Datalogi and is the Swedish term for the Department of Numerical
Analysis and Computing Science.
2
KTH stands for Kungliga Tekniska Hgskolan, and is the Swedish term for the Royal Institute of Technology.
http://www.kth.se/eng/index.html
Master Thesis Project 2004-12-08 8(52)
Allan Nadhmi Faraj




1.3 Equipment and software

We need equipment in order to run any experiments, and software to analyze the data. So we start by
choosing the appropriate equipment to be used to perform the experiments. Five of Possios wireless
gateways (PX30) are used. For the wireless cards that were chosen in these experiments we had
SENAOs
3
pc card with two antenna jacks.

For obtaining and analyzing the data, I need to use the wireless tools package embedded in the
PX30 operating system. Since Iwlist is used to display some information from the wireless network, I
therefore modified the Iwlist source code (written in C) to gather the necessary data in real-time.

The new and modified Iwlist, suitably called Iw_own was developed to do this. Iw_own gathers
the data that is to be used, make some calculations and inserts the proper cost to the available protocol.
This is done in real-time so this new tool now reacts on dynamic changes. The source codes for
Iw_own can be found in APPENDIX C. New additions to the iwlist code are highlighted. More on
how the code works will be found in Chapter 6.


1.4 Possio AB

Possio AB
4
develops and market wireless router products that interconnects between cellular data
networking and local wireless technologies like WLAN and Bluetooth. Possio is a Stockholm based
engineering company with more than 20 years of experience in product development within tele-/data
communication.

Possio develops a programmable wireless router (PX30) that makes it possible to connect pcs,
hand-held devices, phones, and other WLAN or Bluetooth-enabled terminals to cellular networks
using GSM/GPRS, CDMA or UMTS networks. Possio also manufacture the worlds only integrated
GSM Fax as well as PCMCIA cards for GSM/GPRS and GSM-R. [12]


1.5 Project organization

Following persons have been involved in this masters project:

Master thesis author
M.Sc. Allan Nadhmi Faraj

Supervisor at Possio AB
M.Sc. Johan Moberg

Supervisor at Department of Numerical Analysis and Computing Science at Royal Institute of
Technology
Ph.D. Stefan Nilsson

Advisor at Network Operating Center, Royal Institute of Technology
System Engineer Fredrik Widell

Examiner at Royal Institute of Technology
Prof. Stefan Arnborg


3
http://www.senao.com
4
http://www.possio.com
Master Thesis Project 2004-12-08 9(52)
Allan Nadhmi Faraj




1.6 Outline

Chapter 1 is an introduction and a problem definition of the report. Chapters 2 and 3 cover the 802.11
basic concepts. Chapter 4 describes the Spanning Tree Protocol and its concepts. Chapter 5 explains
the bridge and the experimental setup for the wireless router (PX30).

Chapter 6 describes the algorithm and the experiments that were made using it. Chapter 7 and 8
concludes the whole report and chapter 9 holds the references that I have used. The appendices contain
some source code, pictures and an init script that was used.












































Master Thesis Project 2004-12-08 10(52)
Allan Nadhmi Faraj




2 WLAN 802.11b


2.1 802.11 Overview

Wireless Local Area Network has been deployed since 1980 as an appealing alternative to the usual
wired net because of its flexibility in our everyday life. The first WLAN standard arrived 1997 and is
called 802.11, which was developed by IEEE (Institute of Electrical and Electronic Engineers). [5]

For a secure transmission of the data there is a modulation technique called Spread Spectrum
(SS), which several of the 802.11 wireless LAN standards are using, including 802.11b. It basically
means that the information that is being sent is divided over the available bandwidth instead of using
the whole bandwidth as in the case for a channel. That technique was developed to make the
communication safer against eavesdropping or changing in the signal among other things. One of the
two variants of SS is the Direct Sequence Spread Spectrum (DSSS) technique, which encrypts the
data. The encryption is based on that bits of data in a haphazard sequence are mixed with the actual
data, and the sending and receiving station only knows this encryption. All stations are applying the
same code. It is also used to spread the data over a larger frequency spectrum. DSSS spreads the data
over a bandwidth of 25 MHz, which means that there is room in the frequency band for three non-
overlapping channels out of fourteen channels.

To minimize the interference between neighbouring access points you have to plan where to use
which channel and in that way configure multiple DSSS networks to operate simultaneously in the
same area. Fourteen channels are defined in the IEEE 802.11 for operation across the 2.4 GHz
frequency band. In North America 11 channels are allowed ranging from 2.412 GHz to 2.462 GHz. In
most of Europe thirteen channels are allowed ranging from 2.412 GHz to 2.472 GHz. As an example,
the channel arrangement for North America is illustrated in Figure 2.1.





One of the additions that IEEE did 1999 to 802.11 was 802.11b. This addition to the 802.11
standard meant an increase from 2 Mbps up to 11 Mbps in data rate, and can only be implemented if
DSSS is used. It can also use 5.5, 2 and 1 Mbps when 11 Mbps cannot be maintained. The 802.11b
standard is currently the most utilized within WLAN, and operates in the unlicensed 2.4 GHz ISM
band. [2] [5] [10]


2400 GHz 2.412 2.437 2.462 2483 GHz



Figure 2.1 Minimum channels spacing for DSSS Networks in North America
Channel 1 Channel 6 Channel 11
25 MHz 25 MHz
Master Thesis Project 2004-12-08 11(52)
Allan Nadhmi Faraj




Stations in a wireless network must be able to coordinate its admission and its usefulness of the
shared medium, and this is maintained by the MAC- protocol. The 802.11 MAC protocol is
CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance). The protocol can sense if the
channel is busy with the help of that the physical layer reads the energy levels of the
radiofrequencies. This is to determine if another station is transmitting or not and therefore gives this
information to the MAC protocol. Like CSMA/CD (used in wired networks) the CSMA/CA is used to
reduce the collisions in the network by listening to the network before transmission. CA (Collision
Avoidance) broadcasts to the network and warns everybody else that it will use the network for an
amount of time. The problem with CSMA/CA is that it kind of increases the network loads by
broadcasting before the real data actually is transmitted. [7] [10]

Wireless stations, STA (STAtion) and access points (AP) are also defined by the 802.11 standard.
A computer with a network interface card (NIC) but also handheld computers or something similar
with a network card is being able to act as a station. A unit which both can send and receive signals,
but also is able to connect wireless networks with each other or with physical networks is called an
access point. Every network card (NIC) is identified by a 48-bits address, called a MAC address,
which is given out in blocks by IEEE. [5] [10]





































Master Thesis Project 2004-12-08 12(52)
Allan Nadhmi Faraj




Wired LAN, Distribution System
(BSS) (ESS)
Infrastructure Mode Ad Hoc Mode
(IBSS)
2.2 Basic 802.11 definitions

There are two topologies that occur in WLAN and these are Ad Hoc mode and Infrastructure mode as
shown in Figure 2.2. In Ad Hoc, also called peer to peer, the network is detached, where all the
computers can communicate directly with each other within a range of 100 meters. For larger
distances a repeater has to be used and these are so-called signal amplifiers, which easily can double
up the range. If a client in an Ad Hoc mode wishes to communicate outside the cell (the access point
coverage area), then a member of that cell has to operate as a gateway. It means that it cant connect to
another LAN, (at the data link layer), but it is possible to connect to other networks at the IP layer. It is
more like a computer-to-computer network. Ad Hoc LAN is defined as Independent Basic Server Set
(IBSS) by the 802.11 standard. IBSS is a self-contained network, and in which no access to the
distribution system (DS) is available. The distribution system is a fundamental part of an 802.11
infrastructure.

In Infrastructure mode no direct communication can be obtained to the receiver without a so-
called middle hand, an access point, which all data is sent to. It functions like an ethernet bridge and as
a router. Infrastructure mode is defined by the 802.11 standard as a Basic Service Set (BSS).

When several BSSs are connected by a distribution system (DS) its called an Extended Service
Set (ESS). An access point now functions as a portal to the DS, and the ESS can be thought of as
being connected by the distribution system to form a collection of hubs. To network equipment outside
of the ESS, the ESS and all of its mobile stations appears to be a single MAC- layer network where all
stations are physically stationary. If a wireless station (STA) accidentally happen to be encountered
outside a cell the station uses it self of roaming, which means that it seeks the access point that covers
the area best. A closer explanation of the DS will be found in the next chapter. [2] [11]



Figure 2.2 Infrastructure Mode and Ad Hoc Mode




Master Thesis Project 2004-12-08 13(52)
Allan Nadhmi Faraj




3 WDS Wireless Distribution System


3.1 The 802.11 Distribution System

As was shown in the previous chapter the Distribution System (DS) is a system used to interconnect a
set of BSSs (Basic Service Sets) and integrated local area networks to create an ESS (Extended
Service Set). The IEEE 802.11 standard does not necessarily describe the distribution system as a
network and does furthermore not place any restrictions on how it is implemented, only on the
services it must provide. The distribution system may be constructed of either wired or wireless
networks, and it is a fundamental part of an 802.11 infrastructure BSS and ESS. It is a mechanism by
which one access point communicates with another to exchange frames for stations in their BSSs,
forward frames to follow mobile stations from one BSS to another, and exchange frames with wired
networks, if any. It is therefore the backbone of the WLAN. [2] [11]


3.2 What is the WDS?

A Wireless DS (WDS) is used sometimes instead of the wired one, which some access points support.
This means that an access point might send packets bound for a station on another access point over
the wireless network. In order for that to work they must be on the same channel, agree on the same
rates etc. WDS is basically a system/mode that enables transparent bridging. This mode allows the
wireless access points to only communicate with/through each others such that it creates a wireless
backbone (an extension of the wireless network), while at the same time providing a local hot spot.

There are some ways an access point can exchange packets, and one of them is to use the 802.11
WDS by which all four address spots in the 802.11 header are used, (source, destination, transmitter
and receiver). This is accomplished by that both the To DS and From DS bits are set in the 802.11
WDS packet. This method is also the one that we are using in our firmware. Due to a bug in station
firmware code used in Intersil Prism2/2.5/3 cards that prevent standard-compliant 4 address frames,
the Host Ap driver does WDS by using a non-standard frame format. This is done by using three
addresses and embedding the fourth address (which is usually also in the header) in the frame payload.
Jouni Malinen implemented it. For more information regarding these drivers visit the homepage
5
for
this software at [4]. Multiple implementations of a WDS are incompatible with each other hence
interoperability between 802.11 products of different vendors does not always work, and is therefore
not guaranteed. This is probably because the WDS feature is not completely specified in IEEE or Wi-
Fi standards. [16]

The interface of an access point works in a way that when another access point is in reach they
can talk to each other if and when WDS is enabled. Both access points must apply the same wireless
parameters to each other thus enabling the two to communicate. The more WDS peers you add in the
bridging setup, the greater will the coverage area be. One drawback of this setup is that loops easily
can occur in the network if the links arent configured appropriately. This is accomplished by adding
these interfaces to a bridge group and STA (Spanning Tree Algorithm) running over it. When loops
occur it allows duplicate data frames to be forwarded and duplicated endlessly. By discovering other
bridges in the network topology and establishing forwarding rules so only on path exists for data in the
network is of crucial importance for the proper functioning of the network. It is not clear what the
best-automated routing protocol for this arrangement would be. The term STA that is used throughout
the 802.11 specifications is as I said the term for a station, which is any device that participates in
talking on the wireless network. That should not be mixed up with the similar term STA, which stands
for Spanning Tree Algorithm. More of the Spanning Tree Algorithm and STP (Spanning Tree
Protocol) will be found in the next chapter. [10] [11]

5
http://hostap.epitest.fi/
Master Thesis Project 2004-12-08 14(52)
Allan Nadhmi Faraj




4 STP Spanning Tree Protocol


During 1985 IEEE (Institute of Electrical and Electronics Engineers) began to develop a standard
(802.1D) [IEEE90a] for transparent bridge operation and created the Spanning Tree Protocol, (STP). It
is used to allow the Layer 2 network to have more than one path to a destination by blocking ports that
can cause a packet to make a complete circle through the network. The descriptions and discussion of
the STP in this and other chapters relate exclusively to the IEEE 802.1D version of the protocol. [5]
[15]


4.1 The Spanning Tree Protocol Concepts

STP is a link management protocol that prevents undesirable bridging loops in a network, where there
is more than one active path between two stations, while providing path redundancy in case one link
fails. When loops occur it confuses the forwarding process and allows duplicate frames to be
forwarded. To provide path redundancy, Spanning Tree Protocol defines a tree that spans all
switches/bridges in an extended network. If you trace a path from any bridge to any other bridge, you
will find that there is only one possible path and that is the desired topology for our bridged network.
We need to understand some basic concepts of the protocol before going any further. [10]

The logical center of the network is the Root Bridge, which acts as a reference point. Any bridge
can be the Root Bridge depending on the configuration of certain parameters. If the topology changes
the Root Bridge may also change. To ensure a loop free network only one bridge has to be responsible
for forwarding traffic from the direction of the Root Bridge. This bridge is known as a Designated
Bridge, which each link from the Root Bridge will have. The Root Bridge is always the Designated
Bridge for all links to which it is directly connected.

Each bridge and port within a bridge in the network has to be uniquely identified in order for
everything to function properly and for that a Bridge Identifier is used. A Bridge Identifier is a 64-bit
field, which consists of a globally unique 48-bit field, and a 16-bit priority field, unique to each bridge.
The bridge MAC address is used in the 48-bit field of the Bridge Identifier, while the priority field can
be in a range of 0 to 65 535, (default value is 32 768). The determination of the Root and Designated
Bridges is dependent in part of the numerical value of the Bridge Identifier. The bridge with the
numerically lowest Bridge Identifier becomes the Root Bridge. The priority field allows a network
administrator to control the topology independently from that which would result if she depended
solely on the numerical nature of the 48-bit MAC address (i.e. when the default value of the priority
field is set). As in the case with a Bridge Identifier each port on a bridge is assigned a Port Identifier
that contains a unique 8-bit port number with a configurable port priority field. There are three types
of ports for a given Designated Bridge:

A Designated Port
A Root Port
All other ports are not part of the active topology

STP attempts to configure the network topology such that every bridge is reachable from the Root
through the path with the lowest cost. The cost in each port specifies the efficiency of each link, that is
the lower the cost, the more efficient the link is. Remember that the path cost is simply the sum of the
link costs over the path. This means that the Spanning Tree will form such that the highest capacity
links are always used. By default the cost of a given link is 100. [10] [14]


Master Thesis Project 2004-12-08 15(52)
Allan Nadhmi Faraj




STP forces all the redundant data paths into a blocked state. By blocking the paths to destinations
other than the given root path, STP creates only one path through the network. To avoid confusion, let
me clarify that the Spanning Tree Protocol (STP) and the Spanning Tree Algorithm (STA) are two
different entities. After STP discovers all the links in the network, the STA chooses a single path
through the network and blocks redundant links, and does that by electing a Root Bridge. STP will
reconfigure and recalculate the Spanning Tree topology, if any of the network segments in the
Spanning Tree become unreachable, or if the costs change between any links. It does so by using the
once blocked links in the network, (i.e. activating the standby path). The Spanning Tree algorithm is
based on the graph theory, also known as Shortest Path Algorithm, and was developed by Edsger
Dijkstra.

Communications between the bridges is carried out using Bridge Protocol Data Units (BPDUs).
BPDUs are messages passed between bridges/switches to help STP calculate and learn the topology of
a network. These are transmitted with a known multicast address. Under steady state conditions, there
will be only one BPDU received or transmitted on any port every 2 seconds. The multicast messages
contain information that identifies the network link such as:

The bridge presumed to be the Root Bridge
The calculated Root path cost
Other STP bridges
Port identifiers

These messages are exchanged at configurable intervals, and should one or more bridges fail or
another STP member join the network, BPDU messages will help the other STP member bridges to
notice this change in the network topology. The neighbouring bridges will detect the lack of
configuration message and initiate an immediate STA calculation. [13] [15]

Each port on a bridge using STP exists in one of the following five states and moves between
these states as described in the next page: [10] [14]

Blocking state
o A port in this state is neither a Designated Port nor a Root Port. A blocking port
will not receive or forward data. It will not transmit BPDU messages but it will
listen for them and will become active if there are no BPDUs heard. The port does
therefore not put any of the information it hears into the address table. To become
in an active state it will go through different states as shown in the next page.

Listening state
o A port in this state is not forwarding data but it will compare its own information
with information received from other bridges and decides which is best suited for
the Spanning Tree. In this state the port is not learning any addresses.

Learning state
o A port in this state is preparing to forward traffic by learning the relative locations
of attached stations and builds its address table accordingly. It is still not allowed
to send or receive frames. The learning state is similar to the listening state, except
the port can now add information it has learned to the address table.

Forwarding state
o A port in this state is part of the active Spanning Tree and can now begin to learn
from BPDUs and starts to build a filter table.


Master Thesis Project 2004-12-08 16(52)
Allan Nadhmi Faraj




Disabled state
o A Disabled Port will neither nor transmits data frames or BPDUs. A port in this
state has been manually shut down by the network administrator or by the system
due to a hardware problem.

A port moves through these five states as follows: [3]

From Initialization to Blocking.
From Blocking to Listening or to Disabled.
From Listening to Learning or to Disabled.
From Learning to Forwarding or to Disabled.
From Forwarding to Disabled.

STP uses different timers that control the behaviour of the network topology. The timers are used
to determine how long it will take STP to converge after a link failure or change in the network
topology. Three different timers and their default settings are shown: [10] [14] [15]

Hello Time
o This Hello time is the time between configuration BPDUs emitted by the Root
Bridge. Fast Hello times will result in faster detection of topology changes at the
expense of increased STP traffic. The default value is 2 seconds.

Max Age
o This timer determines how long the bridge stores protocol information received
on a port. The default value is set to 20 seconds.

Forward Delay
o This timer determines how long listening and learning will last before the port
begins forwarding. The default value is 15 seconds.

The Spanning Tree is continually and reliably monitoring the network and makes sure that data
loops do not occur. A poem titled Algorhyme was written by the inventor of the Spanning Tree
Algorithm [13]. Here it is:

I think that I shall never see
A graph more lovely than a tree.

A tree whose crucial property
Is loop-free connectivity.

A tree that must be sure to span
So packets can reach every LAN.

First, the root must be selected.
By ID, it is elected.

Least-cost paths from root are traced.
In the tree, these paths are placed.

A mesh is made by folks like me,
Then bridges find a spanning tree.

- Radia Perlman
Master Thesis Project 2004-12-08 17(52)
Allan Nadhmi Faraj




4.2 Quality of Service in routing protocols

It was also desirable to compare the path cost assignment (i.e. in terms of Quality of Service) with
some proposed routing protocols for wireless Ad-Hoc Networks. Internet Engineering Task Force
6
has
a working group that are working on developing and improving routing protocols. This working group
is called MANET (Mobile Ad-Hoc NETworking) [8].

Several routing protocols have been proposed from MANET during the last few years. Some of
the protocols are still under development (work in progress). These documents are known as Internet
drafts and have a maximum lifetime of six months. If they are not updated by that time, they will be
deleted. Internet drafts are the preliminary versions of RFC (Request for Comment) documents. An
RFC is a technical report of proposals for new or revised protocols and may be extended with more
functionality if necessary. [6]

There are currently two RFCs in wireless Ad-Hoc networking presented in MANET.
Unfortunately none of them supports Quality of Service since the number-one concern is not about
finding the best optimized/shortest-path route to a destination. Depending on what these networks will
be used for, then Quality of Service (QoS) might be needful to have into a routing protocol. These are
the following RFCs:

AODV Ad hoc On-Demand Distance Vector protocol, RFC 3561 [1]

The Ad hoc On-Demand Distance Vector (AODV) routing protocol is intended for use by
mobile nodes in an Ad hoc network. It is a reactive protocol, which means that it only
requests a route when needed. This does not require nodes to maintain routes to
destinations that are not in active communication. When a node determines that it needs a
route to a destination a route request is generated. The path from a source to a destination
is determined from the route request that reaches the destination first. Sequence numbers
are used to guarantee a loop free topology and a node is required to select the greatest
sequence number when given the choice between two routes. Hello messages are used to
determine if a neighbour node has moved away or if the link is down. So, by listening for
packets from its set of neighbours a node may determine connectivity. It does however not
support Quality of Service.

OLSR Optimized Link State Routing protocol, RFC 3626 [9]

The Optimized Link State Routing protocol is intended for use by mobile nodes in an Ad
hoc network. It is a proactive protocol, which means that it maintains a topological map of
the entire network. The key concept used in this protocol is that of multipoint relays
(MPRs). The nodes selected as MPRs forwards broadcast messages during the flooding
process and are used to calculate the route between any given nodes. OLSR provides
optimal routes in terms of number of hops using shortest path algorithm. Hello messages
are broadcasts between nodes with information about the state of the link. It does however
neither contains support for Quality of Service.

These routing protocols have two dominated factors that affect the network complexity. The
factors are the rate at which changes occur in the topology and the number of PX30s in the network.
Changes due to surrounding circumstances in a mobile network make the current state information
imprecise, which makes the idea of adding QoS to a real challenge. That is why the focus on routing in
wireless networks is only on best effort data traffic.


6
www.ietf.org
Master Thesis Project 2004-12-08 18(52)
Allan Nadhmi Faraj




5 Bridges and Experimental Setup


In this section I will go through how we did the bridge and the experimental setup for the PX30. By
setting up an experimental test-bed the performance evaluation of the presented algorithms could be
done. Five of Possios wireless gateways (PX30) equipped with IEEE 802.11b cards, a router and a
PC are used in the test-bed. The tests are conducted at Possios premises.

During the first test I had the PX30s placed in different locations in a room with the default
parameters set (e.g. cost of 100 between all WDS-links) in STP. The PING utility was then used to
gather the packet loss statistics to each and every node. This was done by sending TCP packets of
same size (1500 Bytes) from one wireless node to the rest of the nodes simultaneously. At the sender
node the throughput was evaluated as the number of echo requests that was received. A response to the
request is allowed within the default time of one second. The output data was thus saved and a log of
the throughput was obtained. A separate channel was used with the purpose of preventing interference
from other PX30s that was active at Possio. The purpose of this test was to find out how the
mathematical function of the first algorithm (presented in the next chapter) should be estimated.
Further experiments with about the same procedure were done, and a log of the throughput was
obtained.

During the experimental phase the PX30s were initially placed out without any external antennas,
and did undergo about the same procedure as with the first test. This time two pairs of external
antennas were gradually and in a controlled manner taking turn on the PX30s that was placed out. In
other words, the antennas were connected and disconnected from a PX30 during the experimental
phase. Seven different combinations were tried out when moving the antennas around. We could
therefore construct a mobile network by moving the antennas around instead of moving the actual
PX30s. The exactly same procedure was made but this time using one of the algorithms (presented in
the next chapter). The idea is that the data packets generated from the PING utility should choose to
go a more efficient way/path than in the default case. Two different set ups were about to be compared
to each other:

Default parameter set vs. the first presented algorithm, against
Default parameter set vs. the second presented algorithm (additional algorithm)

By placing some of the receiving nodes at certain positions they tend to move in and out of the
sending nodes range. The traffic condition and throughput of the net should be in a poor state by then.
When the sender node loose connectivity with a node the other nodes supports routing through them.
A main router was also used in the test bed. Its main function was to separate the network of the test-
bed with the companys internal network.

A daemon process was running in all of the PX30s in order to calculate a cost from each
reachable node in the network. The modified iwlist software does provide for the SNR measurements
and therefore even the inserted path cost. Because of not risking going through the configuration every
time the PX30 make a reboot or if something goes wrong I had prepared an init script for the setup that
consists of standard configuration. The init script from one of the PX30 can be seen in APPENDIX D.








Master Thesis Project 2004-12-08 19(52)
Allan Nadhmi Faraj




6 Algorithms and method discussion


The signal to noise ratio (SNR) values can be obtained from neighbouring nodes and periodic updates
of these values can be done. By maintaining the history of numerous values over a certain period of
time a weighted moving average was calculated. The modified iwlist software did provide for the SNR
measurements for each neighbouring node and therefore even the inserted path costs into STP. The
modified software does only calculate a cost to a neighbouring node if a WDS-link has been put up to
that node. By base the path cost between each node using a performance measure like SNR the STP
was able to build a more preferable topology of the WDS-enabled network.

A high value of the SNR indicates that we have a good link, where the probability of the packet
loss is low. When having a low value of SNR it indicated that we had a bad link with lots of packet
loss. The unit of the measurements are in dBm. Link conditions and surrounding circumstances
between wirelesses nodes can change quite frequently. We took this into account when calculating the
path cost. The 1
st
and the 2
nd
algorithm that was used throughout the experiments are presented as
output Y and Y
2
, which can be seen later in this chapter. The mathematical model of the first algorithm,
describing the transition between given SNR values to a cost into STP, is roughly estimated through
experiments.


6.1 Costs from SNR 1
st
algorithm

A wireless node, call it N, registers signal to noise ratio (SNR) values from other wireless nodes, call
them M
i
where i = 1... 4. The quality of each link (i.e. SNR values) that I base my calculation upon are
available to an application from the wireless gateway platform, and are collected using iwlist. Iwlist is
used to display some information from a wireless network interface, see APPENDIX B for more
information. The registered signal to noise ratio value is derived from a subtraction of the noise value
from the signal value. If the wireless nodes are far from each other a SNR value of zero is observed,
and when close to each other a SNR value of approximately 36 is noticed.

At node N the 20 most recent registered SNR-values is saved from each node M
i
and will be kept
in separate tables, which we can name Tab
i
where i = 1... 4. The most recent SNR-value in Tab
i
is
stored at position one, and the second recent value is stored at position two etc. See Figure 6.1. Due to
the surrounding changes (e.g. atmospherically disturbances) the registered values will have a slight
random fluctuation around a slowly varying mean level. The noise/disturbance is acting about the
same at different time intervals, where one could assume that the results have been influenced from
similar random mechanisms. Some form of a mean value is preferable.



Figure 6.1 Registered values in each node for a given link



The most recent value is inserted here at position 1.

Pos. 1 Pos. 2 Pos. 20
t = 0s
0 0 0 0 0 0
t = 3s
14 0 0 0 0 0
t = 6s
17 14 0 0 0 0
t = 9s
15 17 14 0 0 0
Master Thesis Project 2004-12-08 20(52)
Allan Nadhmi Faraj




Since that the most recent registered values are more important than the past ones (mobile
system), a weighted moving average should be of interest. Instead of calculating the mean from each
vector at Tab
i
, we multiply this vector with a so-called weight vector, let us call it Weight
i
, where i =
1 20, see Figure 6.2. For example, the value at position i = 1 in Weight
i
, points at the most recent
registered value at Tab
i
. If we used the simple moving average we will treat the i last observations
equally, but with the use of a moving average past values should be treated with a less emphasis than
the recent. So the weight or percentage is set depending on how long we want the most recent values
to remain significant in the calculation.

For example, if 100% is given to the current registered value, then 100% of the current value is
added up with 90% of the previous value. Since the changes in our system should be considered as
slow, then we have to use a long period, which means that we derive a percentage of approximately
10%. That gives us:

Percentage, 9 . 0 ) 1 . 0 1 ( = (1)



Figure 6.2 Weight vector


By looking at Figure 6.1 we can see that the mean value at Tab
i
is initially set to zero, which
means that the output, Y, is 100 when using (2). When the next value (three seconds later) is registered
the mean value quickly changes to 14, which change the value Y to 6, and this value is inserted to the
spanning tree protocol. For each new value in Tab
i
a new Y is calculated using (2).


Y =
|
|
|
|
.
|

\
|
+

=
=
1
) (
) ( ) (
100
1
1
k
i
k
i
i Weight
i Weight i Tab
; k = Number of applied values (2)



If the reported value of Y differentiates more than a given threshold from the current Y value, then the
current value will be reported, see (3). The mathematical model of this first algorithm (2), describing
the transition between given SNR values to a cost into STP, is roughly estimated through experiments.


Report if: 35
) (
) ( ) (
100 >

reported Y
current Y reported Y
(3)




The value at position i = 1 in Weight
i
, points at the most recent registered value at Tab
i
.

1
2

3

18

19

Master Thesis Project 2004-12-08 21(52)
Allan Nadhmi Faraj




The SNR value does usually vary between 0-36, which gives us that Y s variation giving these
boundaries does vary between 100-2. The lower the cost we have on a link indicates that the SNR
value for that link is higher, which means that a good link will give us a low cost. If a link goes down
an SNR value of zero is registered.


6.2 Additional algorithm 2
nd
algorithm

Another way of calculating the output Y was performed (i.e. 2
nd
algorithm) and experimental data was
obtained. It is based upon the theories of Shannons formula of a channel capacity. Since the SNR
values in our case vary between 0-36, a relationship is obtained using (4).

) 10 1 ( log
10
2
SNR
bB a STP + + = (4)


A bad SNR indicates a cost of 100, while a good SNR indicates a cost of two. That is the requirements
that I have set, just as the first algorithm (2).


) 10 1 ( log 1
100
100 100
)) 10 1 ( log 1 (
100
) 10 1 ( log
100
) 10 1 ( log 100 0
) 10 1 ( log 0 36
100 100 0
10
max
2
10
max
2
10
max
2
10
max
2
10
max
2
SNR
SNR SNR
SNR
SNR
bB a
B B B
b
bB bB
bB a STP SNR
bB a bB a STP SNR
+
= =
+
=
+
=
+ + =
+ + = = =
= + = = =



Inserting these values (i.e. a and b) into (4) will give us the relationship between a given SNR value to
a cost into STP.

+
+

+
+
+
+

= + + =
)) 10 1 ( log 1 (
) 10 1 ( log 1
100
100
) 10 1 ( log
)) 10 1 ( log 1 (
100
) 10 1 ( log 1
100
100
) 10 1 ( log
10
2
10
max
2
10
2
10
max
2
10
max
2
10
2
SNR
SNR
SNR
SNR SNR
SNR
bB a STP

Master Thesis Project 2004-12-08 22(52)
Allan Nadhmi Faraj



=
|
|
|
|
.
|

\
|

=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
+
+
=

=
=
36
) (
) ( ) (
;
) 10 1 ( log 1
) 10 1 ( log 1
1 100
max
1
1
10
max
2
10
2
2
SNR
i Weight
i Weight i Tab
SNR
Y
k
i
k
i
SNR
SNR
|
|
|
.
|

\
|
|
|
|
.
|

\
|
+
+
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
+
+

|
|
|
.
|

\
|
+
+

) 10 1 ( log 1
) 10 1 ( log 1
1 100
) 10 1 ( log 1
) 10 1 ( log 1
1 100
) 10 1 ( log 1
) 10 1 ( log 1
100 100
10
max
2
10
2
10
max
2
10
2
10
max
2
10
2
SNR
SNR
SNR
SNR
SNR
SNR
STP



This gives us a new output, Y
2
as shown in (5).




(5)






Experiments as described in the previous chapter where made on both of the algorithms, and
experimental data was obtained. As can be seen from the results in the next chapter, we get a
significant improvement of the networks performance when using the path cost algorithms as
compared to without (i.e. default case). For obtaining and analyzing the data, I need to use the wireless
tools package embedded in the PX30 operating system as mentioned earlier. Since Iwlist is used to
display some information from the wireless network, I therefore modified the Iwlist source code
(written in C) to gather the necessary data in real-time. The new and modified Iwlist, suitably called
Iw_own was developed to do this. Iw_own gathers the data that is to be used, makes some calculations
and inserts the proper cost to the available protocol using either (2) or (5).

















Master Thesis Project 2004-12-08 23(52)
Allan Nadhmi Faraj




7 Results and evaluations


On the experiments that have been run, the first algorithm works better than the second. It provides a
high increased performance of the wireless network. This does not mean that the first algorithm is the
best choice to use in all kind of wireless networks. The gains from using these path cost estimation
algorithms do of course depend on the wireless networks that are being set up. In short the obtained
results depend on the emplacement of the five nodes, and changes in the environment. The two
algorithms will be run under the impact of node movement to evaluate their performances under
dynamic topology changes.

As mentioned in chapter five seven different combinations were tried out when moving the
antennas around. We could therefore construct a mobile network by moving the antennas around
instead of moving the actual PX30s. The packet loss values presented in these tables below are the
average values of the packet loss from a node to another of each combination.


7.1 Results with the 1
st
algorithm

The packet loss values presented in these tables below are the average values of the packet loss from a
node to another of each combination. Figure 7.1 shows the average packet loss between each given
nodes when using the first algorithm as compared to without.

Node-2-node 1 2 13 14 15
Average Packet loss, default settings 52% 26% 49% 61%
Average Packet loss using 1
st
algorithm 16% 5% 14% 26%

Table 7.1 Average Packet loss statistics


Experiment with the 1st algorithm
52%
26%
49%
61%
16%
5%
14%
26%
0%
10%
20%
30%
40%
50%
60%
70%
1--> 2 1--> 3 1--> 4 1--> 5
Node-2-Node
P
a
c
k
e
t

l
o
s
s
Average Packet loss, default settings Average Packet loss using 1st algorithm


Figure 7.1 Average packet loss when using the first algorithm as compared to without
Master Thesis Project 2004-12-08 24(52)
Allan Nadhmi Faraj




7.2 Results with the 2
nd
algorithm

The packet loss values presented in this table below are the average values of the packet loss from a
node to another of each combination. The average packet loss when using the second algorithm
(additional algorithm) as compared to without is shown in Figure 7.2.


Node-2-node 12 13 14 15
Average Packet loss, default settings 28% 26% 24% 32%
Average Packet loss, using 2
nd
algorithm 14% 22% 17% 13%

Table 7.2 Average Packet loss statistics


Experiment with the 2nd algorithm
28%
26%
24%
32%
14%
22%
17%
13%
0%
5%
10%
15%
20%
25%
30%
35%
1--> 2 1--> 3 1--> 4 1--> 5
Node-2-Node
P
a
c
k
e
t

l
o
s
s
Average Packet loss, default settings Average Packet loss, using 2nd algorithm


Figure 7.2 Average packet loss when using the first algorithm as compared to without
















Master Thesis Project 2004-12-08 25(52)
Allan Nadhmi Faraj




8 Conclusions


8.1 Discussion of the obtained results

Experiments have verified that Quality of Service, from a performance perspective, is needed in
wireless networks. This does however not mean that it is always the best choice depending on what the
network will be used for. Changes due to surrounding circumstances in a mobile network make the
current state information imprecise, which makes the idea of adding QoS to a real challenge. That is
why the focus on routing in wireless networks is only on best effort data traffic, and not about finding
the best optimized/shortest-path route to a destination.

The path cost algorithms presented in this paper does improve the networks reliability and
performance. It does so by choosing the best route based on the Quality of Service constraint among
the possible routes that is computed in the Spanning Tree Protocol. On all experiments that have been
run, the first algorithm works better than the second. The obtained results do of course depend on
changes in the environment as mentioned, and the emplacement of the nodes.

Nodes far away but still within transmitting range to a node are considered as valid, despite the
poor connection. Most of the present routing protocols use the shortest hops path, and by doing so
the good quality links may not be used. The revised algorithm may thus improve the chance that a
better bandwidth route is found between two adjacent nodes.


8.2 Future work

There are several issues that could be subject to further studies. These are just some of them:

An approach is to complement the Spanning Tree Protocol with an Ethernet protocol that uses
the Wireless Distribution System to gather values from other bridges and therefore set a path
cost to them.
Investigate the relationship between given SNR values to a path cost by studying the
behaviour of the packet loss in different scenarios. This is accomplished by study the SNR
values and the packet loss between different n-hop neighbours to each other.
Study the advantages of using the Rapid Spanning Tree Protocol (RSTP; IEEE 802.1W) with
the presented path cost algorithms.

















Master Thesis Project 2004-12-08 26(52)
Allan Nadhmi Faraj




9 References


A URL for the reference is provided wherever possible. While all URLs provided below were valid
(and tested) in Aug 2004, URLs can become out of date.

[1] Ad hoc On-Demand Distance Vector (AODV) Routing, http://www.ietf.org/rfc/rfc3561.txt

[2] By Bob OHara and Al Petrick, IEEE 802.11 Handbook A Designers Companion, The
Institute of Electrical and Electronics Engineers, New York, ISBN 0-7381-1855-9.

[3] Cisco Systems
http://www.cisco.com

[4] HostAp driver
http://hostap.epitest.fi/

[5] IEEE, Institute of Electrical and Electronic Engineers
http://www.ieee.org

[6] Internet Engineering Task Force
http://www.ietf.org

[7] James F. Kurose and Keith W. Ross, Computer Networking A Top-Down Approach Featuring
the Internet 2
nd
edition, Addison Wesley Publishing Company, Massachusetts, ISBN 0-201-
97699-4.

[8] Mobile Ad hoc Networking (MANET) Routing Protocol Performance Issues and Evaluation
Considerations, http://www.ietf.org/rfc/rfc2501.txt

[9] Optimized Link State Routing Protocol (OLSR),
http://www.ietf.org/rfc/rfc3626.txt

[10] Part 3: Media Access Control (MAC) Bridges ANSI/IEEE 802.1D,
http://standards.ieee.org./getieee802/

[11] Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY)
Specifications, http://standards.ieee.org/getieee802/802.11.html

[12] Possio AB
http://www.possio.com

[13] Radia Perlman, Interconnections 2
nd
edition Bridges, Routers, Switches, and Internetworking
Protocols, Addison Wesley Publishing Company, Massachusetts, ISBN 0-201-63448-1.

[14] Rich Seifert, The Switch Book, Wiley Computer Publishing, New York, ISBN 0-471-34586-5.

[15] Sean Odom and Hanson Nottingham, CISCO Switching Black Book, the Coriolis Group,
Arizona, ISBN 1-57610-706-X

[16] Wi-Fi Planet
http://www.wi-fiplanet.com/


Master Thesis Project 2004-12-08 27(52)
Allan Nadhmi Faraj




APPENDIX A PX30 pictures
7


A.1 Front picture with shell





A.2 Front picture without shell



A.3 Rear picture

7
http://linuxdevices.com/articles/AT7459336271.html
Master Thesis Project 2004-12-08 28(52)
Allan Nadhmi Faraj




APPENDIX B Manual Reference
8
Page for Iwlist

NAME
iwlist - Get wireless statistics from specific nodes

SYNOPSIS
iwlist interface freq
iwlist interface ap
iwlist interface scan
iwlist interface rate
iwlist interface key
iwlist interface power
iwlist interface txpower
iwlist interface retry
iwlist --help
iwlist --version

DESCRIPTION
Iwlist is used to display some large chunk of information from a wireless network interface that is not displayed
by iwconfig. This is typically list of parameters.

PARAMETERS
Freq/channel
Give the list of available frequencies in the device and the number of defined channels. Please note that usually
the driver returns the total number of channels and only the frequencies available in the present locale, so there is
no one to one mapping between frequencies displayed and channel numbers.

Ap/access point
Give the list of Access Points in range, and optionally the quality of link to them. This feature is obsolete and
now deprecated in favour of scanning support (below), and it will disappear in the future.

Scan [ning]
Give the list of Access Points and Ad-Hoc cells in range, and optionally a whole bunch of information about
them (ESSID, Quality, Frequency, Mode...). The type of information returned depends on what the card support.
Triggering scanning is a privileged operation (root only) and normal users can only read left-over scan results.
By default, the way scanning is done (the scope of the scan) will be impacted by the current setting of the driver.
Also, this command is supposed to take extra arguments to control the scanning behaviour, but this is currently
not implemented.

Rate/bit [rate]
List the bit-rates supported by the device.

Key/enc [ryption]
List the encryption key sizes supported and display all the encryption keys available in the device.

Power
List the various Power Management attributes and modes of the device.

Txpower
List the various Transmit Power available on the device.

Retry
List the transmit retry limits and retry lifetime on the device.

--Version
Display the version of the tools, as well as the recommended and current Wireless Extensions version for the tool
and the various wireless interfaces.

8
http://leaf.sourceforge.net/devel/jnilo/manpages/iwlist.html
Master Thesis Project 2004-12-08 29(52)
Allan Nadhmi Faraj




APPENDIX C Iw_own source code

/*
* Wireless Tools
* Comments in Swedish
*/

#include "iwlib.h"
#include <stdlib.h> /* Header */
#include <ctype.h> /* Header */
#include <sys/time.h>
#include <unistd.h> /* Header */
#include <math.h> /* Header */

#define Antal 20 /* Antal Signalbrus vrden som ska memoreras */

int vikt[Antal]={100,90,81,73,65,59,53,48,43,38,34,31,28,25,22,20,18,16,15,13};
#define Max_WDS 20 /* Antal WDS lnkar som vi kan ha som max */
#define Procent 35 /* Grns fr path cost */

int Tab[Max_WDS][Antal]; /* Reserverad minne fr memorerade vrde */
int TabCount[Max_WDS]; /* Antal vrden som r riktiga eller gller i minnet Tab*/
int Reported[Max_WDS]; /* Sista vrdet som har rapporterats till STP fr varje WDS lnk */

char WDS[Max_WDS][20]; /* Reserverad minne fr alla mac adresser fr WDS lnkarna, som text */
char WDS_text[Max_WDS][20]; /* Reserverad minne fr Namn p alla WDS lnkar t.ex. Wlan0Wds0 */


/*********************** FREQUENCIES/CHANNELS ***********************/

/*------------------------------------------------------------------*/
/*
* Print the number of channels and available frequency for the device
*/
static int
print_freq_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
struct iw_range range;
double freq;
int k;
int channel;
char buffer[128]; /* Temporary buffer */

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Get list of frequencies / channels */
if(iw_get_range_info(skfd, ifname, &range) < 0)
fprintf(stderr, "%-8.8s no frequency information.\n\n",
ifname);
else
{
if(range.num_frequency > 0)
{
printf("%-8.8s %d channels in total; available frequencies :\n",
Master Thesis Project 2004-12-08 30(52)
Allan Nadhmi Faraj




ifname, range.num_channels);
/* Print them all */
for(k = 0; k < range.num_frequency; k++)
{
printf(" Channel %.2d : ", range.freq[k].i);
freq = iw_freq2float(&(range.freq[k]));
if(freq >= GIGA)
printf("%g GHz\n", freq / GIGA);
else
if(freq >= MEGA)
printf("%g MHz\n", freq / MEGA);
else
printf("%g kHz\n", freq / KILO);
}
}
else
printf("%-8.8s %d channels\n",
ifname, range.num_channels);

/* Get current frequency / channel and display it */
if(iw_get_ext(skfd, ifname, SIOCGIWFREQ, &wrq) >= 0)
{
freq = iw_freq2float(&(wrq.u.freq));
iw_print_freq(buffer, freq);
channel = iw_freq_to_channel(freq, &range);
if(channel >= 0)
printf(" Current %s (channel %.2d)\n\n", buffer, channel);
else
printf(" Current %s\n\n", buffer);
}
}
return(0);
}

/************************ ACCESS POINT LIST ************************/
/*
* Note : now that we have scanning support, this is depracted and
* won't survive long. Actually, next version it's out !
*/

/*------------------------------------------------------------------*/
/*
* Display the list of ap addresses and the associated stats
* Exactly the same as the spy list, only with different IOCTL and messages
*/

/*
* FD_print_ap_info r funktionen som hette print_ap_info i iwlist.c
* Funktionen tar reda p information om ntet och skriver ut p skrmen
* Sttet att skriva p skrmen r anpassad till vrt behov
*/

static int
FD_print_ap_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
static struct iwreq wrq;
Master Thesis Project 2004-12-08 31(52)
Allan Nadhmi Faraj




static char buffer[(sizeof(struct iw_quality) +
sizeof(struct sockaddr)) * IW_MAX_AP];
static char temp[128];
static struct sockaddr * hwa;
static struct iw_quality * qual;
static iwrange range;
static int has_range = 0;
static int has_qual = 0;
static int n;
static int i,j;
int w;

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Collect stats */
wrq.u.data.pointer = (caddr_t) buffer;
wrq.u.data.length = IW_MAX_AP;
wrq.u.data.flags = 0;
if(iw_get_ext(skfd, ifname, SIOCGIWAPLIST, &wrq) < 0)
{
fprintf(stderr, "%-8.8s Interface doesn't have a list of Peers/Access-Points\n\n", ifname);
return(-1);
}

/* Number of addresses */
n = wrq.u.data.length;
has_qual = wrq.u.data.flags;

/* The two lists */
hwa = (struct sockaddr *) buffer;
qual = (struct iw_quality *) (buffer + (sizeof(struct sockaddr) * n));

/* Check if we have valid mac address type */
if(iw_check_mac_addr_type(skfd, ifname) < 0)
{
fprintf(stderr, "%-8.8s Interface doesn't support MAC addresses\n\n", ifname);
return(-2);
}

/* Get range info if we can */
if(iw_get_range_info(skfd, ifname, &(range)) >= 0)
has_range = 1;

/* Display it
if(n == 0)
printf("%-8.8s No Peers/Access-Point in range\n", ifname);
else
printf("%-8.8s Peers/Access-Points in range:\n", ifname);
*/


/*
* Skiftar vrden i Tab listan fr varje WDS lnk
* sedan nollstller frsta vrdet i Tab listan
*/
for (i=0 ; i < Max_WDS ; ++i) {
for (j=Antal-1 ; j > 0 ; --j)
Tab[i][j] = Tab[i][j-1];
Master Thesis Project 2004-12-08 32(52)
Allan Nadhmi Faraj




Tab[i][0] = 0;
}


/*
* Lser och memorerar nytt signalbrus vrden fr alla lnkar
* och skriver information p skrmen om det behvs.
*/
for(i = 0; i < n; i++) {
if(has_qual) {

/* Skriver statusen fr den hr adressen p skrmen */
printf(" %s : %d - %d = %d\n", iw_pr_ether(temp, hwa[i].sa_data),
qual[i].level - 0x100, qual[i].noise - 0x100,
qual[i].level-qual[i].noise);

/*
* Frsker hitta samma Mac adress i WDS listan,
* skriver informationen p skrmen
* och memorerar vrdet fr respektive WDS lnk i Tab
*/

for (j = 0 ; j < Max_WDS ; ++j){
if (!strcmp (WDS[j], iw_pr_ether(temp, hwa[i].sa_data))){ /* Samma Mac-adress? */
printf ("%d) ",j);
if (qual[i].updated & 0x7) /* Uppdateras lnken? */
Tab[j][0] = qual[i].level-qual[i].noise; /* Memorera signalbrus vrdet som i
frsta positionen i Tab */
else
Tab[j][0] = 0; /* Annars memoreras 0 som
indikerar att uppdatering inte skett */
if (++TabCount[j] >= Antal) --TabCount[j]; /* Antal gllande vrde i Tab kas
med 1 */

printf ("Styrka=%d Reported=%d (%x)\n", /* Skriver p skrmen information
om signalbrus vrdet, */
Tab[j][0], Reported[j], /* Senaste rapporterade vrde i STP, indikator fr
uppdatering fr WDS lnk */
((qual[i].updated&0x7)?1:0));
for (w=0 ; w<Antal-1 ;++w) /* Skriver alla memorerade vrden i Tab fr
respektive WDS lnk */
printf ("%d,",Tab[j][w]);
printf ("%d\n",Tab[j][Antal-1]);
for (w=0 ; w<Antal-1 ;++w) /* Skriver alla memorerade vrden i Tab mult med
respektive vikt */
printf ("%d,",Tab[j][w]*vikt[w]); /* fr respektive WDS lnk */
printf ("%d\n",Tab[j][Antal-1]*vikt[Antal-1]);
j = Max_WDS; /* Avsluta skning efter samma Mac-adress i WDS listan, till nsta
Mac-adress */

}
}
}
else {
/* Only print the address */
printf(" %s\n", iw_pr_ether(temp, hwa[i].sa_data));
return (-1);
}
}
Master Thesis Project 2004-12-08 33(52)
Allan Nadhmi Faraj




printf("____________________________________\n"); /* Markera slutet av utskrift */
return(0);
}

/*
* Sm till stora bokstver
*/
void
Upper (char *s)
{
for ( ; *s != '\0' ; ++s)
*s = toupper (*s);
}


/*
* print_ap_info anropas frn main funktionen
* FD_print_ap_info anropas hrifrn.
*
* print_ap_info och FD_print_ap_info har samma argumenter.
*
* print_ap_info initierar vrde i reserverade minne
* och initierar WDS listan.
*
*/
static int
print_ap_info( int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
char temp[128];
char W_temp[128];
int i,j;
double sum,vikt_sum;

FILE *WDS_list; /* Pekare till filen WDS list*/

/*
* Nollstllning av alla variabler
*/
for (j=0 ; j<Max_WDS ; ++j){
WDS[j][0] = '\0';
WDS_text[j][0] = '\0';
Reported[j] = 0;
for (i=0 ; i<Antal ; ++i) Tab[j][i] = 0;
TabCount[j] = 0;
}

sprintf (temp, "/proc/net/hostap/%s/wds", ifname); /* Namn med skvg till WDS list */
printf ("WDS file = %s\n", temp); /* Skriver ovanstende p skrmen */
WDS_list = fopen (temp, "r"); /* ppnar WDS listan fr lsning */
if (!WDS_list){ /* Om filen inte ppnas, ge felmeddelande och avsluta */
printf ("Can't find WDS list!\n");
return 0;
}
for (j=0 ; !feof (WDS_list) && j<Max_WDS ; ++j) /* Lsa innehllet av WDS listan till slutet av
filen */
{
Master Thesis Project 2004-12-08 34(52)
Allan Nadhmi Faraj




temp[0]= '\0';
fscanf (WDS_list, "%s %s\n", W_temp, temp); /* Lsa Namnet p WDS lnken samt Mac
adressen */
Upper (temp); /* ndra namnet till stora bokstver */
if (temp[0]!= '\0') /* Om lyckad */
{
strcpy (WDS_text[j], W_temp); /* Kopierar namn till WDS_text i minnet vi
har reserverat */
strcpy (WDS[j], temp); /* Kopierar Mac adressen till WDS i minnet
som vi har reserverat */
printf ("WDS_list #%d: %s temp=\"%s\"\n", j, W_temp, temp); /* Skriver namn och
Mac adressen p skrmen */
}
}
fclose (WDS_list); /* Stnger igen filen */


/*
* "Gra jobbet" tills programmet stoppas
*/
for ( ; ; )
{
j = FD_print_ap_info (skfd, ifname, args, count); /* Verkliga anropet till print_ap_info */
if (j != 0) return j; /* Avsluta om ngot blev fel i FD_print_ap_info */

/*
* Gr igenom Tab listan som nu r uppdaterade
* och avgr om det ska rapporteras ett nytt vrde till STP
*/
for (j = 0 ; j<Max_WDS && WDS[j][0]!='\0'; ++j)
{
sum = 0;

for (i = 0 ; i < TabCount[j] ; ++i) /* Summerar alla memorerade vrden fr lnken
multiplicerad med vikten */
sum = sum + Tab[j][i] * vikt[i];
vikt_sum = 0;
for (i = 0 ; i < TabCount[j] ; ++i) /* Ta reda p totala vikten */
vikt_sum += vikt[i];

sum = 100 / (sum / vikt_sum +1); /* Matematiska uttrycket fr frsta algoritmen*/

/* Matematiska uttrycket fr den andra metoden
*
* sum = 100*(1.0 - (1.0 - log10(1.0 + pow(10.0, sum/vikt_sum/10.0)) /log10(2.0)) / (1.0 -
log10(1.0 + pow(10.0, 3.6)) /log10(2.0)));
*/

/*
* Behvs det rapporteras?
*/

if ((Reported[j] == 0) ||
(Reported[j] != 0 && abs(100*(Reported[j]-sum)/Reported[j]) > Procent))
{
/* r det inte samma vrde som redan r inrapporterad? */
if (Reported[j] != sum){
Reported[j] = sum; /* Memorera vrdet som kommer att
rapporteras */
Master Thesis Project 2004-12-08 35(52)
Allan Nadhmi Faraj




printf ("*** Report to STP : %s,%s : %d\n", WDS_text[j], WDS[j],
Reported[j]);
printf ("*** %s %d\n", WDS_text[j], Reported[j]);

/* Gra klart fr anrop till STP */
sprintf (temp, "brctl setpathcost br0 %s %d\n", WDS_text[j],
Reported[j]);
printf ("%s",temp);
/* Anropet till brctl fr rapportering till STP */
system (temp);
}
}
}
usleep(3e6); /* Vnta i tre sekunder innan nsta lsning av ntet */
}
return 0;
}


/***************************** BITRATES *****************************/

/*------------------------------------------------------------------*/
/*
* Print the number of available bitrates for the device
*/
static int
print_bitrate_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
struct iw_range range;
int k;
char buffer[128];

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Extract range info */
if(iw_get_range_info(skfd, ifname, &range) < 0)
fprintf(stderr, "%-8.8s no bit-rate information.\n\n",
ifname);
else
{
if((range.num_bitrates > 0) && (range.num_bitrates <= IW_MAX_BITRATES))
{
printf("%-8.8s %d available bit-rates :\n",
ifname, range.num_bitrates);
/* Print them all */
for(k = 0; k < range.num_bitrates; k++)
{
iw_print_bitrate(buffer, range.bitrate[k]);
/* Maybe this should be %10s */
printf("\t %s\n", buffer);
}
}
else
printf("%-8.8s No bit-rates ? Please update driver...\n", ifname);
Master Thesis Project 2004-12-08 36(52)
Allan Nadhmi Faraj





/* Get current bit rate */
if(iw_get_ext(skfd, ifname, SIOCGIWRATE, &wrq) >= 0)
{
iw_print_bitrate(buffer, wrq.u.bitrate.value);
printf(" Current Bit Rate%c%s\n\n",
(wrq.u.bitrate.fixed ? '=' : ':'), buffer);
}
}
return(0);
}

/************************* ENCRYPTION KEYS *************************/

/*------------------------------------------------------------------*/
/*
* Print the number of available encryption key for the device
*/
static int
print_keys_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
struct iw_range range;
unsigned char key[IW_ENCODING_TOKEN_MAX];
int k;
char buffer[128];

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Extract range info */
if(iw_get_range_info(skfd, ifname, &range) < 0)
fprintf(stderr, "%-8.8s no encryption keys information.\n\n",
ifname);
else
{
printf("%-8.8s ", ifname);
/* Print key sizes */
if((range.num_encoding_sizes > 0) &&
(range.num_encoding_sizes < IW_MAX_ENCODING_SIZES))
{
printf("%d key sizes : %d", range.num_encoding_sizes,
range.encoding_size[0] * 8);
/* Print them all */
for(k = 1; k < range.num_encoding_sizes; k++)
printf(", %d", range.encoding_size[k] * 8);
printf("bits\n ");
}
/* Print the keys and associate mode */
printf("%d keys available :\n", range.max_encoding_tokens);
for(k = 1; k <= range.max_encoding_tokens; k++)
{
wrq.u.data.pointer = (caddr_t) key;
wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
wrq.u.data.flags = k;
if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) < 0)
Master Thesis Project 2004-12-08 37(52)
Allan Nadhmi Faraj




{
fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno));
break;
}
if((wrq.u.data.flags & IW_ENCODE_DISABLED) ||
(wrq.u.data.length == 0))
printf("\t\t[%d]: off\n", k);
else
{
/* Display the key */
iw_print_key(buffer, key, wrq.u.data.length, wrq.u.data.flags);
printf("\t\t[%d]: %s", k, buffer);

/* Other info... */
printf(" (%d bits)", wrq.u.data.length * 8);
printf("\n");
}
}
/* Print current key and mode */
wrq.u.data.pointer = (caddr_t) key;
wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
wrq.u.data.flags = 0; /* Set index to zero to get current */
if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) < 0)
{
fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno));
return(-1);
}
printf(" Current Transmit Key: [%d]\n",
wrq.u.data.flags & IW_ENCODE_INDEX);
if(wrq.u.data.flags & IW_ENCODE_RESTRICTED)
printf(" Security mode:restricted\n");
if(wrq.u.data.flags & IW_ENCODE_OPEN)
printf(" Security mode:open\n");

printf("\n\n");
}
return(0);
}

/************************* POWER MANAGEMENT *************************/

/*------------------------------------------------------------------*/
/*
* Print Power Management info for each device
*/
static inline int
get_pm_value(int skfd,
char * ifname,
struct iwreq * pwrq,
int flags,
char * buffer)
{
/* Get Another Power Management value */
pwrq->u.power.flags = flags;
if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, pwrq) >= 0)
{
/* Let's check the value and its type */
if(pwrq->u.power.flags & IW_POWER_TYPE)
{
Master Thesis Project 2004-12-08 38(52)
Allan Nadhmi Faraj




iw_print_pm_value(buffer, pwrq->u.power.value, pwrq->u.power.flags);
printf("\n %s", buffer);
}
}
return(pwrq->u.power.flags);
}

/*------------------------------------------------------------------*/
/*
* Print Power Management info for each device
*/
static int
print_pm_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
struct iw_range range;
char buffer[128];

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Extract range info */
if(iw_get_range_info(skfd, ifname, &range) < 0)
fprintf(stderr, "%-8.8s no power management information.\n\n",
ifname);
else
{
printf("%-8.8s ", ifname);
#if WIRELESS_EXT > 9
/* Display modes availables */
if(range.pm_capa & IW_POWER_MODE)
{
printf("Supported modes :\n ");
if(range.pm_capa & (IW_POWER_UNICAST_R | IW_POWER_MULTICAST_R))
printf("\t\to Receive all packets (unicast & multicast)\n ");
if(range.pm_capa & IW_POWER_UNICAST_R)
printf("\t\to Receive Unicast only (discard multicast)\n ");
if(range.pm_capa & IW_POWER_MULTICAST_R)
printf("\t\to Receive Multicast only (discard unicast)\n ");
if(range.pm_capa & IW_POWER_FORCE_S)
printf("\t\to Force sending using Power Management\n ");
if(range.pm_capa & IW_POWER_REPEATER)
printf("\t\to Repeat multicast\n ");
}
/* Display min/max period availables */
if(range.pmp_flags & IW_POWER_PERIOD)
{
int flags = (range.pmp_flags & ~(IW_POWER_MIN | IW_POWER_MAX));
/* Display if auto or fixed */
if(range.pmp_flags & IW_POWER_MIN)
printf("Auto period ; ");
else
printf("Fixed period ; ");
/* Print the range */
iw_print_pm_value(buffer, range.min_pmp, flags | IW_POWER_MIN);
printf("%s\n ", buffer);
Master Thesis Project 2004-12-08 39(52)
Allan Nadhmi Faraj




iw_print_pm_value(buffer, range.max_pmp, flags | IW_POWER_MAX);
printf("%s\n ", buffer);

}
/* Display min/max timeout availables */
if(range.pmt_flags & IW_POWER_TIMEOUT)
{
int flags = (range.pmt_flags & ~(IW_POWER_MIN | IW_POWER_MAX));
/* Display if auto or fixed */
if(range.pmt_flags & IW_POWER_MIN)
printf("Auto timeout ; ");
else
printf("Fixed timeout ; ");
/* Print the range */
iw_print_pm_value(buffer, range.min_pmt, flags | IW_POWER_MIN);
printf("%s\n ", buffer);
iw_print_pm_value(buffer, range.max_pmt, flags | IW_POWER_MAX);
printf("%s\n ", buffer);

}
#endif /* WIRELESS_EXT > 9 */

/* Get current Power Management settings */
wrq.u.power.flags = 0;
if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) >= 0)
{
int flags = wrq.u.power.flags;

/* Is it disabled ? */
if(wrq.u.power.disabled)
printf("Current mode:off\n ");
else
{
int pm_mask = 0;

/* Let's check the mode */
iw_print_pm_mode(buffer, flags);
printf("Current %s", buffer);

/* Let's check if nothing (simply on) */
if((flags & IW_POWER_MODE) == IW_POWER_ON)
printf("mode:on");
printf("\n ");

/* Let's check the value and its type */
if(wrq.u.power.flags & IW_POWER_TYPE)
{
iw_print_pm_value(buffer,
wrq.u.power.value, wrq.u.power.flags);
printf("%s", buffer);
}

/* If we have been returned a MIN value, ask for the MAX */
if(flags & IW_POWER_MIN)
pm_mask = IW_POWER_MAX;
/* If we have been returned a MAX value, ask for the MIN */
if(flags & IW_POWER_MAX)
pm_mask = IW_POWER_MIN;
/* If we have something to ask for... */
Master Thesis Project 2004-12-08 40(52)
Allan Nadhmi Faraj




if(pm_mask)
get_pm_value(skfd, ifname, &wrq, pm_mask, buffer);

#if WIRELESS_EXT > 9
/* And if we have both a period and a timeout, ask the other */
pm_mask = (range.pm_capa & (~(wrq.u.power.flags) &
IW_POWER_TYPE));
if(pm_mask)
{
int base_mask = pm_mask;
flags = get_pm_value(skfd, ifname, &wrq, pm_mask, buffer);
pm_mask = 0;

/* If we have been returned a MIN value, ask for the MAX */
if(flags & IW_POWER_MIN)
pm_mask = IW_POWER_MAX | base_mask;
/* If we have been returned a MAX value, ask for the MIN */
if(flags & IW_POWER_MAX)
pm_mask = IW_POWER_MIN | base_mask;
/* If we have something to ask for... */
if(pm_mask)
get_pm_value(skfd, ifname, &wrq, pm_mask, buffer);
}
#endif /* WIRELESS_EXT > 9 */
}
}
printf("\n");
}
return(0);
}

/************************** TRANSMIT POWER **************************/

/*------------------------------------------------------------------*/
/*
* Print the number of available transmit powers for the device
*/
static int
print_txpower_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
struct iw_range range;
int dbm;
int mwatt;
int k;

/* Avoid "Unused parameter" warning */
args = args; count = count;

#if WIRELESS_EXT > 9
/* Extract range info */
if(iw_get_range_info(skfd, ifname, &range) < 0)
fprintf(stderr, "%-8.8s no transmit-power information.\n\n",
ifname);
else
{
Master Thesis Project 2004-12-08 41(52)
Allan Nadhmi Faraj




if((range.num_txpower <= 0) || (range.num_txpower > IW_MAX_TXPOWER))
printf("%-8.8s No transmit-powers ? Please update driver...\n\n", ifname);
else
{
printf("%-8.8s %d available transmit-powers :\n",
ifname, range.num_txpower);
/* Print them all */
for(k = 0; k < range.num_txpower; k++)
{
if(range.txpower_capa & IW_TXPOW_MWATT)
{
dbm = iw_mwatt2dbm(range.txpower[k]);
mwatt = range.txpower[k];
}
else
{
dbm = range.txpower[k];
mwatt = iw_dbm2mwatt(range.txpower[k]);
}
printf("\t %d dBm \t(%d mW)\n", dbm, mwatt);
}

/* Get current Transmit Power */
if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0)
{
printf(" Current Tx-Power");
/* Disabled ? */
if(wrq.u.txpower.disabled)
printf(":off\n\n");
else
{
/* Fixed ? */
if(wrq.u.txpower.fixed)
printf("=");
else
printf(":");
if(wrq.u.txpower.flags & IW_TXPOW_MWATT)
{
dbm = iw_mwatt2dbm(wrq.u.txpower.value);
mwatt = wrq.u.txpower.value;
}
else
{
dbm = wrq.u.txpower.value;
mwatt = iw_dbm2mwatt(wrq.u.txpower.value);
}
printf("%d dBm \t(%d mW)\n\n", dbm, mwatt);
}
}
}
}
#endif /* WIRELESS_EXT > 9 */
return(0);
}

/*********************** RETRY LIMIT/LIFETIME ***********************/

#if WIRELESS_EXT > 10
/*------------------------------------------------------------------*/
Master Thesis Project 2004-12-08 42(52)
Allan Nadhmi Faraj




/*
* Print one retry value
*/
static inline int
get_retry_value(int skfd,
char * ifname,
struct iwreq * pwrq,
int flags,
char * buffer)
{
/* Get Another retry value */
pwrq->u.retry.flags = flags;
if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, pwrq) >= 0)
{
/* Let's check the value and its type */
if(pwrq->u.retry.flags & IW_RETRY_TYPE)
{
iw_print_retry_value(buffer,
pwrq->u.retry.value, pwrq->u.retry.flags);
printf("%s\n ", buffer);
}
}
return(pwrq->u.retry.flags);
}

/*------------------------------------------------------------------*/
/*
* Print Retry info for each device
*/
static int
print_retry_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
struct iw_range range;
char buffer[128];

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Extract range info */
if(iw_get_range_info(skfd, ifname, &range) < 0)
fprintf(stderr, "%-8.8s no retry limit/lifetime information.\n\n",
ifname);
else
{
printf("%-8.8s ", ifname);

/* Display min/max limit availables */
if(range.retry_flags & IW_RETRY_LIMIT)
{
int flags = (range.retry_flags & ~(IW_RETRY_MIN | IW_RETRY_MAX));
/* Display if auto or fixed */
if(range.retry_flags & IW_RETRY_MIN)
printf("Auto limit ; ");
else
printf("Fixed limit ; ");
Master Thesis Project 2004-12-08 43(52)
Allan Nadhmi Faraj




/* Print the range */
iw_print_retry_value(buffer, range.min_retry, flags | IW_RETRY_MIN);
printf("%s\n ", buffer);
iw_print_retry_value(buffer, range.max_retry, flags | IW_RETRY_MAX);
printf("%s\n ", buffer);

}
/* Display min/max lifetime availables */
if(range.r_time_flags & IW_RETRY_LIFETIME)
{
int flags = (range.r_time_flags & ~(IW_RETRY_MIN | IW_RETRY_MAX));
/* Display if auto or fixed */
if(range.r_time_flags & IW_RETRY_MIN)
printf("Auto lifetime ; ");
else
printf("Fixed lifetime ; ");
/* Print the range */
iw_print_retry_value(buffer, range.min_r_time, flags | IW_RETRY_MIN);
printf("%s\n ", buffer);
iw_print_retry_value(buffer, range.max_r_time, flags | IW_RETRY_MAX);
printf("%s\n ", buffer);

}

/* Get current retry settings */
wrq.u.retry.flags = 0;
if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0)
{
int flags = wrq.u.retry.flags;

/* Is it disabled ? */
if(wrq.u.retry.disabled)
printf("Current mode:off\n ");
else
{
int retry_mask = 0;

/* Let's check the mode */
printf("Current mode:on\n ");

/* Let's check the value and its type */
if(wrq.u.retry.flags & IW_RETRY_TYPE)
{
iw_print_retry_value(buffer,
wrq.u.retry.value, wrq.u.retry.flags);
printf("%s", buffer);
}

/* If we have been returned a MIN value, ask for the MAX */
if(flags & IW_RETRY_MIN)
retry_mask = IW_RETRY_MAX;
/* If we have been returned a MAX value, ask for the MIN */
if(flags & IW_RETRY_MAX)
retry_mask = IW_RETRY_MIN;
/* If we have something to ask for... */
if(retry_mask)
get_retry_value(skfd, ifname, &wrq, retry_mask, buffer);

/* And if we have both a period and a timeout, ask the other */
Master Thesis Project 2004-12-08 44(52)
Allan Nadhmi Faraj




retry_mask = (range.retry_capa & (~(wrq.u.retry.flags) &
IW_RETRY_TYPE));
if(retry_mask)
{
int base_mask = retry_mask;
flags = get_retry_value(skfd, ifname, &wrq, retry_mask,
buffer);
retry_mask = 0;

/* If we have been returned a MIN value, ask for the MAX */
if(flags & IW_RETRY_MIN)
retry_mask = IW_RETRY_MAX | base_mask;
/* If we have been returned a MAX value, ask for the MIN */
if(flags & IW_RETRY_MAX)
retry_mask = IW_RETRY_MIN | base_mask;
/* If we have something to ask for... */
if(retry_mask)
get_retry_value(skfd, ifname, &wrq, retry_mask, buffer);
}
}
}
printf("\n");
}
return(0);
}

#endif /* WIRELESS_EXT > 10 */

/***************************** SCANNING *****************************/
/*
* This one behave quite differently from the others
*/
#if WIRELESS_EXT > 13
/*------------------------------------------------------------------*/
/*
* Print one element from the scanning results
*/
static inline int
print_scanning_token(struct iw_event * event, /* Extracted token */
int ap_num, /* AP number */
struct iw_range * iwrange, /* Range info */
int has_range)
{
char buffer[128]; /* Temporary buffer */

/* Now, let's decode the event */
switch(event->cmd)
{
case SIOCGIWAP:
printf(" Cell %02d - Address: %s\n", ap_num,
iw_pr_ether(buffer, event->u.ap_addr.sa_data));
ap_num++;
break;
case SIOCGIWNWID:
if(event->u.nwid.disabled)
printf(" NWID:off/any\n");
else
printf(" NWID:%X\n", event->u.nwid.value);
break;
Master Thesis Project 2004-12-08 45(52)
Allan Nadhmi Faraj




case SIOCGIWFREQ:
{
double freq; /* Frequency/channel */
freq = iw_freq2float(&(event->u.freq));
iw_print_freq(buffer, freq);
printf(" %s\n", buffer);
}
break;
case SIOCGIWMODE:
printf(" Mode:%s\n",
iw_operation_mode[event->u.mode]);
break;
case SIOCGIWNAME:
printf(" Protocol:%-1.16s\n", event->u.name);
break;
case SIOCGIWESSID:
{
char essid[IW_ESSID_MAX_SIZE+1];
if((event->u.essid.pointer) && (event->u.essid.length))
memcpy(essid, event->u.essid.pointer, event->u.essid.length);
essid[event->u.essid.length] = '\0';
if(event->u.essid.flags)
{
/* Does it have an ESSID index ? */
if((event->u.essid.flags & IW_ENCODE_INDEX) > 1)
printf(" ESSID:\"%s\" [%d]\n", essid,
(event->u.essid.flags & IW_ENCODE_INDEX));
else
printf(" ESSID:\"%s\"\n", essid);
}
else
printf(" ESSID:off/any\n");
}
break;
case SIOCGIWENCODE:
{
unsigned char key[IW_ENCODING_TOKEN_MAX];
if(event->u.data.pointer)
memcpy(key, event->u.essid.pointer, event->u.data.length);
else
event->u.data.flags |= IW_ENCODE_NOKEY;
printf(" Encryption key:");
if(event->u.data.flags & IW_ENCODE_DISABLED)
printf("off\n");
else
{
/* Display the key */
iw_print_key(buffer, key, event->u.data.length,
event->u.data.flags);
printf("%s", buffer);

/* Other info... */
if((event->u.data.flags & IW_ENCODE_INDEX) > 1)
printf(" [%d]", event->u.data.flags & IW_ENCODE_INDEX);
if(event->u.data.flags & IW_ENCODE_RESTRICTED)
printf(" Security mode:restricted");
if(event->u.data.flags & IW_ENCODE_OPEN)
printf(" Security mode:open");
printf("\n");
Master Thesis Project 2004-12-08 46(52)
Allan Nadhmi Faraj




}
}
break;
case SIOCGIWRATE:
iw_print_bitrate(buffer, event->u.bitrate.value);
printf(" Bit Rate:%s\n", buffer);
break;
case IWEVQUAL:
{
event->u.qual.updated = 0x0; /* Not that reliable, disable */
iw_print_stats(buffer, &event->u.qual, iwrange, has_range);
printf(" %s\n", buffer);
break;
}
#if WIRELESS_EXT > 14
case IWEVCUSTOM:
{
char custom[IW_CUSTOM_MAX+1];
if((event->u.data.pointer) && (event->u.data.length))
memcpy(custom, event->u.data.pointer, event->u.data.length);
custom[event->u.data.length] = '\0';
printf(" Extra:%s\n", custom);
}
break;
#endif /* WIRELESS_EXT > 14 */
default:
printf(" (Unknown Wireless Token 0x%04X)\n",
event->cmd);
} /* switch(event->cmd) */

/* May have changed */
return(ap_num);
}

/*------------------------------------------------------------------*/
/*
* Perform a scanning on one device
*/
static int
print_scanning_info(int skfd,
char * ifname,
char * args[], /* Command line args */
int count) /* Args count */
{
struct iwreq wrq;
unsigned char buffer[IW_SCAN_MAX_DATA]; /* Results */
struct timeval tv; /* Select timeout */
int timeout = 5000000; /* 5s */

/* Avoid "Unused parameter" warning */
args = args; count = count;

/* Init timeout value -> 250ms*/
tv.tv_sec = 0;
tv.tv_usec = 250000;

/*
* Here we should look at the command line args and set the IW_SCAN_ flags
* properly
Master Thesis Project 2004-12-08 47(52)
Allan Nadhmi Faraj




*/
wrq.u.param.flags = IW_SCAN_DEFAULT;
wrq.u.param.value = 0; /* Later */

/* Initiate Scanning */
if(iw_set_ext(skfd, ifname, SIOCSIWSCAN, &wrq) < 0)
{
if(errno != EPERM)
{
fprintf(stderr, "%-8.8s Interface doesn't support scanning : %s\n\n",
ifname, strerror(errno));
return(-1);
}
/* If we don't have the permission to initiate the scan, we may
* still have permission to read left-over results.
* But, don't wait !!! */
#if 0
/* Not cool, it display for non wireless interfaces... */
fprintf(stderr, "%-8.8s (Could not trigger scanning, just reading left-over results)\n", ifname);
#endif
tv.tv_usec = 0;
}
timeout -= tv.tv_usec;

/* Forever */
while(1)
{
fd_set rfds; /* File descriptors for select */
int last_fd; /* Last fd */
int ret;

/* Guess what ? We must re-generate rfds each time */
FD_ZERO(&rfds);
last_fd = -1;

/* In here, add the rtnetlink fd in the list */

/* Wait until something happens */
ret = select(last_fd + 1, &rfds, NULL, NULL, &tv);

/* Check if there was an error */
if(ret < 0)
{
if(errno == EAGAIN || errno == EINTR)
continue;
fprintf(stderr, "Unhandled signal - exiting...\n");
return(-1);
}

/* Check if there was a timeout */
if(ret == 0)
{
/* Try to read the results */
wrq.u.data.pointer = buffer;
wrq.u.data.flags = 0;
wrq.u.data.length = sizeof(buffer);
if(iw_get_ext(skfd, ifname, SIOCGIWSCAN, &wrq) < 0)
{
/* Check if results not available yet */
Master Thesis Project 2004-12-08 48(52)
Allan Nadhmi Faraj




if(errno == EAGAIN)
{
/* Restart timer for only 100ms*/
tv.tv_sec = 0;
tv.tv_usec = 100000;
timeout -= tv.tv_usec;
if(timeout > 0)
continue; /* Try again later */
}

/* Bad error */
fprintf(stderr, "%-8.8s Failed to read scan data : %s\n\n",
ifname, strerror(errno));
return(-2);
}
else
/* We have the results, go to process them */
break;
}

/* In here, check if event and event type
* if scan event, read results. All errors bad & no reset timeout */
}

if(wrq.u.data.length)
{
struct iw_event iwe;
struct stream_descr stream;
int ap_num = 1;
int ret;
struct iw_range range;
int has_range;
#if 0
/* Debugging code. In theory useless, because it's debugged ;-) */
int i;
printf("Scan result [%02X", buffer[0]);
for(i = 1; i < wrq.u.data.length; i++)
printf(":%02X", buffer[i]);
printf("]\n");
#endif
has_range = (iw_get_range_info(skfd, ifname, &range) >= 0);
printf("%-8.8s Scan completed :\n", ifname);
iw_init_event_stream(&stream, buffer, wrq.u.data.length);
do
{
/* Extract an event and print it */
ret = iw_extract_event_stream(&stream, &iwe);
if(ret > 0)
ap_num = print_scanning_token(&iwe, ap_num, &range, has_range);
}
while(ret > 0);
printf("\n");
}
else
printf("%-8.8s No scan results\n", ifname);

return(0);
}
#endif /* WIRELESS_EXT > 13 */
Master Thesis Project 2004-12-08 49(52)
Allan Nadhmi Faraj





/************************* COMMON UTILITIES *************************/
/*
* This section was written by Michael Tokarev <mjt@tls.msk.ru>
* But modified by me ;-)
*/

/* command list */
typedef struct iwlist_entry {
const char *cmd;
iw_enum_handler fn;
int min_count;
int max_count;
} iwlist_cmd;

static const struct iwlist_entry iwlist_cmds[] = {
{ "frequency", print_freq_info, 0, 0 },
{ "channel", print_freq_info, 0, 0 },
{ "ap", print_ap_info, 0, 0 },
{ "accesspoints", print_ap_info, 0, 0 },
{ "peers", print_ap_info, 0, 0 },
{ "bitrate", print_bitrate_info, 0, 0 },
{ "rate", print_bitrate_info, 0, 0 },
{ "encryption", print_keys_info, 0, 0 },
{ "key", print_keys_info, 0, 0 },
{ "power", print_pm_info, 0, 0 },
{ "txpower", print_txpower_info, 0, 0 },
#if WIRELESS_EXT > 10
{ "retry", print_retry_info, 0, 0 },
#endif
#if WIRELESS_EXT > 13
{ "scanning", print_scanning_info, 0, 5 },
#endif
{ NULL, NULL, 0, 0 },
};

/*------------------------------------------------------------------*/
/*
* Find the most appropriate command matching the command line
*/
static inline const iwlist_cmd *
find_command(const char * cmd)
{
const iwlist_cmd * found = NULL;
int ambig = 0;
unsigned int len = strlen(cmd);
int i;

/* Go through all commands */
for(i = 0; iwlist_cmds[i].cmd != NULL; ++i)
{
/* No match -> next one */
if(strncasecmp(iwlist_cmds[i].cmd, cmd, len) != 0)
continue;

/* Exact match -> perfect */
if(len == strlen(iwlist_cmds[i].cmd))
return &iwlist_cmds[i];

Master Thesis Project 2004-12-08 50(52)
Allan Nadhmi Faraj




/* Partial match */
if(found == NULL)
/* First time */
found = &iwlist_cmds[i];
else
/* Another time */
if (iwlist_cmds[i].fn != found->fn)
ambig = 1;
}

if(found == NULL)
{
fprintf(stderr, "iwlist: unknown command `%s'\n", cmd);
return NULL;
}

if(ambig)
{
fprintf(stderr, "iwlist: command `%s' is ambiguous\n", cmd);
return NULL;
}

return found;
}

/*------------------------------------------------------------------*/
/*
* Display help
*/
static void iw_usage(int status)
{
FILE* f = status ? stderr : stdout;
int i;

fprintf(f, "Usage: iwlist [interface] %s\n", iwlist_cmds[0].cmd);
for(i = 1; iwlist_cmds[i].cmd != NULL; ++i)
fprintf(f, " [interface] %s\n", iwlist_cmds[i].cmd);
exit(status);
}

/******************************* MAIN ********************************/

/*------------------------------------------------------------------*/
/*
* The main !
*/
int
main(int argc,
char ** argv)
{
int skfd; /* generic raw socket desc. */
char *dev; /* device name */
char *cmd; /* command */
char **args; /* Command arguments */
int count; /* Number of arguments */
const iwlist_cmd *iwcmd;

if(argc == 1 || argc > 3)
iw_usage(1);
Master Thesis Project 2004-12-08 51(52)
Allan Nadhmi Faraj





if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
iw_usage(0);

/* This is also handled slightly differently */
if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))
return(iw_print_version_info("iwlist"));

if (argc == 2)
{
cmd = argv[1];
dev = NULL;
args = NULL;
count = 0;
}
else
{
cmd = argv[2];
dev = argv[1];
args = argv + 3;
count = argc - 3;
}

/* find a command */
iwcmd = find_command(cmd);
if(iwcmd == NULL)
return 1;

/* Check arg numbers */
if(count < iwcmd->min_count)
{
fprintf(stderr, "iwlist: command `%s' needs more arguments\n", cmd);
return 1;
}
if(count > iwcmd->max_count)
{
fprintf(stderr, "iwlist: command `%s' needs fewer arguments\n", cmd);
return 1;
}

/* Create a channel to the NET kernel. */
if((skfd = iw_sockets_open()) < 0)
{
perror("socket");
return -1;
}

/* do the actual work */
if (dev)
(*iwcmd->fn)(skfd, dev, args, count);
else
iw_enum_devices(skfd, iwcmd->fn, args, count);

/* Close the socket. */
close(skfd);

return 0;
}

Master Thesis Project 2004-12-08 52(52)
Allan Nadhmi Faraj




APPENDIX D Bridge Init script


Because of not risking going through the configuration everytime the PX30 make a reboot or if
something goes wrong I have prepared an init script for the setup that consists of standard
configuration.

#Init script
iwpriv wlan0 wds_add 00:02:6F:31:03:E6 (1)
iwpriv wlan0 wds_add 00:02:6F:30:DA:81
iwpriv wlan0 wds_add 00:02:6F:31:03:EA
iwpriv wlan0 wds_add 00:02:6F:07:23:14

brctl addbr br0 (2)
brctl addif br0 wlan0 (3)
brctl addif br0 eth0
brctl addif br0 wlan0wds0 (4)
brctl addif br0 wlan0wds1
brctl addif br0 wlan0wds2
brctl addif br0 wlan0wds3

/etc/rc.d/init.d/rc.firewall (5)
/etc/rc.d/init.d/sshd start (6)

ifconfig wlan0wds0 0.0.0.0 (7)
ifconfig wlan0wds1 0.0.0.0
ifconfig wlan0wds2 0.0.0.0
ifconfig wlan0wds3 0.0.0.0

ifconfig br0 192.168.0.2 (8)
route add -net 0.0.0.0/0 gw 192.168.0.1 br0 (9)
iwconfig wlan0 channel 3 (10)
iwconfig wlan0 enc ************************** (11)
iwconfig wlan0 essid test_allan (12)
hostname Allan1 (13)
exit 0

(1) This command adds new WDS link connections towards a bridge with a certain MAC address
(2) This command creates a logical bridge interface named br0
(3) This command connects each corresponding interface with the bridge br0
(4) We are also interested in enslaving all of the WDS links to this logical bridge br0
(5) Changing the filtering and firewall parameters
(6) Enables SSH connections
(7) Brings the interface up
(8) Assign an IP address to the bridge interface
(9) Creating an entry for the gateway to use in the routing table
(10) Determine which channel to use
(11) Enable encryption in the wireless interface
(12) Creating an essid for the wireless interface
(13) Changing the hostname of the wireless gateway to Allan1

You might also like