Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ boot/Makefile.common	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -122,5 +122,6 @@
 	test/test1 \
 	test/test2 \
-	test/test3
+	test/test3 \
+	nic/lo
 
 RD_DRV_CFG =
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -117,5 +117,6 @@
 	drv/bus/usb/usbmid \
 	drv/bus/usb/usbmouse \
-	drv/bus/usb/vhc
+	drv/bus/usb/vhc \
+	drv/nic/lo
 
 ifeq ($(CONFIG_PCC),y)
@@ -181,4 +182,5 @@
 	lib/fb \
 	lib/net \
+	lib/nic \
 	lib/ext2 \
 	lib/usb \
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/Makefile.common	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -124,4 +124,5 @@
 LIBDRV_PREFIX = $(LIB_PREFIX)/drv
 LIBNET_PREFIX = $(LIB_PREFIX)/net
+LIBNIC_PREFIX = $(LIB_PREFIX)/nic
 LIBMINIX_PREFIX = $(LIB_PREFIX)/minix
 
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/app/init/init.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -306,4 +306,6 @@
 	srv_start("/srv/s3c24ts");
 	
+	spawn("/srv/net");
+	
 	spawn("/srv/fb");
 	spawn("/srv/input");
Index: uspace/doc/doxygroups.h
===================================================================
--- uspace/doc/doxygroups.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/doc/doxygroups.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -33,16 +33,16 @@
 
 		/**
-		 * @defgroup netif Network interface drivers
-		 * @ingroup net
-		 */
-
-			/**
-			 * @defgroup lo Loopback Service
-			 * @ingroup netif
-			 */
-
-			/**
-			 * @defgroup ne2000 NE2000 network interface service
-			 * @ingroup netif
+		 * @defgroup nic Network interface controllers
+		 * @ingroup net
+		 */
+
+			/**
+			 * @defgroup libnic Base NIC framework library
+			 * @ingroup nic
+			 */
+
+			/**
+			 * @defgroup nic_drivers Drivers using the NICF
+			 * @ingroup nic
 			 */
 
Index: uspace/drv/infrastructure/rootvirt/devices.def
===================================================================
--- uspace/drv/infrastructure/rootvirt/devices.def	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/drv/infrastructure/rootvirt/devices.def	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -4,5 +4,13 @@
  * Unless the list is empty, the last item shall be followed by a comma.
  */
+
+/* Loopback network interface */
+{
+    .name = "lo",
+    .match_id = "virtual&loopback"
+},
+
 #ifdef CONFIG_TEST_DRIVERS
+
 {
 	.name = "test1",
@@ -25,6 +33,9 @@
 	.match_id = "virtual&test3"
 },
+
 #endif
+
 #ifdef CONFIG_RUN_VIRTUAL_USB_HC
+
 /* Virtual USB host controller. */
 {
@@ -32,3 +43,4 @@
 	.match_id = "usb&hc=vhc"
 },
+
 #endif
Index: uspace/drv/nic/lo/Makefile
===================================================================
--- uspace/drv/nic/lo/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/drv/nic/lo/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2011 Radim Vansa
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../../..
+LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBNET_PREFIX)/libnet.a $(LIBNIC_PREFIX)/libnic.a
+EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBNET_PREFIX)/include -I$(LIBNIC_PREFIX)/include
+BINARY = lo
+
+SOURCES = \
+	lo.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/nic/lo/lo.c
===================================================================
--- uspace/drv/nic/lo/lo.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/drv/nic/lo/lo.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup drv_lo
+ * @brief Loopback virtual device driver
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <async.h>
+#include <nic.h>
+#include <packet_client.h>
+
+#define NAME  "lo"
+
+static nic_address_t lo_addr = {
+	.address = {0, 0, 0, 0, 0, 0}
+};
+
+static ddf_dev_ops_t lo_dev_ops;
+
+static nic_device_info_t lo_info = {
+	.vendor_name = "HelenOS",
+	.model_name = "loopback",
+	.part_number = "N/A (virtual device)",
+	.serial_number = "N/A (virtual device)"
+};
+
+static void lo_write_packet(nic_t *nic_data, packet_t *packet)
+{
+	nic_report_send_ok(nic_data, 1, packet_get_data_length(packet));
+	nic_received_noneth_packet(nic_data, packet);
+}
+
+static int lo_set_address(ddf_fun_t *fun, const nic_address_t *address)
+{
+	printf("%s: Set loopback HW to " PRIMAC "\n", NAME,
+	    ARGSMAC(address->address));
+	return ENOTSUP;
+}
+
+static int lo_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
+{
+	assert(info);
+	memcpy(info, &lo_info, sizeof(nic_device_info_t));
+	return EOK;
+}
+
+static int lo_add_device(ddf_dev_t *dev)
+{
+	nic_t *nic_data = nic_create_and_bind(dev);
+	if (nic_data == NULL) {
+		printf("%s: Failed to initialize\n", NAME);
+		return ENOMEM;
+	}
+	
+	dev->driver_data = nic_data;
+	nic_set_write_packet_handler(nic_data, lo_write_packet);
+	
+	int rc = nic_connect_to_services(nic_data);
+	if (rc != EOK) {
+		printf("%s: Failed to connect to services\n", NAME);
+		nic_unbind_and_destroy(dev);
+		return rc;
+	}
+	
+	rc = nic_register_as_ddf_fun(nic_data, &lo_dev_ops);
+	if (rc != EOK) {
+		printf("%s: Failed to register as DDF function\n", NAME);
+		nic_unbind_and_destroy(dev);
+		return rc;
+	}
+	
+	rc = nic_report_address(nic_data, &lo_addr);
+	if (rc != EOK) {
+		printf("%s: Failed to setup loopback address\n", NAME);
+		nic_unbind_and_destroy(dev);
+		return rc;
+	}
+	
+	printf("%s: Adding loopback device '%s'\n", NAME, dev->name);
+	return EOK;
+}
+
+static nic_iface_t lo_nic_iface;
+
+static driver_ops_t lo_driver_ops = {
+	.add_device = lo_add_device,
+};
+
+static driver_t lo_driver = {
+	.name = NAME,
+	.driver_ops = &lo_driver_ops
+};
+
+int main(int argc, char *argv[])
+{
+	nic_driver_init(NAME);
+	nic_driver_implement(&lo_driver_ops, &lo_dev_ops, &lo_nic_iface);
+	lo_nic_iface.set_address = lo_set_address;
+	lo_nic_iface.get_device_info = lo_get_device_info;
+	
+	return ddf_driver_main(&lo_driver);
+}
+
+/** @}
+ */
Index: uspace/drv/nic/lo/lo.ma
===================================================================
--- uspace/drv/nic/lo/lo.ma	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/drv/nic/lo/lo.ma	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,1 @@
+10 virtual&loopback
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/c/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -67,4 +67,5 @@
 	generic/devman.c \
 	generic/device/hw_res.c \
+	generic/device/hw_res_parsed.c \
 	generic/device/char_dev.c \
 	generic/device/nic.c \
@@ -104,4 +105,5 @@
 	generic/adt/list.c \
 	generic/adt/hash_table.c \
+	generic/adt/hash_set.c \
 	generic/adt/dynamic_fifo.c \
 	generic/adt/measured_strings.c \
Index: uspace/lib/c/generic/device/hw_res_parsed.c
===================================================================
--- uspace/lib/c/generic/device/hw_res_parsed.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/c/generic/device/hw_res_parsed.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2011 Jiri Michalec
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <device/hw_res_parsed.h>
+#include <malloc.h>
+#include <assert.h>
+#include <errno.h>
+
+static void hw_res_parse_add_irq(hw_res_list_parsed_t *out, hw_resource_t *res,
+    int flags)
+{
+	assert(res && (res->type == INTERRUPT));
+	
+	int irq = res->res.interrupt.irq;
+	size_t count = out->irqs.count;
+	int keep_duplicit = flags & HW_RES_KEEP_DUPLICIT;
+	
+	if (!keep_duplicit) {
+		for (size_t i = 0; i < count; i++) {
+			if (out->irqs.irqs[i] == irq)
+				return;
+		}
+	}
+	
+	out->irqs.irqs[count] = irq;
+	out->irqs.count++;
+}
+
+static void hw_res_parse_add_io_range(hw_res_list_parsed_t *out,
+    hw_resource_t *res, int flags)
+{
+	assert(res && (res->type == IO_RANGE));
+	
+	uint64_t address = res->res.io_range.address;
+	endianness_t endianness = res->res.io_range.endianness;
+	size_t size = res->res.io_range.size;
+	
+	if ((size == 0) && (!(flags & HW_RES_KEEP_ZERO_AREA)))
+		return;
+	
+	int keep_duplicit = flags & HW_RES_KEEP_DUPLICIT;
+	size_t count = out->io_ranges.count;
+	
+	if (!keep_duplicit) {
+		for (size_t i = 0; i < count; i++) {
+			uint64_t s_address = out->io_ranges.ranges[i].address;
+			size_t s_size = out->io_ranges.ranges[i].size;
+			
+			if ((address == s_address) && (size == s_size))
+				return;
+		}
+	}
+	
+	out->io_ranges.ranges[count].address = address;
+	out->io_ranges.ranges[count].endianness = endianness;
+	out->io_ranges.ranges[count].size = size;
+	out->io_ranges.count++;
+}
+
+static void hw_res_parse_add_mem_range(hw_res_list_parsed_t *out,
+    hw_resource_t *res, int flags)
+{
+	assert(res && (res->type == MEM_RANGE));
+	
+	uint64_t address = res->res.mem_range.address;
+	endianness_t endianness = res->res.mem_range.endianness;
+	size_t size = res->res.mem_range.size;
+	
+	if ((size == 0) && (!(flags & HW_RES_KEEP_ZERO_AREA)))
+		return;
+	
+	int keep_duplicit = flags & HW_RES_KEEP_DUPLICIT;
+	size_t count = out->mem_ranges.count;
+	
+	if (!keep_duplicit) {
+		for (size_t i = 0; i < count; ++i) {
+			uint64_t s_address = out->mem_ranges.ranges[i].address;
+			size_t s_size = out->mem_ranges.ranges[i].size;
+			
+			if ((address == s_address) && (size == s_size))
+				return;
+		}
+	}
+	
+	out->mem_ranges.ranges[count].address = address;
+	out->mem_ranges.ranges[count].endianness = endianness;
+	out->mem_ranges.ranges[count].size = size;
+	out->mem_ranges.count++;
+}
+
+/** Parse list of hardware resources
+ *
+ * @param      hw_resources Original structure resource
+ * @param[out] out          Output parsed resources
+ * @param      flags        Flags of the parsing.
+ *                          HW_RES_KEEP_ZERO_AREA for keeping
+ *                          zero-size areas, HW_RES_KEEP_DUPLICITIES
+ *                          for keep duplicit areas
+ *
+ * @return EOK if succeed, error code otherwise.
+ *
+ */
+int hw_res_list_parse(hw_resource_list_t *hw_resources,
+    hw_res_list_parsed_t *out, int flags)
+{
+	if ((!hw_resources) || (!out))
+		return EINVAL;
+	
+	size_t res_count = hw_resources->count;
+	hw_res_list_parsed_clean(out);
+	
+	out->irqs.irqs = malloc(res_count * sizeof(int));
+	out->io_ranges.ranges = malloc(res_count * sizeof(io_range_t));
+	out->mem_ranges.ranges = malloc(res_count * sizeof(mem_range_t));
+	
+	for (size_t i = 0; i < res_count; ++i) {
+		hw_resource_t *resource = &(hw_resources->resources[i]);
+		
+		switch (resource->type) {
+		case INTERRUPT:
+			hw_res_parse_add_irq(out, resource, flags);
+			break;
+		case IO_RANGE:
+			hw_res_parse_add_io_range(out, resource, flags);
+			break;
+		case MEM_RANGE:
+			hw_res_parse_add_mem_range(out, resource, flags);
+			break;
+		default:
+			return EINVAL;
+		}
+	}
+	
+	return EOK;
+};
+
+/** Get hw_resources from the parent device.
+ *
+ * The output must be inited, will be cleared
+ *
+ * @see get_hw_resources
+ * @see hw_resources_parse
+ *
+ * @param sess                Session to the parent device
+ * @param hw_resources_parsed Output list
+ * @param flags               Parsing flags
+ *
+ * @return EOK if succeed, error code otherwise
+ *
+ */
+int hw_res_get_list_parsed(async_sess_t *sess,
+    hw_res_list_parsed_t *hw_res_parsed, int flags)
+{
+	if (!hw_res_parsed)
+		return EBADMEM;
+	
+	hw_resource_list_t hw_resources;
+	hw_res_list_parsed_clean(hw_res_parsed);
+	bzero(&hw_resources, sizeof(hw_resource_list_t));
+	
+	int rc = hw_res_get_resource_list(sess, &hw_resources);
+	if (rc != EOK)
+		return rc;
+	
+	rc = hw_res_list_parse(&hw_resources, hw_res_parsed, flags);
+	hw_res_clean_resource_list(&hw_resources);
+	
+	return rc;
+};
+
+/** @}
+ */
Index: uspace/lib/c/generic/device/nic.c
===================================================================
--- uspace/lib/c/generic/device/nic.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/c/generic/device/nic.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -137,16 +137,16 @@
 	
 	async_exch_t *exch = async_exchange_begin(dev_sess);
-	
-	int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_GET_ADDRESS);
-	if (rc != EOK) {
-		async_exchange_end(exch);
-		return rc;
-	}
-	
-	rc = async_data_read_start(exch, address, sizeof(nic_address_t));
-	
-	async_exchange_end(exch);
-	
-	return rc;
+	aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
+	    NIC_GET_ADDRESS, NULL);
+	int rc = async_data_read_start(exch, address, sizeof(nic_address_t));
+	async_exchange_end(exch);
+	
+	sysarg_t res;
+	async_wait_for(aid, &res);
+	
+	if (rc != EOK)
+		return rc;
+	
+	return (int) res;
 }
 
@@ -164,5 +164,5 @@
 	
 	async_exch_t *exch = async_exchange_begin(dev_sess);
-	aid_t message_id = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
+	aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
 	    NIC_SET_ADDRESS, NULL);
 	int rc = async_data_write_start(exch, address, sizeof(nic_address_t));
@@ -170,5 +170,5 @@
 	
 	sysarg_t res;
-	async_wait_for(message_id, &res);
+	async_wait_for(aid, &res);
 	
 	if (rc != EOK)
Index: uspace/lib/c/include/device/hw_res_parsed.h
===================================================================
--- uspace/lib/c/include/device/hw_res_parsed.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/c/include/device/hw_res_parsed.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2011 Jiri Michalec
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_DEVICE_HW_RES_PARSED_H_
+#define LIBC_DEVICE_HW_RES_PARSED_H_
+
+#include <device/hw_res.h>
+#include <str.h>
+
+/** Keep areas of the zero size in the list */
+#define HW_RES_KEEP_ZERO_AREA  0x1
+
+/** Keep duplicit entries */
+#define HW_RES_KEEP_DUPLICIT   0x2
+
+/** Address range structure */
+typedef struct addr_range {
+	/** Start address */
+	uint64_t address;
+	
+	/** Endianness */
+	endianness_t endianness;
+	
+	/** Area size */
+	size_t size;
+} addr_range_t;
+
+/** IO range type */
+typedef addr_range_t io_range_t;
+
+/** Memory range type */
+typedef addr_range_t mem_range_t;
+
+/** List of IRQs */
+typedef struct irq_list {
+	/** Irq count */
+	size_t count;
+	
+	/** Array of IRQs */
+	int *irqs;
+} irq_list_t;
+
+/** List of memory areas */
+typedef struct addr_range_list {
+	/** Areas count */
+	size_t count;
+	
+	/** Array of areas */
+	addr_range_t *ranges;
+} addr_range_list_t;
+
+/** List of IO mapped areas */
+typedef addr_range_list_t io_range_list_t;
+
+/** Memory range type */
+typedef addr_range_list_t mem_range_list_t;
+
+/** HW resources parsed according to resource type */
+typedef struct hw_resource_list_parsed {
+	/** List of IRQs */
+	irq_list_t irqs;
+	
+	/** List of memory areas */
+	mem_range_list_t mem_ranges;
+	
+	/** List of IO areas */
+	io_range_list_t io_ranges;
+} hw_res_list_parsed_t;
+
+/** Clean hw_resource_list_parsed_t structure
+ *
+ * All allocated memory will be released, data amd pointers set to 0.
+ *
+ * @param list The structure to clear
+ */
+static inline void hw_res_list_parsed_clean(hw_res_list_parsed_t *list)
+{
+	if (list == NULL)
+		return;
+	
+	free(list->irqs.irqs);
+	free(list->io_ranges.ranges);
+	free(list->mem_ranges.ranges);
+	
+	bzero(list, sizeof(hw_res_list_parsed_t));
+}
+
+/** Initialize the hw_resource_list_parsed_t structure
+ *
+ *  @param list The structure to initialize
+ */
+static inline void hw_res_list_parsed_init(hw_res_list_parsed_t *list)
+{
+	bzero(list, sizeof(hw_res_list_parsed_t));
+}
+
+extern int hw_res_list_parse(hw_resource_list_t *, hw_res_list_parsed_t *, int);
+extern int hw_res_get_list_parsed(async_sess_t *, hw_res_list_parsed_t *, int);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/net/device.h
===================================================================
--- uspace/lib/c/include/net/device.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/c/include/net/device.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -41,4 +41,5 @@
 #include <adt/int_map.h>
 #include <net/eth_phys.h>
+#include <bool.h>
 
 /** Ethernet address length. */
@@ -51,4 +52,12 @@
 #define ARGSMAC(__a) \
 	(__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5]
+
+/* Compare MAC address with specific value */
+#define MAC_EQUALS_VALUE(__a, __a0, __a1, __a2, __a3, __a4, __a5) \
+	((__a)[0] == (__a0) && (__a)[1] == (__a1) && (__a)[2] == (__a2) \
+	&& (__a)[3] == (__a3) && (__a)[4] == (__a4) && (__a)[5] == (__a5))
+
+#define MAC_IS_ZERO(__x) \
+	MAC_EQUALS_VALUE(__x, 0, 0, 0, 0, 0, 0)
 
 /** Device identifier to generic type map declaration. */
@@ -221,4 +230,29 @@
 } nic_device_stats_t;
 
+/** Errors corresponding to those in the nic_device_stats_t */
+typedef enum {
+	NIC_SEC_BUFFER_FULL,
+	NIC_SEC_ABORTED,
+	NIC_SEC_CARRIER_LOST,
+	NIC_SEC_FIFO_OVERRUN,
+	NIC_SEC_HEARTBEAT,
+	NIC_SEC_WINDOW_ERROR,
+	/* Error encountered during TX but with other type of error */
+	NIC_SEC_OTHER
+} nic_send_error_cause_t;
+
+/** Errors corresponding to those in the nic_device_stats_t */
+typedef enum {
+	NIC_REC_BUFFER_FULL,
+	NIC_REC_LENGTH,
+	NIC_REC_BUFFER_OVERFLOW,
+	NIC_REC_CRC,
+	NIC_REC_FRAME_ALIGNMENT,
+	NIC_REC_FIFO_OVERRUN,
+	NIC_REC_MISSED,
+	/* Error encountered during RX but with other type of error */
+	NIC_REC_OTHER
+} nic_receive_error_cause_t;
+
 /**
  * Information about the NIC that never changes - name, vendor, model,
@@ -246,4 +280,13 @@
 
 /**
+ * Type of the ethernet frame
+ */
+typedef enum nic_frame_type {
+	NIC_FRAME_UNICAST,
+	NIC_FRAME_MULTICAST,
+	NIC_FRAME_BROADCAST
+} nic_frame_type_t;
+
+/**
  * Specifies which unicast frames is the NIC receiving.
  */
@@ -292,4 +335,25 @@
 
 /**
+ * Structure passed as argument for virtue NIC_WV_MAGIC_PACKET.
+ */
+typedef struct nic_wv_magic_packet_data {
+	uint8_t password[6];
+} nic_wv_magic_packet_data_t;
+
+/**
+ * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV4
+ */
+typedef struct nic_wv_ipv4_data {
+	uint8_t address[4];
+} nic_wv_ipv4_data_t;
+
+/**
+ * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV6
+ */
+typedef struct nic_wv_ipv6_data {
+	uint8_t address[16];
+} nic_wv_ipv6_data_t;
+
+/**
  * WOL virtue types defining the interpretation of data passed to the virtue.
  * Those tagged with S can have only single virtue active at one moment, those
@@ -376,4 +440,24 @@
 	NIC_POLL_SOFTWARE_PERIODIC
 } nic_poll_mode_t;
+
+/**
+ * Says if this virtue type is a multi-virtue (there can be multiple virtues of
+ * this type at once).
+ *
+ * @param type
+ *
+ * @return true or false
+ */
+static inline int nic_wv_is_multi(nic_wv_type_t type) {
+	switch (type) {
+	case NIC_WV_FULL_MATCH:
+	case NIC_WV_DESTINATION:
+	case NIC_WV_DIRECTED_IPV4:
+	case NIC_WV_DIRECTED_IPV6:
+		return true;
+	default:
+		return false;
+	}
+}
 
 static inline const char *nic_device_state_to_string(nic_device_state_t state)
