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