[haiku-commits] r39783 - haiku/trunk/src/servers/net

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 9 Dec 2010 01:11:15 +0100 (CET)

Author: axeld
Date: 2010-12-09 01:11:15 +0100 (Thu, 09 Dec 2010)
New Revision: 39783
Changeset: http://dev.haiku-os.org/changeset/39783

Modified:
   haiku/trunk/src/servers/net/NetServer.cpp
   haiku/trunk/src/servers/net/Settings.cpp
   haiku/trunk/src/servers/net/Settings.h
Log:
* Work in progress of WLAN support in the net_server.


Modified: haiku/trunk/src/servers/net/NetServer.cpp
===================================================================
--- haiku/trunk/src/servers/net/NetServer.cpp   2010-12-09 00:09:51 UTC (rev 
39782)
+++ haiku/trunk/src/servers/net/NetServer.cpp   2010-12-09 00:11:15 UTC (rev 
39783)
@@ -75,6 +75,10 @@
                        void                            _StartServices();
                        void                            
_HandleDeviceMonitor(BMessage* message);
 
+                       status_t                        _JoinNetwork(const 
BMessage& message,
+                                                                       const 
char* name = NULL);
+                       status_t                        _LeaveNetwork(const 
BMessage& message);
+
 private:
                        Settings                        fSettings;
                        LooperMap                       fDeviceMap;
@@ -249,6 +253,26 @@
                        break;
                }
 
+               case kMsgJoinNetwork:
+               {
+                       status_t status = _JoinNetwork(*message);
+
+                       BMessage reply(B_REPLY);
+                       reply.AddInt32("status", status);
+                       message->SendReply(&reply);
+                       break;
+               }
+
+               case kMsgLeaveNetwork:
+               {
+                       status_t status = _LeaveNetwork(*message);
+
+                       BMessage reply(B_REPLY);
+                       reply.AddInt32("status", status);
+                       message->SendReply(&reply);
+                       break;
+               }
+
                default:
                        BApplication::MessageReceived(message);
                        return;
@@ -351,32 +375,54 @@
 
 
 status_t
-NetServer::_ConfigureInterface(BMessage& interface)
+NetServer::_ConfigureInterface(BMessage& message)
 {
-       const char* device;
-       if (interface.FindString("device", &device) != B_OK)
+       const char* name;
+       if (message.FindString("device", &name) != B_OK)
                return B_BAD_VALUE;
 
        bool startAutoConfig = false;
 
        int32 flags;
-       if (interface.FindInt32("flags", &flags) < B_OK)
+       if (message.FindInt32("flags", &flags) < B_OK)
                flags = IFF_UP;
 
        bool autoConfigured;
-       if (interface.FindBool("auto", &autoConfigured) == B_OK && 
autoConfigured)
+       if (message.FindBool("auto", &autoConfigured) == B_OK && autoConfigured)
                flags |= IFF_AUTO_CONFIGURED;
 
        int32 mtu;
-       if (interface.FindInt32("mtu", &mtu) < B_OK)
+       if (message.FindInt32("mtu", &mtu) < B_OK)
                mtu = -1;
 
        int32 metric;
-       if (interface.FindInt32("metric", &metric) < B_OK)
+       if (message.FindInt32("metric", &metric) < B_OK)
                metric = -1;
 
+       BNetworkInterface interface(name);
+       if (!interface.Exists()) {
+               // the interface does not exist yet, we have to add it first
+               BNetworkRoster& roster = BNetworkRoster::Default();
+
+               status_t status = roster.AddInterface(interface);
+               if (status != B_OK) {
+                       fprintf(stderr, "%s: Could not add interface: %s\n",
+                               interface.Name(), strerror(status));
+                       return status;
+               }
+       }
+
+       const char* networkName;
+       if (message.FindString("network", &networkName) != B_OK) {
+               status_t status = _JoinNetwork(message, networkName);
+               if (status != B_OK) {
+                       fprintf(stderr, "%s: joining network \"%s\" failed: 
%s\n",
+                               interface.Name(), networkName, 
strerror(status));
+               }
+       }
+
        BMessage addressMessage;
-       for (int32 index = 0; interface.FindMessage("address", index,
+       for (int32 index = 0; message.FindMessage("address", index,
                        &addressMessage) == B_OK; index++) {
                int32 family;
                if (addressMessage.FindInt32("family", &family) != B_OK) {
@@ -392,19 +438,6 @@
                                family = AF_UNSPEC;
                }
 
-               BNetworkInterface interface(device);
-               if (!interface.Exists()) {
-                       // the interface does not exist yet, we have to add it 
first
-                       BNetworkRoster& roster = BNetworkRoster::Default();
-
-                       status_t status = roster.AddInterface(interface);
-                       if (status != B_OK) {
-                               fprintf(stderr, "%s: Could not add interface: 
%s\n", Name(),
-                                       strerror(status));
-                               return status;
-                       }
-               }
-
                // retrieve addresses
 
                bool autoConfig;
@@ -435,7 +468,7 @@
                }
 
                if (autoConfig) {
-                       _QuitLooperForDevice(device);
+                       _QuitLooperForDevice(name);
                        startAutoConfig = true;
                } else if (addressMessage.FindString("gateway", &string) == B_OK
                        && parse_address(family, string, gateway)) {
@@ -447,7 +480,7 @@
                        status_t status = interface.AddDefaultRoute(gateway);
                        if (status != B_OK) {
                                fprintf(stderr, "%s: Could not add route for 
%s: %s\n",
-                                       Name(), device, strerror(errno));
+                                       Name(), name, strerror(errno));
                        }
                }
 
@@ -506,10 +539,10 @@
 
        if (startAutoConfig) {
                // start auto configuration
-               AutoconfigLooper* looper = new AutoconfigLooper(this, device);
+               AutoconfigLooper* looper = new AutoconfigLooper(this, name);
                looper->Run();
 
-               fDeviceMap[device] = looper;
+               fDeviceMap[name] = looper;
        }
 
        return B_OK;
@@ -730,6 +763,63 @@
 }
 
 
+status_t
+NetServer::_JoinNetwork(const BMessage& message, const char* name)
+{
+       BNetworkAddress address;
+       message.FindFlat("address", &address);
+
+       if (name == NULL)
+               message.FindString("name", &name);
+       if (name == NULL) {
+               // No name specified, we need a network address
+               if (address.Family() != AF_LINK)
+                       return B_BAD_VALUE;
+       }
+
+       // Search for a network configuration that may override the defaults
+
+       bool found = false;
+       uint32 cookie = 0;
+       BMessage network;
+       while (fSettings.GetNextNetwork(cookie, network) == B_OK) {
+               const char* networkName;
+               if (network.FindString("name", &networkName) == B_OK
+                       && name != NULL && address.Family() != AF_LINK
+                       && !strcmp(name, networkName)) {
+                       found = true;
+                       break;
+               }
+
+               const char* mac;
+               if (network.FindString("mac", &mac) == B_OK
+                       && address.Family() == AF_LINK) {
+                       BNetworkAddress link(AF_LINK, mac);
+                       if (link == address) {
+                               found = true;
+                               break;
+                       }
+               }
+       }
+
+       const char* password;
+       if (message.FindString("password", &password) != B_OK && found)
+               password = network.FindString("password");
+
+       // TODO: if password is still NULL, ask password manager once we have 
one
+       // TODO: join for real!
+       return B_ERROR;
+}
+
+
+status_t
+NetServer::_LeaveNetwork(const BMessage& message)
+{
+       // TODO: not yet implemented
+       return B_NOT_SUPPORTED;
+}
+
+
 //     #pragma mark -
 
 

Modified: haiku/trunk/src/servers/net/Settings.cpp
===================================================================
--- haiku/trunk/src/servers/net/Settings.cpp    2010-12-09 00:09:51 UTC (rev 
39782)
+++ haiku/trunk/src/servers/net/Settings.cpp    2010-12-09 00:11:15 UTC (rev 
39783)
@@ -44,14 +44,24 @@
        {B_STRING_TYPE, "device", NULL, true},
        {B_BOOL_TYPE, "disabled", NULL},
        {B_MESSAGE_TYPE, "address", kInterfaceAddressTemplate},
+       {B_STRING_TYPE, "network", NULL},
        {B_INT32_TYPE, "flags", NULL},
        {B_INT32_TYPE, "metric", NULL},
        {B_INT32_TYPE, "mtu", NULL},
        {0, NULL, NULL}
 };
 