Index: uspace/lib/net/generic/generic.c
===================================================================
--- uspace/lib/net/generic/generic.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/generic/generic.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -79,5 +79,5 @@
 {
 	async_exch_t *exch = async_exchange_begin(sess);
-	int rc = async_req_2_0(exch, message, (sysarg_t) device_id,
+	int rc = async_req_3_0(exch, message, (sysarg_t) device_id, 0,
 	    (sysarg_t) service);
 	async_exchange_end(exch);
Index: uspace/lib/net/generic/net_checksum.c
===================================================================
--- uspace/lib/net/generic/net_checksum.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/generic/net_checksum.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -45,4 +45,7 @@
 #define CRC_DIVIDER_LE  0xedb88320
 
+/** Polynomial used in multicast address hashing */
+#define CRC_MCAST_POLYNOMIAL  0x04c11db6
+
 /** Compacts the computed checksum to the 16 bit number adding the carries.
  *
@@ -221,4 +224,39 @@
 }
 
+/** Compute the standard hash from MAC
+ *
+ * Hashing MAC into 64 possible values and using the value as index to
+ * 64bit number.
+ *
+ * The code is copied from qemu-0.13's implementation of ne2000 and rt8139
+ * drivers, but according to documentation there it originates in FreeBSD.
+ *
+ * @param[in] addr The 6-byte MAC address to be hashed
+ *
+ * @return 64-bit number with only single bit set to 1
+ *
+ */
+uint64_t multicast_hash(const uint8_t addr[6])
+{
+	uint32_t crc;
+    int carry, i, j;
+    uint8_t b;
+
+    crc = 0xffffffff;
+    for (i = 0; i < 6; i++) {
+        b = addr[i];
+        for (j = 0; j < 8; j++) {
+            carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
+            crc <<= 1;
+            b >>= 1;
+            if (carry)
+                crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry);
+        }
+    }
+	
+    uint64_t one64 = 1;
+    return one64 << (crc >> 26);
+}
+
 /** @}
  */
Index: uspace/lib/net/il/ip_remote.c
===================================================================
--- uspace/lib/net/il/ip_remote.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/il/ip_remote.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -123,5 +123,5 @@
  *
  */
-int ip_device_req_remote(async_sess_t *sess, nic_device_id_t device_id,
+int ip_device_req(async_sess_t *sess, nic_device_id_t device_id,
     services_t service)
 {
Index: uspace/lib/net/include/ip_interface.h
===================================================================
--- uspace/lib/net/include/ip_interface.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/include/ip_interface.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -46,5 +46,4 @@
 #define ip_set_gateway_req     ip_set_gateway_req_remote
 #define ip_packet_size_req     ip_packet_size_req_remote
-#define ip_device_req          ip_device_req_remote
 #define ip_add_route_req       ip_add_route_req_remote
 #define ip_send_msg            ip_send_msg_remote
Index: uspace/lib/net/include/ip_remote.h
===================================================================
--- uspace/lib/net/include/ip_remote.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/include/ip_remote.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -48,5 +48,5 @@
 extern int ip_received_error_msg_remote(async_sess_t *, nic_device_id_t, packet_t *,
     services_t, services_t);
-extern int ip_device_req_remote(async_sess_t *, nic_device_id_t, services_t);
+extern int ip_device_req(async_sess_t *, nic_device_id_t, services_t);
 extern int ip_add_route_req_remote(async_sess_t *, nic_device_id_t, in_addr_t,
     in_addr_t, in_addr_t);
Index: uspace/lib/net/include/net_checksum.h
===================================================================
--- uspace/lib/net/include/net_checksum.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/include/net_checksum.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -67,4 +67,5 @@
 extern uint16_t flip_checksum(uint16_t);
 extern uint16_t ip_checksum(uint8_t *, size_t);
+extern uint64_t multicast_hash(const uint8_t addr[6]);
 
 #endif
Index: uspace/lib/net/tl/tl_skel.c
===================================================================
--- uspace/lib/net/tl/tl_skel.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/lib/net/tl/tl_skel.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -123,4 +123,5 @@
 		goto out;
 	
+	task_retval(0);
 	async_manager();
 	
Index: uspace/lib/nic/Makefile
===================================================================
--- uspace/lib/nic/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 2011 Radim Vansa
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+LIBRARY = libnic
+LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBNET_PREFIX)/libnet.a
+EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include -I$(LIBNET_PREFIX)/include
+
+SOURCES = \
+	src/nic_driver.c \
+	src/nic_addr_db.c \
+	src/nic_rx_control.c \
+	src/nic_wol_virtues.c \
+	src/nic_impl.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/nic/include/nic.h
===================================================================
--- uspace/lib/nic/include/nic.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/include/nic.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,283 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Public header exposing NICF to drivers
+ */
+
+#ifndef __NIC_H__
+#define __NIC_H__
+
+#include <adt/list.h>
+#include <ddf/driver.h>
+#include <device/hw_res_parsed.h>
+#include <net/packet.h>
+#include <ops/nic.h>
+
+struct nic;
+typedef struct nic nic_t;
+
+/**
+ * Single WOL virtue descriptor.
+ */
+typedef struct nic_wol_virtue {
+	link_t item;
+	nic_wv_id_t id;
+	nic_wv_type_t type;
+	const void *data;
+	size_t length;
+	struct nic_wol_virtue *next;
+} nic_wol_virtue_t;
+
+/**
+ * Simple structure for sending the allocated frames (packets) in a list.
+ */
+typedef struct {
+	link_t link;
+	packet_t *packet;
+} nic_frame_t;
+
+typedef list_t nic_frame_list_t;
+
+/**
+ * Handler for writing packet data to the NIC device.
+ * The function is responsible for releasing the packet.
+ * It does not return anything, if some error is detected the function just
+ * silently fails (logging on debug level is suggested).
+ *
+ * @param nic_data
+ * @param packet	Pointer to the packet to be sent
+ */
+typedef void (*write_packet_handler)(nic_t *, packet_t *);
+/**
+ * The handler for transitions between driver states.
+ * If the handler returns negative error code, the transition between
+ * states is canceled (the state is not changed).
+ *
+ * @param nic_data	NICF main structure
+ *
+ * @return EOK	If everything is all right.
+ * @return negative error code on error.
+ */
+typedef int (*state_change_handler)(nic_t *);
+/**
+ * Handler for unicast filtering mode change.
+ *
+ * @param nic_data		NICF main structure
+ * @param new_mode		The mode that should be set up
+ * @param address_list	Addresses as argument to the mode
+ * @param address_count	Number of addresses in the list
+ *
+ * @return EOK		If the mode is set up
+ * @return ENOTSUP	If this mode is not supported
+ */
+typedef int (*unicast_mode_change_handler)(nic_t *,
+	nic_unicast_mode_t, const nic_address_t *, size_t);
+/**
+ * Handler for multicast filtering mode change.
+ *
+ * @param nic_data		NICF main structure
+ * @param new_mode		The mode that should be set up
+ * @param address_list	Addresses as argument to the mode
+ * @param address_count	Number of addresses in the list
+ *
+ * @return EOK		If the mode is set up
+ * @return ENOTSUP	If this mode is not supported
+ */
+typedef int (*multicast_mode_change_handler)(nic_t *,
+	nic_multicast_mode_t, const nic_address_t *, size_t);
+/**
+ * Handler for broadcast filtering mode change.
+ *
+ * @param nic_data	NICF main structure
+ * @param new_mode	The mode that should be set up
+ *
+ * @return EOK		If the mode is set up
+ * @return ENOTSUP	If this mode is not supported
+ */
+typedef int (*broadcast_mode_change_handler)(nic_t *, nic_broadcast_mode_t);
+/**
+ * Handler for blocked sources list change.
+ *
+ * @param nic_data		NICF main structure
+ * @param address_list	Addresses as argument to the mode
+ * @param address_count	Number of addresses in the list
+ */
+typedef void (*blocked_sources_change_handler)(nic_t *,
+	const nic_address_t *, size_t);
+/**
+ * Handler for VLAN filtering mask change.
+ * @param nic_data		NICF main structure
+ * @param vlan_mask		The new mask | NULL for disabling vlan filter
+ */
+typedef void (*vlan_mask_change_handler)(nic_t *, const nic_vlan_mask_t *);
+/**
+ * Handler called when a WOL virtue is added.
+ * If the maximum of accepted WOL virtues changes due to adding this virtue
+ * you should update the vector wol_virtues.caps_max.
+ * The driver is allowed to store pointer to the virtue data until
+ * on_wol_virtue_remove on these data is called (although probably this is
+ * not a good practice).
+ *
+ * @param nic_data	NICF main structure
+ * @param virtue	Structure with virtue description
+ *
+ * @return EOK		If the filter can be used. Software emulation of the
+ * 					filter is activated unless the emulate is set to 0.
+ * @return ENOTSUP	If this filter cannot work on this NIC (e.g. the NIC
+ * 					cannot run in promiscuous node or the limit of WOL
+ * 					packets' specifications was reached).
+ * @return ELIMIT	If this filter must implemented in HW but currently the
+ * 					limit of these HW filters was reached.
+ */
+typedef int (*wol_virtue_add_handler)(nic_t *, const nic_wol_virtue_t *);
+/**
+ * Handler called when a WOL virtue is removed.
+ * If the maximum of accepted WOL virtues changes due to removing this
+ * virtue you should update the vector wol_virtues.caps_max.
+ *
+ * @param nic_data	NICF main structure
+ * @param virtue		Structure with virtue description
+ */
+typedef void (*wol_virtue_remove_handler)(nic_t *, const nic_wol_virtue_t *);
+/**
+ * Handler for poll mode change.
+ *
+ * @param nic_data	NICF main structure
+ * @param mode		Mode to be set up
+ * @param period	New period of polling (with NIC_POLL_PERIODIC)
+ *
+ * @return EOK		If the mode was fully setup
+ * @return ENOTSUP	If NICF should do the periodic polling
+ * @return EINVAL	If this mode cannot be set up under no circumstances
+ */
+typedef int (*poll_mode_change_handler)(nic_t *,
+	nic_poll_mode_t, const struct timeval *);
+/**
+ * Event handler called when the NIC should poll its buffers for a new frame
+ * (in NIC_POLL_PERIODIC or NIC_POLL_ON_DEMAND) modes.
+ *
+ * @param nic_data	NICF main structure
+ */
+typedef void (*poll_request_handler)(nic_t *);
+
+/* nic_t allocation and deallocation */
+extern nic_t *nic_create_and_bind(ddf_dev_t *);
+extern void nic_unbind_and_destroy(ddf_dev_t *);
+
+/* Functions called in the main function */
+extern int nic_driver_init(const char *);
+extern void nic_driver_implement(driver_ops_t *, ddf_dev_ops_t *,
+	nic_iface_t *);
+
+/* Functions called in add_device */
+extern int nic_connect_to_services(nic_t *);
+extern int nic_register_as_ddf_fun(nic_t *, ddf_dev_ops_t *);
+extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *);
+extern void nic_set_specific(nic_t *, void *);
+extern void nic_set_write_packet_handler(nic_t *, write_packet_handler);
+extern void nic_set_state_change_handlers(nic_t *,
+	state_change_handler, state_change_handler, state_change_handler);
+extern void nic_set_filtering_change_handlers(nic_t *,
+	unicast_mode_change_handler, multicast_mode_change_handler,
+	broadcast_mode_change_handler, blocked_sources_change_handler,
+	vlan_mask_change_handler);
+extern void nic_set_wol_virtue_change_handlers(nic_t *,
+	wol_virtue_add_handler, wol_virtue_remove_handler);
+extern void nic_set_poll_handlers(nic_t *,
+	poll_mode_change_handler, poll_request_handler);
+
+/* Functions called in device_added */
+extern int nic_ready(nic_t *);
+
+/* General driver functions */
+extern ddf_dev_t *nic_get_ddf_dev(nic_t *);
+extern ddf_fun_t *nic_get_ddf_fun(nic_t *);
+extern nic_t *nic_get_from_ddf_dev(ddf_dev_t *);
+extern nic_t *nic_get_from_ddf_fun(ddf_fun_t *);
+extern void *nic_get_specific(nic_t *);
+extern nic_device_state_t nic_query_state(nic_t *);
+extern void nic_set_tx_busy(nic_t *, int);
+extern int nic_report_address(nic_t *, const nic_address_t *);
+extern int nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct timeval *);
+extern void nic_query_address(nic_t *, nic_address_t *);
+extern void nic_received_packet(nic_t *, packet_t *);
+extern void nic_received_noneth_packet(nic_t *, packet_t *);
+extern void nic_received_frame(nic_t *, nic_frame_t *);
+extern void nic_received_frame_list(nic_t *, nic_frame_list_t *);
+extern void nic_disable_interrupt(nic_t *, int);
+extern void nic_enable_interrupt(nic_t *, int);
+extern nic_poll_mode_t nic_query_poll_mode(nic_t *, struct timeval *);
+
+/* Statistics updates */
+extern void nic_report_send_ok(nic_t *, size_t, size_t);
+extern void nic_report_send_error(nic_t *, nic_send_error_cause_t, unsigned);
+extern void nic_report_receive_error(nic_t *, nic_receive_error_cause_t,
+    unsigned);
+extern void nic_report_collisions(nic_t *, unsigned);
+
+/* Packet / frame / frame list allocation and deallocation */
+extern packet_t *nic_alloc_packet(nic_t *, size_t);
+extern void nic_release_packet(nic_t *, packet_t *);
+extern nic_frame_t *nic_alloc_frame(nic_t *, size_t);
+extern nic_frame_list_t *nic_alloc_frame_list(void);
+extern void nic_frame_list_append(nic_frame_list_t *, nic_frame_t *);
+extern void nic_release_frame(nic_t *, nic_frame_t *);
+
+/* RXC query and report functions */
+extern void nic_report_hw_filtering(nic_t *, int, int, int);
+extern void nic_query_unicast(const nic_t *,
+	nic_unicast_mode_t *, size_t, nic_address_t *, size_t *);
+extern void nic_query_multicast(const nic_t *,
+	nic_multicast_mode_t *, size_t, nic_address_t *, size_t *);
+extern void nic_query_broadcast(const nic_t *, nic_broadcast_mode_t *);
+extern void nic_query_blocked_sources(const nic_t *,
+	size_t, nic_address_t *, size_t *);
+extern int nic_query_vlan_mask(const nic_t *, nic_vlan_mask_t *);
+extern int nic_query_wol_max_caps(const nic_t *, nic_wv_type_t);
+extern void nic_set_wol_max_caps(nic_t *, nic_wv_type_t, int);
+extern uint64_t nic_mcast_hash(const nic_address_t *, size_t);
+extern uint64_t nic_query_mcast_hash(nic_t *);
+
+/* Software period functions */
+extern void nic_sw_period_start(nic_t *);
+extern void nic_sw_period_stop(nic_t *);
+
+/* Packet DMA lock */
+extern void * nic_dma_lock_packet(packet_t * packet);
+extern void nic_dma_unlock_packet(packet_t * packet);
+
+#endif // __NIC_H__
+
+/** @}
+ */
Index: uspace/lib/nic/include/nic_addr_db.h
===================================================================
--- uspace/lib/nic/include/nic_addr_db.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/include/nic_addr_db.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Generic hash-set based database of addresses
+ */
+
+#ifndef __NIC_ADDR_DB_H__
+#define __NIC_ADDR_DB_H__
+
+#ifndef LIBNIC_INTERNAL
+#error "This is internal libnic header, please don't include it"
+#endif
+
+#include <adt/hash_set.h>
+
+/**
+ * Initial size of DB's hash set
+ */
+#define NIC_ADDR_DB_INIT_SIZE 	8
+/**
+ * Maximal length of addresses in the DB (in bytes).
+ */
+#define NIC_ADDR_MAX_LENGTH		16
+
+/**
+ * Fibril-safe database of addresses implemented using hash set.
+ */
+typedef struct nic_addr_db {
+	hash_set_t set;
+	size_t addr_len;
+} nic_addr_db_t;
+
+/**
+ * Helper structure for keeping the address in the hash set.
+ */
+typedef struct nic_addr_entry {
+	link_t item;
+	size_t addr_len;
+	uint8_t addr[NIC_ADDR_MAX_LENGTH];
+} nic_addr_entry_t;
+
+extern int nic_addr_db_init(nic_addr_db_t *db, size_t addr_len);
+extern void nic_addr_db_clear(nic_addr_db_t *db);
+extern void nic_addr_db_destroy(nic_addr_db_t *db);
+extern size_t nic_addr_db_count(const nic_addr_db_t *db);
+extern int nic_addr_db_insert(nic_addr_db_t *db, const uint8_t *addr);
+extern int nic_addr_db_remove(nic_addr_db_t *db, const uint8_t *addr);
+extern void nic_addr_db_remove_selected(nic_addr_db_t *db,
+	int (*func)(const uint8_t *, void *), void *arg);
+extern int nic_addr_db_contains(const nic_addr_db_t *db, const uint8_t *addr);
+extern void nic_addr_db_foreach(const nic_addr_db_t *db,
+	void (*func)(const uint8_t *, void *), void *arg);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/nic/include/nic_driver.h
===================================================================
--- uspace/lib/nic/include/nic_driver.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/include/nic_driver.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Internal NICF structures
+ */
+
+#ifndef __NIC_DRIVER_H__
+#define __NIC_DRIVER_H__
+
+#ifndef LIBNIC_INTERNAL
+#error "This is internal libnic's header, please do not include it"
+#endif
+
+#include <fibril_synch.h>
+#include <net/device.h>
+#include <async.h>
+
+#include "nic.h"
+#include "nic_rx_control.h"
+#include "nic_wol_virtues.h"
+
+#define DEVICE_CATEGORY_NIC "nic"
+
+struct sw_poll_info {
+	fid_t fibril;
+	volatile int run;
+	volatile int running;
+};
+
+struct nic {
+	/**
+	 * Device from device manager's point of view.
+	 * The value must be set within the add_device handler
+	 * (in nic_create_and_bind) and must not be changed.
+	 */
+	ddf_dev_t *dev;
+	/**
+	 * Device's NIC function.
+	 * The value must be set within the add_device handler
+	 * (in nic_driver_register_as_ddf_function) and must not be changed.
+	 */
+	ddf_fun_t *fun;
+	/** Identifier for higher network stack layers */
+	nic_device_id_t device_id;
+	/** Current state of the device */
+	nic_device_state_t state;
+	/** Transmiter is busy - messages are dropped */
+	int tx_busy;
+	/** Device's MAC address */
+	nic_address_t mac;
+	/** Device's default MAC address (assigned the first time, used in STOP) */
+	nic_address_t default_mac;
+	/** Session to SERVICE_NETWORKING */
+	async_sess_t *net_session;
+	/** Session to SERVICE_ETHERNET or SERVICE_NILDUMMY */
+	async_sess_t *nil_session;
+	/** Phone to APIC or i8259 */
+	async_sess_t *irc_session;
+	/** Current polling mode of the NIC */
+	nic_poll_mode_t poll_mode;
+	/** Polling period (applicable when poll_mode == NIC_POLL_PERIODIC) */
+	struct timeval poll_period;
+	/** Current polling mode of the NIC */
+	nic_poll_mode_t default_poll_mode;
+	/** Polling period (applicable when default_poll_mode == NIC_POLL_PERIODIC) */
+	struct timeval default_poll_period;
+	/** Software period fibrill information */
+	struct sw_poll_info sw_poll_info;
+	/**
+	 * Lock on everything but statistics, rx control and wol virtues. This lock
+	 * cannot be used if filters_lock or stats_lock is already held - you must
+	 * acquire main_lock first (otherwise deadlock could happen).
+	 */
+	fibril_rwlock_t main_lock;
+	/** Device statistics */
+	nic_device_stats_t stats;
+	/**
+	 * Lock for statistics. You must not hold any other lock from nic_t except
+	 * the main_lock at the same moment. If both this lock and main_lock should
+	 * be locked, the main_lock must be locked as the first.
+	 */
+	fibril_rwlock_t stats_lock;
+	/** Receive control configuration */
+	nic_rxc_t rx_control;
+	/**
+	 * Lock for receive control. You must not hold any other lock from nic_t
+	 * except the main_lock at the same moment. If both this lock and main_lock
+	 * should be locked, the main_lock must be locked as the first.
+	 */
+	fibril_rwlock_t rxc_lock;
+	/** WOL virtues configuration */
+	nic_wol_virtues_t wol_virtues;
+	/**
+	 * Lock for WOL virtues. You must not hold any other lock from nic_t
+	 * except the main_lock at the same moment. If both this lock and main_lock
+	 * should be locked, the main_lock must be locked as the first.
+	 */
+	fibril_rwlock_t wv_lock;
+	/**
+	 * Function really sending the data. This MUST be filled in if the 
+	 * nic_send_message_impl function is used for sending messages (filled 
+	 * as send_message member of the nic_iface_t structure).
+	 * Called with the main_lock locked for reading.
+	 */
+	write_packet_handler write_packet;
+	/**
+	 * Event handler called when device goes to the ACTIVE state.
+	 * The implementation is optional.
+	 * Called with the main_lock locked for writing.
+	 */
+	state_change_handler on_activating;
+	/**
+	 * Event handler called when device goes to the DOWN state.
+	 * The implementation is optional.
+	 * Called with the main_lock locked for writing.
+	 */
+	state_change_handler on_going_down;
+	/**
+	 * Event handler called when device goes to the STOPPED state.
+	 * The implementation is optional.
+	 * Called with the main_lock locked for writing.
+	 */
+	state_change_handler on_stopping;
+	/**
+	 * Event handler called when the unicast receive mode is changed.
+	 * The implementation is optional. Called with rxc_lock locked for writing.
+	 */
+	unicast_mode_change_handler on_unicast_mode_change;
+	/**
+	 * Event handler called when the multicast receive mode is changed.
+	 * The implementation is optional. Called with rxc_lock locked for writing.
+	 */
+	multicast_mode_change_handler on_multicast_mode_change;
+	/**
+	 * Event handler called when the broadcast receive mode is changed.
+	 * The implementation is optional. Called with rxc_lock locked for writing.
+	 */
+	broadcast_mode_change_handler on_broadcast_mode_change;
+	/**
+	 * Event handler called when the blocked sources set is changed.
+	 * The implementation is optional. Called with rxc_lock locked for writing.
+	 */
+	blocked_sources_change_handler on_blocked_sources_change;
+	/**
+	 * Event handler called when the VLAN mask is changed.
+	 * The implementation is optional. Called with rxc_lock locked for writing.
+	 */
+	vlan_mask_change_handler on_vlan_mask_change;
+	/**
+	 * Event handler called when a new WOL virtue is added.
+	 * The implementation is optional.
+	 * Called with filters_lock locked for writing.
+	 */
+	wol_virtue_add_handler on_wol_virtue_add;
+	/**
+	 * Event handler called when a WOL virtue is removed.
+	 * The implementation is optional.
+	 * Called with filters_lock locked for writing.
+	 */
+	wol_virtue_remove_handler on_wol_virtue_remove;
+	/**
+	 * Event handler called when the polling mode is changed.
+	 * The implementation is optional.
+	 * Called with main_lock locked for writing.
+	 */
+	poll_mode_change_handler on_poll_mode_change;
+	/**
+	 * Event handler called when the NIC should poll its buffers for a new frame
+	 * (in NIC_POLL_PERIODIC or NIC_POLL_ON_DEMAND) modes.
+	 * Called with the main_lock locked for reading.
+	 * The implementation is optional.
+	 */
+	poll_request_handler on_poll_request;
+	/** Data specific for particular driver */
+	void *specific;
+};
+
+/**
+ * Structure keeping global data
+ */
+typedef struct nic_globals {
+	list_t frame_list_cache;
+	size_t frame_list_cache_size;
+	list_t frame_cache;
+	size_t frame_cache_size;
+	fibril_mutex_t lock;
+} nic_globals_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/nic/include/nic_impl.h
===================================================================
--- uspace/lib/nic/include/nic_impl.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/include/nic_impl.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Prototypes of default DDF NIC interface methods implementations
+ */
+
+#ifndef NIC_IMPL_H__
+#define NIC_IMPL_H__
+
+#include <assert.h>
+#include <net/device.h>
+#include <ddf/driver.h>
+#include <nil_remote.h>
+
+/* Inclusion of this file is not prohibited, because drivers could want to
+ * inject some adaptation layer between the DDF call and NICF implementation */
+
+extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address);
+extern int nic_send_message_impl(ddf_fun_t *dev_fun, packet_id_t packet_id);
+extern int nic_connect_to_nil_impl(ddf_fun_t *dev_fun, services_t nil_service,
+	int device_id);
+extern int nic_get_state_impl(ddf_fun_t *dev_fun, nic_device_state_t *state);
+extern int nic_set_state_impl(ddf_fun_t *dev_fun, nic_device_state_t state);
+extern int nic_get_stats_impl(ddf_fun_t *dev_fun, nic_device_stats_t *stats);
+extern int nic_unicast_get_mode_impl(ddf_fun_t *dev_fun,
+	nic_unicast_mode_t *, size_t, nic_address_t *, size_t *);
+extern int nic_unicast_set_mode_impl(ddf_fun_t *dev_fun,
+	nic_unicast_mode_t, const nic_address_t *, size_t);
+extern int nic_multicast_get_mode_impl(ddf_fun_t *dev_fun,
+	nic_multicast_mode_t *, size_t, nic_address_t *, size_t *);
+extern int nic_multicast_set_mode_impl(ddf_fun_t *dev_fun,
+	nic_multicast_mode_t, const nic_address_t *, size_t);
+extern int nic_broadcast_get_mode_impl(ddf_fun_t *, nic_broadcast_mode_t *);
+extern int nic_broadcast_set_mode_impl(ddf_fun_t *, nic_broadcast_mode_t);
+extern int nic_blocked_sources_get_impl(ddf_fun_t *,
+	size_t, nic_address_t *, size_t *);
+extern int nic_blocked_sources_set_impl(ddf_fun_t *, const nic_address_t *, size_t);
+extern int nic_vlan_get_mask_impl(ddf_fun_t *, nic_vlan_mask_t *);
+extern int nic_vlan_set_mask_impl(ddf_fun_t *, const nic_vlan_mask_t *);
+extern int nic_wol_virtue_add_impl(ddf_fun_t *dev_fun, nic_wv_type_t type,
+	const void *data, size_t length, nic_wv_id_t *new_id);
+extern int nic_wol_virtue_remove_impl(ddf_fun_t *dev_fun, nic_wv_id_t id);
+extern int nic_wol_virtue_probe_impl(ddf_fun_t *dev_fun, nic_wv_id_t id,
+	nic_wv_type_t *type, size_t max_length, void *data, size_t *length);
+extern int nic_wol_virtue_list_impl(ddf_fun_t *dev_fun, nic_wv_type_t type,
+	size_t max_count, nic_wv_id_t *id_list, size_t *id_count);
+extern int nic_wol_virtue_get_caps_impl(ddf_fun_t *, nic_wv_type_t, int *);
+extern int nic_poll_get_mode_impl(ddf_fun_t *,
+	nic_poll_mode_t *, struct timeval *);
+extern int nic_poll_set_mode_impl(ddf_fun_t *,
+	nic_poll_mode_t, const struct timeval *);
+extern int nic_poll_now_impl(ddf_fun_t *);
+
+extern void nic_default_handler_impl(ddf_fun_t *dev_fun,
+	ipc_callid_t callid, ipc_call_t *call);
+extern int nic_open_impl(ddf_fun_t *fun);
+extern void nic_close_impl(ddf_fun_t *fun);
+
+extern void nic_device_added_impl(ddf_dev_t *dev);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/nic/include/nic_rx_control.h
===================================================================
--- uspace/lib/nic/include/nic_rx_control.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/include/nic_rx_control.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Incoming packets (frames) filtering control structures
+ */
+
+#ifndef __NIC_FILTERS_H__
+#define __NIC_FILTERS_H__
+
+#ifndef LIBNIC_INTERNAL
+#error "This is internal libnic's header, please do not include it"
+#endif
+
+#include <adt/hash_table.h>
+#include <fibril_synch.h>
+#include <net/device.h>
+#include <net/packet_header.h>
+
+#include "nic_addr_db.h"
+
+/**
+ * General structure describing receive control.
+ * The structure is not synchronized inside, the nic_driver should provide
+ * a synchronized facade.
+ */
+typedef struct nic_rxc {
+	/**
+	 * Allowed unicast destination MAC addresses
+	 */
+	nic_addr_db_t unicast_addrs;
+	/**
+	 * Allowed unicast destination MAC addresses
+	 */
+	nic_addr_db_t multicast_addrs;
+	/**
+	 * Single flag if any source is blocked
+	 */
+	int block_sources;
+	/**
+	 * Blocked source MAC addresses
+	 */
+	nic_addr_db_t blocked_sources;
+	/**
+	 * Selected mode for unicast frames
+	 */
+	nic_unicast_mode_t unicast_mode;
+	/**
+	 * Selected mode for multicast frames
+	 */
+	nic_multicast_mode_t multicast_mode;
+	/**
+	 * Selected mode for broadcast frames
+	 */
+	nic_broadcast_mode_t broadcast_mode;
+	/**
+	 * Mask for VLAN tags. This vector must be at least 512 bytes long.
+	 */
+	nic_vlan_mask_t *vlan_mask;
+	/**
+	 * If true, the NIC is receiving only unicast frames which we really want to
+	 * receive (the filtering is perfect).
+	 */
+	int unicast_exact;
+	/**
+	 * If true, the NIC is receiving only multicast frames which we really want
+	 * to receive (the filtering is perfect).
+	 */
+	int multicast_exact;
+	/**
+	 * If true, the NIC is receiving only frames with VLAN tags which we really
+	 * want to receive (the filtering is perfect).
+	 */
+	int vlan_exact;
+} nic_rxc_t;
+
+#define VLAN_TPID_UPPER 0x81
+#define VLAN_TPID_LOWER 0x00
+
+typedef struct vlan_header {
+	uint8_t tpid_upper;
+	uint8_t tpid_lower;
+	uint8_t vid_upper;
+	uint8_t vid_lower;
+} __attribute__ ((packed)) vlan_header_t;
+
+extern int nic_rxc_init(nic_rxc_t *rxc);
+extern int nic_rxc_clear(nic_rxc_t *rxc);
+extern int nic_rxc_set_addr(nic_rxc_t *rxc,
+	const nic_address_t *prev_addr, const nic_address_t *curr_addr);
+extern int nic_rxc_check(const nic_rxc_t *rxc,
+	const packet_t *packet, nic_frame_type_t *frame_type);
+extern void nic_rxc_hw_filtering(nic_rxc_t *rxc,
+	int unicast_exact, int multicast_exact, int vlan_exact);
+extern uint64_t nic_rxc_mcast_hash(const nic_address_t *list, size_t count);
+extern uint64_t nic_rxc_multicast_get_hash(const nic_rxc_t *rxc);
+extern void nic_rxc_unicast_get_mode(const nic_rxc_t *, nic_unicast_mode_t *,
+	size_t max_count, nic_address_t *address_list, size_t *address_count);
+extern int nic_rxc_unicast_set_mode(nic_rxc_t *rxc, nic_unicast_mode_t mode,
+	const nic_address_t *address_list, size_t address_count);
+extern void nic_rxc_multicast_get_mode(const nic_rxc_t *,
+	nic_multicast_mode_t *, size_t, nic_address_t *, size_t *);
+extern int nic_rxc_multicast_set_mode(nic_rxc_t *, nic_multicast_mode_t mode,
+	const nic_address_t *address_list, size_t address_count);
+extern void nic_rxc_broadcast_get_mode(const nic_rxc_t *,
+	nic_broadcast_mode_t *mode);
+extern int nic_rxc_broadcast_set_mode(nic_rxc_t *,
+	nic_broadcast_mode_t mode);
+extern void nic_rxc_blocked_sources_get(const nic_rxc_t *,
+	size_t max_count, nic_address_t *address_list, size_t *address_count);
+extern int nic_rxc_blocked_sources_set(nic_rxc_t *,
+	const nic_address_t *address_list, size_t address_count);
+extern int nic_rxc_vlan_get_mask(const nic_rxc_t *rxc, nic_vlan_mask_t *mask);
+extern int nic_rxc_vlan_set_mask(nic_rxc_t *rxc, const nic_vlan_mask_t *mask);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/nic/include/nic_wol_virtues.h
===================================================================
--- uspace/lib/nic/include/nic_wol_virtues.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/include/nic_wol_virtues.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Wake-on-LAN support
+ */
+
+#ifndef __NIC_WOL_VIRTUES_H__
+#define __NIC_WOL_VIRTUES_H__
+
+#ifndef LIBNIC_INTERNAL
+#error "This is internal libnic's header, please do not include it"
+#endif
+
+#include <net/device.h>
+#include <adt/hash_table.h>
+#include "nic.h"
+
+typedef struct nic_wol_virtues {
+	/**
+	 * Operations for table
+	 */
+	hash_table_operations_t table_operations;
+	/**
+	 * WOL virtues hashed by their ID's.
+	 */
+	hash_table_t table;
+	/**
+	 * WOL virtues in lists by their type
+	 */
+	nic_wol_virtue_t *lists[NIC_WV_MAX];
+	/**
+	 * Number of virtues in the wv_types list
+	 */
+	size_t lists_sizes[NIC_WV_MAX];
+	/**
+	 * Counter for the ID's
+	 */
+	nic_wv_id_t next_id;
+	/**
+	 * Maximum capabilities
+	 */
+	int caps_max[NIC_WV_MAX];
+} nic_wol_virtues_t;
+
+extern int nic_wol_virtues_init(nic_wol_virtues_t *);
+extern void nic_wol_virtues_clear(nic_wol_virtues_t *);
+extern int nic_wol_virtues_verify(nic_wv_type_t, const void *, size_t);
+extern int nic_wol_virtues_list(const nic_wol_virtues_t *, nic_wv_type_t type,
+	size_t max_count, nic_wv_id_t *id_list, size_t *id_count);
+extern int nic_wol_virtues_add(nic_wol_virtues_t *, nic_wol_virtue_t *);
+extern nic_wol_virtue_t *nic_wol_virtues_remove(nic_wol_virtues_t *,
+	nic_wv_id_t);
+extern const nic_wol_virtue_t *nic_wol_virtues_find(const nic_wol_virtues_t *,
+	nic_wv_id_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/nic/src/nic_addr_db.c
===================================================================
--- uspace/lib/nic/src/nic_addr_db.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/src/nic_addr_db.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Generic hash-set based database of addresses
+ */
+#include <assert.h>
+#include <stdlib.h>
+#include <bool.h>
+#include <errno.h>
+#include <mem.h>
+
+#include "nic_addr_db.h"
+
+/**
+ * Hash set helper function
+ */
+static int nic_addr_equals(const link_t *item1, const link_t *item2)
+{
+	assert(item1 && item2);
+	size_t addr_len = ((const nic_addr_entry_t *) item1)->addr_len;
+
+	assert(addr_len	== ((const nic_addr_entry_t *) item2)->addr_len);
+
+	size_t i;
+	for (i = 0; i < addr_len; ++i) {
+		if (((nic_addr_entry_t *) item1)->addr[i] !=
+			((nic_addr_entry_t *) item2)->addr[i])
+			return false;
+	}
+	return true;
+}
+
+/**
+ * Hash set helper function
+ */
+static unsigned long nic_addr_hash(const link_t *item)
+{
+	assert(item);
+	const nic_addr_entry_t *entry = (const nic_addr_entry_t *) item;
+	unsigned long hash = 0;
+
+	size_t i;
+	for (i = 0; i < entry->addr_len; ++i) {
+		hash = (hash << 8) ^ (hash >> 24) ^ entry->addr[i];
+	}
+	return hash;
+}
+
+/**
+ * Helper wrapper
+ */
+static void nic_addr_destroy(link_t *item, void *unused)
+{
+	free(item);
+}
+
+/**
+ * Initialize the database
+ *
+ * @param[in,out]	db			Uninitialized storage
+ * @param[in]		addr_len	Size of addresses in the db
+ *
+ * @return EOK		If successfully initialized
+ * @return EINVAL	If the address length is too big
+ * @return ENOMEM	If there was not enough memory to initialize the storage
+ */
+int nic_addr_db_init(nic_addr_db_t *db, size_t addr_len)
+{
+	assert(db);
+	if (addr_len > NIC_ADDR_MAX_LENGTH) {
+		return EINVAL;
+	}
+	if (!hash_set_init(&db->set, nic_addr_hash, nic_addr_equals,
+		NIC_ADDR_DB_INIT_SIZE)) {
+		return ENOMEM;
+	}
+	db->addr_len = addr_len;
+	return EOK;
+}
+
+/**
+ * Remove all records from the DB
+ *
+ * @param db
+ */
+void nic_addr_db_clear(nic_addr_db_t *db)
+{
+	assert(db);
+	hash_set_clear(&db->set, nic_addr_destroy, NULL);
+}
+
+/**
+ * Free the memory used by db, including all records...
+ *
+ * @param	db
+ */
+void nic_addr_db_destroy(nic_addr_db_t *db)
+{
+	assert(db);
+	hash_set_apply(&db->set, nic_addr_destroy, NULL);
+	hash_set_destroy(&db->set);
+}
+
+/**
+ * Get number of addresses in the db
+ *
+ * @param	db
+ *
+ * @return Number of adresses
+ */
+size_t nic_addr_db_count(const nic_addr_db_t *db)
+{
+	assert(db);
+	return hash_set_count(&db->set);
+}
+
+/**
+ * Insert an address to the db
+ *
+ * @param	db
+ * @param	addr 	Inserted address. Length is implicitly concluded from the
+ * 					db's address length.
+ *
+ * @return EOK		If the address was inserted
+ * @return ENOMEM	If there was not enough memory
+ * @return EEXIST	If this adress already is in the db
+ */
+int nic_addr_db_insert(nic_addr_db_t *db, const uint8_t *addr)
+{
+	assert(db && addr);
+	nic_addr_entry_t *entry = malloc(sizeof (nic_addr_entry_t));
+	if (entry == NULL) {
+		return ENOMEM;
+	}
+	entry->addr_len = db->addr_len;
+	memcpy(entry->addr, addr, db->addr_len);
+
+	return hash_set_insert(&db->set, &entry->item) ? EOK : EEXIST;
+}
+
+/**
+ * Remove the address from the db
+ *
+ * @param	db
+ * @param	addr	Removed address.
+ *
+ * @return EOK		If the address was removed
+ * @return ENOENT	If there is no address
+ */
+int nic_addr_db_remove(nic_addr_db_t *db, const uint8_t *addr)
+{
+	assert(db && addr);
+	nic_addr_entry_t entry;
+	entry.addr_len = db->addr_len;
+	memcpy(entry.addr, addr, db->addr_len);
+
+	link_t *removed = hash_set_remove(&db->set, &entry.item);
+	free(removed);
+	return removed != NULL ? EOK : ENOENT;
+}
+
+/**
+ * Test if the address is contained in the db
+ *
+ * @param	db
+ * @param	addr	Tested addresss
+ *
+ * @return true if the address is in the db, false otherwise
+ */
+int nic_addr_db_contains(const nic_addr_db_t *db, const uint8_t *addr)
+{
+	assert(db && addr);
+	nic_addr_entry_t entry;
+	entry.addr_len = db->addr_len;
+	memcpy(entry.addr, addr, db->addr_len);
+
+	return hash_set_contains(&db->set, &entry.item);
+}
+
+/**
+ * Helper structure for nic_addr_db_foreach
+ */
+typedef struct {
+	void (*func)(const uint8_t *, void *);
+	void *arg;
+} nic_addr_db_fe_arg_t;
+
+/**
+ * Helper function for nic_addr_db_foreach
+ */
+static void nic_addr_db_fe_helper(link_t *item, void *arg) {
+	nic_addr_db_fe_arg_t *hs = (nic_addr_db_fe_arg_t *) arg;
+	hs->func(((nic_addr_entry_t *) item)->addr, hs->arg);
+}
+
+/**
+ * Executes a user-defined function on all addresses in the DB. The function
+ * must not change the addresses.
+ *
+ * @param	db
+ * @param	func	User-defined function
+ * @param	arg		Custom argument passed to the function
+ */
+void nic_addr_db_foreach(const nic_addr_db_t *db,
+	void (*func)(const uint8_t *, void *), void *arg)
+{
+	nic_addr_db_fe_arg_t hs = { .func = func, .arg = arg };
+	hash_set_apply((hash_set_t *) &db->set, nic_addr_db_fe_helper, &hs);
+}
+
+/**
+ * Helper structure for nic_addr_db_remove_selected
+ */
+typedef struct {
+	int (*func)(const uint8_t *, void *);
+	void *arg;
+} nic_addr_db_rs_arg_t;
+
+/**
+ * Helper function for nic_addr_db_foreach
+ */
+static int nic_addr_db_rs_helper(link_t *item, void *arg) {
+	nic_addr_db_rs_arg_t *hs = (nic_addr_db_rs_arg_t *) arg;
+	int retval = hs->func(((nic_addr_entry_t *) item)->addr, hs->arg);
+	if (retval) {
+		free(item);
+	}
+	return retval;
+}
+
+/**
+ * Removes all addresses for which the function returns non-zero.
+ *
+ * @param	db
+ * @param	func	User-defined function
+ * @param	arg		Custom argument passed to the function
+ */
+void nic_addr_db_remove_selected(nic_addr_db_t *db,
+	int (*func)(const uint8_t *, void *), void *arg)
+{
+	nic_addr_db_rs_arg_t hs = { .func = func, .arg = arg };
+	hash_set_remove_selected(&db->set, nic_addr_db_rs_helper, &hs);
+}
+
+/** @}
+ */
Index: uspace/lib/nic/src/nic_driver.c
===================================================================
--- uspace/lib/nic/src/nic_driver.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/src/nic_driver.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,1368 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * Copyright (c) 2011 Jiri Michalec
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Internal implementation of general NIC operations
+ */
+
+#include <assert.h>
+#include <fibril_synch.h>
+#include <ns.h>
+#include <stdio.h>
+#include <str_error.h>
+#include <ipc/services.h>
+#include <ipc/ns.h>
+#include <ipc/irc.h>
+#include <sysinfo.h>
+
+#include <devman.h>
+#include <ddf/interrupt.h>
+#include <net_interface.h>
+#include <ops/nic.h>
+#include <packet_client.h>
+#include <packet_remote.h>
+#include <net/packet_header.h>
+#include <errno.h>
+
+#include "nic_driver.h"
+#include "nic_impl.h"
+
+#define NIC_GLOBALS_MAX_CACHE_SIZE 16
+
+nic_globals_t nic_globals;
+
+/**
+ * Initializes libraries required for NIC framework - logger, packet manager
+ *
+ * @param name	Name of the device/driver (used in logging)
+ */
+int nic_driver_init(const char *name)
+{
+	list_initialize(&nic_globals.frame_list_cache);
+	nic_globals.frame_list_cache_size = 0;
+	list_initialize(&nic_globals.frame_cache);
+	nic_globals.frame_cache_size = 0;
+	fibril_mutex_initialize(&nic_globals.lock);
+	
+	char buffer[256];
+	snprintf(buffer, 256, "drv/" DEVICE_CATEGORY_NIC "/%s", name);
+	
+	/* Initialize packet manager */
+	return pm_init();
+}
+
+/**
+ * Fill in the default implementations for device options and NIC interface.
+ *
+ * @param driver_ops
+ * @param dev_ops
+ * @param iface
+ */
+void nic_driver_implement(driver_ops_t *driver_ops, ddf_dev_ops_t *dev_ops,
+    nic_iface_t *iface)
+{
+	if (driver_ops) {
+		if (!driver_ops->device_added)
+			driver_ops->device_added = nic_device_added_impl;
+	}
+
+	if (dev_ops) {
+		if (!dev_ops->open)
+			dev_ops->open = nic_open_impl;
+		if (!dev_ops->close)
+			dev_ops->close = nic_close_impl;
+		if (!dev_ops->interfaces[NIC_DEV_IFACE])
+			dev_ops->interfaces[NIC_DEV_IFACE] = iface;
+		if (!dev_ops->default_handler)
+			dev_ops->default_handler = nic_default_handler_impl;
+	}
+
+	if (iface) {
+		if (!iface->get_state)
+			iface->get_state = nic_get_state_impl;
+		if (!iface->set_state)
+			iface->set_state = nic_set_state_impl;
+		if (!iface->send_message)
+			iface->send_message = nic_send_message_impl;
+		if (!iface->connect_to_nil)
+			iface->connect_to_nil = nic_connect_to_nil_impl;
+		if (!iface->get_address)
+			iface->get_address = nic_get_address_impl;
+		if (!iface->get_stats)
+			iface->get_stats = nic_get_stats_impl;
+		if (!iface->unicast_get_mode)
+			iface->unicast_get_mode = nic_unicast_get_mode_impl;
+		if (!iface->unicast_set_mode)
+			iface->unicast_set_mode = nic_unicast_set_mode_impl;
+		if (!iface->multicast_get_mode)
+			iface->multicast_get_mode = nic_multicast_get_mode_impl;
+		if (!iface->multicast_set_mode)
+			iface->multicast_set_mode = nic_multicast_set_mode_impl;
+		if (!iface->broadcast_get_mode)
+			iface->broadcast_get_mode = nic_broadcast_get_mode_impl;
+		if (!iface->broadcast_set_mode)
+			iface->broadcast_set_mode = nic_broadcast_set_mode_impl;
+		if (!iface->blocked_sources_get)
+			iface->blocked_sources_get = nic_blocked_sources_get_impl;
+		if (!iface->blocked_sources_set)
+			iface->blocked_sources_set = nic_blocked_sources_set_impl;
+		if (!iface->vlan_get_mask)
+			iface->vlan_get_mask = nic_vlan_get_mask_impl;
+		if (!iface->vlan_set_mask)
+			iface->vlan_set_mask = nic_vlan_set_mask_impl;
+		if (!iface->wol_virtue_add)
+			iface->wol_virtue_add = nic_wol_virtue_add_impl;
+		if (!iface->wol_virtue_remove)
+			iface->wol_virtue_remove = nic_wol_virtue_remove_impl;
+		if (!iface->wol_virtue_probe)
+			iface->wol_virtue_probe = nic_wol_virtue_probe_impl;
+		if (!iface->wol_virtue_list)
+			iface->wol_virtue_list = nic_wol_virtue_list_impl;
+		if (!iface->wol_virtue_get_caps)
+			iface->wol_virtue_get_caps = nic_wol_virtue_get_caps_impl;
+		if (!iface->poll_get_mode)
+			iface->poll_get_mode = nic_poll_get_mode_impl;
+		if (!iface->poll_set_mode)
+			iface->poll_set_mode = nic_poll_set_mode_impl;
+		if (!iface->poll_now)
+			iface->poll_now = nic_poll_now_impl;
+	}
+}
+
+/**
+ * Setup write packet handler. This MUST be called in the add_device handler
+ * if the nic_send_message_impl function is used for sending messages (filled
+ * as send_message member of the nic_iface_t structure). The function must not
+ * be called anywhere else.
+ *
+ * @param nic_data
+ * @param wpfunc		Function handling the write_packet request
+ */
+void nic_set_write_packet_handler(nic_t *nic_data, write_packet_handler wpfunc)
+{
+	nic_data->write_packet = wpfunc;
+}
+
+/**
+ * Setup event handlers for transitions between driver states.
+ * This function can be called only in the add_device handler.
+ *
+ * @param on_activating	Called when device is going to the ACTIVE state.
+ * @param on_going_down Called when device is going to the DOWN state.
+ * @param on_stopping	Called when device is going to the STOP state.
+ */
+void nic_set_state_change_handlers(nic_t *nic_data,
+	state_change_handler on_activating, state_change_handler on_going_down,
+	state_change_handler on_stopping)
+{
+	nic_data->on_activating = on_activating;
+	nic_data->on_going_down = on_going_down;
+	nic_data->on_stopping = on_stopping;
+}
+
+/**
+ * Setup event handlers for changing the filtering modes.
+ * This function can be called only in the add_device handler.
+ *
+ * @param nic_data
+ * @param on_unicast_mode_change
+ * @param on_multicast_mode_change
+ * @param on_broadcast_mode_change
+ * @param on_blocked_sources_change
+ * @param on_vlan_mask_change
+ */
+void nic_set_filtering_change_handlers(nic_t *nic_data,
+	unicast_mode_change_handler on_unicast_mode_change,
+	multicast_mode_change_handler on_multicast_mode_change,
+	broadcast_mode_change_handler on_broadcast_mode_change,
+	blocked_sources_change_handler on_blocked_sources_change,
+	vlan_mask_change_handler on_vlan_mask_change)
+{
+	nic_data->on_unicast_mode_change = on_unicast_mode_change;
+	nic_data->on_multicast_mode_change = on_multicast_mode_change;
+	nic_data->on_broadcast_mode_change = on_broadcast_mode_change;
+	nic_data->on_blocked_sources_change = on_blocked_sources_change;
+	nic_data->on_vlan_mask_change = on_vlan_mask_change;
+}
+
+/**
+ * Setup filters for WOL virtues add and removal.
+ * This function can be called only in the add_device handler. Both handlers
+ * must be set or none of them.
+ *
+ * @param on_wv_add		Called when a virtue is added
+ * @param on_wv_remove	Called when a virtue is removed
+ */
+void nic_set_wol_virtue_change_handlers(nic_t *nic_data,
+	wol_virtue_add_handler on_wv_add, wol_virtue_remove_handler on_wv_remove)
+{
+	assert(on_wv_add != NULL && on_wv_remove != NULL);
+	nic_data->on_wol_virtue_add = on_wv_add;
+	nic_data->on_wol_virtue_remove = on_wv_remove;
+}
+
+/**
+ * Setup poll handlers.
+ * This function can be called only in the add_device handler.
+ *
+ * @param on_poll_mode_change	Called when the mode is about to be changed
+ * @param on_poll_request		Called when poll request is triggered
+ */
+void nic_set_poll_handlers(nic_t *nic_data,
+	poll_mode_change_handler on_poll_mode_change, poll_request_handler on_poll_req)
+{
+	nic_data->on_poll_mode_change = on_poll_mode_change;
+	nic_data->on_poll_request = on_poll_req;
+}
+
+/**
+ * Connect to the parent's driver and get HW resources list in parsed format.
+ * Note: this function should be called only from add_device handler, therefore
+ * we don't need to use locks.
+ *
+ * @param		nic_data
+ * @param[out]	resources	Parsed lists of resources.
+ *
+ * @return EOK or negative error code
+ */
+int nic_get_resources(nic_t *nic_data, hw_res_list_parsed_t *resources)
+{
+	ddf_dev_t *dev = nic_data->dev;
+	
+	/* Connect to the parent's driver. */
+	dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
+		dev->handle, IPC_FLAG_BLOCKING);
+	if (dev->parent_sess == NULL)
+		return EPARTY;
+	
+	return hw_res_get_list_parsed(nic_data->dev->parent_sess, resources, 0);
+}
+
+/**
+ * Just a wrapper over the packet_get_1_remote function
+ */
+packet_t *nic_alloc_packet(nic_t *nic_data, size_t data_size)
+{
+	return packet_get_1_remote(nic_data->net_session, data_size);
+}
+
+
+/**
+ * Just a wrapper over the pq_release_remote function
+ */
+void nic_release_packet(nic_t *nic_data, packet_t *packet)
+{
+	pq_release_remote(nic_data->net_session, packet_get_id(packet));
+}
+
+/** Allocate frame and packet
+ *
+ *  @param nic_data 	The NIC driver data
+ *  @param packet_size	Size of packet
+ *  @param offload_size	Size of packet offload
+ *  @return pointer to allocated frame if success, NULL otherwise
+ */
+nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t packet_size)
+{
+	nic_frame_t *frame;
+	fibril_mutex_lock(&nic_globals.lock);
+	if (nic_globals.frame_cache_size > 0) {
+		link_t *first = list_first(&nic_globals.frame_cache);
+		list_remove(first);
+		nic_globals.frame_cache_size--;
+		frame = list_get_instance(first, nic_frame_t, link);
+		fibril_mutex_unlock(&nic_globals.lock);
+	} else {
+		fibril_mutex_unlock(&nic_globals.lock);
+		frame = malloc(sizeof(nic_frame_t));
+		if (!frame)
+			return NULL;
+		
+		link_initialize(&frame->link);
+	}
+
+	packet_t *packet = nic_alloc_packet(nic_data, packet_size);
+	if (!packet) {
+		free(frame);
+		return NULL;
+	}
+
+	frame->packet = packet;
+	return frame;
+}
+
+/** Release frame
+ *
+ * @param nic_data	The driver data
+ * @param frame		The frame to release
+ */
+void nic_release_frame(nic_t *nic_data, nic_frame_t *frame)
+{
+	if (!frame)
+		return;
+	if (frame->packet != NULL) {
+		nic_release_packet(nic_data, frame->packet);
+	}
+	fibril_mutex_lock(&nic_globals.lock);
+	if (nic_globals.frame_cache_size >= NIC_GLOBALS_MAX_CACHE_SIZE) {
+		fibril_mutex_unlock(&nic_globals.lock);
+		free(frame);
+	} else {
+		list_prepend(&frame->link, &nic_globals.frame_cache);
+		nic_globals.frame_cache_size++;
+		fibril_mutex_unlock(&nic_globals.lock);
+	}
+}
+
+/**
+ * Allocate a new frame list
+ *
+ * @return New frame list or NULL on error.
+ */
+nic_frame_list_t *nic_alloc_frame_list(void)
+{
+	nic_frame_list_t *frames;
+	fibril_mutex_lock(&nic_globals.lock);
+	
+	if (nic_globals.frame_list_cache_size > 0) {
+		frames =
+		    list_get_instance(list_first(&nic_globals.frame_list_cache),
+		    nic_frame_list_t, head);
+		list_remove(&frames->head);
+		list_initialize(frames);
+		nic_globals.frame_list_cache_size--;
+		fibril_mutex_unlock(&nic_globals.lock);
+	} else {
+		fibril_mutex_unlock(&nic_globals.lock);
+		
+		frames = malloc(sizeof (nic_frame_list_t));
+		if (frames != NULL)
+			list_initialize(frames);
+	}
+	
+	return frames;
+}
+
+static void nic_driver_release_frame_list(nic_frame_list_t *frames)
+{
+	if (!frames)
+		return;
+	fibril_mutex_lock(&nic_globals.lock);
+	if (nic_globals.frame_list_cache_size >= NIC_GLOBALS_MAX_CACHE_SIZE) {
+		fibril_mutex_unlock(&nic_globals.lock);
+		free(frames);
+	} else {
+		list_prepend(&frames->head, &nic_globals.frame_list_cache);
+		nic_globals.frame_list_cache_size++;
+		fibril_mutex_unlock(&nic_globals.lock);
+	}
+}
+
+/**
+ * Append a frame to the frame list
+ *
+ * @param frames	Frame list
+ * @param frame		Appended frame
+ */
+void nic_frame_list_append(nic_frame_list_t *frames,
+	nic_frame_t *frame)
+{
+	assert(frame != NULL && frames != NULL);
+	list_append(&frame->link, frames);
+}
+
+
+/**
+ * Enable interrupts for this driver.
+ *
+ * @param nic_data
+ * @param irq			The IRQ number for this device
+ */
+void nic_enable_interrupt(nic_t *nic_data, int irq)
+{
+	async_exch_t *exch = async_exchange_begin(nic_data->irc_session);
+	async_msg_1(exch, IRC_ENABLE_INTERRUPT, irq);
+	async_exchange_end(exch);
+}
+
+/**
+ * Disable interrupts for this driver.
+ *
+ * @param nic_data
+ * @param irq			The IRQ number for this device
+ */
+void nic_disable_interrupt(nic_t *nic_data, int irq)
+{
+	async_exch_t *exch = async_exchange_begin(nic_data->irc_session);
+	async_msg_1(exch, IRC_CLEAR_INTERRUPT, irq);
+	async_exchange_end(exch);
+}
+
+/** Get the polling mode information from the device 
+ *
+ *	The main lock should be locked, otherwise the inconsistency between
+ *	mode and period can occure.
+ *
+ *  @param nic_data The controller data
+ *  @param period [out] The the period. Valid only if mode == NIC_POLL_PERIODIC
+ *  @return Current polling mode of the controller
+ */
+nic_poll_mode_t nic_query_poll_mode(nic_t *nic_data, struct timeval *period)
+{
+	if (period)
+		*period = nic_data->poll_period;
+	return nic_data->poll_mode;
+};
+
+/**
+ * Connect to the NET and IRQ services. This function should be called only from
+ * the add_device handler, thus no locking is required.
+ *
+ * @param nic_data
+ *
+ * @return EOK		If connection was successful.
+ * @return EINVAL	If the IRC service cannot be determined.
+ * @return EREFUSED	If NET or IRC service cannot be connected.
+ */
+int nic_connect_to_services(nic_t *nic_data)
+{
+	/* NET service */
+	nic_data->net_session = service_connect_blocking(EXCHANGE_SERIALIZE,
+		SERVICE_NETWORKING, 0, 0);
+	if (nic_data->net_session == NULL)
+		return errno;
+	
+	/* IRC service */
+	sysarg_t apic;
+	sysarg_t i8259;
+	services_t irc_service = -1;
+	if (((sysinfo_get_value("apic", &apic) == EOK) && (apic)) ||
+	    ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)))
+		irc_service = SERVICE_IRC;
+	else
+		return EINVAL;
+	
+	nic_data->irc_session = service_connect_blocking(EXCHANGE_SERIALIZE,
+		irc_service, 0, 0);
+	if (nic_data->irc_session == NULL)
+		return errno;
+	
+	return EOK;
+}
+
+/** Notify the NET service that the device is ready
+ *
+ * @param nic NICF structure
+ *
+ * @return EOK on success
+ *
+ */
+int nic_ready(nic_t *nic)
+{
+	fibril_rwlock_read_lock(&nic->main_lock);
+	
+	async_sess_t *session = nic->net_session;
+	devman_handle_t handle = nic->dev->handle;
+	
+	fibril_rwlock_read_unlock(&nic->main_lock);
+	
+	if (session == NULL)
+		return EINVAL;
+	
+	return net_driver_ready(session, handle);
+}
+
+/** Inform the NICF about poll mode
+ *
+ *  @param nic_data The controller data
+ *  @param mode
+ *  @param period [out] The the period. Valid only if mode == NIC_POLL_PERIODIC
+ *  @return EOK
+ *  @return EINVAL
+ */
+int nic_report_poll_mode(nic_t *nic_data, nic_poll_mode_t mode,
+	struct timeval *period)
+{
+	int rc = EOK;
+	fibril_rwlock_write_lock(&nic_data->main_lock);
+	nic_data->poll_mode = mode;
+	nic_data->default_poll_mode = mode;
+	if (mode == NIC_POLL_PERIODIC) {
+		if (period) {
+			memcpy(&nic_data->default_poll_period, period, sizeof (struct timeval));
+			memcpy(&nic_data->poll_period, period, sizeof (struct timeval));
+		} else {
+			rc = EINVAL;
+		}
+	}
+	fibril_rwlock_write_unlock(&nic_data->main_lock);
+	return rc;
+}
+
+/** Inform the NICF about device's MAC adress.
+ *
+ * @return EOK On success
+ *
+ */
+int nic_report_address(nic_t *nic_data, const nic_address_t *address)
+{
+	assert(nic_data);
+	
+	if (address->address[0] & 1)
+		return EINVAL;
+	
+	fibril_rwlock_write_lock(&nic_data->main_lock);
+	
+	/* Notify NIL layer (and uppper) if bound - not in add_device */
+	if (nic_data->nil_session != NULL) {
+		int rc = nil_addr_changed_msg(nic_data->nil_session,
+		    nic_data->device_id, address);
+		if (rc != EOK) {
+			fibril_rwlock_write_unlock(&nic_data->main_lock);
+			return rc;
+		}
+	}
+	
+	fibril_rwlock_write_lock(&nic_data->rxc_lock);
+	
+	/*
+	 * The initial address (all zeroes) shouldn't be
+	 * there and we will ignore that error -- in next
+	 * calls this should not happen.
+	 */
+	int rc = nic_rxc_set_addr(&nic_data->rx_control,
+	    &nic_data->mac, address);
+	
+	/* For the first time also record the default MAC */
+	if (MAC_IS_ZERO(nic_data->default_mac.address)) {
+		assert(MAC_IS_ZERO(nic_data->mac.address));
+		memcpy(&nic_data->default_mac, address, sizeof(nic_address_t));
+	}
+	
+	fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+	
+	if ((rc != EOK) && (rc != ENOENT)) {
+		fibril_rwlock_write_unlock(&nic_data->main_lock);
+		return rc;
+	}
+	
+	memcpy(&nic_data->mac, address, sizeof(nic_address_t));
+	
+	fibril_rwlock_write_unlock(&nic_data->main_lock);
+	
+	return EOK;
+}
+
+/**
+ * Used to obtain devices MAC address.
+ *
+ * The main lock should be locked, otherwise the inconsistent address
+ * can be returend.
+ *
+ * @param nic_data The controller data
+ * @param address The output for address.
+ */
+void nic_query_address(nic_t *nic_data, nic_address_t *addr) {
+	if (!addr)
+		return;
+	if (!nic_data)
+		memset(addr, 0, sizeof(nic_address_t));
+
+	memcpy(addr, &nic_data->mac, sizeof(nic_address_t));
+};
+
+/**
+ * The busy flag can be set to 1 only in the write_packet handler, to 0 it can
+ * be set anywhere.
+ *
+ * @param nic_data
+ * @param busy
+ */
+void nic_set_tx_busy(nic_t *nic_data, int busy)
+{
+	/*
+	 * When the function is called in write_packet handler the main lock is
+	 * locked so no race can happen.
+	 * Otherwise, when it is unexpectedly set to 0 (even with main lock held
+	 * by other fibril) it cannot crash anything.
+	 */
+	nic_data->tx_busy = busy;
+}
+
+/**
+ * Provided for correct naming conventions.
+ * The packet is checked by filters and then sent up to the NIL layer or
+ * discarded, the frame is released.
+ *
+ * @param nic_data
+ * @param frame		The frame containing received packet
+ */
+void nic_received_frame(nic_t *nic_data, nic_frame_t *frame)
+{
+	nic_received_packet(nic_data, frame->packet);
+	frame->packet = NULL;
+	nic_release_frame(nic_data, frame);
+}
+
+/**
+ * This is the function that the driver should call when it receives a packet.
+ * The packet is checked by filters and then sent up to the NIL layer or
+ * discarded.
+ *
+ * @param nic_data
+ * @param packet		The received packet
+ */
+void nic_received_packet(nic_t *nic_data, packet_t *packet)
+{
+	/* Note: this function must not lock main lock, because loopback driver
+	 * 		 calls it inside write_packet handler (with locked main lock) */
+	packet_id_t pid = packet_get_id(packet);
+	
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	nic_frame_type_t frame_type;
+	int check = nic_rxc_check(&nic_data->rx_control, packet, &frame_type);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	/* Update statistics */
+	fibril_rwlock_write_lock(&nic_data->stats_lock);
+	/* Both sending message up and releasing packet are atomic IPC calls */
+	if (nic_data->state == NIC_STATE_ACTIVE && check) {
+		nic_data->stats.receive_packets++;
+		nic_data->stats.receive_bytes += packet_get_data_length(packet);
+		switch (frame_type) {
+		case NIC_FRAME_MULTICAST:
+			nic_data->stats.receive_multicast++;
+			break;
+		case NIC_FRAME_BROADCAST:
+			nic_data->stats.receive_broadcast++;
+			break;
+		default:
+			break;
+		}
+		fibril_rwlock_write_unlock(&nic_data->stats_lock);
+		nil_received_msg(nic_data->nil_session, pid, nic_data->device_id);
+	} else {
+		switch (frame_type) {
+		case NIC_FRAME_UNICAST:
+			nic_data->stats.receive_filtered_unicast++;
+			break;
+		case NIC_FRAME_MULTICAST:
+			nic_data->stats.receive_filtered_multicast++;
+			break;
+		case NIC_FRAME_BROADCAST:
+			nic_data->stats.receive_filtered_broadcast++;
+			break;
+		}
+		fibril_rwlock_write_unlock(&nic_data->stats_lock);
+		nic_release_packet(nic_data, packet);
+	}
+}
+
+/**
+ * This function is to be used only in the loopback driver. It's workaround
+ * for the situation when the packet does not contain ethernet address.
+ * The filtering is therefore not applied here.
+ *
+ * @param nic_data
+ * @param packet
+ */
+void nic_received_noneth_packet(nic_t *nic_data, packet_t *packet)
+{
+	fibril_rwlock_write_lock(&nic_data->stats_lock);
+	nic_data->stats.receive_packets++;
+	nic_data->stats.receive_bytes += packet_get_data_length(packet);
+	fibril_rwlock_write_unlock(&nic_data->stats_lock);
+
+	nil_received_msg(nic_data->nil_session, packet_get_id(packet),
+		nic_data->device_id);
+}
+
+/**
+ * Some NICs can receive multiple packets during single interrupt. These can
+ * send them in whole list of frames (actually nic_frame_t structures), then
+ * the list is deallocated and each packet is passed to the
+ * nic_received_packet function.
+ *
+ * @param nic_data
+ * @param frames		List of received frames
+ */
+void nic_received_frame_list(nic_t *nic_data, nic_frame_list_t *frames)
+{
+	if (frames == NULL)
+		return;
+	while (!list_empty(frames)) {
+		nic_frame_t *frame =
+			list_get_instance(list_first(frames), nic_frame_t, link);
+
+		list_remove(&frame->link);
+		nic_received_packet(nic_data, frame->packet);
+		frame->packet = NULL;
+		nic_release_frame(nic_data, frame);
+	}
+	nic_driver_release_frame_list(frames);
+}
+
+/** Allocate and initialize the driver data.
+ *
+ * @return Allocated structure or NULL.
+ *
+ */
+static nic_t *nic_create(void)
+{
+	nic_t *nic_data = malloc(sizeof(nic_t));
+	if (nic_data == NULL)
+		return NULL;
+	
+	/* Force zero to all uninitialized fields (e.g. added in future) */
+	bzero(nic_data, sizeof(nic_t));
+	if (nic_rxc_init(&nic_data->rx_control) != EOK) {
+		free(nic_data);
+		return NULL;
+	}
+	
+	if (nic_wol_virtues_init(&nic_data->wol_virtues) != EOK) {
+		free(nic_data);
+		return NULL;
+	}
+	
+	nic_data->dev = NULL;
+	nic_data->fun = NULL;
+	nic_data->device_id = NIC_DEVICE_INVALID_ID;
+	nic_data->state = NIC_STATE_STOPPED;
+	nic_data->net_session = NULL;
+	nic_data->nil_session = NULL;
+	nic_data->irc_session = NULL;
+	nic_data->poll_mode = NIC_POLL_IMMEDIATE;
+	nic_data->default_poll_mode = NIC_POLL_IMMEDIATE;
+	nic_data->write_packet = NULL;
+	nic_data->on_activating = NULL;
+	nic_data->on_going_down = NULL;
+	nic_data->on_stopping = NULL;
+	nic_data->specific = NULL;
+	
+	fibril_rwlock_initialize(&nic_data->main_lock);
+	fibril_rwlock_initialize(&nic_data->stats_lock);
+	fibril_rwlock_initialize(&nic_data->rxc_lock);
+	fibril_rwlock_initialize(&nic_data->wv_lock);
+	
+	bzero(&nic_data->mac, sizeof(nic_address_t));
+	bzero(&nic_data->default_mac, sizeof(nic_address_t));
+	bzero(&nic_data->stats, sizeof(nic_device_stats_t));
+	
+	return nic_data;
+}
+
+/** Create NIC structure for the device and bind it to dev_fun_t
+ *
+ * The pointer to the created and initialized NIC structure will
+ * be stored in device->nic_data.
+ *
+ * @param device The NIC device structure
+ *
+ * @return Pointer to created nic_t structure or NULL
+ *
+ */
+nic_t *nic_create_and_bind(ddf_dev_t *device)
+{
+	assert(device);
+	assert(!device->driver_data);
+	
+	nic_t *nic_data = nic_create();
+	if (!nic_data)
+		return NULL;
+	
+	nic_data->dev = device;
+	device->driver_data = nic_data;
+	
+	return nic_data;
+}
+
+/**
+ * Hangs up the phones in the structure, deallocates specific data and then
+ * the structure itself.
+ *
+ * @param data
+ */
+static void nic_destroy(nic_t *nic_data) {
+	if (nic_data->net_session != NULL) {
+		async_hangup(nic_data->net_session);
+	}
+
+	if (nic_data->nil_session != NULL) {
+		async_hangup(nic_data->nil_session);
+	}
+
+	free(nic_data->specific);
+	free(nic_data);
+}
+
+/**
+ * Unbind and destroy nic_t stored in ddf_dev_t.nic_data.
+ * The ddf_dev_t.nic_data will be set to NULL, specific driver data will be
+ * destroyed.
+ *
+ * @param device The NIC device structure
+ */
+void nic_unbind_and_destroy(ddf_dev_t *device){
+	if (!device)
+		return;
+	if (!device->driver_data)
+		return;
+
+	nic_destroy((nic_t *) device->driver_data);
+	device->driver_data = NULL;
+	return;
+}
+
+/**
+ * Creates an exposed DDF function for the device, named "port0".
+ * Device options are set as this function's options. The function is bound
+ * (see ddf_fun_bind) and then registered to the DEVICE_CATEGORY_NIC class.
+ * Note: this function should be called only from add_device handler, therefore
+ * we don't need to use locks.
+ *
+ * @param nic_data	The NIC structure
+ * @param ops		Device options for the DDF function.
+ */
+int nic_register_as_ddf_fun(nic_t *nic_data, ddf_dev_ops_t *ops)
+{
+	int rc;
+	assert(nic_data);
+
+	nic_data->fun = ddf_fun_create(nic_data->dev, fun_exposed, "port0");
+	if (nic_data->fun == NULL)
+		return ENOMEM;
+	
+	nic_data->fun->ops = ops;
+	nic_data->fun->driver_data = nic_data;
+
+	rc = ddf_fun_bind(nic_data->fun);
+	if (rc != EOK) {
+		ddf_fun_destroy(nic_data->fun);
+		return rc;
+	}
+
+	rc = ddf_fun_add_to_category(nic_data->fun, DEVICE_CATEGORY_NIC);
+	if (rc != EOK) {
+		ddf_fun_destroy(nic_data->fun);
+		return rc;
+	}
+	
+	return EOK;
+}
+
+/**
+ * Set information about current HW filtering.
+ *  1 ...	Only those frames we want to receive are passed through HW
+ *  0 ...	The HW filtering is imperfect
+ * -1 ...	Don't change the setting
+ * Can be called only from the on_*_change handler.
+ *
+ * @param	nic_data
+ * @param	unicast_exact	Unicast frames
+ * @param	mcast_exact		Multicast frames
+ * @param	vlan_exact		VLAN tags
+ */
+void nic_report_hw_filtering(nic_t *nic_data,
+	int unicast_exact, int multicast_exact, int vlan_exact)
+{
+	nic_rxc_hw_filtering(&nic_data->rx_control,
+		unicast_exact, multicast_exact, vlan_exact);
+}
+
+/**
+ * Computes hash for the address list based on standard multicast address
+ * hashing.
+ *
+ * @param address_list
+ * @param count
+ *
+ * @return Multicast hash
+ *
+ * @see multicast_hash
+ */
+uint64_t nic_mcast_hash(const nic_address_t *list, size_t count)
+{
+	return nic_rxc_mcast_hash(list, count);
+}
+
+/**
+ * Computes hash for multicast addresses currently set up in the RX multicast
+ * filtering. For promiscuous mode returns all ones, for blocking all zeroes.
+ * Can be called only from the state change handlers (on_activating,
+ * on_going_down and on_stopping).
+ *
+ * @param nic_data
+ *
+ * @return Multicast hash
+ *
+ * @see multicast_hash
+ */
+uint64_t nic_query_mcast_hash(nic_t *nic_data)
+{
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	uint64_t hash = nic_rxc_multicast_get_hash(&nic_data->rx_control);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	return hash;
+}
+
+/**
+ * Queries the current mode of unicast frames receiving.
+ * Can be called only from the on_*_change handler.
+ *
+ * @param nic_data
+ * @param mode			The new unicast mode
+ * @param max_count		Max number of addresses that can be written into the
+ * 						address_list.
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of addresses in the list
+ */
+void nic_query_unicast(const nic_t *nic_data,
+	nic_unicast_mode_t *mode,
+	size_t max_count, nic_address_t *address_list, size_t *address_count)
+{
+	assert(mode != NULL);
+	nic_rxc_unicast_get_mode(&nic_data->rx_control, mode,
+		max_count, address_list, address_count);
+}
+
+/**
+ * Queries the current mode of multicast frames receiving.
+ * Can be called only from the on_*_change handler.
+ *
+ * @param nic_data
+ * @param mode			The current multicast mode
+ * @param max_count		Max number of addresses that can be written into the
+ * 						address_list.
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of addresses in the list
+ */
+void nic_query_multicast(const nic_t *nic_data,
+	nic_multicast_mode_t *mode,
+	size_t max_count, nic_address_t *address_list, size_t *address_count)
+{
+	assert(mode != NULL);
+	nic_rxc_multicast_get_mode(&nic_data->rx_control, mode,
+		max_count, address_list, address_count);
+}
+
+/**
+ * Queries the current mode of broadcast frames receiving.
+ * Can be called only from the on_*_change handler.
+ *
+ * @param nic_data
+ * @param mode			The new broadcast mode
+ */
+void nic_query_broadcast(const nic_t *nic_data,
+	nic_broadcast_mode_t *mode)
+{
+	assert(mode != NULL);
+	nic_rxc_broadcast_get_mode(&nic_data->rx_control, mode);
+}
+
+/**
+ * Queries the current blocked source addresses.
+ * Can be called only from the on_*_change handler.
+ *
+ * @param nic_data
+ * @param max_count		Max number of addresses that can be written into the
+ * 						address_list.
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of addresses in the list
+ */
+void nic_query_blocked_sources(const nic_t *nic_data,
+	size_t max_count, nic_address_t *address_list, size_t *address_count)
+{
+	nic_rxc_blocked_sources_get(&nic_data->rx_control,
+		max_count, address_list, address_count);
+}
+
+/**
+ * Query mask used for filtering according to the VLAN tags.
+ * Can be called only from the on_*_change handler.
+ *
+ * @param nic_data
+ * @param mask		Must be 512 bytes long
+ *
+ * @return EOK
+ * @return ENOENT
+ */
+int nic_query_vlan_mask(const nic_t *nic_data, nic_vlan_mask_t *mask)
+{
+	assert(mask);
+	return nic_rxc_vlan_get_mask(&nic_data->rx_control, mask);
+}
+
+/**
+ * Query maximum number of WOL virtues of specified type allowed on the device.
+ * Can be called only from add_device and on_wol_virtue_* handlers.
+ *
+ * @param nic_data
+ * @param type		The type of the WOL virtues
+ *
+ * @return	Maximal number of allowed virtues of this type. -1 means this type
+ * 			is not supported at all.
+ */
+int nic_query_wol_max_caps(const nic_t *nic_data, nic_wv_type_t type)
+{
+	return nic_data->wol_virtues.caps_max[type];
+}
+
+/**
+ * Sets maximum number of WOL virtues of specified type allowed on the device.
+ * Can be called only from add_device and on_wol_virtue_* handlers.
+ *
+ * @param nic_data
+ * @param type		The type of the WOL virtues
+ * @param count		Maximal number of allowed virtues of this type. -1 means
+ * 					this type is not supported at all.
+ */
+void nic_set_wol_max_caps(nic_t *nic_data, nic_wv_type_t type, int count)
+{
+	nic_data->wol_virtues.caps_max[type] = count;
+}
+
+/**
+ * @param nic_data
+ * @return The driver-specific structure for this NIC.
+ */
+void *nic_get_specific(nic_t *nic_data)
+{
+	return nic_data->specific;
+}
+
+/**
+ * @param nic_data
+ * @param specific The driver-specific structure for this NIC.
+ */
+void nic_set_specific(nic_t *nic_data, void *specific)
+{
+	nic_data->specific = specific;
+}
+
+/**
+ * You can call the function only from one of the state change handlers.
+ * @param	nic_data
+ * @return	Current state of the NIC, prior to the actually executed change
+ */
+nic_device_state_t nic_query_state(nic_t *nic_data)
+{
+	return nic_data->state;
+}
+
+/**
+ * @param nic_data
+ * @return DDF device associated with this NIC.
+ */
+ddf_dev_t *nic_get_ddf_dev(nic_t *nic_data)
+{
+	return nic_data->dev;
+}
+
+/**
+ * @param nic_data
+ * @return DDF function associated with this NIC.
+ */
+ddf_fun_t *nic_get_ddf_fun(nic_t *nic_data)
+{
+	return nic_data->fun;
+}
+
+/** 
+ * @param dev DDF device associated with NIC
+ * @return The associated NIC structure
+ */
+nic_t *nic_get_from_ddf_dev(ddf_dev_t *dev)
+{
+	return (nic_t *) dev->driver_data;
+};
+
+/** 
+ * @param dev DDF function associated with NIC
+ * @return The associated NIC structure
+ */
+nic_t *nic_get_from_ddf_fun(ddf_fun_t *fun)
+{
+	return (nic_t *) fun->driver_data;
+};
+
+/**
+ * Raises the send_packets and send_bytes in device statistics.
+ *
+ * @param nic_data
+ * @param packets	Number of received packets
+ * @param bytes		Number of received bytes
+ */
+void nic_report_send_ok(nic_t *nic_data, size_t packets, size_t bytes)
+{
+	fibril_rwlock_write_lock(&nic_data->stats_lock);
+	nic_data->stats.send_packets += packets;
+	nic_data->stats.send_bytes += bytes;
+	fibril_rwlock_write_unlock(&nic_data->stats_lock);
+}
+
+/**
+ * Raises total error counter (send_errors) and the concrete send error counter
+ * determined by the cause argument.
+ *
+ * @param nic_data
+ * @param cause		The concrete error cause.
+ */
+void nic_report_send_error(nic_t *nic_data, nic_send_error_cause_t cause, 
+    unsigned count)
+{
+	if (count == 0)
+		return;
+	
+	fibril_rwlock_write_lock(&nic_data->stats_lock);
+	nic_data->stats.send_errors += count;
+	switch (cause) {
+	case NIC_SEC_BUFFER_FULL:
+		nic_data->stats.send_dropped += count;
+		break;
+	case NIC_SEC_ABORTED:
+		nic_data->stats.send_aborted_errors += count;
+		break;
+	case NIC_SEC_CARRIER_LOST:
+		nic_data->stats.send_carrier_errors += count;
+		break;
+	case NIC_SEC_FIFO_OVERRUN:
+		nic_data->stats.send_fifo_errors += count;
+		break;
+	case NIC_SEC_HEARTBEAT:
+		nic_data->stats.send_heartbeat_errors += count;
+		break;
+	case NIC_SEC_WINDOW_ERROR:
+		nic_data->stats.send_window_errors += count;
+		break;
+	case NIC_SEC_OTHER:
+		break;
+	}
+	fibril_rwlock_write_unlock(&nic_data->stats_lock);
+}
+
+/**
+ * Raises total error counter (receive_errors) and the concrete receive error
+ * counter determined by the cause argument.
+ *
+ * @param nic_data
+ * @param cause		The concrete error cause
+ */
+void nic_report_receive_error(nic_t *nic_data,
+	nic_receive_error_cause_t cause, unsigned count)
+{
+	fibril_rwlock_write_lock(&nic_data->stats_lock);
+	nic_data->stats.receive_errors += count;
+	switch (cause) {
+	case NIC_REC_BUFFER_FULL:
+		nic_data->stats.receive_dropped += count;
+		break;
+	case NIC_REC_LENGTH:
+		nic_data->stats.receive_length_errors += count;
+		break;
+	case NIC_REC_BUFFER_OVERFLOW:
+		nic_data->stats.receive_dropped += count;
+		break;
+	case NIC_REC_CRC:
+		nic_data->stats.receive_crc_errors += count;
+		break;
+	case NIC_REC_FRAME_ALIGNMENT:
+		nic_data->stats.receive_frame_errors += count;
+		break;
+	case NIC_REC_FIFO_OVERRUN:
+		nic_data->stats.receive_fifo_errors += count;
+		break;
+	case NIC_REC_MISSED:
+		nic_data->stats.receive_missed_errors += count;
+		break;
+	case NIC_REC_OTHER:
+		break;
+	}
+	fibril_rwlock_write_unlock(&nic_data->stats_lock);
+}
+
+/**
+ * Raises the collisions counter in device statistics.
+ */
+void nic_report_collisions(nic_t *nic_data, unsigned count)
+{
+	fibril_rwlock_write_lock(&nic_data->stats_lock);
+	nic_data->stats.collisions += count;
+	fibril_rwlock_write_unlock(&nic_data->stats_lock);
+}
+
+/** Just wrapper for checking nonzero time interval 
+ *
+ *  @oaram t The interval to check
+ *  @returns Zero if the t is nonzero interval
+ *  @returns Nonzero if t is zero interval
+ */
+static int timeval_nonpositive(struct timeval t) {
+	return (t.tv_sec <= 0) && (t.tv_usec <= 0);
+}
+
+/** Main function of software period fibrill
+ *
+ *  Just calls poll() in the nic->poll_period period
+ *
+ *  @param  data The NIC structure pointer
+ *
+ *  @return 0, never reached
+ */
+static int period_fibril_fun(void *data)
+{
+	nic_t *nic = data;
+	struct sw_poll_info *info = &nic->sw_poll_info;
+	while (true) {
+		fibril_rwlock_read_lock(&nic->main_lock);
+		int run = info->run;
+		int running = info->running;
+		struct timeval remaining = nic->poll_period;
+		fibril_rwlock_read_unlock(&nic->main_lock);
+
+		if (!running) {
+			remaining.tv_sec = 5;
+			remaining.tv_usec = 0;
+		}
+
+		/* Wait the period (keep attention to overflows) */
+		while (!timeval_nonpositive(remaining)) {
+			suseconds_t wait = 0;
+			if (remaining.tv_sec > 0) {
+				time_t wait_sec = remaining.tv_sec;
+				/* wait maximaly 5 seconds to get reasonable reaction time
+				 * when period is reset
+				 */
+				if (wait_sec > 5)
+					wait_sec = 5;
+
+				wait = (suseconds_t) wait_sec * 1000000;
+
+				remaining.tv_sec -= wait_sec;
+			} else {
+				wait = remaining.tv_usec;
+
+				if (wait > 5 * 1000000) {
+					wait = 5 * 1000000;
+				}
+
+				remaining.tv_usec -= wait;
+			}
+			async_usleep(wait);
+			
+			/* Check if the period was not reset */
+			if (info->run != run)
+				break;
+		}
+		
+		/* Provide polling if the period finished */
+		fibril_rwlock_read_lock(&nic->main_lock);
+		if (info->running && info->run == run) {
+			nic->on_poll_request(nic);
+		}
+		fibril_rwlock_read_unlock(&nic->main_lock);
+	}
+	return 0;
+}
+
+/** Starts software periodic polling
+ *
+ *  Reset to new period if the original period was running
+ *
+ *  @param nic_data Nic data structure
+ */
+void nic_sw_period_start(nic_t *nic_data)
+{
+	/* Create the fibril if it is not crated */
+	if (nic_data->sw_poll_info.fibril == 0) {
+		nic_data->sw_poll_info.fibril = fibril_create(period_fibril_fun, 
+		    nic_data);
+		nic_data->sw_poll_info.running = 0;
+		nic_data->sw_poll_info.run = 0;
+
+		/* Start fibril */
+		fibril_add_ready(nic_data->sw_poll_info.fibril);
+	}
+
+	/* Inform fibril about running with new period */
+	nic_data->sw_poll_info.run = (nic_data->sw_poll_info.run + 1) % 100;
+	nic_data->sw_poll_info.running = 1;
+}
+
+/** Stops software periodic polling
+ *
+ *  @param nic_data Nic data structure
+ */
+void nic_sw_period_stop(nic_t *nic_data)
+{
+	nic_data->sw_poll_info.running = 0;
+}
+
+// FIXME: Later
+#if 0
+
+/** Lock packet for DMA usage
+ *
+ * @param packet
+ * @return physical address of packet
+ */
+void *nic_dma_lock_packet(packet_t *packet)
+{
+	void *phys_addr;
+	size_t locked;
+	int rc = dma_lock(packet, &phys_addr, 1, &locked);
+	if (rc != EOK)
+		return NULL;
+	
+	assert(locked == 1);
+	return phys_addr;
+}
+
+/** Unlock packet after DMA usage
+ *
+ * @param packet
+ */
+void nic_dma_unlock_packet(packet_t *packet)
+{
+	size_t unlocked;
+	int rc = dma_unlock(packet, 1, &unlocked);
+	if (rc != EOK)
+		return;
+	
+	assert(unlocked == 1);
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/nic/src/nic_impl.c
===================================================================
--- uspace/lib/nic/src/nic_impl.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/src/nic_impl.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,878 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Default DDF NIC interface methods implementations
+ */
+
+#include <str_error.h>
+#include <ipc/services.h>
+#include <ns.h>
+#include <packet_client.h>
+#include <packet_remote.h>
+#include "nic_driver.h"
+#include "nic_impl.h"
+
+/**
+ * Default implementation of the set_state method. Trivial.
+ *
+ * @param		fun
+ * @param[out]	state
+ *
+ * @return EOK always.
+ */
+int nic_get_state_impl(ddf_fun_t *fun, nic_device_state_t *state)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->main_lock);
+	*state = nic_data->state;
+	fibril_rwlock_read_unlock(&nic_data->main_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of the set_state method. Changes the internal
+ * driver's state, calls the appropriate callback and notifies the NIL service
+ * about this change.
+ *
+ * @param	fun
+ * @param	state	The new device's state
+ *
+ * @return EOK		If the state was changed
+ * @return EINVAL	If the state cannot be changed
+ */
+int nic_set_state_impl(ddf_fun_t *fun, nic_device_state_t state)
+{
+	if (state >= NIC_STATE_MAX) {
+		return EINVAL;
+	}
+
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+
+	fibril_rwlock_write_lock(&nic_data->main_lock);
+	if (nic_data->state == state) {
+		/* No change, nothing to do */
+		fibril_rwlock_write_unlock(&nic_data->main_lock);
+		return EOK;
+	}
+	if (state == NIC_STATE_ACTIVE) {
+		if (nic_data->nil_session == NULL || nic_data->net_session == NULL
+		    || nic_data->device_id < 0) {
+			fibril_rwlock_write_unlock(&nic_data->main_lock);
+			return EINVAL;
+		}
+	}
+
+	state_change_handler event_handler = NULL;
+	switch (state) {
+	case NIC_STATE_STOPPED:
+		event_handler = nic_data->on_stopping;
+		break;
+	case NIC_STATE_DOWN:
+		event_handler = nic_data->on_going_down;
+		break;
+	case NIC_STATE_ACTIVE:
+		event_handler = nic_data->on_activating;
+		break;
+	default:
+		break;
+	}
+	if (event_handler != NULL) {
+		int rc = event_handler(nic_data);
+		if (rc != EOK) {
+			fibril_rwlock_write_unlock(&nic_data->main_lock);
+			return EINVAL;
+		}
+	}
+
+	if (state == NIC_STATE_STOPPED) {
+		/* Notify upper layers that we are reseting the MAC */
+		int rc = nil_addr_changed_msg(nic_data->nil_session,
+			nic_data->device_id, &nic_data->default_mac);
+		nic_data->poll_mode = nic_data->default_poll_mode;
+		memcpy(&nic_data->poll_period, &nic_data->default_poll_period,
+			sizeof (struct timeval));
+		if (rc != EOK) {
+			/* We have already ran the on stopped handler, even if we
+			 * terminated the state change we would end up in undefined state.
+			 * Therefore we just log the problem. */
+		}
+
+		fibril_rwlock_write_lock(&nic_data->stats_lock);
+		bzero(&nic_data->stats, sizeof (nic_device_stats_t));
+		fibril_rwlock_write_unlock(&nic_data->stats_lock);
+
+		fibril_rwlock_write_lock(&nic_data->rxc_lock);
+		nic_rxc_clear(&nic_data->rx_control);
+		/* Reinsert device's default MAC */
+		nic_rxc_set_addr(&nic_data->rx_control, NULL,
+			&nic_data->default_mac);
+		fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+		memcpy(&nic_data->mac, &nic_data->default_mac, sizeof (nic_address_t));
+
+		fibril_rwlock_write_lock(&nic_data->wv_lock);
+		nic_wol_virtues_clear(&nic_data->wol_virtues);
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+
+		/* Ensure stopping period of NIC_POLL_SOFTWARE_PERIODIC */
+		nic_sw_period_stop(nic_data);
+	}
+
+	nic_data->state = state;
+
+	nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state);
+
+	fibril_rwlock_write_unlock(&nic_data->main_lock);
+
+	return EOK;
+}
+
+/**
+ * Default implementation of the send_message method.
+ * Send messages to the network.
+ *
+ * @param	fun
+ * @param	packet_id	ID of the first packet in a queue of sent packets
+ *
+ * @return EOK		If the message was sent
+ * @return EBUSY	If the device is not in state when the packet can be set.
+ * @return EINVAL	If the packet ID is invalid
+ */
+int nic_send_message_impl(ddf_fun_t *fun, packet_id_t packet_id)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	packet_t *packet, *next;
+
+	fibril_rwlock_read_lock(&nic_data->main_lock);
+	if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) {
+		fibril_rwlock_read_unlock(&nic_data->main_lock);
+		pq_release_remote(nic_data->net_session, packet_id);
+		return EBUSY;
+	}
+
+	int rc = packet_translate_remote(nic_data->net_session, &packet, packet_id);
+
+	if (rc != EOK) {
+		fibril_rwlock_read_unlock(&nic_data->main_lock);
+		return EINVAL;
+	}
+
+	/*
+	 * Process the packet queue. Each sent packet must be detached from the
+	 * queue and destroyed. This is why the cycle differs from loopback's
+	 * cycle, where the packets are immediately used in upper layers and
+	 * therefore they must not be destroyed (released).
+	 */
+	assert(nic_data->write_packet != NULL);
+	do {
+		next = pq_detach(packet);
+		nic_data->write_packet(nic_data, packet);
+		packet = next;
+	} while (packet);
+	fibril_rwlock_read_unlock(&nic_data->main_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of the connect_to_nil method.
+ * Connects the driver to the NIL service.
+ *
+ * @param	fun
+ * @param	nil_service	ID of the server implementing the NIL service
+ * @param	device_id	ID of the device as used in higher layers
+ *
+ * @return EOK		If the services were bound
+ * @return 			Negative error code from service_connect_blocking
+ */
+int nic_connect_to_nil_impl(ddf_fun_t *fun, services_t nil_service,
+    nic_device_id_t device_id)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_write_lock(&nic_data->main_lock);
+	
+	nic_data->device_id = device_id;
+	
+	nic_data->nil_session = service_connect_blocking(EXCHANGE_SERIALIZE,
+	    nil_service, 0, 0);
+	if (nic_data->nil_session != NULL) {
+		fibril_rwlock_write_unlock(&nic_data->main_lock);
+		return EOK;
+	}
+	
+	fibril_rwlock_write_unlock(&nic_data->main_lock);
+	return EHANGUP;
+}
+
+/**
+ * Default implementation of the get_address method.
+ * Retrieves the NIC's physical address.
+ *
+ * @param	fun
+ * @param	address	Pointer to the structure where the address will be stored.
+ *
+ * @return EOK		If the services were bound
+ * @return ELIMIT	If the buffer is too short
+ */
+int nic_get_address_impl(ddf_fun_t *fun, nic_address_t *address)
+{
+	assert(address);
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->main_lock);
+	memcpy(address, &nic_data->mac, sizeof (nic_address_t));
+	fibril_rwlock_read_unlock(&nic_data->main_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of the get_stats method. Copies the statistics from
+ * the drivers data to supplied buffer.
+ *
+ * @param		fun
+ * @param[out]	stats	The buffer for statistics
+ *
+ * @return EOK (cannot fail)
+ */
+int nic_get_stats_impl(ddf_fun_t *fun, nic_device_stats_t *stats)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	assert (stats != NULL);
+	fibril_rwlock_read_lock(&nic_data->stats_lock);
+	memcpy(stats, &nic_data->stats, sizeof (nic_device_stats_t));
+	fibril_rwlock_read_unlock(&nic_data->stats_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of unicast_get_mode method.
+ *
+ * @param		fun
+ * @param[out]	mode		Current operation mode
+ * @param[in]	max_count	Max number of addresses that can be written into the
+ * 							buffer (addr_list).
+ * @param[out]	addr_list	Buffer for addresses
+ * @param[out]	addr_count	Number of addresses written into the list
+ *
+ * @return EOK
+ */
+int nic_unicast_get_mode_impl(ddf_fun_t *fun, nic_unicast_mode_t *mode,
+	size_t max_count, nic_address_t *addr_list, size_t *addr_count)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	nic_rxc_unicast_get_mode(&nic_data->rx_control, mode, max_count,
+		addr_list, addr_count);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of unicast_set_mode method.
+ *
+ * @param		fun
+ * @param[in]	mode		New operation mode
+ * @param[in]	addr_list	List of unicast addresses
+ * @param[in]	addr_count	Number of addresses in the list
+ *
+ * @return EOK
+ * @return EINVAL
+ * @return ENOTSUP
+ * @return ENOMEM
+ */
+int nic_unicast_set_mode_impl(ddf_fun_t *fun,
+	nic_unicast_mode_t mode, const nic_address_t *addr_list, size_t addr_count)
+{
+	assert((addr_count == 0 && addr_list == NULL)
+		|| (addr_count != 0 && addr_list != NULL));
+	size_t i;
+	for (i = 0; i < addr_count; ++i) {
+		if (addr_list[i].address[0] & 1)
+			return EINVAL;
+	}
+
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_write_lock(&nic_data->rxc_lock);
+	int rc = ENOTSUP;
+	if (nic_data->on_unicast_mode_change) {
+		rc = nic_data->on_unicast_mode_change(nic_data,
+			mode, addr_list, addr_count);
+	}
+	if (rc == EOK) {
+		rc = nic_rxc_unicast_set_mode(&nic_data->rx_control, mode,
+			addr_list, addr_count);
+		/* After changing the mode the addr db gets cleared, therefore we have
+		 * to reinsert also the physical address of NIC.
+		 */
+		nic_rxc_set_addr(&nic_data->rx_control, NULL, &nic_data->mac);
+	}
+	fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+	return rc;
+}
+
+
+/**
+ * Default implementation of multicast_get_mode method.
+ *
+ * @param		fun
+ * @param[out]	mode		Current operation mode
+ * @param[in]	max_count	Max number of addresses that can be written into the
+ * 							buffer (addr_list).
+ * @param[out]	addr_list	Buffer for addresses
+ * @param[out]	addr_count	Number of addresses written into the list
+ *
+ * @return EOK
+ */
+int nic_multicast_get_mode_impl(ddf_fun_t *fun, nic_multicast_mode_t *mode,
+	size_t max_count, nic_address_t *addr_list, size_t *addr_count)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	nic_rxc_multicast_get_mode(&nic_data->rx_control, mode, max_count,
+		addr_list, addr_count);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of multicast_set_mode method.
+ *
+ * @param		fun
+ * @param[in]	mode		New operation mode
+ * @param[in]	addr_list	List of multicast addresses
+ * @param[in]	addr_count	Number of addresses in the list
+ *
+ * @return EOK
+ * @return EINVAL
+ * @return ENOTSUP
+ * @return ENOMEM
+ */
+int nic_multicast_set_mode_impl(ddf_fun_t *fun,	nic_multicast_mode_t mode,
+	const nic_address_t *addr_list, size_t addr_count)
+{
+	assert((addr_count == 0 && addr_list == NULL)
+		|| (addr_count != 0 && addr_list != NULL));
+	size_t i;
+	for (i = 0; i < addr_count; ++i) {
+		if (!(addr_list[i].address[0] & 1))
+			return EINVAL;
+	}
+
+	nic_t *nic_data = (nic_t *) fun->dev->driver_data;
+	fibril_rwlock_write_lock(&nic_data->rxc_lock);
+	int rc = ENOTSUP;
+	if (nic_data->on_multicast_mode_change) {
+		rc = nic_data->on_multicast_mode_change(nic_data, mode, addr_list, addr_count);
+	}
+	if (rc == EOK) {
+		rc = nic_rxc_multicast_set_mode(&nic_data->rx_control, mode,
+			addr_list, addr_count);
+	}
+	fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of broadcast_get_mode method.
+ *
+ * @param		fun
+ * @param[out]	mode		Current operation mode
+ *
+ * @return EOK
+ */
+int nic_broadcast_get_mode_impl(ddf_fun_t *fun, nic_broadcast_mode_t *mode)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	nic_rxc_broadcast_get_mode(&nic_data->rx_control, mode);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of broadcast_set_mode method.
+ *
+ * @param		fun
+ * @param[in]	mode		New operation mode
+ *
+ * @return EOK
+ * @return EINVAL
+ * @return ENOTSUP
+ * @return ENOMEM
+ */
+int nic_broadcast_set_mode_impl(ddf_fun_t *fun, nic_broadcast_mode_t mode)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_write_lock(&nic_data->rxc_lock);
+	int rc = ENOTSUP;
+	if (nic_data->on_broadcast_mode_change) {
+		rc = nic_data->on_broadcast_mode_change(nic_data, mode);
+	}
+	if (rc == EOK) {
+		rc = nic_rxc_broadcast_set_mode(&nic_data->rx_control, mode);
+	}
+	fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of blocked_sources_get method.
+ *
+ * @param		fun
+ * @param[in]	max_count	Max number of addresses that can be written into the
+ * 							buffer (addr_list).
+ * @param[out]	addr_list	Buffer for addresses
+ * @param[out]	addr_count	Number of addresses written into the list
+ *
+ * @return EOK
+ */
+int nic_blocked_sources_get_impl(ddf_fun_t *fun,
+	size_t max_count, nic_address_t *addr_list, size_t *addr_count)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	nic_rxc_blocked_sources_get(&nic_data->rx_control,
+		max_count, addr_list, addr_count);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of blocked_sources_set method.
+ *
+ * @param		fun
+ * @param[in]	addr_list	List of blocked addresses
+ * @param[in]	addr_count	Number of addresses in the list
+ *
+ * @return EOK
+ * @return EINVAL
+ * @return ENOTSUP
+ * @return ENOMEM
+ */
+int nic_blocked_sources_set_impl(ddf_fun_t *fun,
+	const nic_address_t *addr_list, size_t addr_count)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_write_lock(&nic_data->rxc_lock);
+	if (nic_data->on_blocked_sources_change) {
+		nic_data->on_blocked_sources_change(nic_data, addr_list, addr_count);
+	}
+	int rc = nic_rxc_blocked_sources_set(&nic_data->rx_control,
+		addr_list, addr_count);
+	fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of vlan_get_mask method.
+ *
+ * @param		fun
+ * @param[out]	mask	Current VLAN mask
+ *
+ * @return EOK
+ * @return ENOENT	If the mask is not set
+ */
+int nic_vlan_get_mask_impl(ddf_fun_t *fun, nic_vlan_mask_t *mask)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->rxc_lock);
+	int rc = nic_rxc_vlan_get_mask(&nic_data->rx_control, mask);
+	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of vlan_set_mask method.
+ *
+ * @param		fun
+ * @param[in]	mask	The new VLAN mask
+ *
+ * @return EOK
+ * @return ENOMEM
+ */
+int nic_vlan_set_mask_impl(ddf_fun_t *fun, const nic_vlan_mask_t *mask)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_write_lock(&nic_data->rxc_lock);
+	int rc = nic_rxc_vlan_set_mask(&nic_data->rx_control, mask);
+	if (rc == EOK && nic_data->on_vlan_mask_change) {
+		nic_data->on_vlan_mask_change(nic_data, mask);
+	}
+	fibril_rwlock_write_unlock(&nic_data->rxc_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of the wol_virtue_add method.
+ * Create a new WOL virtue.
+ *
+ * @param[in]	fun
+ * @param[in]	type		Type of the virtue
+ * @param[in]	data		Data required for this virtue (depends on type)
+ * @param[in]	length		Length of the data
+ * @param[out]	filter		Identifier of the new virtue
+ *
+ * @return EOK		If the operation was successfully completed
+ * @return EINVAL	If virtue type is not supported or the data are invalid
+ * @return ELIMIT	If the driver does not allow to create more virtues
+ * @return ENOMEM	If there was not enough memory to complete the operation
+ */
+int nic_wol_virtue_add_impl(ddf_fun_t *fun, nic_wv_type_t type,
+	const void *data, size_t length, nic_wv_id_t *new_id)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	if (nic_data->on_wol_virtue_add == NULL
+		|| nic_data->on_wol_virtue_remove == NULL) {
+		return ENOTSUP;
+	}
+	if (type == NIC_WV_NONE || type >= NIC_WV_MAX) {
+		return EINVAL;
+	}
+	if (nic_wol_virtues_verify(type, data, length) != EOK) {
+		return EINVAL;
+	}
+	nic_wol_virtue_t *virtue = malloc(sizeof (nic_wol_virtue_t));
+	if (virtue == NULL) {
+		return ENOMEM;
+	}
+	bzero(virtue, sizeof (nic_wol_virtue_t));
+	if (length != 0) {
+		virtue->data = malloc(length);
+		if (virtue->data == NULL) {
+			free(virtue);
+			return ENOMEM;
+		}
+		memcpy((void *) virtue->data, data, length);
+	}
+	virtue->type = type;
+	virtue->length = length;
+
+	fibril_rwlock_write_lock(&nic_data->wv_lock);
+	/* Check if we haven't reached the maximum */
+	if (nic_data->wol_virtues.caps_max[type] < 0) {
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+		return EINVAL;
+	}
+	if ((int) nic_data->wol_virtues.lists_sizes[type] >=
+		nic_data->wol_virtues.caps_max[type]) {
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+		return ELIMIT;
+	}
+	/* Call the user-defined add callback */
+	int rc = nic_data->on_wol_virtue_add(nic_data, virtue);
+	if (rc != EOK) {
+		free(virtue->data);
+		free(virtue);
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+		return rc;
+	}
+	rc = nic_wol_virtues_add(&nic_data->wol_virtues, virtue);
+	if (rc != EOK) {
+		/* If the adding fails, call user-defined remove callback */
+		nic_data->on_wol_virtue_remove(nic_data, virtue);
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+		free(virtue->data);
+		free(virtue);
+		return rc;
+	} else {
+		*new_id = virtue->id;
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+	}
+	return EOK;
+}
+
+/**
+ * Default implementation of the wol_virtue_remove method.
+ * Destroys the WOL virtue.
+ *
+ * @param[in] fun
+ * @param[in] id	WOL virtue identification
+ *
+ * @return EOK		If the operation was successfully completed
+ * @return ENOTSUP	If the function is not supported by the driver or device
+ * @return ENOENT	If the virtue identifier is not valid.
+ */
+int nic_wol_virtue_remove_impl(ddf_fun_t *fun, nic_wv_id_t id)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	if (nic_data->on_wol_virtue_add == NULL
+		|| nic_data->on_wol_virtue_remove == NULL) {
+		return ENOTSUP;
+	}
+	fibril_rwlock_write_lock(&nic_data->wv_lock);
+	nic_wol_virtue_t *virtue =
+		nic_wol_virtues_remove(&nic_data->wol_virtues, id);
+	if (virtue == NULL) {
+		fibril_rwlock_write_unlock(&nic_data->wv_lock);
+		return ENOENT;
+	}
+	/* The event handler is called after the filter was removed */
+	nic_data->on_wol_virtue_remove(nic_data, virtue);
+	fibril_rwlock_write_unlock(&nic_data->wv_lock);
+	free(virtue->data);
+	free(virtue);
+	return EOK;
+}
+
+/**
+ * Default implementation of the wol_virtue_probe method.
+ * Queries the type and data of the virtue.
+ *
+ * @param[in]	fun
+ * @param[in]	id		Virtue identifier
+ * @param[out]	type		Type of the virtue. Can be NULL.
+ * @param[out]	data		Data used when the virtue was created. Can be NULL.
+ * @param[out]	length		Length of the data. Can be NULL.
+ *
+ * @return EOK		If the operation was successfully completed
+ * @return ENOENT	If the virtue identifier is not valid.
+ * @return ENOMEM	If there was not enough memory to complete the operation
+ */
+int nic_wol_virtue_probe_impl(ddf_fun_t *fun, nic_wv_id_t id,
+	nic_wv_type_t *type, size_t max_length, void *data, size_t *length)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->wv_lock);
+	const nic_wol_virtue_t *virtue =
+			nic_wol_virtues_find(&nic_data->wol_virtues, id);
+	if (virtue == NULL) {
+		*type = NIC_WV_NONE;
+		*length = 0;
+		fibril_rwlock_read_unlock(&nic_data->wv_lock);
+		return ENOENT;
+	} else {
+		*type = virtue->type;
+		if (max_length > virtue->length) {
+			max_length = virtue->length;
+		}
+		memcpy(data, virtue->data, max_length);
+		*length = virtue->length;
+		fibril_rwlock_read_unlock(&nic_data->wv_lock);
+		return EOK;
+	}
+}
+
+/**
+ * Default implementation of the wol_virtue_list method.
+ * List filters of the specified type. If NIC_WV_NONE is the type, it lists all
+ * filters.
+ *
+ * @param[in]	fun
+ * @param[in]	type	Type of the virtues
+ * @param[out]	virtues	Vector of virtue ID's.
+ * @param[out]	count	Length of the data. Can be NULL.
+ *
+ * @return EOK		If the operation was successfully completed
+ * @return ENOENT	If the filter identification is not valid.
+ * @return ENOMEM	If there was not enough memory to complete the operation
+ */
+int nic_wol_virtue_list_impl(ddf_fun_t *fun, nic_wv_type_t type,
+	size_t max_count, nic_wv_id_t *id_list, size_t *id_count)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->wv_lock);
+	int rc = nic_wol_virtues_list(&nic_data->wol_virtues, type,
+		max_count, id_list, id_count);
+	fibril_rwlock_read_unlock(&nic_data->wv_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of the wol_virtue_get_caps method.
+ * Queries for the current capabilities for some type of filter.
+ *
+ * @param[in]	fun
+ * @param[in]	type	Type of the virtues
+ * @param[out]	count	Number of virtues of this type that can be currently set
+ *
+ * @return EOK		If the operation was successfully completed
+  */
+int nic_wol_virtue_get_caps_impl(ddf_fun_t *fun, nic_wv_type_t type, int *count)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->wv_lock);
+	*count = nic_data->wol_virtues.caps_max[type]
+	    - (int) nic_data->wol_virtues.lists_sizes[type];
+	fibril_rwlock_read_unlock(&nic_data->wv_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of the poll_get_mode method.
+ * Queries the current interrupt/poll mode of the NIC
+ *
+ * @param[in]	fun
+ * @param[out]	mode		Current poll mode
+ * @param[out]	period		Period used in periodic polling. Can be NULL.
+ *
+ * @return EOK		If the operation was successfully completed
+ * @return ENOTSUP	This function is not supported.
+ * @return EPARTY	Error in communication protocol
+ */
+int nic_poll_get_mode_impl(ddf_fun_t *fun,
+	nic_poll_mode_t *mode, struct timeval *period)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->main_lock);
+	*mode = nic_data->poll_mode;
+	memcpy(period, &nic_data->poll_period, sizeof (struct timeval));
+	fibril_rwlock_read_unlock(&nic_data->main_lock);
+	return EOK;
+}
+
+/**
+ * Default implementation of the poll_set_mode_impl method.
+ * Sets the interrupt/poll mode of the NIC.
+ *
+ * @param[in]	fun
+ * @param[in]	mode		The new poll mode
+ * @param[in]	period		Period used in periodic polling. Can be NULL.
+ *
+ * @return EOK		If the operation was successfully completed
+ * @return ENOTSUP	This operation is not supported.
+ * @return EPARTY	Error in communication protocol
+ */
+int nic_poll_set_mode_impl(ddf_fun_t *fun,
+	nic_poll_mode_t mode, const struct timeval *period)
+{
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	/* If the driver does not implement the poll mode change handler it cannot
+	 * switch off interrupts and this is not supported. */
+	if (nic_data->on_poll_mode_change == NULL)
+		return ENOTSUP;
+
+	if ((mode == NIC_POLL_ON_DEMAND) && nic_data->on_poll_request == NULL)
+		return ENOTSUP;
+
+	if (mode == NIC_POLL_PERIODIC || mode == NIC_POLL_SOFTWARE_PERIODIC) {
+		if (period == NULL)
+			return EINVAL;
+		if (period->tv_sec == 0 && period->tv_usec == 0)
+			return EINVAL;
+		if (period->tv_sec < 0 || period->tv_usec < 0)
+			return EINVAL;
+	}
+	fibril_rwlock_write_lock(&nic_data->main_lock);
+	int rc = nic_data->on_poll_mode_change(nic_data, mode, period);
+	assert(rc == EOK || rc == ENOTSUP || rc == EINVAL);
+	if (rc == ENOTSUP && (nic_data->on_poll_request != NULL) && 
+	    (mode == NIC_POLL_PERIODIC || mode == NIC_POLL_SOFTWARE_PERIODIC) ) {
+
+		rc = nic_data->on_poll_mode_change(nic_data, NIC_POLL_ON_DEMAND, NULL);
+		assert(rc == EOK || rc == ENOTSUP);
+		if (rc == EOK) 
+			nic_sw_period_start(nic_data);
+	}
+	if (rc == EOK) {
+		nic_data->poll_mode = mode;
+		if (period)
+			nic_data->poll_period = *period;
+	}
+	fibril_rwlock_write_unlock(&nic_data->main_lock);
+	return rc;
+}
+
+/**
+ * Default implementation of the poll_now method.
+ * Wrapper for the actual poll implementation.
+ *
+ * @param[in]	fun
+ *
+ * @return EOK		If the NIC was polled
+ * @return ENOTSUP	If the function is not supported
+ * @return EINVAL	If the NIC is not in state where it allows on demand polling
+ */
+int nic_poll_now_impl(ddf_fun_t *fun) {
+	nic_t *nic_data = (nic_t *) fun->driver_data;
+	fibril_rwlock_read_lock(&nic_data->main_lock);
+	if (nic_data->poll_mode != NIC_POLL_ON_DEMAND) {
+		fibril_rwlock_read_unlock(&nic_data->main_lock);
+		return EINVAL;
+	}
+	if (nic_data->on_poll_request != NULL) {
+		nic_data->on_poll_request(nic_data);
+		fibril_rwlock_read_unlock(&nic_data->main_lock);
+		return EOK;
+	} else {
+		fibril_rwlock_read_unlock(&nic_data->main_lock);
+		return ENOTSUP;
+	}
+}
+
+/** Default implementation of the device_added method
+ *
+ * Just calls nic_ready.
+ *
+ * @param dev
+ *
+ */
+void nic_device_added_impl(ddf_dev_t *dev)
+{
+	nic_ready((nic_t *) dev->driver_data);
+}
+
+/**
+ * Default handler for unknown methods (outside of the NIC interface).
+ * Logs a warning message and returns ENOTSUP to the caller.
+ *
+ * @param fun		The DDF function where the method should be called.
+ * @param callid	IPC call identifier
+ * @param call		IPC call data
+ */
+void nic_default_handler_impl(ddf_fun_t *fun, ipc_callid_t callid,
+    ipc_call_t *call)
+{
+	async_answer_0(callid, ENOTSUP);
+}
+
+/**
+ * Default (empty) OPEN function implementation.
+ *
+ * @param fun	The DDF function
+ *
+ * @return EOK always.
+ */
+int nic_open_impl(ddf_fun_t *fun)
+{
+	return EOK;
+}
+
+/**
+ * Default (empty) OPEN function implementation.
+ *
+ * @param fun	The DDF function
+ */
+void nic_close_impl(ddf_fun_t *fun)
+{
+}
+
+/** @}
+ */
Index: uspace/lib/nic/src/nic_rx_control.c
===================================================================
--- uspace/lib/nic/src/nic_rx_control.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/src/nic_rx_control.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,539 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Incoming packets (frames) filtering functions
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <bool.h>
+#include <errno.h>
+#include <net/device.h>
+#include <net_checksum.h>
+#include <packet_client.h>
+#include "nic_rx_control.h"
+
+/**
+ * Initializes the receive control structure
+ *
+ * @param rxc
+ *
+ * @return EOK		On success
+ * @return ENOMEM	On not enough memory
+ * @return EINVAL	Internal error, should not happen
+ */
+int nic_rxc_init(nic_rxc_t *rxc)
+{
+	bzero(rxc, sizeof (nic_rxc_t));
+	int rc;
+	rc = nic_addr_db_init(&rxc->blocked_sources, ETH_ADDR);
+	if (rc != EOK) {
+		return rc;
+	}
+	rc = nic_addr_db_init(&rxc->unicast_addrs, ETH_ADDR);
+	if (rc != EOK) {
+		return rc;
+	}
+	rc = nic_addr_db_init(&rxc->multicast_addrs, ETH_ADDR);
+	if (rc != EOK) {
+		return rc;
+	}
+	rxc->block_sources = false;
+	rxc->unicast_mode = NIC_UNICAST_DEFAULT;
+	rxc->multicast_mode = NIC_MULTICAST_BLOCKED;
+	rxc->broadcast_mode = NIC_BROADCAST_ACCEPTED;
+
+	/* Default NIC behavior */
+	rxc->unicast_exact = true;
+	rxc->multicast_exact = false;
+	rxc->vlan_exact = true;
+	return EOK;
+}
+
+/** Reinitialize the structure.
+ *
+ * @param filters
+ */
+int nic_rxc_clear(nic_rxc_t *rxc)
+{
+	nic_addr_db_destroy(&rxc->unicast_addrs);
+	nic_addr_db_destroy(&rxc->multicast_addrs);
+	nic_addr_db_destroy(&rxc->blocked_sources);
+	return nic_rxc_init(rxc);
+}
+
+/** Set the NIC's address that should be used as the default address during
+ * the checks.
+ *
+ * @param rxc
+ * @param prev_addr Previously used default address. Can be NULL
+ *                  if this is the first call after filters' initialization.
+ * @param curr_addr The new default address.
+ *
+ * @return EOK On success
+ *
+ */
+int nic_rxc_set_addr(nic_rxc_t *rxc, const nic_address_t *prev_addr,
+    const nic_address_t *curr_addr)
+{
+	if (prev_addr != NULL) {
+		int rc = nic_addr_db_remove(&rxc->unicast_addrs,
+		    (const uint8_t *) &prev_addr->address);
+		if (rc != EOK)
+			return rc;
+	}
+	
+	return nic_addr_db_insert(&rxc->unicast_addrs,
+	    (const uint8_t *) &curr_addr->address);
+}
+
+/* Helper structure */
+typedef struct {
+	size_t max_count;
+	nic_address_t *address_list;
+	size_t address_count;
+} nic_rxc_add_addr_t;
+
+/** Helper function */
+static void nic_rxc_add_addr(const uint8_t *addr, void *arg)
+{
+	nic_rxc_add_addr_t *hs = (nic_rxc_add_addr_t *) arg;
+	if (hs->address_count < hs->max_count && hs->address_list != NULL) {
+		memcpy(&hs->address_list[hs->address_count].address, addr, ETH_ADDR);
+	}
+	hs->address_count++;
+}
+
+/**
+ * Queries the current mode of unicast frames receiving.
+ *
+ * @param rxc
+ * @param mode			The new unicast mode
+ * @param max_count		Max number of addresses that can be written into the
+ * 						address_list.
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of accepted addresses (can be > max_count)
+ */
+void nic_rxc_unicast_get_mode(const nic_rxc_t *rxc, nic_unicast_mode_t *mode,
+	size_t max_count, nic_address_t *address_list, size_t *address_count)
+{
+	*mode = rxc->unicast_mode;
+	if (rxc->unicast_mode == NIC_UNICAST_LIST) {
+		nic_rxc_add_addr_t hs = {
+			.max_count = max_count,
+			.address_list = address_list,
+			.address_count = 0
+		};
+		nic_addr_db_foreach(&rxc->unicast_addrs, nic_rxc_add_addr, &hs);
+		if (address_count) {
+			*address_count = hs.address_count;
+		}
+	}
+}
+
+/**
+ * Sets the current mode of unicast frames receiving.
+ *
+ * @param rxc
+ * @param mode			The current unicast mode
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of addresses in the list
+ *
+ * @return EOK		On success
+ * @return EINVAL	If any of the MAC addresses is not a unicast address.
+ * @return ENOMEM	If there was not enough memory
+ */
+int nic_rxc_unicast_set_mode(nic_rxc_t *rxc, nic_unicast_mode_t mode,
+	const nic_address_t *address_list, size_t address_count)
+{
+	if (mode == NIC_UNICAST_LIST && address_list == NULL) {
+		return EINVAL;
+	} else if (mode != NIC_UNICAST_LIST && address_list != NULL) {
+		return EINVAL;
+	}
+
+	if (rxc->unicast_mode == NIC_UNICAST_LIST) {
+		nic_addr_db_clear(&rxc->unicast_addrs);
+	}
+	rxc->unicast_mode = mode;
+	size_t i;
+	for (i = 0; i < address_count; ++i) {
+		int rc = nic_addr_db_insert(&rxc->unicast_addrs,
+			(const uint8_t *) &address_list[i].address);
+		if (rc == ENOMEM) {
+			return ENOMEM;
+		}
+	}
+	return EOK;
+}
+
+/**
+ * Queries the current mode of multicast frames receiving.
+ *
+ * @param rxc
+ * @param mode			The current multicast mode
+ * @param max_count		Max number of addresses that can be written into the
+ * 						address_list.
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of accepted addresses (can be > max_count)
+ */
+void nic_rxc_multicast_get_mode(const nic_rxc_t *rxc,
+	nic_multicast_mode_t *mode, size_t max_count, nic_address_t *address_list,
+	size_t *address_count)
+{
+	*mode = rxc->multicast_mode;
+	if (rxc->multicast_mode == NIC_MULTICAST_LIST) {
+		nic_rxc_add_addr_t hs = {
+			.max_count = max_count,
+			.address_list = address_list,
+			.address_count = 0
+		};
+		nic_addr_db_foreach(&rxc->multicast_addrs, nic_rxc_add_addr, &hs);
+		if (address_count) {
+			*address_count = hs.address_count;
+		}
+	}
+}
+
+/**
+ * Sets the current mode of multicast frames receiving.
+ *
+ * @param rxc
+ * @param mode			The new multicast mode
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of addresses in the list
+ *
+ * @return EOK		On success
+ * @return EINVAL	If any of the MAC addresses is not a multicast address.
+ * @return ENOMEM	If there was not enough memory
+ */
+int nic_rxc_multicast_set_mode(nic_rxc_t *rxc, nic_multicast_mode_t mode,
+	const nic_address_t *address_list, size_t address_count)
+{
+	if (mode == NIC_MULTICAST_LIST && address_list == NULL)
+		return EINVAL;
+	else if (mode != NIC_MULTICAST_LIST && address_list != NULL)
+		return EINVAL;
+	
+	if (rxc->multicast_mode == NIC_MULTICAST_LIST)
+		nic_addr_db_clear(&rxc->multicast_addrs);
+	
+	rxc->multicast_mode = mode;
+	size_t i;
+	for (i = 0; i < address_count; ++i) {
+		int rc = nic_addr_db_insert(&rxc->multicast_addrs,
+			(const uint8_t *)&address_list[i].address);
+		if (rc == ENOMEM) {
+			return ENOMEM;
+		}
+	}
+	return EOK;
+}
+
+/**
+ * Queries the current mode of broadcast frames receiving.
+ *
+ * @param rxc
+ * @param mode			The new broadcast mode
+ */
+void nic_rxc_broadcast_get_mode(const nic_rxc_t *rxc, nic_broadcast_mode_t *mode)
+{
+	*mode = rxc->broadcast_mode;
+}
+
+/**
+ * Sets the current mode of broadcast frames receiving.
+ *
+ * @param rxc
+ * @param mode			The new broadcast mode
+ *
+ * @return EOK		On success
+ */
+int nic_rxc_broadcast_set_mode(nic_rxc_t *rxc, nic_broadcast_mode_t mode)
+{
+	rxc->broadcast_mode = mode;
+	return EOK;
+}
+
+/**
+ * Queries the current blocked source addresses.
+ *
+ * @param rxc
+ * @param max_count		Max number of addresses that can be written into the
+ * 						address_list.
+ * @param address_list	List of MAC addresses or NULL.
+ * @param address_count Number of blocked addresses (can be > max_count)
+ */
+void nic_rxc_blocked_sources_get(const nic_rxc_t *rxc,
+	size_t max_count, nic_address_t *address_list, size_t *address_count)
+{
+	nic_rxc_add_addr_t hs = {
+		.max_count = max_count,
+		.address_list = address_list,
+		.address_count = 0
+	};
+	nic_addr_db_foreach(&rxc->blocked_sources, nic_rxc_add_addr, &hs);
+	if (address_count) {
+		*address_count = hs.address_count;
+	}
+}
+
+/**
+ * Clears the currently blocked addresses and sets the addresses contained in
+ * the list as the set of blocked source addresses (no frame with this source
+ * address will be received). Duplicated addresses are ignored.
+ *
+ * @param rxc
+ * @param address_list	List of the blocked addresses. Can be NULL.
+ * @param address_count Number of addresses in the list
+ *
+ * @return EOK		On success
+ * @return ENOMEM	If there was not enough memory
+ */
+int nic_rxc_blocked_sources_set(nic_rxc_t *rxc,
+	const nic_address_t *address_list, size_t address_count)
+{
+	assert((address_count == 0 && address_list == NULL)
+		|| (address_count != 0 && address_list != NULL));
+
+	nic_addr_db_clear(&rxc->blocked_sources);
+	rxc->block_sources = (address_count != 0);
+	size_t i;
+	for (i = 0; i < address_count; ++i) {
+		int rc = nic_addr_db_insert(&rxc->blocked_sources,
+			(const uint8_t *) &address_list[i].address);
+		if (rc == ENOMEM) {
+			return ENOMEM;
+		}
+	}
+	return EOK;
+}
+
+/**
+ * Query mask used for filtering according to the VLAN tags.
+ *
+ * @param rxc
+ * @param mask		Must be 512 bytes long
+ *
+ * @return EOK
+ * @return ENOENT
+ */
+int nic_rxc_vlan_get_mask(const nic_rxc_t *rxc, nic_vlan_mask_t *mask)
+{
+	if (rxc->vlan_mask == NULL) {
+		return ENOENT;
+	}
+	memcpy(mask, rxc->vlan_mask, sizeof (nic_vlan_mask_t));
+	return EOK;
+}
+
+/**
+ * Set mask for filtering according to the VLAN tags.
+ *
+ * @param rxc
+ * @param mask		Must be 512 bytes long
+ *
+ * @return EOK
+ * @return ENOMEM
+ */
+int nic_rxc_vlan_set_mask(nic_rxc_t *rxc, const nic_vlan_mask_t *mask)
+{
+	if (mask == NULL) {
+		if (rxc->vlan_mask) {
+			free(rxc->vlan_mask);
+		}
+		rxc->vlan_mask = NULL;
+		return EOK;
+	}
+	if (!rxc->vlan_mask) {
+		rxc->vlan_mask = malloc(sizeof (nic_vlan_mask_t));
+		if (rxc->vlan_mask == NULL) {
+			return ENOMEM;
+		}
+	}
+	memcpy(rxc->vlan_mask, mask, sizeof (nic_vlan_mask_t));
+	return EOK;
+}
+
+
+/**
+ * Check if the frame passes through the receive control.
+ *
+ * @param rxc
+ * @param packet	The probed frame
+ *
+ * @return True if the frame passes, false if it does not
+ */
+int nic_rxc_check(const nic_rxc_t *rxc, const packet_t *packet,
+	nic_frame_type_t *frame_type)
+{
+	assert(frame_type != NULL);
+	uint8_t *dest_addr = (uint8_t *) packet + packet->data_start;
+	uint8_t *src_addr = dest_addr + ETH_ADDR;
+
+	if (dest_addr[0] & 1) {
+		/* Multicast or broadcast */
+		if (*(uint32_t *) dest_addr == 0xFFFFFFFF &&
+		    *(uint16_t *) (dest_addr + 4) == 0xFFFF) {
+			/* It is broadcast */
+			*frame_type = NIC_FRAME_BROADCAST;
+			if (rxc->broadcast_mode == NIC_BROADCAST_BLOCKED)
+				return false;
+		} else {
+			*frame_type = NIC_FRAME_MULTICAST;
+			/* In promiscuous mode the multicast_exact should be set to true */
+			if (!rxc->multicast_exact) {
+				if (rxc->multicast_mode == NIC_MULTICAST_BLOCKED)
+					return false;
+				else {
+					if (!nic_addr_db_contains(&rxc->multicast_addrs,
+					    dest_addr))
+						return false;
+				}
+			}
+		}
+	} else {
+		/* Unicast */
+		*frame_type = NIC_FRAME_UNICAST;
+		/* In promiscuous mode the unicast_exact should be set to true */
+		if (!rxc->unicast_exact) {
+			if (rxc->unicast_mode == NIC_UNICAST_BLOCKED)
+				return false;
+			else {
+				if (!nic_addr_db_contains(&rxc->unicast_addrs,
+				    dest_addr))
+					return false;
+			}
+		}
+	}
+	/* Blocked source addresses */
+	if (rxc->block_sources) {
+		if (nic_addr_db_contains(&rxc->blocked_sources, src_addr))
+			return false;
+	}
+	/* VLAN filtering */
+	if (!rxc->vlan_exact && rxc->vlan_mask != NULL) {
+		vlan_header_t *vlan_header = (vlan_header_t *)
+			((uint8_t *) packet + packet->data_start + 2 * ETH_ADDR);
+		if (vlan_header->tpid_upper == VLAN_TPID_UPPER &&
+			vlan_header->tpid_lower == VLAN_TPID_LOWER) {
+			int index = ((int) (vlan_header->vid_upper & 0xF) << 5) |
+			    (vlan_header->vid_lower >> 3);
+			if (!(rxc->vlan_mask->bitmap[index] &
+			    (1 << (vlan_header->vid_lower & 0x7))))
+				return false;
+		}
+	}
+	
+	return true;
+}
+
+/**
+ * Set information about current HW filtering.
+ *  1 ...	Only those frames we want to receive are passed through HW
+ *  0 ...	The HW filtering is imperfect
+ * -1 ...	Don't change the setting
+ * This function should be called only from the mode change event handler.
+ *
+ * @param	rxc
+ * @param	unicast_exact	Unicast frames
+ * @param	mcast_exact		Multicast frames
+ * @param	vlan_exact		VLAN tags
+ */
+void nic_rxc_hw_filtering(nic_rxc_t *rxc,
+	int unicast_exact, int multicast_exact, int vlan_exact)
+{
+	if (unicast_exact >= 0)
+		rxc->unicast_exact = unicast_exact;
+	if (multicast_exact >= 0)
+		rxc->multicast_exact = multicast_exact;
+	if (vlan_exact >= 0)
+		rxc->vlan_exact = vlan_exact;
+}
+
+/**
+ * Computes hash for the address list based on standard multicast address
+ * hashing.
+ *
+ * @param address_list
+ * @param count
+ *
+ * @return Multicast hash
+ *
+ * @see multicast_hash
+ */
+uint64_t nic_rxc_mcast_hash(const nic_address_t *address_list, size_t count)
+{
+	size_t i;
+	uint64_t hash = 0;
+	for (i = 0; i < count; ++i) {
+		hash |= multicast_hash(address_list[i].address);
+	}
+	return hash;
+}
+
+static void nic_rxc_hash_addr(const uint8_t *address, void *arg)
+{
+	*((uint64_t *) arg) |= multicast_hash(address);
+}
+
+/**
+ * Computes hash for multicast addresses currently set up in the RX multicast
+ * filtering. For promiscuous mode returns all ones, for blocking all zeroes.
+ * Can be called only from the on_*_change handler.
+ *
+ * @param rxc
+ *
+ * @return Multicast hash
+ *
+ * @see multicast_hash
+ */
+uint64_t nic_rxc_multicast_get_hash(const nic_rxc_t *rxc)
+{
+	switch (rxc->multicast_mode) {
+	case NIC_MULTICAST_UNKNOWN:
+	case NIC_MULTICAST_BLOCKED:
+		return 0;
+	case NIC_MULTICAST_LIST:
+		break;
+	case NIC_MULTICAST_PROMISC:
+		return ~ (uint64_t) 0;
+	}
+	uint64_t hash;
+	nic_addr_db_foreach(&rxc->multicast_addrs, nic_rxc_hash_addr, &hash);
+	return hash;
+}
+
+/** @}
+ */
Index: uspace/lib/nic/src/nic_wol_virtues.c
===================================================================
--- uspace/lib/nic/src/nic_wol_virtues.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
+++ uspace/lib/nic/src/nic_wol_virtues.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2011 Radim Vansa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup libnic
+ * @{
+ */
+/**
+ * @file
+ * @brief Wake-on-LAN support
+ */
+
+#include "nic_wol_virtues.h"
+#include <assert.h>
+
+#define NIC_WV_HASH_COUNT 32
+
+/**
+ * Hash table helper function
+ */
+static int nic_wv_compare(unsigned long key[], hash_count_t keys,
+	link_t *item)
+{
+	nic_wol_virtue_t *virtue = (nic_wol_virtue_t *) item;
+	return (virtue->id == (nic_wv_id_t) key[0]);
+}
+
+/**
+ * Hash table helper function
+ */
+static void nic_wv_rc(link_t *item)
+{
+}
+
+/**
+ * Hash table helper function
+ */
+static hash_index_t nic_wv_hash(unsigned long keys[])
+{
+	return keys[0] % NIC_WV_HASH_COUNT;
+}
+
+/**
+ * Initializes the WOL virtues structure
+ *
+ * @param wvs
+ *
+ * @return EOK		On success
+ * @return ENOMEM	On not enough memory
+ */
+int nic_wol_virtues_init(nic_wol_virtues_t *wvs)
+{
+	bzero(wvs, sizeof (nic_wol_virtues_t));
+	wvs->table_operations.compare = nic_wv_compare;
+	wvs->table_operations.hash = nic_wv_hash;
+	wvs->table_operations.remove_callback = nic_wv_rc;
+	if (!hash_table_create(&wvs->table, NIC_WV_HASH_COUNT, 1,
+		&wvs->table_operations)) {
+		return ENOMEM;
+	}
+	size_t i;
+	for (i = 0; i < NIC_WV_MAX; ++i) {
+		wvs->caps_max[i] = -1;
+	}
+	wvs->next_id = 0;
+	return EOK;
+}
+
+/**
+ * Reinitializes the structure, destroying all virtues. The next_id is not
+ * changed (some apps could still hold the filter IDs).
+ *
+ * @param wvs
+ */
+void nic_wol_virtues_clear(nic_wol_virtues_t *wvs)
+{
+	hash_table_clear(&wvs->table);
+	nic_wv_type_t type;
+	for (type = NIC_WV_NONE; type < NIC_WV_MAX; ++type) {
+		nic_wol_virtue_t *virtue = wvs->lists[type];
+		while (virtue != NULL) {
+			nic_wol_virtue_t *next = virtue->next;
+			free(virtue->data);
+			free(virtue);
+			virtue = next;
+		}
+		wvs->lists_sizes[type] = 0;
+	}
+}
+
+/**
+ * Verifies that the arguments for the WOL virtues are correct.
+ *
+ * @param type		Type of the virtue
+ * @param data		Data argument for the virtue
+ * @param length	Length of the data
+ *
+ * @return EOK		The arguments are correct
+ * @return EINVAL	The arguments are incorrect
+ * @return ENOTSUP	This type is unknown
+ */
+int nic_wol_virtues_verify(nic_wv_type_t type, const void *data, size_t length)
+{
+	switch (type) {
+	case NIC_WV_ARP_REQUEST:
+	case NIC_WV_BROADCAST:
+	case NIC_WV_LINK_CHANGE:
+		return EOK;
+	case NIC_WV_DESTINATION:
+		return length == sizeof (nic_address_t) ? EOK : EINVAL;
+	case NIC_WV_DIRECTED_IPV4:
+		return length == sizeof (nic_wv_ipv4_data_t) ? EOK : EINVAL;
+	case NIC_WV_DIRECTED_IPV6:
+		return length == sizeof (nic_wv_ipv6_data_t) ? EOK : EINVAL;
+	case NIC_WV_FULL_MATCH:
+		return length % 2 == 0 ? EOK : EINVAL;
+	case NIC_WV_MAGIC_PACKET:
+		return data == NULL || length == sizeof (nic_wv_magic_packet_data_t) ?
+			EOK : EINVAL;
+	default:
+		return ENOTSUP;
+	}
+}
+
+/**
+ * Adds the virtue to the list of known virtues, activating it.
+ *
+ * @param wvs
+ * @param virtue	The virtue structure
+ *
+ * @return EOK		On success
+ * @return ENOTSUP	If the virtue type is not supported
+ * @return EINVAL	If the virtue type is a single-filter and there's already
+ * 					a virtue of this type defined, or there is something wrong
+ * 					with the data
+ * @return ENOMEM	Not enough memory to activate the virtue
+ */
+int nic_wol_virtues_add(nic_wol_virtues_t *wvs, nic_wol_virtue_t *virtue)
+{
+	if (!nic_wv_is_multi(virtue->type) &&
+		wvs->lists[virtue->type] != NULL) {
+		return EINVAL;
+	}
+	do {
+		virtue->id = wvs->next_id++;
+	} while (NULL !=
+		hash_table_find(&wvs->table, (unsigned long *) &virtue->id));
+	hash_table_insert(&wvs->table,
+		(unsigned long *) &virtue->id, &virtue->item);
+	virtue->next = wvs->lists[virtue->type];
+	wvs->lists[virtue->type] = virtue;
+	wvs->lists_sizes[virtue->type]++;
+	return EOK;
+}
+
+/**
+ * Removes the virtue from the list of virtues, but NOT deallocating the
+ * nic_wol_virtue structure.
+ *
+ * @param wvs
+ * @param id	Identifier of the removed virtue
+ *
+ * @return Removed virtue structure or NULL if not found.
+ */
+nic_wol_virtue_t *nic_wol_virtues_remove(nic_wol_virtues_t *wvs, nic_wv_id_t id)
+{
+	nic_wol_virtue_t *virtue = (nic_wol_virtue_t *)
+		hash_table_find(&wvs->table, (unsigned long *) &id);
+	if (virtue == NULL) {
+		return NULL;
+	}
+
+	/* Remove from filter_table */
+	hash_table_remove(&wvs->table, (unsigned long *) &id, 1);
+
+	/* Remove from filter_types */
+	assert(wvs->lists[virtue->type] != NULL);
+	if (wvs->lists[virtue->type] == virtue) {
+		wvs->lists[virtue->type] = virtue->next;
+	} else {
+		nic_wol_virtue_t *wv = wvs->lists[virtue->type];
+		while (wv->next != virtue) {
+			wv = wv->next;
+			assert(wv != NULL);
+		}
+		wv->next = virtue->next;
+	}
+	wvs->lists_sizes[virtue->type]--;
+
+	virtue->next = NULL;
+	return virtue;
+}
+
+
+/**
+ * Searches the filters table for a filter with specified ID
+ *
+ * @param wvs
+ * @param id	Identifier of the searched virtue
+ *
+ * @return Requested filter or NULL if not found.
+ */
+const nic_wol_virtue_t *nic_wol_virtues_find(const nic_wol_virtues_t *wvs,
+	nic_wv_id_t id)
+{
+	/*
+	 * The hash_table_find cannot be const, because it would require the
+	 * returned link to be const as well. But in this case, when we're returning
+	 * constant virtue the retyping is correct.
+	 */
+	link_t *virtue = hash_table_find(
+		&((nic_wol_virtues_t *) wvs)->table, (unsigned long *) &id);
+	return (const nic_wol_virtue_t *) virtue;
+}
+
+/**
+ * Fill identifiers of current wol virtues of the specified type into the list.
+ * If the type is set to NIC_WV_NONE, all virtues are used.
+ *
+ * @param		wvs
+ * @param[in]	type		Type of the virtues or NIC_WV_NONE
+ * @param[out]	id_list		The new vector of filter IDs. Can be NULL.
+ * @param[out]	count		Number of IDs in the filter_list. Can be NULL.
+ *
+ * @return EOK		If it completes successfully
+ * @return EINVAL	If the filter type is invalid
+ */
+int nic_wol_virtues_list(const nic_wol_virtues_t *wvs, nic_wv_type_t type,
+	size_t max_count, nic_wv_id_t *id_list, size_t *id_count)
+{
+	size_t count = 0;
+	if (type == NIC_WV_NONE) {
+		size_t i;
+		for (i = NIC_WV_NONE; i < NIC_WV_MAX; ++i) {
+			if (id_list != NULL) {
+				nic_wol_virtue_t *virtue = wvs->lists[i];
+				while (virtue != NULL) {
+					if (count < max_count) {
+						id_list[count] = virtue->id;
+					}
+					++count;
+					virtue = virtue->next;
+				}
+			} else {
+				count += wvs->lists_sizes[i];
+			}
+		}
+	} else if (type >= NIC_WV_MAX) {
+		return EINVAL;
+	} else {
+		if (id_list != NULL) {
+			nic_wol_virtue_t *virtue = wvs->lists[type];
+			while (virtue != NULL) {
+				if (count < max_count) {
+					id_list[count] = virtue->id;
+				}
+				++count;
+				virtue = virtue->next;
+			}
+		} else {
+			count = wvs->lists_sizes[type];
+		}
+	}
+	if (id_count != NULL) {
+		*id_count = count;
+	}
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/il/ip/ip.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -354,5 +354,5 @@
 	ip_netif->routing = NET_DEFAULT_IP_ROUTING;
 	configuration = &names[0];
-
+	
 	/* Get configuration */
 	rc = net_get_device_conf_req(ip_globals.net_sess, ip_netif->device_id,
@@ -406,5 +406,5 @@
 			return ENOTSUP;
 		}
-
+		
 		if (configuration[6].value) {
 			ip_netif->arp = get_running_module(&ip_globals.modules,
@@ -417,10 +417,11 @@
 			}
 		}
+		
 		if (configuration[7].value)
 			ip_netif->routing = (configuration[7].value[0] == 'y');
-
+		
 		net_free_settings(configuration, data);
 	}
-
+	
 	/* Bind netif service which also initializes the device */
 	ip_netif->sess = nil_bind_service(ip_netif->service,
@@ -432,5 +433,5 @@
 		return ENOENT;
 	}
-
+	
 	/* Has to be after the device netif module initialization */
 	if (ip_netif->arp) {
@@ -448,5 +449,5 @@
 		}
 	}
