2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 /*! Provides the stack internal notification API.
9 The actual message sending happens in another module to make the
10 notification listeners independent from the stack status.
14 #include <net_device.h>
15 #include <net_notifications.h>
17 #include <util/KMessage.h>
19 #include "stack_private.h"
22 static net_notifications_module_info
* sNotificationModule
;
26 notify_interface_added(net_interface
* interface
)
28 if (sNotificationModule
== NULL
)
29 return B_NOT_SUPPORTED
;
31 char messageBuffer
[512];
33 message
.SetTo(messageBuffer
, sizeof(messageBuffer
), B_NETWORK_MONITOR
);
34 message
.AddInt32("opcode", B_NETWORK_INTERFACE_ADDED
);
35 message
.AddString("interface", interface
->name
);
37 return sNotificationModule
->send_notification(&message
);
42 notify_interface_removed(net_interface
* interface
)
44 if (sNotificationModule
== NULL
)
45 return B_NOT_SUPPORTED
;
47 char messageBuffer
[512];
49 message
.SetTo(messageBuffer
, sizeof(messageBuffer
), B_NETWORK_MONITOR
);
50 message
.AddInt32("opcode", B_NETWORK_INTERFACE_REMOVED
);
51 message
.AddString("interface", interface
->name
);
53 return sNotificationModule
->send_notification(&message
);
58 notify_interface_changed(net_interface
* interface
, uint32 oldFlags
,
61 if (sNotificationModule
== NULL
)
62 return B_NOT_SUPPORTED
;
64 char messageBuffer
[512];
66 message
.SetTo(messageBuffer
, sizeof(messageBuffer
), B_NETWORK_MONITOR
);
67 message
.AddInt32("opcode", B_NETWORK_INTERFACE_CHANGED
);
68 message
.AddString("interface", interface
->name
);
69 if (oldFlags
!= newFlags
) {
70 message
.AddInt32("old flags", oldFlags
);
71 message
.AddInt32("new flags", newFlags
);
74 return sNotificationModule
->send_notification(&message
);
79 notify_link_changed(net_device
* device
)
81 if (sNotificationModule
== NULL
)
82 return B_NOT_SUPPORTED
;
84 char messageBuffer
[512];
86 message
.SetTo(messageBuffer
, sizeof(messageBuffer
), B_NETWORK_MONITOR
);
87 message
.AddInt32("opcode", B_NETWORK_DEVICE_LINK_CHANGED
);
88 message
.AddString("device", device
->name
);
89 message
.AddInt32("media", device
->media
);
90 message
.AddInt64("link speed", device
->link_speed
);
91 message
.AddInt32("link quality", device
->link_quality
);
93 return sNotificationModule
->send_notification(&message
);
100 return get_module(NET_NOTIFICATIONS_MODULE_NAME
,
101 (module_info
**)&sNotificationModule
);
106 uninit_notifications()
108 if (sNotificationModule
!= NULL
)
109 put_module(NET_NOTIFICATIONS_MODULE_NAME
);