+const static settings_template kNetworkTemplate[] = {
+       {B_STRING_TYPE, "name", NULL, true},
+       {B_STRING_TYPE, "mac", NULL},
+       {B_STRING_TYPE, "password", NULL},
+       // TODO: possibility to specify encryption modes
+       {0, NULL, NULL}
+};
+
 const static settings_template kInterfacesTemplate[] = {
        {B_MESSAGE_TYPE, "interface", kInterfaceTemplate},
+       {B_MESSAGE_TYPE, "network", kNetworkTemplate},
        {0, NULL, NULL}
 };
 
@@ -359,7 +369,7 @@
 Settings::GetNextInterface(uint32& cookie, BMessage& interface)
 {
        status_t status = fInterfaces.FindMessage("interface", cookie, 
&interface);
-       if (status < B_OK)
+       if (status != B_OK)
                return status;
 
        cookie++;
@@ -368,10 +378,22 @@
 
 
 status_t
+Settings::GetNextNetwork(uint32& cookie, BMessage& network)
+{
+       status_t status = fInterfaces.FindMessage("network", cookie, &network);
+       if (status != B_OK)
+               return status;
+
+       cookie++;
+       return B_OK;
+}
+
+
+status_t
 Settings::GetNextService(uint32& cookie, BMessage& service)
 {
        status_t status = fServices.FindMessage("service", cookie, &service);
-       if (status < B_OK)
+       if (status != B_OK)
                return status;
 
        cookie++;

Modified: haiku/trunk/src/servers/net/Settings.h
===================================================================
--- haiku/trunk/src/servers/net/Settings.h      2010-12-09 00:09:51 UTC (rev 
39782)
+++ haiku/trunk/src/servers/net/Settings.h      2010-12-09 00:11:15 UTC (rev 
39783)
@@ -25,6 +25,8 @@
 
                        status_t                        
GetNextInterface(uint32& cookie,
                                                                        
BMessage& interface);
+                       status_t                        GetNextNetwork(uint32& 
cookie,
+                                                                       
BMessage& network);
                        status_t                        GetNextService(uint32& 
cookie,
                                                                        
BMessage& service);
                        const BMessage&         Services() const;


Other related posts:

  • » [haiku-commits] r39783 - haiku/trunk/src/servers/net - axeld