-
+	
 	/* Get packet dimensions */
 	rc = nil_packet_size_req(ip_netif->sess, ip_netif->device_id,
@@ -461,5 +462,5 @@
 		ip_netif->packet_dimension.content = IP_MIN_CONTENT;
 	}
-
+	
 	index = ip_netifs_add(&ip_globals.netifs, ip_netif->device_id, ip_netif);
 	if (index < 0)
@@ -478,5 +479,5 @@
 		printf("%s: Default gateway (%s)\n", NAME, defgateway);
 	}
-
+	
 	return EOK;
 }
@@ -498,9 +499,9 @@
 		return rc;
 	}
-
+	
 	ip_netif->device_id = device_id;
 	ip_netif->service = netif;
 	ip_netif->state = NIC_STATE_STOPPED;
-
+	
 	fibril_rwlock_write_lock(&ip_globals.netifs_lock);
 
Index: uspace/srv/net/net/Makefile
===================================================================
--- uspace/srv/net/net/Makefile	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/net/Makefile	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -43,5 +43,4 @@
 SOURCES = \
 	net.c \
-	net_standalone.c \
 	packet_server.c
 
Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/net/net.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -30,9 +30,4 @@
 /** @addtogroup net
  * @{
- */
-
-/** @file
- * Networking subsystem central module implementation.
- *
  */
 
