summaryrefslogtreecommitdiff
path: root/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
blob: 4f8af60ea0a8f3dfda0e3ca6b480fe8d6cff81fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <opie2/onetwork.h>
#include <opie2/ostation.h>
#include <opie2/omanufacturerdb.h>

#include <unistd.h>

using namespace Opie::Net;

int main( int argc, char** argv )
{
    qDebug( "OPIE Network Demo" );

    ONetwork* net = ONetwork::instance();

    ONetwork::InterfaceIterator it = net->iterator();

    while ( it.current() )
    {
        qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
        qDebug( "DEMO: Datalink code is '%d'", it.current()->dataLinkType() );
        qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
        qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) );
        qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() );
        qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) );
        qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) );
        qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
        if ( it.current()->isWireless() )
        {
            OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
            qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
            qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
            qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );

            //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
            //{
                //qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() );
            //}

            /*

            // nickname
            qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
            iface->setNickName( "MyNickName" );
            if ( iface->nickName() != "MyNickName" )
                qDebug( "DEMO: Warning! Can't change nickname" );
            else
                qDebug( "DEMO: Nickname change successful." );

            /*

            // operation mode
            qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() );
            iface->setMode( "adhoc" );
            if ( iface->mode() != "adhoc" )
                qDebug( "DEMO: Warning! Can't change operation mode" );
            else
                qDebug( "DEMO: Operation Mode change successful." );

            // RF channel
            qDebug( "DEMO: Current Channel is '%d'", iface->channel() );
            iface->setChannel( 1 );
            if ( iface->channel() != 1 )
                qDebug( "DEMO: Warning! Can't change RF channel" );
            else
                qDebug( "DEMO: RF channel change successful." );

            iface->setMode( "managed" );

            */

            /*

            // network scan

            OStationList* stations = iface->scanNetwork();
            if ( stations )
            {
                qDebug( "DEMO: # of stations around = %d", stations->count() );
                OStation* station;
                for ( station = stations->first(); station != 0; station = stations->next() )
                {
                    qDebug( "DEMO: station dump following..." );
                    station->dump();
                }
            }

            else
            {
                qDebug( "DEMO: Warning! Scan didn't work!" );
            }

            /*

            // first some wrong calls to check if this is working
            iface->setPrivate( "seppel", 10 );
            iface->setPrivate( "monitor", 0 );

            // now the real deal
            iface->setPrivate( "monitor", 2, 2, 3 );

            // trying to set hw address to 12:34:56:AB:CD:EF

            /*

            OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
            iface->setUp( false );
            iface->setMacAddress( addr );
            iface->setUp( true );
            qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );

            */

            // monitor test

            

            qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
            iface->setMode( "monitor" );
            qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );

            sleep( 1 );

            iface->setChannel( 1 );
            iface->setMode( "managed" );

            //sleep( 1 );
            qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );

            /*iface->setMode( "adhoc" );
            sleep( 1 );
            qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
            iface->setMode( "managed" );
            sleep( 1 );
            qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
            iface->setMode( "master" );
            sleep( 1 );
            qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );*/

        }
        ++it;
    }

    return 0;

}