1 /* 2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 /*! Provides the stack internal notification API. 8 9 The actual message sending happens in another module to make the 10 notification listeners independent from the stack status. 11 */ 12 13 14 #include <net_device.h> 15 #include <net_notifications.h> 16 17 #include <util/KMessage.h> 18 19 #include "stack_private.h" 20 21 22 static net_notifications_module_info* sNotificationModule; 23 24 25 status_t 26 notify_interface_added(net_interface* interface) 27 { 28 if (sNotificationModule == NULL) 29 return B_NOT_SUPPORTED; 30 31 char messageBuffer[512]; 32 KMessage message; 33 message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); 34 message.AddInt32("opcode", B_NETWORK_INTERFACE_ADDED); 35 message.AddString("interface", interface->name); 36 37 return sNotificationModule->send_notification(&message); 38 } 39 40 41 status_t 42 notify_interface_removed(net_interface* interface) 43 { 44 if (sNotificationModule == NULL) 45 return B_NOT_SUPPORTED; 46 47 char messageBuffer[512]; 48 KMessage message; 49 message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); 50 message.AddInt32("opcode", B_NETWORK_INTERFACE_REMOVED); 51 message.AddString("interface", interface->name); 52 53 return sNotificationModule->send_notification(&message); 54 } 55 56 57 status_t 58 notify_interface_changed(net_interface* interface, uint32 oldFlags, 59 uint32 newFlags) 60 { 61 if (sNotificationModule == NULL) 62 return B_NOT_SUPPORTED; 63 64 char messageBuffer[512]; 65 KMessage message; 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); 72 } 73 74 return sNotificationModule->send_notification(&message); 75 } 76 77 78 status_t 79 notify_link_changed(net_device* device) 80 { 81 if (sNotificationModule == NULL) 82 return B_NOT_SUPPORTED; 83 84 char messageBuffer[512]; 85 KMessage message; 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); 92 93 return sNotificationModule->send_notification(&message); 94 } 95 96 97 status_t 98 init_notifications() 99 { 100 return get_module(NET_NOTIFICATIONS_MODULE_NAME, 101 (module_info**)&sNotificationModule); 102 } 103 104 105 void 106 uninit_notifications() 107 { 108 if (sNotificationModule != NULL) 109 put_module(NET_NOTIFICATIONS_MODULE_NAME); 110 } 111