@@ -55,5 +50,4 @@
 #include <ipc/ip.h>
 #include <ipc/nil.h>
-#include <net/modules.h>
 #include <net/packet.h>
 #include <net/device.h>
@@ -72,7 +66,4 @@
 #include "packet_server.h"
 
-/** Networking module name. */
-#define NAME  "net"
-
 #define MAX_PATH_LENGTH  1024
 
@@ -82,6 +73,4 @@
 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
 DEVICE_MAP_IMPLEMENT(netifs, netif_t);
-
-static int startup(void);
 
 /** Add the configured setting to the configuration map.
@@ -95,6 +84,6 @@
  *
  */
-int add_configuration(measured_strings_t *configuration, const uint8_t *name,
-    const uint8_t *value)
+static int add_configuration(measured_strings_t *configuration,
+    const uint8_t *name, const uint8_t *value)
 {
 	int rc;
@@ -146,5 +135,4 @@
 		    (uint8_t *) entry->key, (uint8_t *) entry->value);
 		if (rc != EOK) {
-			printf("%s: Error processing configuration\n", NAME);
 			cfg_unload(&cfg);
 			return rc;
@@ -180,91 +168,4 @@
 	return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE,
 	    &net_globals.configuration);
-}
-
-/** Initialize the networking module.
- *
- * @param[in] client_connection The client connection processing
- *                              function. The module skeleton propagates
- *                              its own one.
- *
- * @return EOK on success.
- * @return ENOMEM if there is not enough memory left.
- *
- */
-static int net_initialize(async_client_conn_t client_connection)
-{
-	int rc;
-	
-	netifs_initialize(&net_globals.netifs);
-	char_map_initialize(&net_globals.netif_hwpaths);
-	modules_initialize(&net_globals.modules);
-	measured_strings_initialize(&net_globals.configuration);
-	
-	rc = read_configuration();
-	if (rc != EOK)
-		return rc;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
-	    (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
-	if (rc != EOK)
-		return rc;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
-	    (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
-	if (rc != EOK)
-		return rc;
-	
-	/* Build specific initialization */
-	return net_initialize_build(client_connection);
-}
-
-/** Start the networking module.
- *
- * Initializes the client connection serving function,
- * initializes the module, registers the module service
- * and starts the async manager, processing IPC messages
- * in an infinite loop.
- *
- * @param[in] client_connection The client connection
- *                              processing function. The
- *                              module skeleton propagates
- *                              its own one.
- *
- * @return EOK on successful module termination.
- * @return Other error codes as defined for the net_initialize() function.
- * @return Other error codes as defined for the REGISTER_ME() macro function.
- *
- */
-static int net_module_start(async_client_conn_t client_connection)
-{
-	int rc;
-	
-	async_set_client_connection(client_connection);
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
-	
-	rc = packet_server_init();
-	if (rc != EOK)
-		goto out;
-	
-	rc = net_initialize(client_connection);
-	if (rc != EOK)
-		goto out;
-	
-	rc = startup();
-	if (rc != EOK)
-		goto out;
-	
-	rc = service_register(SERVICE_NETWORKING);
-	if (rc != EOK)
-		goto out;
-	
-	task_retval(0);
-	async_manager();
-
-out:
-	pm_destroy();
-	return rc;
 }
 
@@ -388,4 +289,6 @@
 static int init_device(netif_t *netif, devman_handle_t handle)
 {
+	printf("%s: Initializing device '%s'\n", NAME, netif->name);
+	
 	netif->handle = handle;
 	netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle,
@@ -459,8 +362,9 @@
 	}
 	
+	printf("%s: Activating device '%s'\n", NAME, netif->name);
 	return nic_set_state(netif->sess, NIC_STATE_ACTIVE);
 }
 
-static int net_driver_port_ready(devman_handle_t handle)
+static int net_port_ready(devman_handle_t handle)
 {
 	char hwpath[MAX_PATH_LENGTH];
@@ -500,105 +404,9 @@
 	
 	for (size_t i = 0; i < count; i++) {
-		rc = net_driver_port_ready(funs[i]);
+		rc = net_port_ready(funs[i]);
 		if (rc != EOK)
 			return rc;
 	}
 	
-	return EOK;
-}
-
-/** Read the configuration and start all network interfaces.
- *
- * @return EOK on success.
- * @return EXDEV if there is no available system-unique device identifier.
- * @return EINVAL if any of the network interface names are not configured.
- * @return ENOMEM if there is not enough memory left.
- * @return Other error codes as defined for the read_configuration()
- *         function.
- * @return Other error codes as defined for the read_netif_configuration()
- *         function.
- * @return Other error codes as defined for the start_device() function.
- *
- */
-static int startup(void)
-{
-	int rc;
-	
-	DIR *config_dir = opendir(CONF_DIR);
-	if (config_dir == NULL)
-		return ENOENT;
-	
-	struct dirent *dir_entry;
-	while ((dir_entry = readdir(config_dir))) {
-		if (str_cmp(dir_entry->d_name + str_length(dir_entry->d_name)
-			- str_length(CONF_EXT), CONF_EXT) != 0)
-			continue;
-		
-		netif_t *netif = (netif_t *) malloc(sizeof(netif_t));
-		if (!netif)
-			continue;
-		
-		netif->handle = -1;
-		netif->sess = NULL;
-		
-		netif->id = generate_new_device_id();
-		if (!netif->id) {
-			free(netif);
-			continue;
-		}
-		
-		rc = measured_strings_initialize(&netif->configuration);
-		if (rc != EOK) {
-			free(netif);
-			continue;
-		}
-		
-		rc = read_netif_configuration(dir_entry->d_name, netif);
-		if (rc != EOK) {
-			free(netif);
-			continue;
-		}
-		
-		/* Mandatory name */
-		measured_string_t *name = measured_strings_find(&netif->configuration,
-		    (uint8_t *) CONF_NAME, 0);
-		if (!name) {
-			printf("%s: Network interface name is missing\n", NAME);
-			measured_strings_destroy(&netif->configuration, free);
-			free(netif);
-			continue;
-		}
-		
-		netif->name = name->value;
-		
-		/* Mandatory hardware path */
-		measured_string_t *hwpath = measured_strings_find(
-		    &netif->configuration, (const uint8_t *) CONF_HWPATH, 0);
-		if (!hwpath) {
-			measured_strings_destroy(&netif->configuration, free);
-			free(netif);
-		}
-		
-		/* Add to the netifs map */
-		int index = netifs_add(&net_globals.netifs, netif->id, netif);
-		if (index < 0) {
-			measured_strings_destroy(&netif->configuration, free);
-			free(netif);
-			continue;
-		}
-		
-		/*
-		 * Add to the hardware paths map and init network interfaces
-		 * and needed modules.
-		 */
-		rc = char_map_add(&net_globals.netif_hwpaths, hwpath->value, 0, index);
-		if (rc != EOK) {
-			measured_strings_destroy(&netif->configuration, free);
-			netifs_exclude_index(&net_globals.netifs, index, free);
-			continue;
-		}
-	}
-	
-	closedir(config_dir);
 	return EOK;
 }
@@ -619,6 +427,6 @@
  *
  */
-int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
-    size_t *answer_count)
+static int net_message(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, size_t *answer_count)
 {
 	measured_string_t *strings;
@@ -699,6 +507,6 @@
 		/* Clear the answer structure */
 		ipc_call_t answer;
-		size_t answer_count;
-		refresh_answer(&answer, &answer_count);
+		size_t count;
+		refresh_answer(&answer, &count);
 		
 		/* Fetch the next message */
@@ -707,5 +515,9 @@
 		
 		/* Process the message */
-		int res = net_module_message(callid, &call, &answer, &answer_count);
+		int res;
+		if (IS_NET_PACKET_MESSAGE(call))
+			res = packet_server_message(callid, &call, &answer, &count);
+		else
+			res = net_message(callid, &call, &answer, &count);
 		
 		/* End if told to either by the message or the processing result */
@@ -714,5 +526,5 @@
 		
 		/* Answer the message */
-		answer_call(callid, res, &answer, answer_count);
+		answer_call(callid, res, &answer, count);
 	}
 }
@@ -720,5 +532,172 @@
 int main(int argc, char *argv[])
 {
-	return net_module_start(net_client_connection);
+	netifs_initialize(&net_globals.netifs);
+	char_map_initialize(&net_globals.netif_hwpaths);
+	modules_initialize(&net_globals.modules);
+	measured_strings_initialize(&net_globals.configuration);
+	async_set_client_connection(net_client_connection);
+	
+	int rc = pm_init();
+	if (rc != EOK) {
+		printf("%s: Unable to initialize packet management\n", NAME);
+		return rc;
+	}
+	
+	rc = packet_server_init();
+	if (rc != EOK) {
+		printf("%s: Unable to initialize packet server\n", NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	rc = read_configuration();
+	if (rc != EOK) {
+		printf("%s: Error reading configuration\n", NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	DIR *config_dir = opendir(CONF_DIR);
+	if (config_dir != NULL) {
+		struct dirent *dir_entry;
+		while ((dir_entry = readdir(config_dir))) {
+			/* Ignore files without the CONF_EXT extension */
+			if ((str_size(dir_entry->d_name) < str_size(CONF_EXT)) ||
+			    (str_cmp(dir_entry->d_name + str_size(dir_entry->d_name) -
+			    str_size(CONF_EXT), CONF_EXT) != 0))
+				continue;
+			
+			
+			netif_t *netif = (netif_t *) malloc(sizeof(netif_t));
+			if (!netif)
+				continue;
+			
+			netif->handle = -1;
+			netif->sess = NULL;
+			
+			netif->id = generate_new_device_id();
+			if (!netif->id) {
+				free(netif);
+				continue;
+			}
+			
+			rc = measured_strings_initialize(&netif->configuration);
+			if (rc != EOK) {
+				free(netif);
+				continue;
+			}
+			
+			rc = read_netif_configuration(dir_entry->d_name, netif);
+			if (rc != EOK) {
+				printf("%s: Error reading configuration %s\n", NAME,
+				    dir_entry->d_name);
+				free(netif);
+				continue;
+			}
+			
+			measured_string_t *name = measured_strings_find(&netif->configuration,
+			    (uint8_t *) CONF_NAME, 0);
+			if (!name) {
+				printf("%s: Network interface name is missing in %s\n",
+				    NAME, dir_entry->d_name);
+				measured_strings_destroy(&netif->configuration, free);
+				free(netif);
+				continue;
+			}
+			
+			netif->name = name->value;
+			
+			/* Mandatory hardware path */
+			measured_string_t *hwpath = measured_strings_find(
+			    &netif->configuration, (const uint8_t *) CONF_HWPATH, 0);
+			if (!hwpath) {
+				printf("%s: Hardware path is missing in %s\n",
+				    NAME, dir_entry->d_name);
+				measured_strings_destroy(&netif->configuration, free);
+				free(netif);
+				continue;
+			}
+			
+			int index = netifs_add(&net_globals.netifs, netif->id, netif);
+			if (index < 0) {
+				measured_strings_destroy(&netif->configuration, free);
+				free(netif);
+				continue;
+			}
+			
+			/*
+			 * Add to the hardware paths map and init network interfaces
+			 * and needed modules.
+			 */
+			rc = char_map_add(&net_globals.netif_hwpaths, hwpath->value, 0, index);
+			if (rc != EOK) {
+				measured_strings_destroy(&netif->configuration, free);
+				netifs_exclude_index(&net_globals.netifs, index, free);
+				continue;
+			}
+		}
+		
+		closedir(config_dir);
+	}
+	
+	rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
+	    (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
+	if (rc != EOK) {
+		printf("%s: Error adding module '%s'\n", NAME, ETHERNET_NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
+	    (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
+	if (rc != EOK) {
+		printf("%s: Error adding module '%s'\n", NAME, NILDUMMY_NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	task_id_t task_id = net_spawn((uint8_t *) IP_FILENAME);
+	if (!task_id) {
+		printf("%s: Error spawning IP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	rc = add_module(NULL, &net_globals.modules, (uint8_t *) IP_NAME,
+	    (uint8_t *) IP_FILENAME, SERVICE_IP, task_id, ip_connect_module);
+	if (rc != EOK) {
+		printf("%s: Error adding module '%s'\n", NAME, IP_NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	if (!net_spawn((uint8_t *) "/srv/icmp")) {
+		printf("%s: Error spawning ICMP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	if (!net_spawn((uint8_t *) "/srv/udp")) {
+		printf("%s: Error spawning UDP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	if (!net_spawn((uint8_t *) "/srv/tcp")) {
+		printf("%s: Error spawning TCP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	rc = service_register(SERVICE_NETWORKING);
+	if (rc != EOK) {
+		printf("%s: Error registering service\n", NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	task_retval(0);
+	async_manager();
+	return 0;
 }
 
Index: uspace/srv/net/net/net.h
===================================================================
--- uspace/srv/net/net/net.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/net/net.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -32,9 +32,4 @@
  */
 
-/** @file
- * Networking subsystem central module.
- *
- */
-
 #ifndef NET_NET_H_
 #define NET_NET_H_
@@ -48,7 +43,5 @@
 #include <devman.h>
 
-/** @name Modules definitions
- * @{
- */
+#define NAME  "net"
 
 #define ETHERNET_FILENAME  "/srv/eth"
@@ -95,14 +88,17 @@
  */
 typedef struct {
-	uint8_t *name;     			/**< System-unique network interface name. */
-	nic_device_id_t id;  		/**< System-unique network interface identifier. */
-	measured_strings_t configuration;  /**< Configuration. */
+	/** System-unique network interface name. */
+	uint8_t *name;
+	/** System-unique network interface identifier. */
+	nic_device_id_t id;
+	/** Configuration. */
+	measured_strings_t configuration;
 	
 	/** Serving network interface driver module index. */
-	devman_handle_t handle;		/**< Handle for devman */
-	async_sess_t *sess;		 	/**< Driver session. */
+	devman_handle_t handle;  /**< Handle for devman */
+	async_sess_t *sess;      /**< Driver session. */
 	
-	module_t *nil;   /**< Serving link layer module index. */
-	module_t *il;    /**< Serving internet layer module index. */
+	module_t *nil;  /**< Serving link layer module index. */
+	module_t *il;   /**< Serving internet layer module index. */
 } netif_t;
 
@@ -129,10 +125,4 @@
 } net_globals_t;
 
-extern int add_configuration(measured_strings_t *, const uint8_t *,
-    const uint8_t *);
-extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);
-extern int net_initialize_build(async_client_conn_t);
-extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);
-
 #endif
 
Index: pace/srv/net/net/net_standalone.c
===================================================================
--- uspace/srv/net/net/net_standalone.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup net
- * @{
- */
-
-/** @file
- * Wrapper for the standalone networking module.
- */
-
-#include <str.h>
-#include <adt/measured_strings.h>
-#include <adt/module_map.h>
-#include <ipc/net.h>
-#include <errno.h>
-#include <ip_interface.h>
-#include "net.h"
-#include "packet_server.h"
-
-/** Networking module global data. */
-extern net_globals_t net_globals;
-
-/** Initialize the networking module for the chosen subsystem build type.
- *
- *  @param[in] client_connection The client connection processing function.
- *                               The module skeleton propagates its own one.
- *
- *  @return EOK on success.
- *  @return ENOMEM if there is not enough memory left.
- *
- */
-int net_initialize_build(async_client_conn_t client_connection)
-{
-	int rc;
-	
-	task_id_t task_id = net_spawn((uint8_t *) IP_FILENAME);
-	if (!task_id)
-		return EINVAL;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) IP_NAME,
-	    (uint8_t *) IP_FILENAME, SERVICE_IP, task_id, ip_connect_module);
-	if (rc != EOK)
-		return rc;
-	
-	if (!net_spawn((uint8_t *) "/srv/icmp"))
-		return EINVAL;
-	
-	if (!net_spawn((uint8_t *) "/srv/udp"))
-		return EINVAL;
-	
-	if (!net_spawn((uint8_t *) "/srv/tcp"))
-		return EINVAL;
-	
-	return EOK;
-}
-
-/** Process the module message.
- *
- * Distribute the message to the right module.
- *
- * @param[in]  callid       The message identifier.
- * @param[in]  call         The message parameters.
- * @param[out] answer       The message answer parameters.
- * @param[out] answer_count The last parameter for the actual answer in
- *                          the answer parameter.
- *
- * @return EOK on success.
- * @return ENOTSUP if the message is not known.
- * @return Other error codes.
- *
- */
-int net_module_message(ipc_callid_t callid, ipc_call_t *call,
-    ipc_call_t *answer, size_t *count)
-{
-	if (IS_NET_PACKET_MESSAGE(*call))
-		return packet_server_message(callid, call, answer, count);
-	
-	return net_message(callid, call, answer, count);
-}
-
-/** @}
- */
Index: uspace/srv/net/net/packet_server.h
===================================================================
--- uspace/srv/net/net/packet_server.h	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/net/packet_server.h	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -43,6 +43,6 @@
  */
 
-#ifndef LIBPACKET_PACKET_SERVER_H_
-#define LIBPACKET_PACKET_SERVER_H_
+#ifndef NET_PACKET_SERVER_H_
+#define NET_PACKET_SERVER_H_
 
 #include <ipc/common.h>
Index: uspace/srv/net/nil/eth/eth.c
===================================================================
--- uspace/srv/net/nil/eth/eth.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/nil/eth/eth.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -629,5 +629,5 @@
 	}
 	
-	printf("%s: Protocol registered (protocol: %d, service: %d)\n",
+	printf("%s: Protocol registered (protocol: %d, service: %#x)\n",
 	    NAME, proto->protocol, proto->service);
 	
Index: uspace/srv/net/nil/nildummy/nildummy.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.c	(revision e2c50e102fd16362a7ce19b5f3ae930df486f779)
+++ uspace/srv/net/nil/nildummy/nildummy.c	(revision 00d7e1bfe06501df61aed156666d5597397d910a)
@@ -324,5 +324,5 @@
 	nildummy_globals.proto.sess = sess;
 	
-	printf("%s: Protocol registered (service: %d)\n",
+	printf("%s: Protocol registered (service: %#x)\n",
 	    NAME, nildummy_globals.proto.service);
 	
