Index: boot/Makefile
===================================================================
--- boot/Makefile	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ boot/Makefile	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -115,5 +115,5 @@
 		cp "$(USPACE_PATH)/$(DRVS_PATH)/$$file_dir/$$file_name/$$file_name.dev" "$(DIST_PATH)/$(DRVS_PATH)/$$file_name/" ; \
 	done
-	for file in $(RD_DRV_FW) ; do \
+	for file in $(RD_DRVS_FW) ; do \
 		file_dir="`dirname "$$file"`" ; \
 		file_name="`basename "$$file"`" ; \
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ boot/Makefile.common	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -139,11 +139,11 @@
 	nic/rtl8139 \
 	nic/rtl8169 \
-        nic/ar9271 \
+	nic/ar9271 \
 	block/ahci
 
 RD_DRV_CFG =
 
-RD_DRV_FW = \
-        nic/ar9271
+RD_DRVS_FW_NON_ESSENTIAL = \
+	nic/ar9271
 
 RD_LIBS =
@@ -228,5 +228,5 @@
 	$(USPACE_PATH)/app/df/df \
 	$(USPACE_PATH)/app/fontviewer/fontviewer \
-        $(USPACE_PATH)/app/wifi_supplicant/wifi_supplicant
+	$(USPACE_PATH)/app/wifi_supplicant/wifi_supplicant
 
 RD_TESTS = \
@@ -252,8 +252,10 @@
 RD_APPS = $(RD_APPS_ESSENTIAL)
 RD_DRVS = $(RD_DRVS_ESSENTIAL)
+RD_DRVS_FW = $(RD_DRVS_FW_ESSENTIAL)
 else
 RD_SRVS = $(RD_SRVS_ESSENTIAL) $(RD_SRVS_NON_ESSENTIAL)
 RD_APPS = $(RD_APPS_ESSENTIAL) $(RD_APPS_NON_ESSENTIAL)
 RD_DRVS = $(RD_DRVS_ESSENTIAL) $(RD_DRVS_NON_ESSENTIAL)
+RD_DRVS_FW = $(RD_DRVS_FW_ESSENTIAL) $(RD_DRVS_FW_NON_ESSENTIAL)
 endif
 
Index: boot/arch/amd64/Makefile.inc
===================================================================
--- boot/arch/amd64/Makefile.inc	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ boot/arch/amd64/Makefile.inc	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -61,5 +61,5 @@
 RD_DRV_CFG += \
 	bus/isa
-	
+
 RD_APPS_ESSENTIAL += \
 	$(USPACE_PATH)/app/edit/edit \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/Makefile	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -252,5 +252,5 @@
 	lib/mbr \
 	lib/gpt \
-	lib/ieee80211 \
+	lib/ieee80211
 
 LIBC_BUILD = $(addsuffix .build,$(LIBC))
Index: uspace/app/wifi_supplicant/Makefile
===================================================================
--- uspace/app/wifi_supplicant/Makefile	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/app/wifi_supplicant/Makefile	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -35,3 +35,3 @@
 	wifi_supplicant.c
 
-include $(USPACE_PREFIX)/Makefile.common 
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/wifi_supplicant/wifi_supplicant.c
===================================================================
--- uspace/app/wifi_supplicant/wifi_supplicant.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/app/wifi_supplicant/wifi_supplicant.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -42,7 +42,8 @@
 #include <loc.h>
 
-#define NAME "wifi_supplicant"
-
-#define enum_name(name_arr, i) ((i < 0) ? "NA" : name_arr[i])
+#define NAME  "wifi_supplicant"
+
+#define enum_name(name_arr, i) \
+	((i < 0) ? "NA" : name_arr[i])
 
 static const char* ieee80211_security_type_strs[] = {
@@ -65,23 +66,21 @@
 	printf("\tlist - list wifi devices in <index>: <name> format\n");
 	printf("\tscan <index> [-n] - output scan results (force scan "
-		"immediately)\n");
+	    "immediately)\n");
 	printf("\tconnect <index> <ssid_prefix> [<password>] - connect to "
-		"network\n");
+	    "network\n");
 	printf("\tdisconnect <index> - disconnect from network\n");
 }
 
-static char *nic_addr_format(nic_address_t *a)
-{
-	int rc;
-	char *s;
-
-	rc = asprintf(&s, "%02x:%02x:%02x:%02x:%02x:%02x",
-	    a->address[0], a->address[1], a->address[2],
-	    a->address[3], a->address[4], a->address[5]);
-
+static char *nic_addr_format(nic_address_t *addr)
+{
+	char *str;
+	int rc = asprintf(&str, "%02x:%02x:%02x:%02x:%02x:%02x",
+	    addr->address[0], addr->address[1], addr->address[2],
+	    addr->address[3], addr->address[4], addr->address[5]);
+	
 	if (rc < 0)
 		return NULL;
-
-	return s;
+	
+	return str;
 }
 
@@ -89,5 +88,4 @@
 {
 	category_id_t wifi_cat;
-
 	int rc = loc_category_get_id("ieee80211", &wifi_cat, 0);
 	if (rc != EOK) {
@@ -95,5 +93,5 @@
 		return rc;
 	}
-
+	
 	rc = loc_category_get_svcs(wifi_cat, wifis, count);
 	if (rc != EOK) {
@@ -107,9 +105,8 @@
 static async_sess_t *get_wifi_by_index(size_t i)
 {
-	int rc;
+	service_id_t *wifis = NULL;
 	size_t count;
-	service_id_t *wifis = NULL;
-
-	rc = get_wifi_list(&wifis, &count);
+	
+	int rc = get_wifi_list(&wifis, &count);
 	if (rc != EOK) {
 		printf("Error fetching wifi list.\n");
@@ -117,12 +114,12 @@
 	}
 	
-	if(i >= count) {
+	if (i >= count) {
 		printf("Invalid wifi index.\n");
 		free(wifis);
 		return NULL;
 	}
-
-	async_sess_t *sess = 
-		loc_service_connect(EXCHANGE_SERIALIZE, wifis[i], 0);
+	
+	async_sess_t *sess =
+	    loc_service_connect(EXCHANGE_SERIALIZE, wifis[i], 0);
 	if (sess == NULL) {
 		printf("Error connecting to service.\n");
@@ -130,5 +127,5 @@
 		return NULL;
 	}
-
+	
 	return sess;
 }
@@ -138,15 +135,14 @@
 	service_id_t *wifis = NULL;
 	size_t count;
-	char *svc_name;
-	int rc;
-
-	rc = get_wifi_list(&wifis, &count);
+	
+	int rc = get_wifi_list(&wifis, &count);
 	if (rc != EOK) {
 		printf("Error fetching wifi list.\n");
 		return EINVAL;
 	}
-
+	
 	printf("[Index]: [Service Name]\n");
 	for (size_t i = 0; i < count; i++) {
+		char *svc_name;
 		rc = loc_service_get_name(wifis[i], &svc_name);
 		if (rc != EOK) {
@@ -157,8 +153,8 @@
 		
 		printf("%zu: %s\n", i, svc_name);
-
+		
 		free(svc_name);
 	}
-
+	
 	return EOK;
 }
@@ -171,5 +167,5 @@
 	if (sess == NULL) {
 		printf("Specified WIFI doesn't exist or cannot connect to "
-			"it.\n");
+		    "it.\n");
 		return EINVAL;
 	}
@@ -177,10 +173,9 @@
 	int rc = ieee80211_disconnect(sess);
 	if(rc != EOK) {
-		if(rc == EREFUSED) {
-			printf("Device is not ready yet.\n");			
-		} else {
+		if (rc == EREFUSED)
+			printf("Device is not ready yet.\n");
+		else
 			printf("Error when disconnecting device. "
-				"Error: %d\n", rc);
-		}
+			    "Error: %d\n", rc);
 		
 		return rc;
@@ -189,19 +184,18 @@
 	rc = ieee80211_connect(sess, ssid_start, password);
 	if(rc != EOK) {
-		if(rc == EREFUSED) {
-			printf("Device is not ready yet.\n");			
-		} else if(rc == ETIMEOUT) {
+		if (rc == EREFUSED)
+			printf("Device is not ready yet.\n");
+		else if (rc == ETIMEOUT)
 			printf("Timeout when authenticating to network.\n");
-		} else if(rc == ENOENT) {
+		else if (rc == ENOENT)
 			printf("Given SSID not in scan results.\n");
-		} else {
+		else
 			printf("Error when connecting to network. "
-				"Error: %d\n", rc);
-		}
-		
-		return rc;
-	}
-	
-	// TODO: Wait for DHCP address ?
+			    "Error: %d\n", rc);
+		
+		return rc;
+	}
+	
+	// TODO: Wait for DHCP address?
 	
 	printf("Successfully connected to network!\n");
@@ -215,18 +209,18 @@
 	if (sess == NULL) {
 		printf("Specified WIFI doesn't exist or cannot connect to "
-			"it.\n");
+		    "it.\n");
 		return EINVAL;
 	}
 	
 	int rc = ieee80211_disconnect(sess);
-	if(rc != EOK) {
-		if(rc == EREFUSED) {
+	if (rc != EOK) {
+		if (rc == EREFUSED)
 			printf("Device is not ready yet.\n");
-		} else if(rc == EINVAL) {
+		else if (rc == EINVAL)
 			printf("Not connected to any WiFi network.\n");
-		} else {
+		else
 			printf("Error when disconnecting from network. "
-				"Error: %d\n", rc);
-		}
+			    "Error: %d\n", rc);
+		
 		return rc;
 	}
@@ -239,46 +233,38 @@
 static int wifi_scan(uint32_t index, bool now)
 {
-	ieee80211_scan_results_t scan_results;
-	
 	async_sess_t *sess = get_wifi_by_index(index);
 	if (sess == NULL) {
 		printf("Specified WIFI doesn't exist or cannot connect to "
-			"it.\n");
+		    "it.\n");
 		return EINVAL;
 	}
 	
+	ieee80211_scan_results_t scan_results;
 	int rc = ieee80211_get_scan_results(sess, &scan_results, now);
-	if(rc != EOK) {
-		if(rc == EREFUSED) {
+	if (rc != EOK) {
+		if (rc == EREFUSED)
 			printf("Device is not ready yet.\n");
-		} else {
+		else
 			printf("Failed to fetch scan results. Error: %d\n", rc);
-		}
-		
-		return rc;
-	}
-	
-	if(scan_results.length == 0)
+		
+		return rc;
+	}
+	
+	if (scan_results.length == 0)
 		return EOK;
 	
-	printf("%16.16s %17s %4s %5s %5s %7s %7s\n", 
-		"SSID", "MAC", "CHAN", "TYPE", "AUTH", "UNI-ALG", "GRP-ALG");
-	
-	for(int i = 0; i < scan_results.length; i++) {
+	printf("%16.16s %17s %4s %5s %5s %7s %7s\n",
+	    "SSID", "MAC", "CHAN", "TYPE", "AUTH", "UNI-ALG", "GRP-ALG");
+	
+	for (uint8_t i = 0; i < scan_results.length; i++) {
 		ieee80211_scan_result_t result = scan_results.results[i];
 		
-		printf("%16.16s %17s %4d %5s %5s %7s %7s\n", 
-			result.ssid, 
-			nic_addr_format(&result.bssid),
-			result.channel,
-			enum_name(ieee80211_security_type_strs,
-				result.security.type),
-			enum_name(ieee80211_security_auth_strs,
-				result.security.auth),
-			enum_name(ieee80211_security_alg_strs,
-				result.security.pair_alg),
-			enum_name(ieee80211_security_alg_strs,
-				result.security.group_alg)
-		);
+		printf("%16.16s %17s %4d %5s %5s %7s %7s\n",
+		    result.ssid, nic_addr_format(&result.bssid),
+		    result.channel,
+		    enum_name(ieee80211_security_type_strs, result.security.type),
+		    enum_name(ieee80211_security_auth_strs, result.security.auth),
+		    enum_name(ieee80211_security_alg_strs, result.security.pair_alg),
+		    enum_name(ieee80211_security_alg_strs, result.security.group_alg));
 	}
 	
@@ -288,11 +274,8 @@
 int main(int argc, char *argv[])
 {
-	int rc;
-	uint32_t index;
-	
-	rc = inetcfg_init();
-	if (rc != EOK) {
-		printf(NAME ": Failed connecting to inetcfg service (%d).\n",
-		    rc);
+	int rc = inetcfg_init();
+	if (rc != EOK) {
+		printf("%s: Failed connecting to inetcfg service (%d).\n",
+		    NAME, rc);
 		return 1;
 	}
@@ -300,35 +283,38 @@
 	rc = dhcp_init();
 	if (rc != EOK) {
-		printf(NAME ": Failed connecting to dhcp service (%d).\n", rc);
+		printf("%s: Failed connecting to dhcp service (%d).\n",
+		    NAME, rc);
 		return 1;
 	}
 	
-	if(argc == 2) {
-		if(!str_cmp(argv[1], "list")) {
+	if (argc == 2) {
+		if (!str_cmp(argv[1], "list"))
 			return wifi_list();
-		}
-	} else if(argc > 2) {
+	} else if (argc > 2) {
+		uint32_t index;
 		rc = str_uint32_t(argv[2], NULL, 10, false, &index);
-		if(rc != EOK) {
-			printf(NAME ": Invalid argument.\n");
+		if (rc != EOK) {
+			printf("%s: Invalid argument.\n", NAME);
 			print_syntax();
 			return EINVAL;
 		}
-		if(!str_cmp(argv[1], "scan")) {
+		
+		if (!str_cmp(argv[1], "scan")) {
 			bool now = false;
-			if(argc > 3)
-				if(!str_cmp(argv[3], "-n"))
+			if (argc > 3)
+				if (!str_cmp(argv[3], "-n"))
 					now = true;
+			
 			return wifi_scan(index, now);
-		} else if(!str_cmp(argv[1], "connect")) {
+		} else if (!str_cmp(argv[1], "connect")) {
 			char *pass = NULL;
-			if(argc > 3) {
-				if(argc > 4)
+			if (argc > 3) {
+				if (argc > 4)
 					pass = argv[4];
+				
 				return wifi_connect(index, argv[3], pass);
-			} 
-		} else if(!str_cmp(argv[1], "disconnect")) {
+			}
+		} else if (!str_cmp(argv[1], "disconnect"))
 			return wifi_disconnect(index);
-		}
 	}
 	
Index: uspace/drv/nic/ar9271/Makefile
===================================================================
--- uspace/drv/nic/ar9271/Makefile	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/Makefile	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -36,5 +36,5 @@
 	$(LIBIEEE80211_PREFIX)/libieee80211.a \
 	$(LIBCRYPTO_PREFIX)/libcrypto.a
-	
+
 EXTRA_CFLAGS += \
 	-I. \
@@ -45,5 +45,5 @@
 	-I$(LIBIEEE80211_PREFIX)/include \
 	-I$(LIBCRYPTO_PREFIX)
-	
+
 BINARY = ar9271
 
Index: uspace/drv/nic/ar9271/ar9271.c
===================================================================
--- uspace/drv/nic/ar9271/ar9271.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/ar9271.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -42,5 +42,4 @@
 #include <nic.h>
 #include <macros.h>
-
 #include "ath_usb.h"
 #include "wmi.h"
@@ -48,6 +47,6 @@
 #include "ar9271.h"
 
-#define NAME "ar9271"
-#define FIRMWARE_FILENAME "/drv/ar9271/ar9271.fw"
+#define NAME  "ar9271"
+#define FIRMWARE_FILENAME  "/drv/ar9271/ar9271.fw"
 
 const usb_endpoint_description_t usb_ar9271_out_bulk_endpoint_description = {
@@ -91,6 +90,6 @@
 	&usb_ar9271_out_bulk_endpoint_description,
 	&usb_ar9271_in_bulk_endpoint_description,
-        &usb_ar9271_in_int_endpoint_description,
-        &usb_ar9271_out_int_endpoint_description,
+	&usb_ar9271_in_int_endpoint_description,
+	&usb_ar9271_out_int_endpoint_description,
 	NULL
 };
@@ -100,13 +99,10 @@
 
 /* IEEE 802.11 callbacks */
-static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev);
-static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
-	void *buffer, size_t buffer_size);
-static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev,
-	uint16_t freq);
-static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *ieee80211_dev,
-	bool connected);
-static int ar9271_ieee80211_key_config(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_key_config_t *key_conf, bool insert);
+static int ar9271_ieee80211_start(ieee80211_dev_t *);
+static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *, void *, size_t);
+static int ar9271_ieee80211_set_freq(ieee80211_dev_t *, uint16_t);
+static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *, bool);
+static int ar9271_ieee80211_key_config(ieee80211_dev_t *, ieee80211_key_config_t *,
+    bool);
 
 static driver_ops_t ar9271_driver_ops = {
@@ -129,8 +125,8 @@
 static ieee80211_iface_t ar9271_ieee80211_iface;
 
-static int ar9271_get_device_info(ddf_fun_t *dev, nic_device_info_t *info);
+static int ar9271_get_device_info(ddf_fun_t *, nic_device_info_t *);
 static int ar9271_get_cable_state(ddf_fun_t *, nic_cable_state_t *);
-static int ar9271_get_operation_mode(ddf_fun_t *, int *, 
-	nic_channel_mode_t *, nic_role_t *);
+static int ar9271_get_operation_mode(ddf_fun_t *, int *, nic_channel_mode_t *,
+    nic_role_t *);
 
 static nic_iface_t ar9271_ieee80211_nic_iface = {
@@ -142,6 +138,5 @@
 static ddf_dev_ops_t ar9271_ieee80211_dev_ops;
 
-/** 
- * Get device information.
+/** Get device information.
  *
  */
@@ -153,5 +148,5 @@
 	memset(info, 0, sizeof(nic_device_info_t));
 	
-	info->vendor_id = 0x0CF3;
+	info->vendor_id = 0x0cf3;
 	info->device_id = 0x9271;
 	str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH,
@@ -163,6 +158,5 @@
 }
 
-/** 
- * Get cable state.
+/** Get cable state.
  *
  */
@@ -174,6 +168,5 @@
 }
 
-/** 
- * Get operation mode of the device.
+/** Get operation mode of the device.
  *
  */
@@ -188,36 +181,28 @@
 }
 
-/** 
- * Set multicast frames acceptance mode.
- *
- */
-static int ar9271_on_multicast_mode_change(nic_t *nic, 
-	nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)
-{
-	/*
-	ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) 
-		nic_get_specific(nic);
-	ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
-	 */
-	
+/** Set multicast frames acceptance mode.
+ *
+ */
+static int ar9271_on_multicast_mode_change(nic_t *nic,
+    nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)
+{
 	switch (mode) {
-		case NIC_MULTICAST_BLOCKED:
-			/* TODO */
-			break;
-		case NIC_MULTICAST_LIST:
-			/* TODO */
-			break;
-		case NIC_MULTICAST_PROMISC:
-			/* TODO */
-			break;
-		default:
-			return ENOTSUP;
-	}
-	
-	return EOK;
-}
-
-/** 
- * Set unicast frames acceptance mode.
+	case NIC_MULTICAST_BLOCKED:
+		/* TODO */
+		break;
+	case NIC_MULTICAST_LIST:
+		/* TODO */
+		break;
+	case NIC_MULTICAST_PROMISC:
+		/* TODO */
+		break;
+	default:
+		return ENOTSUP;
+	}
+	
+	return EOK;
+}
+
+/** Set unicast frames acceptance mode.
  *
  */
@@ -225,52 +210,39 @@
     const nic_address_t *addr, size_t addr_cnt)
 {
-	/*
-	ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) 
-		nic_get_specific(nic);
-	ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
-	 */
-	
 	switch (mode) {
-		case NIC_UNICAST_BLOCKED:
-			/* TODO */
-			break;
-		case NIC_UNICAST_DEFAULT:
-			/* TODO */
-			break;
-		case NIC_UNICAST_LIST:
-			/* TODO */
-			break;
-		case NIC_UNICAST_PROMISC:
-			/* TODO */
-			break;
-		default:
-			return ENOTSUP;
-	}
-	
-	return EOK;
-}
-
-/** 
- * Set broadcast frames acceptance mode.
- *
- */
-static int ar9271_on_broadcast_mode_change(nic_t *nic, 
-	nic_broadcast_mode_t mode)
-{
-	/*
-	ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) 
-		nic_get_specific(nic);
-	ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
-	 */
-	
+	case NIC_UNICAST_BLOCKED:
+		/* TODO */
+		break;
+	case NIC_UNICAST_DEFAULT:
+		/* TODO */
+		break;
+	case NIC_UNICAST_LIST:
+		/* TODO */
+		break;
+	case NIC_UNICAST_PROMISC:
+		/* TODO */
+		break;
+	default:
+		return ENOTSUP;
+	}
+	
+	return EOK;
+}
+
+/** Set broadcast frames acceptance mode.
+ *
+ */
+static int ar9271_on_broadcast_mode_change(nic_t *nic,
+    nic_broadcast_mode_t mode)
+{
 	switch (mode) {
-		case NIC_BROADCAST_BLOCKED:
-			/* TODO */
-			break;
-		case NIC_BROADCAST_ACCEPTED:
-			/* TODO */
-			break;
-		default:
-			return ENOTSUP;
+	case NIC_BROADCAST_BLOCKED:
+		/* TODO */
+		break;
+	case NIC_BROADCAST_ACCEPTED:
+		/* TODO */
+		break;
+	default:
+		return ENOTSUP;
 	}
 	
@@ -292,45 +264,45 @@
 	void *buffer = malloc(buffer_size);
 	
-	while(true) {
+	while (true) {
 		size_t transferred_size;
-		if(htc_read_data_message(ar9271->htc_device, 
-			buffer, buffer_size, &transferred_size) == EOK) {
-			size_t strip_length = 
-				sizeof(ath_usb_data_header_t) +
-				sizeof(htc_frame_header_t) + 
-				sizeof(htc_rx_status_t);
-			
-			if(transferred_size < strip_length)
+		if (htc_read_data_message(ar9271->htc_device,
+		    buffer, buffer_size, &transferred_size) == EOK) {
+			size_t strip_length =
+			    sizeof(ath_usb_data_header_t) +
+			    sizeof(htc_frame_header_t) +
+			    sizeof(htc_rx_status_t);
+			
+			if (transferred_size < strip_length)
 				continue;
-
-			ath_usb_data_header_t *data_header = 
-				(ath_usb_data_header_t *) buffer;
-
+			
+			ath_usb_data_header_t *data_header =
+			    (ath_usb_data_header_t *) buffer;
+			
 			/* Invalid packet. */
-			if(data_header->tag != uint16_t_le2host(RX_TAG))
+			if (data_header->tag != uint16_t_le2host(RX_TAG))
 				continue;
 			
 			htc_rx_status_t *rx_status =
-				(htc_rx_status_t *) ((void *) buffer +
-				sizeof(ath_usb_data_header_t) +
-				sizeof(htc_frame_header_t));
+			    (htc_rx_status_t *) ((void *) buffer +
+			    sizeof(ath_usb_data_header_t) +
+			    sizeof(htc_frame_header_t));
 			
 			uint16_t data_length =
-				uint16_t_be2host(rx_status->data_length);
-			
-			int16_t payload_length = 
-				transferred_size - strip_length;
-			
-			if(payload_length - data_length < 0)
+			    uint16_t_be2host(rx_status->data_length);
+			
+			int16_t payload_length =
+			    transferred_size - strip_length;
+			
+			if (payload_length - data_length < 0)
 				continue;
 			
-			if(ar9271_rx_status_error(rx_status->status))
+			if (ar9271_rx_status_error(rx_status->status))
 				continue;
 			
 			void *strip_buffer = buffer + strip_length;
-
+			
 			ieee80211_rx_handler(ar9271->ieee80211_dev,
-				strip_buffer,
-				payload_length);
+			    strip_buffer,
+			    payload_length);
 		}
 	}
@@ -341,10 +313,9 @@
 }
 
-/** 
- * IEEE 802.11 handlers. 
- */
-
+/** IEEE 802.11 handlers.
+ *
+ */
 static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev,
-	uint16_t freq)
+    uint16_t freq)
 {
 	assert(ieee80211_dev);
@@ -357,5 +328,5 @@
 	
 	int rc = hw_freq_switch(ar9271, freq);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW switch frequency.\n");
 		return rc;
@@ -365,5 +336,5 @@
 	
 	rc = hw_rx_init(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to initialize RX.\n");
 		return rc;
@@ -371,6 +342,6 @@
 	
 	uint16_t htc_mode = host2uint16_t_be(1);
-	wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 
-		(uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
+	wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
+	    (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
 	wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL);
 	
@@ -379,44 +350,43 @@
 
 static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *ieee80211_dev,
-	bool connected)
+    bool connected)
 {
 	assert(ieee80211_dev);
 	
 	ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
-
-	if(connected) {
+	
+	if (connected) {
 		nic_address_t bssid;
 		ieee80211_query_bssid(ieee80211_dev, &bssid);
-
+		
 		htc_sta_msg_t sta_msg;
 		memset(&sta_msg, 0, sizeof(htc_sta_msg_t));
 		sta_msg.is_vif_sta = 0;
-		sta_msg.max_ampdu = 
-			host2uint16_t_be(1 << IEEE80211_MAX_AMPDU_FACTOR);
+		sta_msg.max_ampdu =
+		    host2uint16_t_be(1 << IEEE80211_MAX_AMPDU_FACTOR);
 		sta_msg.sta_index = 1;
 		sta_msg.vif_index = 0;
 		memcpy(&sta_msg.addr, bssid.address, ETH_ADDR);
-
-		wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE, 
-			(uint8_t *) &sta_msg, sizeof(sta_msg), NULL);
-
+		
+		wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE,
+		    (uint8_t *) &sta_msg, sizeof(sta_msg), NULL);
+		
 		htc_rate_msg_t rate_msg;
 		memset(&rate_msg, 0, sizeof(htc_rate_msg_t));
 		rate_msg.sta_index = 1;
 		rate_msg.is_new = 1;
-		rate_msg.legacy_rates_count = 
-			ARRAY_SIZE(ieee80211bg_data_rates);
-		memcpy(&rate_msg.legacy_rates, 
-			ieee80211bg_data_rates, 
-			ARRAY_SIZE(ieee80211bg_data_rates));
-
-		wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE, 
-			(uint8_t *) &rate_msg, sizeof(rate_msg), NULL);
-
+		rate_msg.legacy_rates_count = ARRAY_SIZE(ieee80211bg_data_rates);
+		memcpy(&rate_msg.legacy_rates,
+		    ieee80211bg_data_rates, 
+		    ARRAY_SIZE(ieee80211bg_data_rates));
+		
+		wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE,
+		    (uint8_t *) &rate_msg, sizeof(rate_msg), NULL);
+		
 		hw_set_rx_filter(ar9271, true);
 	} else {
 		uint8_t station_id = 1;
 		wmi_send_command(ar9271->htc_device, WMI_NODE_REMOVE,
-			&station_id, sizeof(station_id), NULL);
+		    &station_id, sizeof(station_id), NULL);
 		
 		hw_set_rx_filter(ar9271, false);
@@ -429,5 +399,5 @@
 
 static int ar9271_ieee80211_key_config(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_key_config_t *key_conf, bool insert)
+    ieee80211_key_config_t *key_conf, bool insert)
 {
 	assert(ieee80211_dev);
@@ -446,24 +416,24 @@
 		ieee80211_query_bssid(ieee80211_dev, &bssid);
 		
-		switch(key_conf->suite) {
-			case IEEE80211_SECURITY_SUITE_WEP40:
-				key_type = AR9271_KEY_TABLE_TYPE_WEP40;
-				break;
-			case IEEE80211_SECURITY_SUITE_WEP104:
-				key_type = AR9271_KEY_TABLE_TYPE_WEP104;
-				break;
-			case IEEE80211_SECURITY_SUITE_TKIP:
-				key_type = AR9271_KEY_TABLE_TYPE_TKIP;
-				break;
-			case IEEE80211_SECURITY_SUITE_CCMP:
-				key_type = AR9271_KEY_TABLE_TYPE_CCMP;
-				break;
-			default:
-				key_type = -1;
+		switch (key_conf->suite) {
+		case IEEE80211_SECURITY_SUITE_WEP40:
+			key_type = AR9271_KEY_TABLE_TYPE_WEP40;
+			break;
+		case IEEE80211_SECURITY_SUITE_WEP104:
+			key_type = AR9271_KEY_TABLE_TYPE_WEP104;
+			break;
+		case IEEE80211_SECURITY_SUITE_TKIP:
+			key_type = AR9271_KEY_TABLE_TYPE_TKIP;
+			break;
+		case IEEE80211_SECURITY_SUITE_CCMP:
+			key_type = AR9271_KEY_TABLE_TYPE_CCMP;
+			break;
+		default:
+			key_type = -1;
 		}
 		
-		uint8_t key_id = 
-			(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ?
-				AR9271_STA_KEY_INDEX : key_conf->id;
+		uint8_t key_id =
+		    (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ?
+		    AR9271_STA_KEY_INDEX : key_conf->id;
 		
 		reg_ptr = AR9271_KEY_TABLE(key_id);
@@ -471,19 +441,13 @@
 		data_start = (void *) key_conf->data;
 		
-		key[0] = uint32_t_le2host(
-			*((uint32_t *) data_start));
-		key[1] = uint16_t_le2host(
-			*((uint16_t *) (data_start + 4)));
-		key[2] = uint32_t_le2host(
-			*((uint32_t *) (data_start + 6)));
-		key[3] = uint16_t_le2host(
-			*((uint16_t *) (data_start + 10)));
-		key[4] = uint32_t_le2host(
-			*((uint32_t *) (data_start + 12)));
-
-		if(key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40 ||
-		   key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104) {
+		key[0] = uint32_t_le2host(*((uint32_t *) data_start));
+		key[1] = uint16_t_le2host(*((uint16_t *) (data_start + 4)));
+		key[2] = uint32_t_le2host(*((uint32_t *) (data_start + 6)));
+		key[3] = uint16_t_le2host(*((uint16_t *) (data_start + 10)));
+		key[4] = uint32_t_le2host(*((uint32_t *) (data_start + 12)));
+		
+		if ((key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40) ||
+		    (key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104))
 			key[4] &= 0xFF;
-		}
 		
 		wmi_reg_write(ar9271->htc_device, reg_ptr + 0, key[0]);
@@ -494,58 +458,47 @@
 		wmi_reg_write(ar9271->htc_device, reg_ptr + 20, key_type);
 		
-		uint32_t macL, macH;
-		if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) {
+		uint32_t macl;
+		uint32_t mach;
+		if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) {
 			data_start = (void *) bssid.address;
-			macL = uint32_t_le2host(*((uint32_t *) data_start));
-			macH = uint16_t_le2host(*((uint16_t *) 
-				(data_start + 4)));
+			macl = uint32_t_le2host(*((uint32_t *) data_start));
+			mach = uint16_t_le2host(*((uint16_t *) (data_start + 4)));
 		} else {
-			macL = macH = 0;
+			macl = 0;
+			mach = 0;
 		}
 		
-		macL >>= 1;
-		macL |= (macH & 1) << 31;
-		macH >>= 1;
-		macH |= 0x8000;
-		
-		wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macL);
-		wmi_reg_write(ar9271->htc_device, reg_ptr + 28, macH);
+		macl >>= 1;
+		macl |= (mach & 1) << 31;
+		mach >>= 1;
+		mach |= 0x8000;
+		
+		wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macl);
+		wmi_reg_write(ar9271->htc_device, reg_ptr + 28, mach);
 		
 		/* Setup MIC keys for TKIP. */
-		if(key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) {
+		if (key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) {
 			uint32_t mic[5];
-			uint8_t *gen_mic = 
-				data_start + IEEE80211_TKIP_RX_MIC_OFFSET;
+			uint8_t *gen_mic = data_start + IEEE80211_TKIP_RX_MIC_OFFSET;
 			uint8_t *tx_mic;
-			if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) {
+			
+			if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
 				tx_mic = gen_mic;
-			} else {
-				tx_mic = data_start + 
-					IEEE80211_TKIP_TX_MIC_OFFSET;
-			}
-			
-			mic[0] = uint32_t_le2host(
-				*((uint32_t *) gen_mic));
-			mic[1] = uint16_t_le2host(
-				*((uint16_t *) (tx_mic + 2))) & 0xFFFF;
-			mic[2] = uint32_t_le2host(
-				*((uint32_t *) (gen_mic + 4)));
-			mic[3] = uint16_t_le2host(
-				*((uint16_t *) tx_mic)) & 0xFFFF;
-			mic[4] = uint32_t_le2host(
-				*((uint32_t *) (tx_mic + 4)));
-			
-			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, 
-				mic[0]);
-			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, 
-				mic[1]);
-			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 8, 
-				mic[2]);
-			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 12, 
-				mic[3]);
-			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 16, 
-				mic[4]);
-			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20, 
-				AR9271_KEY_TABLE_TYPE_CLR);
+			else
+				tx_mic = data_start + IEEE80211_TKIP_TX_MIC_OFFSET;
+			
+			mic[0] = uint32_t_le2host(*((uint32_t *) gen_mic));
+			mic[1] = uint16_t_le2host(*((uint16_t *) (tx_mic + 2))) & 0xFFFF;
+			mic[2] = uint32_t_le2host(*((uint32_t *) (gen_mic + 4)));
+			mic[3] = uint16_t_le2host(*((uint16_t *) tx_mic)) & 0xFFFF;
+			mic[4] = uint32_t_le2host(*((uint32_t *) (tx_mic + 4)));
+			
+			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, mic[0]);
+			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, mic[1]);
+			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 8, mic[2]);
+			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 12, mic[3]);
+			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 16, mic[4]);
+			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20,
+			    AR9271_KEY_TABLE_TYPE_CLR);
 			
 			wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 24, 0);
@@ -553,5 +506,5 @@
 		}
 		
-		if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
+		if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
 			ieee80211_setup_key_confirm(ieee80211_dev, true);
 	} else {
@@ -564,9 +517,10 @@
 
 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
-	void *buffer, size_t buffer_size)
+    void *buffer, size_t buffer_size)
 {
 	assert(ieee80211_dev);
 	
-	size_t complete_size, offset;
+	size_t complete_size;
+	size_t offset;
 	void *complete_buffer;
 	int endpoint;
@@ -575,18 +529,18 @@
 	
 	uint16_t frame_ctrl = *((uint16_t *) buffer);
-	if(ieee80211_is_data_frame(frame_ctrl)) {
+	if (ieee80211_is_data_frame(frame_ctrl)) {
 		offset = sizeof(htc_tx_data_header_t) +
-			sizeof(htc_frame_header_t);
+		    sizeof(htc_frame_header_t);
 		complete_size = buffer_size + offset;
 		complete_buffer = malloc(complete_size);
 		memset(complete_buffer, 0, complete_size);
 		
-		/* 
+		/*
 		 * Because we handle just station mode yet, node ID and VIF ID
 		 * are fixed.
 		 */
 		htc_tx_data_header_t *data_header =
-			(htc_tx_data_header_t *) 
-			(complete_buffer + sizeof(htc_frame_header_t));
+		    (htc_tx_data_header_t *)
+		    (complete_buffer + sizeof(htc_frame_header_t));
 		data_header->data_type = HTC_DATA_NORMAL;
 		data_header->node_idx = 1;
@@ -594,22 +548,21 @@
 		data_header->cookie = 0;
 		
-		if(ieee80211_query_using_key(ieee80211_dev)) {
+		if (ieee80211_query_using_key(ieee80211_dev)) {
 			data_header->keyix = AR9271_STA_KEY_INDEX;
-			int sec_suite = 
-				ieee80211_get_pairwise_security(ieee80211_dev);
-			switch(sec_suite) {
-				case IEEE80211_SECURITY_SUITE_WEP40:
-				case IEEE80211_SECURITY_SUITE_WEP104:
-					data_header->key_type =
-						AR9271_KEY_TYPE_WEP;
-					break;
-				case IEEE80211_SECURITY_SUITE_TKIP:
-					data_header->key_type =
-						AR9271_KEY_TYPE_TKIP;
-					break;
-				case IEEE80211_SECURITY_SUITE_CCMP:
-					data_header->key_type =
-						AR9271_KEY_TYPE_AES;
-					break;
+			
+			int sec_suite =
+			    ieee80211_get_pairwise_security(ieee80211_dev);
+			
+			switch (sec_suite) {
+			case IEEE80211_SECURITY_SUITE_WEP40:
+			case IEEE80211_SECURITY_SUITE_WEP104:
+				data_header->key_type = AR9271_KEY_TYPE_WEP;
+				break;
+			case IEEE80211_SECURITY_SUITE_TKIP:
+				data_header->key_type = AR9271_KEY_TYPE_TKIP;
+				break;
+			case IEEE80211_SECURITY_SUITE_CCMP:
+				data_header->key_type = AR9271_KEY_TYPE_AES;
+				break;
 			}
 		} else {
@@ -621,16 +574,16 @@
 	} else {
 		offset = sizeof(htc_tx_management_header_t) +
-			sizeof(htc_frame_header_t);
+		    sizeof(htc_frame_header_t);
 		complete_size = buffer_size + offset;
 		complete_buffer = malloc(complete_size);
 		memset(complete_buffer, 0, complete_size);
 		
-		/* 
+		/*
 		 * Because we handle just station mode yet, node ID and VIF ID
 		 * are fixed.
 		 */
 		htc_tx_management_header_t *mgmt_header =
-			(htc_tx_management_header_t *) 
-			(complete_buffer + sizeof(htc_frame_header_t));
+		    (htc_tx_management_header_t *)
+		    (complete_buffer + sizeof(htc_frame_header_t));
 		mgmt_header->node_idx = 0;
 		mgmt_header->vif_idx = 0;
@@ -645,5 +598,5 @@
 	
 	htc_send_data_message(ar9271->htc_device, complete_buffer,
-		complete_size, endpoint);
+	    complete_size, endpoint);
 	
 	free(complete_buffer);
@@ -661,5 +614,5 @@
 	
 	int rc = hw_reset(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to do HW reset.\n");
 		return rc;
@@ -667,6 +620,6 @@
 	
 	uint16_t htc_mode = host2uint16_t_be(1);
-	wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 
-		(uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
+	wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
+	    (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
 	wmi_send_command(ar9271->htc_device, WMI_ATH_INIT, NULL, 0, NULL);
 	wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL);
@@ -674,5 +627,5 @@
 	
 	rc = hw_rx_init(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to initialize RX.\n");
 		return rc;
@@ -681,14 +634,14 @@
 	/* Send capability message to target. */
 	htc_cap_msg_t cap_msg;
-	cap_msg.ampdu_limit = host2uint32_t_be(0xFFFF);
-	cap_msg.ampdu_subframes = 0xFF;
+	cap_msg.ampdu_limit = host2uint32_t_be(0xffff);
+	cap_msg.ampdu_subframes = 0xff;
 	cap_msg.enable_coex = 0;
 	cap_msg.tx_chainmask = 0x1;
 	
 	wmi_send_command(ar9271->htc_device, WMI_TARGET_IC_UPDATE,
-		(uint8_t *) &cap_msg, sizeof(cap_msg), NULL);
+	    (uint8_t *) &cap_msg, sizeof(cap_msg), NULL);
 	
 	rc = htc_init_new_vif(ar9271->htc_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to initialize new VIF.\n");
 		return rc;
@@ -697,7 +650,7 @@
 	/* Add data polling fibril. */
 	fid_t fibril = fibril_create(ar9271_data_polling, ar9271);
-	if (fibril == 0) {
+	if (fibril == 0)
 		return ENOMEM;
-	}
+	
 	fibril_add_ready(fibril);
 	
@@ -725,5 +678,5 @@
 	
 	int rc = ath_usb_init(ar9271->ath_device, usb_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		free(ar9271->ath_device);
 		usb_log_error("Failed to initialize ath device.\n");
@@ -741,17 +694,17 @@
 	
 	rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271->ddf_dev);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		free(ar9271->ieee80211_dev);
 		free(ar9271->ath_device);
 		usb_log_error("Failed to initialize IEEE80211 device structure."
-			"\n");
+		    "\n");
 		return rc;
 	}
 	
 	ieee80211_set_specific(ar9271->ieee80211_dev, ar9271);
-		
+	
 	/* HTC device structure initialization. */
 	ar9271->htc_device = calloc(1, sizeof(htc_device_t));
-	if(!ar9271->htc_device) {
+	if (!ar9271->htc_device) {
 		free(ar9271->ieee80211_dev);
 		free(ar9271->ath_device);
@@ -761,7 +714,7 @@
 	}
 	
-	rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev, 
-		ar9271->htc_device);
-	if(rc != EOK) {
+	rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev,
+	    ar9271->htc_device);
+	if (rc != EOK) {
 		free(ar9271->htc_device);
 		free(ar9271->ieee80211_dev);
@@ -774,18 +727,16 @@
 }
 
-/**
- * Upload firmware to WiFi device.
- * 
+/** Upload firmware to WiFi device.
+ *
  * @param ar9271 AR9271 device structure
- * 
+ *
  * @return EOK if succeed, negative error code otherwise
+ *
  */
 static int ar9271_upload_fw(ar9271_t *ar9271)
 {
-	int rc;
-	
 	usb_device_t *usb_device = ar9271->usb_device;
-        
-        /* TODO: Set by maximum packet size in pipe. */
+	
+	/* TODO: Set by maximum packet size in pipe. */
 	static const size_t MAX_TRANSFER_SIZE = 512;
 	
@@ -802,10 +753,10 @@
 	
 	void *fw_data = malloc(file_size);
-	if(fw_data == NULL) {
+	if (fw_data == NULL) {
 		fclose(fw_file);
 		usb_log_error("Failed allocating memory for firmware.\n");
 		return ENOMEM;
 	}
-
+	
 	fread(fw_data, file_size, 1, fw_file);
 	fclose(fw_file);
@@ -816,8 +767,9 @@
 	uint8_t *current_data = fw_data;
 	uint8_t *buffer = malloc(MAX_TRANSFER_SIZE);
-	while(remain_size > 0) {
+	
+	while (remain_size > 0) {
 		size_t chunk_size = min(remain_size, MAX_TRANSFER_SIZE);
 		memcpy(buffer, current_data, chunk_size);
-		rc = usb_control_request_set(&usb_device->ctrl_pipe,
+		int rc = usb_control_request_set(&usb_device->ctrl_pipe,
 		    USB_REQUEST_TYPE_VENDOR,
 		    USB_REQUEST_RECIPIENT_DEVICE,
@@ -825,5 +777,5 @@
 		    uint16_host2usb(current_addr >> 8),
 		    0, buffer, chunk_size);
-		if(rc != EOK) {
+		if (rc != EOK) {
 			free(fw_data);
 			free(buffer);
@@ -841,9 +793,10 @@
 	free(buffer);
 	
-	/* Send command that firmware is successfully uploaded. 
-         * This should initiate creating confirmation message in
-         * device side buffer which we will check in htc_check_ready function.
-         */
-	rc = usb_control_request_set(&usb_device->ctrl_pipe,
+	/*
+	 * Send command that firmware is successfully uploaded.
+	 * This should initiate creating confirmation message in
+	 * device side buffer which we will check in htc_check_ready function.
+	*/
+	int rc = usb_control_request_set(&usb_device->ctrl_pipe,
 	    USB_REQUEST_TYPE_VENDOR,
 	    USB_REQUEST_RECIPIENT_DEVICE,
@@ -852,7 +805,7 @@
 	    0, NULL, 0);
 	
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("IO error when sending fw upload confirmation "
-                        "message.\n");
+		    "message.\n");
 		return rc;
 	}
@@ -867,7 +820,7 @@
 
 /** Create driver data structure.
- * 
+ *
  *  @param dev The device structure
- * 
+ *
  *  @return Intialized device data structure or NULL if error occured
  */
@@ -883,5 +836,5 @@
 	const char *err_msg = NULL;
 	int rc = usb_device_init(usb_device, dev, endpoints, &err_msg);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		free(usb_device);
 		usb_log_error("Failed to create USB device: %s, "
@@ -902,9 +855,9 @@
 	
 	rc = ar9271_init(ar9271, usb_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		free(ar9271);
 		free(usb_device);
-		usb_log_error("Failed to initialize AR9271 structure: %d\n", 
-			rc);
+		usb_log_error("Failed to initialize AR9271 structure: %d\n",
+		    rc);
 		return NULL;
 	}
@@ -948,5 +901,5 @@
 	/* Initialize AR9271 HTC services. */
 	int rc = htc_init(ar9271->htc_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		ar9271_delete_dev_data(ar9271);
 		usb_log_error("HTC initialization failed.\n");
@@ -956,5 +909,5 @@
 	/* Initialize AR9271 HW. */
 	rc = hw_init(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		ar9271_delete_dev_data(ar9271);
 		usb_log_error("HW initialization failed.\n");
@@ -964,7 +917,7 @@
 	/* Initialize AR9271 IEEE 802.11 framework. */
 	rc = ieee80211_init(ar9271->ieee80211_dev, &ar9271_ieee80211_ops,
-		&ar9271_ieee80211_iface, &ar9271_ieee80211_nic_iface,
-		&ar9271_ieee80211_dev_ops);
-	if(rc != EOK) {
+	    &ar9271_ieee80211_iface, &ar9271_ieee80211_nic_iface,
+	    &ar9271_ieee80211_dev_ops);
+	if (rc != EOK) {
 		ar9271_delete_dev_data(ar9271);
 		usb_log_error("Failed to initialize IEEE80211 framework.\n");
@@ -973,6 +926,6 @@
 	
 	nic_set_filtering_change_handlers(nic_get_from_ddf_dev(dev),
-		ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change,
-		ar9271_on_broadcast_mode_change, NULL, NULL);
+	    ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change,
+	    ar9271_on_broadcast_mode_change, NULL, NULL);
 	
 	usb_log_info("HelenOS AR9271 added device.\n");
@@ -989,5 +942,5 @@
 	
 	usb_log_info("HelenOS AR9271 driver started.\n");
-
+	
 	return ddf_driver_main(&ar9271_driver);
 }
Index: uspace/drv/nic/ar9271/ar9271.h
===================================================================
--- uspace/drv/nic/ar9271/ar9271.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/ar9271.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -37,22 +37,21 @@
 
 #include <usb/dev/driver.h>
-
 #include "htc.h"
 
 /** Number of transmission queues */
-#define AR9271_QUEUES_COUNT 10
+#define AR9271_QUEUES_COUNT  10
 
 /** Number of GPIO pin used for handling led light */
-#define AR9271_LED_PIN 15
+#define AR9271_LED_PIN  15
 
 /** Nominal value for AR9271 noise floor calibration. */
-#define AR9271_CALIB_NOMINAL_VALUE_2GHZ -118
+#define AR9271_CALIB_NOMINAL_VALUE_2GHZ  -118
 
 /** RX errors values. */
-#define AR9271_RX_ERROR_CRC 0x01
-#define AR9271_RX_ERROR_PHY 0x02
+#define AR9271_RX_ERROR_CRC  0x01
+#define AR9271_RX_ERROR_PHY  0x02
 
 /** Key index used for device in station mode. */
-#define AR9271_STA_KEY_INDEX 4
+#define AR9271_STA_KEY_INDEX  4
 
 /* HW encryption key indicator. */
@@ -83,14 +82,14 @@
 	AR9271_RC = 0x4000,
 	AR9271_RC_AHB = 0x00000001,
-		
+	
 	/* GPIO registers */
-	AR9271_GPIO_IN_OUT = 0x4048,		/**< GPIO value read/set  */
-	AR9271_GPIO_OE_OUT = 0x404C,		/**< GPIO set to output  */
-	AR9271_GPIO_OE_OUT_ALWAYS = 0x3,	/**< GPIO always drive output */
+	AR9271_GPIO_IN_OUT = 0x4048,       /**< GPIO value read/set  */
+	AR9271_GPIO_OE_OUT = 0x404C,       /**< GPIO set to output  */
+	AR9271_GPIO_OE_OUT_ALWAYS = 0x3,   /**< GPIO always drive output */
 	AR9271_GPIO_OUT_MUX1 = 0x4060,
 	AR9271_GPIO_OUT_MUX2 = 0x4064,
 	AR9271_GPIO_OUT_MUX3 = 0x4068,
-	AR9271_GPIO_OUT_MUX_AS_OUT = 0x0,	/**< GPIO set mux as output */
-    
+	AR9271_GPIO_OUT_MUX_AS_OUT = 0x0,  /**< GPIO set mux as output */
+	
 	/* RTC related registers */
 	AR9271_RTC_RC = 0x7000,
@@ -109,18 +108,18 @@
 	AR9271_RTC_FORCE_WAKE_ENABLE = 0x00000001,
 	AR9271_RTC_FORCE_WAKE_ON_INT = 0x00000002,
-		
+	
 	/* MAC Registers */
-	AR9271_STATION_ID0 = 0x8000,	/**< STA Address Lower 32 Bits */
-	AR9271_STATION_ID1 = 0x8004,	/**< STA Address Upper 16 Bits */
-	AR9271_BSSID0 = 0x8008,		/**< BSSID Lower 32 Bits */
-	AR9271_BSSID1 = 0x800C,		/**< BSSID Upper 16 Bits */
-	AR9271_BSSID_MASK0 = 0x80E0,	/**< BSSID Mask Lower 32 Bits */
-	AR9271_BSSID_MASK1 = 0x80E4,	/**< BSSID Mask Upper 16 Bits */
+	AR9271_STATION_ID0 = 0x8000,  /**< STA Address Lower 32 Bits */
+	AR9271_STATION_ID1 = 0x8004,  /**< STA Address Upper 16 Bits */
+	AR9271_BSSID0 = 0x8008,       /**< BSSID Lower 32 Bits */
+	AR9271_BSSID1 = 0x800C,       /**< BSSID Upper 16 Bits */
+	AR9271_BSSID_MASK0 = 0x80E0,  /**< BSSID Mask Lower 32 Bits */
+	AR9271_BSSID_MASK1 = 0x80E4,  /**< BSSID Mask Upper 16 Bits */
 	AR9271_STATION_ID1_MASK = 0x0000FFFF,
 	AR9271_STATION_ID1_POWER_SAVING = 0x00040000,
 	AR9271_MULTICAST_FILTER1 = 0x8040,
-	AR9271_MULTICAST_FILTER2 = 0x8044,	
+	AR9271_MULTICAST_FILTER2 = 0x8044,
 	AR9271_DIAG = 0x8048,
-		
+	
 	/* RX filtering register */
 	AR9271_RX_FILTER = 0x803C,
@@ -134,5 +133,5 @@
 	AR9271_RX_FILTER_MYBEACON = 0x00000200,
 	AR9271_RX_FILTER_MCAST_BCAST_ALL = 0x00008000,
-		
+	
 	/* Key related registers */
 	AR9271_KEY_TABLE_BASE = 0x8800,
@@ -142,5 +141,5 @@
 	AR9271_KEY_TABLE_TYPE_CCMP = 0x6,
 	AR9271_KEY_TABLE_TYPE_CLR = 0x7,
-		
+	
 	/* Physical layer registers */
 	AR9271_PHY_ACTIVE = 0x981C,
@@ -168,15 +167,15 @@
 	AR9271_PHY_TPCRG1_PD_CALIB = 0x00400000,
 	AR9271_CARRIER_LEAK_CALIB = 0x00000002,
-		
+	
 	AR9271_OPMODE_STATION_AP_MASK =	0x00010000,
 	AR9271_OPMODE_ADHOC_MASK = 0x00020000,
-		
+	
 	AR9271_CLOCK_CONTROL = 0x50040,
 	AR9271_MAX_CPU_CLOCK = 0x304,
-		
+	
 	AR9271_RESET_POWER_DOWN_CONTROL = 0x50044,
 	AR9271_RADIO_RF_RESET = 0x20,
 	AR9271_GATE_MAC_CONTROL = 0x4000,
-    
+	
 	/* FW Addresses */
 	AR9271_FW_ADDRESS = 0x501000,
@@ -185,5 +184,5 @@
 
 /** Compute key table base position for key by its id. */
-#define AR9271_KEY_TABLE(id) (AR9271_KEY_TABLE_BASE + (id)*32)
+#define AR9271_KEY_TABLE(id)  (AR9271_KEY_TABLE_BASE + (id) * 32)
 
 /** AR9271 Requests */
@@ -217,10 +216,12 @@
 } ar9271_t;
 
-/**
- * AR9271 init values for 2GHz mode operation.
- * 
+/** AR9271 init values for 2GHz mode operation.
+ *
  * Including settings of noise floor limits.
- * 
- * Taken from Linux sources.
+ *
+ * Taken from the Linux driver (drivers/net/wireless/ath/ath9k/)
+ * Copyright (c) 2008-2011 Atheros Communications Inc.
+ * Licensed under the terms of ISC
+ *
  */
 static const uint32_t ar9271_2g_mode_array[][2] = {
@@ -232,8 +233,8 @@
 	{0x0000801c, 0x12e0002b},
 	{0x00008318, 0x00003440},
-	{0x00009804, 0x000003c0},/*< note: overridden */
+	{0x00009804, 0x000003c0},  /*< Note: overridden */
 	{0x00009820, 0x02020200},
 	{0x00009824, 0x01000e0e},
-	{0x00009828, 0x0a020001},/*< note: overridden */
+	{0x00009828, 0x0a020001},  /*< Note: overridden */
 	{0x00009834, 0x00000e0e},
 	{0x00009838, 0x00000007},
@@ -530,8 +531,10 @@
 };
 
-/**
- * AR9271 TX init values for 2GHz mode operation.
- * 
- * Taken from Linux sources.
+/** AR9271 TX init values for 2GHz mode operation.
+ *
+ * Taken from the Linux driver (drivers/net/wireless/ath/ath9k/)
+ * Copyright (c) 2008-2011 Atheros Communications Inc.
+ * Licensed under the terms of ISC
+ *
  */
 static const uint32_t ar9271_2g_tx_array[][2] = {
@@ -571,8 +574,10 @@
 };
 
-/**
- * AR9271 hardware init values.
- * 
- * Taken from Linux sources, some values omitted.
+/** AR9271 hardware init values.
+ *
+ * Taken from the Linux driver (drivers/net/wireless/ath/ath9k/)
+ * Copyright (c) 2008-2011 Atheros Communications Inc.
+ * Licensed under the terms of ISC
+ *
  */
 static const uint32_t ar9271_init_array[][2] = {
@@ -766,5 +771,5 @@
 	{0x0000833c, 0x00000000},
 	{0x00008340, 0x00010380},
-	{0x00008344, 0x00481083},/*< note: disabled ADHOC_MCAST_KEYID feature */
+	{0x00008344, 0x00481083},  /**< Note: disabled ADHOC_MCAST_KEYID feature */
 	{0x00007010, 0x00000030},
 	{0x00007034, 0x00000002},
Index: uspace/drv/nic/ar9271/ath.h
===================================================================
--- uspace/drv/nic/ar9271/ath.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/ath.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -34,5 +34,5 @@
 
 #ifndef ATHEROS_ATH_H
-#define	ATHEROS_ATH_H
+#define ATHEROS_ATH_H
 
 struct ath;
@@ -61,3 +61,3 @@
 } ath_t;
 
-#endif	/* ATHEROS_ATH_H */
+#endif  /* ATHEROS_ATH_H */
Index: uspace/drv/nic/ar9271/ath_usb.c
===================================================================
--- uspace/drv/nic/ar9271/ath_usb.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/ath_usb.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -36,18 +36,10 @@
 #include <usb/debug.h>
 #include <malloc.h>
-
 #include "ath_usb.h"
 
-static int ath_usb_send_ctrl_message(ath_t *ath, void *buffer, 
-	size_t buffer_size);
-
-static int ath_usb_read_ctrl_message(ath_t *ath, void *buffer, 
-	size_t buffer_size, size_t *transferred_size);
-
-static int ath_usb_send_data_message(ath_t *ath, void *buffer, 
-	size_t buffer_size);
-
-static int ath_usb_read_data_message(ath_t *ath, void *buffer, 
-	size_t buffer_size, size_t *transferred_size);
+static int ath_usb_send_ctrl_message(ath_t *, void *, size_t);
+static int ath_usb_read_ctrl_message(ath_t *, void *, size_t, size_t *);
+static int ath_usb_send_data_message(ath_t *, void *, size_t);
+static int ath_usb_read_data_message(ath_t *, void *, size_t, size_t *);
 
 static ath_ops_t ath_usb_ops = {
@@ -58,11 +50,11 @@
 };
 
-/**
- * Initialize Atheros WiFi USB device.
- * 
+/** Initialize Atheros WiFi USB device.
+ *
  * @param ath Generic Atheros WiFi device structure.
- * @param usb_device Connected USB device.
- * 
+ * @param usb_device  Connected USB device.
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ath_usb_init(ath_t *ath, usb_device_t *usb_device)
@@ -92,75 +84,72 @@
 }
 
-/**
- * Send control message.
- * 
- * @param ath Generic Atheros WiFi device structure. 
- * @param buffer Buffer with data to send.
+/** Send control message.
+ *
+ * @param ath         Generic Atheros WiFi device structure.
+ * @param buffer      Buffer with data to send.
  * @param buffer_size Buffer size.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
-static int ath_usb_send_ctrl_message(ath_t *ath, void *buffer, 
-	size_t buffer_size)
+static int ath_usb_send_ctrl_message(ath_t *ath, void *buffer,
+    size_t buffer_size)
 {
 	ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
-	usb_pipe_t *pipe = 
-		&ath_usb->usb_device->pipes[ath_usb->output_ctrl_pipe_number].
-		pipe;
+	usb_pipe_t *pipe =
+	    &ath_usb->usb_device->pipes[ath_usb->output_ctrl_pipe_number].pipe;
 	
 	return usb_pipe_write(pipe, buffer, buffer_size);
 }
 
-/**
- * Read control message.
- * 
- * @param ath Generic Atheros WiFi device structure. 
- * @param buffer Buffer with data to send.
- * @param buffer_size Buffer size.
+/** Read control message.
+ *
+ * @param ath              Generic Atheros WiFi device structure.
+ * @param buffer           Buffer with data to send.
+ * @param buffer_size      Buffer size.
  * @param transferred_size Real size of read data.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
-static int ath_usb_read_ctrl_message(ath_t *ath, void *buffer, 
-	size_t buffer_size, size_t *transferred_size)
+static int ath_usb_read_ctrl_message(ath_t *ath, void *buffer,
+    size_t buffer_size, size_t *transferred_size)
 {
 	ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
-	usb_pipe_t *pipe = 
-		&ath_usb->usb_device->pipes[ath_usb->input_ctrl_pipe_number].
-		pipe;
+	usb_pipe_t *pipe =
+	    &ath_usb->usb_device->pipes[ath_usb->input_ctrl_pipe_number].pipe;
 	
 	return usb_pipe_read(pipe, buffer, buffer_size, transferred_size);
 }
 
-/**
- * Send data message.
- * 
- * @param ath Generic Atheros WiFi device structure. 
- * @param buffer Buffer with data to send.
+/** Send data message.
+ *
+ * @param ath         Generic Atheros WiFi device structure. 
+ * @param buffer      Buffer with data to send.
  * @param buffer_size Buffer size.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
-static int ath_usb_send_data_message(ath_t *ath, void *buffer, 
-	size_t buffer_size)
+static int ath_usb_send_data_message(ath_t *ath, void *buffer,
+    size_t buffer_size)
 {
-	size_t complete_buffer_size = buffer_size + 
-		sizeof(ath_usb_data_header_t);
+	size_t complete_buffer_size = buffer_size +
+	    sizeof(ath_usb_data_header_t);
 	void *complete_buffer = malloc(complete_buffer_size);
-	memcpy(complete_buffer + sizeof(ath_usb_data_header_t), 
-		buffer, buffer_size);
+	memcpy(complete_buffer + sizeof(ath_usb_data_header_t),
+	    buffer, buffer_size);
 	
-	ath_usb_data_header_t *data_header = 
-		(ath_usb_data_header_t *) complete_buffer;
+	ath_usb_data_header_t *data_header =
+	    (ath_usb_data_header_t *) complete_buffer;
 	data_header->length = host2uint16_t_le(buffer_size);
 	data_header->tag = host2uint16_t_le(TX_TAG);
 	
 	ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
-	usb_pipe_t *pipe = 
-		&ath_usb->usb_device->pipes[ath_usb->output_data_pipe_number].
-		pipe;
+	usb_pipe_t *pipe =
+	    &ath_usb->usb_device->pipes[ath_usb->output_data_pipe_number].pipe;
 	
-	int ret_val = usb_pipe_write(pipe, complete_buffer, 
-		complete_buffer_size);
+	int ret_val = usb_pipe_write(pipe, complete_buffer,
+	    complete_buffer_size);
 	
 	free(complete_buffer);
@@ -169,23 +158,22 @@
 }
 
-/**
- * Read data message.
- * 
- * @param ath Generic Atheros WiFi device structure. 
- * @param buffer Buffer with data to send.
- * @param buffer_size Buffer size.
+/** Read data message.
+ *
+ * @param ath              Generic Atheros WiFi device structure.
+ * @param buffer           Buffer with data to send.
+ * @param buffer_size      Buffer size.
  * @param transferred_size Real size of read data.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
-static int ath_usb_read_data_message(ath_t *ath, void *buffer, 
-	size_t buffer_size, size_t *transferred_size)
+static int ath_usb_read_data_message(ath_t *ath, void *buffer,
+    size_t buffer_size, size_t *transferred_size)
 {
 	ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
-	usb_pipe_t *pipe = 
-		&ath_usb->usb_device->pipes[ath_usb->input_data_pipe_number].
-		pipe;
+	usb_pipe_t *pipe =
+	    &ath_usb->usb_device->pipes[ath_usb->input_data_pipe_number].pipe;
 	
-	return usb_pipe_read(pipe, buffer, buffer_size, 
-		transferred_size);
+	return usb_pipe_read(pipe, buffer, buffer_size,
+	    transferred_size);
 }
Index: uspace/drv/nic/ar9271/ath_usb.h
===================================================================
--- uspace/drv/nic/ar9271/ath_usb.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/ath_usb.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -34,12 +34,11 @@
 
 #ifndef ATHEROS_ATH_USB_H
-#define	ATHEROS_ATH_USB_H
+#define ATHEROS_ATH_USB_H
 
 #include <usb/dev/driver.h>
-
 #include "ath.h"
 
-#define RX_TAG 0x4e00
-#define TX_TAG 0x697e
+#define RX_TAG  0x4e00
+#define TX_TAG  0x697e
 
 /** Atheros USB wifi device structure */
@@ -56,9 +55,9 @@
 
 typedef struct {
-	uint16_t length;		/**< Little Endian value! */
-	uint16_t tag;			/**< Little Endian value! */
+	uint16_t length;  /**< Little Endian value! */
+	uint16_t tag;     /**< Little Endian value! */
 } ath_usb_data_header_t;
 
-extern int ath_usb_init(ath_t *ath, usb_device_t *usb_device);
+extern int ath_usb_init(ath_t *, usb_device_t *);
 
-#endif	/* ATHEROS_ATH_USB_H */
+#endif  /* ATHEROS_ATH_USB_H */
Index: uspace/drv/nic/ar9271/htc.c
===================================================================
--- uspace/drv/nic/ar9271/htc.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/htc.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -36,5 +36,4 @@
 #include <byteorder.h>
 #include <errno.h>
-
 #include "wmi.h"
 #include "htc.h"
@@ -42,10 +41,10 @@
 #include "ar9271.h"
 
-/**
- * HTC download pipes mapping.
- * 
+/** HTC download pipes mapping.
+ *
  * @param service_id Identification of WMI service.
- * 
+ *
  * @return Number of pipe used for this service.
+ *
  */
 static inline uint8_t wmi_service_to_download_pipe(wmi_services_t service_id)
@@ -54,10 +53,10 @@
 }
 
-/**
- * HTC upload pipes mapping.
- * 
+/** HTC upload pipes mapping.
+ *
  * @param service_id Identification of WMI service.
- * 
+ *
  * @return Number of pipe used for this service.
+ *
  */
 static inline uint8_t wmi_service_to_upload_pipe(wmi_services_t service_id)
@@ -75,8 +74,6 @@
 	
 	nic_address_t addr;
-	nic_t *nic = 
-		nic_get_from_ddf_dev(
-			ieee80211_get_ddf_dev(htc_device->ieee80211_dev)
-		);
+	nic_t *nic =
+	    nic_get_from_ddf_dev(ieee80211_get_ddf_dev(htc_device->ieee80211_dev));
 	nic_query_address(nic, &addr);
 	
@@ -84,20 +81,20 @@
 	memcpy(&sta_msg.addr, &addr.address, ETH_ADDR);
 	
-	ieee80211_operating_mode_t op_mode = 
-		ieee80211_query_current_op_mode(htc_device->ieee80211_dev);
-	
-	switch(op_mode) {
-		case IEEE80211_OPMODE_ADHOC:
-			vif_msg.op_mode = HTC_OPMODE_ADHOC;
-			break;
-		case IEEE80211_OPMODE_AP:
-			vif_msg.op_mode = HTC_OPMODE_AP;
-			break;
-		case IEEE80211_OPMODE_MESH:
-			vif_msg.op_mode = HTC_OPMODE_MESH;
-			break;
-		case IEEE80211_OPMODE_STATION:
-			vif_msg.op_mode = HTC_OPMODE_STATION;
-			break;
+	ieee80211_operating_mode_t op_mode =
+	    ieee80211_query_current_op_mode(htc_device->ieee80211_dev);
+	
+	switch (op_mode) {
+	case IEEE80211_OPMODE_ADHOC:
+		vif_msg.op_mode = HTC_OPMODE_ADHOC;
+		break;
+	case IEEE80211_OPMODE_AP:
+		vif_msg.op_mode = HTC_OPMODE_AP;
+		break;
+	case IEEE80211_OPMODE_MESH:
+		vif_msg.op_mode = HTC_OPMODE_MESH;
+		break;
+	case IEEE80211_OPMODE_STATION:
+		vif_msg.op_mode = HTC_OPMODE_STATION;
+		break;
 	}
 	
@@ -105,6 +102,6 @@
 	vif_msg.rts_thres = host2uint16_t_be(HTC_RTS_THRESHOLD);
 	
-	wmi_send_command(htc_device, WMI_VAP_CREATE, (uint8_t *) &vif_msg, 
-		sizeof(vif_msg), NULL);
+	wmi_send_command(htc_device, WMI_VAP_CREATE, (uint8_t *) &vif_msg,
+	    sizeof(vif_msg), NULL);
 	
 	sta_msg.is_vif_sta = 1;
@@ -113,6 +110,6 @@
 	sta_msg.vif_index = 0;
 	
-	wmi_send_command(htc_device, WMI_NODE_CREATE, (uint8_t *) &sta_msg, 
-		sizeof(sta_msg), NULL);
+	wmi_send_command(htc_device, WMI_NODE_CREATE, (uint8_t *) &sta_msg,
+	    sizeof(sta_msg), NULL);
 	
 	/* Write first 4 bytes of MAC address. */
@@ -121,9 +118,9 @@
 	id0 = host2uint32_t_le(id0);
 	wmi_reg_write(htc_device, AR9271_STATION_ID0, id0);
-
+	
 	/* Write last 2 bytes of MAC address (and preserve existing data). */
 	uint32_t id1;
 	wmi_reg_read(htc_device, AR9271_STATION_ID1, &id1);
-
+	
 	uint16_t id1_addr;
 	memcpy(&id1_addr, &addr.address[4], 2);
@@ -134,113 +131,116 @@
 }
 
-static void htc_config_frame_header(htc_frame_header_t *header, 
-	size_t buffer_size, uint8_t endpoint_id)
+static void htc_config_frame_header(htc_frame_header_t *header,
+    size_t buffer_size, uint8_t endpoint_id)
 {
 	memset(header, 0, sizeof(htc_frame_header_t));
 	
 	header->endpoint_id = endpoint_id;
-	header->payload_length = 
-		host2uint16_t_be(buffer_size - sizeof(htc_frame_header_t));
-}
-
-/**
- * Send control HTC message to USB device.
- * 
- * @param htc_device HTC device structure.
- * @param buffer Buffer with data to be sent to USB device (without HTC frame
- *              header).
+	header->payload_length =
+	    host2uint16_t_be(buffer_size - sizeof(htc_frame_header_t));
+}
+
+/** Send control HTC message to USB device.
+ *
+ * @param htc_device  HTC device structure.
+ * @param buffer      Buffer with data to be sent to USB device
+ *                    (without HTC frame header).
  * @param buffer_size Size of buffer (including HTC frame header).
  * @param endpoint_id Destination endpoint.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int htc_send_control_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, uint8_t endpoint_id)
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int htc_send_control_message(htc_device_t *htc_device, void *buffer,
+    size_t buffer_size, uint8_t endpoint_id)
 {
 	htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size,
-		endpoint_id);
+	    endpoint_id);
 	
 	ath_t *ath_device = htc_device->ath_device;
 	
-	return ath_device->ops->send_ctrl_message(ath_device, buffer, 
-		buffer_size);
-}
-
-/**
- * Send data HTC message to USB device.
- * 
- * @param htc_device HTC device structure.
- * @param buffer Buffer with data to be sent to USB device (without HTC frame
- *              header).
+	return ath_device->ops->send_ctrl_message(ath_device, buffer,
+	    buffer_size);
+}
+
+/** Send data HTC message to USB device.
+ *
+ * @param htc_device  HTC device structure.
+ * @param buffer      Buffer with data to be sent to USB device
+ *                    (without HTC frame header).
  * @param buffer_size Size of buffer (including HTC frame header).
  * @param endpoint_id Destination endpoint.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int htc_send_data_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, uint8_t endpoint_id)
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int htc_send_data_message(htc_device_t *htc_device, void *buffer,
+    size_t buffer_size, uint8_t endpoint_id)
 {
 	htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size,
-		endpoint_id);
+	    endpoint_id);
 	
 	ath_t *ath_device = htc_device->ath_device;
 	
-	return ath_device->ops->send_data_message(ath_device, buffer, 
-		buffer_size);
-}
-
-/**
- * Read HTC data message from USB device.
- * 
- * @param htc_device HTC device structure.
- * @param buffer Buffer where data from USB device will be stored.
- * @param buffer_size Size of buffer.
+	return ath_device->ops->send_data_message(ath_device, buffer,
+	    buffer_size);
+}
+
+/** Read HTC data message from USB device.
+ *
+ * @param htc_device       HTC device structure.
+ * @param buffer           Buffer where data from USB device
+ *                         will be stored.
+ * @param buffer_size      Size of buffer.
  * @param transferred_size Real size of read data.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int htc_read_data_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, size_t *transferred_size)
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int htc_read_data_message(htc_device_t *htc_device, void *buffer,
+    size_t buffer_size, size_t *transferred_size)
 {
 	ath_t *ath_device = htc_device->ath_device;
 	
-	return ath_device->ops->read_data_message(ath_device, buffer, 
-		buffer_size, transferred_size);
-}
-
-/**
- * Read HTC control message from USB device.
- * 
- * @param htc_device HTC device structure.
- * @param buffer Buffer where data from USB device will be stored.
- * @param buffer_size Size of buffer.
+	return ath_device->ops->read_data_message(ath_device, buffer,
+	    buffer_size, transferred_size);
+}
+
+/** Read HTC control message from USB device.
+ *
+ * @param htc_device       HTC device structure.
+ * @param buffer           Buffer where data from USB device
+ *                         will be stored.
+ * @param buffer_size      Size of buffer.
  * @param transferred_size Real size of read data.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int htc_read_control_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, size_t *transferred_size)
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int htc_read_control_message(htc_device_t *htc_device, void *buffer,
+    size_t buffer_size, size_t *transferred_size)
 {
 	ath_t *ath_device = htc_device->ath_device;
 	
-	return ath_device->ops->read_ctrl_message(ath_device, buffer, 
-		buffer_size, transferred_size);
-}
-
-/**
- * Initialize HTC service.
- * 
- * @param htc_device HTC device structure.
- * @param service_id Identification of WMI service.
- * @param response_endpoint_no HTC endpoint to be used for this service.
- * 
- * @return EOK if succeed, EINVAL when failed to connect service, 
- * negative error code otherwise.
- */
-static int htc_connect_service(htc_device_t *htc_device, 
+	return ath_device->ops->read_ctrl_message(ath_device, buffer,
+	    buffer_size, transferred_size);
+}
+
+/** Initialize HTC service.
+ *
+ * @param htc_device           HTC device structure.
+ * @param service_id           Identification of WMI service.
+ * @param response_endpoint_no HTC endpoint to be used for
+ *                             this service.
+ *
+ * @return EOK if succeed, EINVAL when failed to connect service,
+ *         negative error code otherwise.
+ *
+ */
+static int htc_connect_service(htc_device_t *htc_device,
     wmi_services_t service_id, int *response_endpoint_no)
 {
-	size_t buffer_size = sizeof(htc_frame_header_t) + 
-		sizeof(htc_service_msg_t);
+	size_t buffer_size = sizeof(htc_frame_header_t) +
+	    sizeof(htc_service_msg_t);
 	void *buffer = malloc(buffer_size);
 	memset(buffer, 0, buffer_size);
@@ -248,19 +248,19 @@
 	/* Fill service message structure. */
 	htc_service_msg_t *service_message = (htc_service_msg_t *)
-		((void *) buffer + sizeof(htc_frame_header_t));
-	service_message->service_id = 
-		host2uint16_t_be(service_id);
-	service_message->message_id = 
-		host2uint16_t_be(HTC_MESSAGE_CONNECT_SERVICE);
-	service_message->download_pipe_id = 
-		wmi_service_to_download_pipe(service_id);
-	service_message->upload_pipe_id = 
-		wmi_service_to_upload_pipe(service_id);
+	    ((void *) buffer + sizeof(htc_frame_header_t));
+	service_message->service_id =
+	    host2uint16_t_be(service_id);
+	service_message->message_id =
+	    host2uint16_t_be(HTC_MESSAGE_CONNECT_SERVICE);
+	service_message->download_pipe_id =
+	    wmi_service_to_download_pipe(service_id);
+	service_message->upload_pipe_id =
+	    wmi_service_to_upload_pipe(service_id);
 	service_message->connection_flags = 0;
 	
 	/* Send HTC message. */
 	int rc = htc_send_control_message(htc_device, buffer, buffer_size,
-		htc_device->endpoints.ctrl_endpoint);
-	if(rc != EOK) {
+	    htc_device->endpoints.ctrl_endpoint);
+	if (rc != EOK) {
 		free(buffer);
 		usb_log_error("Failed to send HTC message. Error: %d\n", rc);
@@ -275,24 +275,27 @@
 	/* Read response from device. */
 	rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		free(buffer);
 		usb_log_error("Failed to receive HTC service connect response. "
-			"Error: %d\n", rc);
+		    "Error: %d\n", rc);
 		return rc;
 	}
 	
 	htc_service_resp_msg_t *response_message = (htc_service_resp_msg_t *)
-		((void *) buffer + sizeof(htc_frame_header_t));
-
-	/* If service was successfully connected, write down HTC endpoint number
-	 * that will be used for communication. */
-	if(response_message->status == HTC_SERVICE_SUCCESS) {
+	    ((void *) buffer + sizeof(htc_frame_header_t));
+	
+	/*
+	 * If service was successfully connected,
+	 * write down HTC endpoint number that will
+	 * be used for communication.
+	 */
+	if (response_message->status == HTC_SERVICE_SUCCESS) {
 		*response_endpoint_no = response_message->endpoint_id;
 		rc = EOK;
 	} else {
 		usb_log_error("Failed to connect HTC service. "
-			"Message status: %d\n", response_message->status);
+		    "Message status: %d\n", response_message->status);
 		rc = EINVAL;
-        }
+	}
 	
 	free(buffer);
@@ -301,32 +304,32 @@
 }
 
-/**
- * HTC credits initialization message.
- * 
+/** HTC credits initialization message.
+ *
  * @param htc_device HTC device structure.
- * 
- * @return EOK if succeed, negative error code otherwise.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int htc_config_credits(htc_device_t *htc_device)
 {
-	size_t buffer_size = sizeof(htc_frame_header_t) + 
-		sizeof(htc_config_msg_t);
+	size_t buffer_size = sizeof(htc_frame_header_t) +
+	    sizeof(htc_config_msg_t);
 	void *buffer = malloc(buffer_size);
 	htc_config_msg_t *config_message = (htc_config_msg_t *)
-		((void *) buffer + sizeof(htc_frame_header_t));
+	    ((void *) buffer + sizeof(htc_frame_header_t));
 	
 	config_message->message_id = 
-		host2uint16_t_be(HTC_MESSAGE_CONFIG);
+	    host2uint16_t_be(HTC_MESSAGE_CONFIG);
 	/* Magic number to initialize device. */
 	config_message->credits = 33;
 	config_message->pipe_id = 1;
-
+	
 	/* Send HTC message. */
 	int rc = htc_send_control_message(htc_device, buffer, buffer_size,
-		htc_device->endpoints.ctrl_endpoint);
-	if(rc != EOK) {
+	    htc_device->endpoints.ctrl_endpoint);
+	if (rc != EOK) {
 		free(buffer);
 		usb_log_error("Failed to send HTC config message. "
-			"Error: %d\n", rc);
+		    "Error: %d\n", rc);
 		return rc;
 	}
@@ -336,57 +339,57 @@
 	buffer_size = htc_device->ath_device->ctrl_response_length;
 	buffer = malloc(buffer_size);
-
+	
 	/* Check response from device. */
 	rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to receive HTC config response message. "
-			"Error: %d\n", rc);
+		    "Error: %d\n", rc);
 	}
 	
 	free(buffer);
-
+	
 	return rc;
 }
 
-/**
- * HTC setup complete confirmation message.
- * 
+/** HTC setup complete confirmation message.
+ *
  * @param htc_device HTC device structure.
- * 
- * @return EOK if succeed, negative error code otherwise.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int htc_complete_setup(htc_device_t *htc_device)
 {
-	size_t buffer_size = sizeof(htc_frame_header_t) + 
-		sizeof(htc_setup_complete_msg_t);
+	size_t buffer_size = sizeof(htc_frame_header_t) +
+	    sizeof(htc_setup_complete_msg_t);
 	void *buffer = malloc(buffer_size);
-	htc_setup_complete_msg_t *complete_message = 
-		(htc_setup_complete_msg_t *)
-		((void *) buffer + sizeof(htc_frame_header_t));
-	
-	complete_message->message_id = 
-		host2uint16_t_be(HTC_MESSAGE_SETUP_COMPLETE);
-
+	htc_setup_complete_msg_t *complete_message =
+	    (htc_setup_complete_msg_t *)
+	    ((void *) buffer + sizeof(htc_frame_header_t));
+	
+	complete_message->message_id =
+	    host2uint16_t_be(HTC_MESSAGE_SETUP_COMPLETE);
+	
 	/* Send HTC message. */
-	int rc = htc_send_control_message(htc_device, buffer, buffer_size, 
-		htc_device->endpoints.ctrl_endpoint);
-	if(rc != EOK) {
+	int rc = htc_send_control_message(htc_device, buffer, buffer_size,
+	    htc_device->endpoints.ctrl_endpoint);
+	if (rc != EOK)
 		usb_log_error("Failed to send HTC setup complete message. "
-			"Error: %d\n", rc);
-	}
+		    "Error: %d\n", rc);
 	
 	free(buffer);
-
+	
 	return rc;
 }
 
-/**
- * Try to fetch ready message from device.
+/** Try to fetch ready message from device.
+ *
  * Checks that firmware was successfully loaded on device side.
- * 
+ *
  * @param htc_device HTC device structure.
- * 
- * @return EOK if succeed, EINVAL if response error, negative error code 
- * otherwise.
+ *
+ * @return EOK if succeed, EINVAL if response error,
+ *         negative error code otherwise.
+ *
  */
 static int htc_check_ready(htc_device_t *htc_device)
@@ -394,22 +397,21 @@
 	size_t buffer_size = htc_device->ath_device->ctrl_response_length;
 	void *buffer = malloc(buffer_size);
-
+	
 	/* Read response from device. */
-	int rc = htc_read_control_message(htc_device, buffer, buffer_size, 
-		NULL);
-	if(rc != EOK) {
+	int rc = htc_read_control_message(htc_device, buffer, buffer_size,
+	    NULL);
+	if (rc != EOK) {
 		free(buffer);
 		usb_log_error("Failed to receive HTC check ready message. "
-			"Error: %d\n", rc);
-		return rc;
-	}
-
-	uint16_t *message_id = (uint16_t *) ((void *) buffer + 
-		sizeof(htc_frame_header_t));
-	if(uint16_t_be2host(*message_id) == HTC_MESSAGE_READY) {
+		    "Error: %d\n", rc);
+		return rc;
+	}
+	
+	uint16_t *message_id = (uint16_t *) ((void *) buffer +
+	    sizeof(htc_frame_header_t));
+	if (uint16_t_be2host(*message_id) == HTC_MESSAGE_READY)
 		rc = EOK;
-	} else {
+	else
 		rc = EINVAL;
-	}
 	
 	free(buffer);
@@ -418,14 +420,15 @@
 }
 
-/**
- * Initialize HTC device structure.
- * 
- * @param ath_device Atheros WiFi device connected with this HTC device.
+/** Initialize HTC device structure.
+ *
+ * @param ath_device Atheros WiFi device connected
+ *                   with this HTC device.
  * @param htc_device HTC device structure to be initialized.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev, 
-	htc_device_t *htc_device)
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev,
+    htc_device_t *htc_device)
 {
 	fibril_mutex_initialize(&htc_device->rx_lock);
@@ -440,10 +443,10 @@
 }
 
-/**
- * HTC communication initalization.
- * 
+/** HTC communication initalization.
+ *
  * @param htc_device HTC device structure.
- * 
- * @return EOK if succeed, negative error code otherwise.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int htc_init(htc_device_t *htc_device)
@@ -451,46 +454,44 @@
 	/* First check ready message in device. */
 	int rc = htc_check_ready(htc_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Device is not in ready state after loading "
-			"firmware.\n");
-		return rc;
-	}
-
-	/* 
+		    "firmware.\n");
+		return rc;
+	}
+	
+	/*
 	 * HTC services initialization start.
-	 * 
 	 */
-	
 	rc = htc_connect_service(htc_device, WMI_CONTROL_SERVICE,
 	    &htc_device->endpoints.wmi_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing WMI service.\n");
 		return rc;
 	}
-
+	
 	rc = htc_connect_service(htc_device, WMI_BEACON_SERVICE,
 	    &htc_device->endpoints.beacon_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing beacon service.\n");
 		return rc;
 	}
-
+	
 	rc = htc_connect_service(htc_device, WMI_CAB_SERVICE,
 	    &htc_device->endpoints.cab_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing CAB service.\n");
 		return rc;
 	}
-
+	
 	rc = htc_connect_service(htc_device, WMI_UAPSD_SERVICE,
 	    &htc_device->endpoints.uapsd_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing UAPSD service.\n");
 		return rc;
 	}
-
+	
 	rc = htc_connect_service(htc_device, WMI_MGMT_SERVICE,
 	    &htc_device->endpoints.mgmt_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing MGMT service.\n");
 		return rc;
@@ -499,21 +500,21 @@
 	rc = htc_connect_service(htc_device, WMI_DATA_BE_SERVICE,
 	    &htc_device->endpoints.data_be_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing data best effort "
 		    "service.\n");
 		return rc;
 	}
-
+	
 	rc = htc_connect_service(htc_device, WMI_DATA_BK_SERVICE,
 	    &htc_device->endpoints.data_bk_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing data background "
 		    "service.\n");
 		return rc;
 	}
-
+	
 	rc = htc_connect_service(htc_device, WMI_DATA_VIDEO_SERVICE,
 	    &htc_device->endpoints.data_video_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing data video service.\n");
 		return rc;
@@ -522,28 +523,27 @@
 	rc = htc_connect_service(htc_device, WMI_DATA_VOICE_SERVICE,
 	    &htc_device->endpoints.data_voice_endpoint);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Error while initalizing data voice service.\n");
 		return rc;
 	}
-
-	/* 
+	
+	/*
 	 * HTC services initialization end.
-	 * 
 	 */
-
+	
 	/* Credits initialization message. */
 	rc = htc_config_credits(htc_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to send HTC config message.\n");
 		return rc;
 	}
-
+	
 	/* HTC setup complete confirmation message. */
 	rc = htc_complete_setup(htc_device);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to send HTC complete setup message.\n");
 		return rc;
 	}
-
+	
 	usb_log_info("HTC services initialization finished successfully.\n");
 	
Index: uspace/drv/nic/ar9271/htc.h
===================================================================
--- uspace/drv/nic/ar9271/htc.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/htc.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -29,5 +29,5 @@
 /** @file htc.h
  *
- * Definitions of the Atheros HTC (Host Target Communication) technology 
+ * Definitions of the Atheros HTC (Host Target Communication) technology
  * for communication between host (PC) and target (device firmware).
  *
@@ -35,5 +35,5 @@
 
 #ifndef ATHEROS_HTC_H
-#define	ATHEROS_HTC_H
+#define ATHEROS_HTC_H
 
 #include <ieee80211.h>
@@ -41,34 +41,33 @@
 #include <sys/types.h>
 #include <nic.h>
-
 #include "ath.h"
 
-#define HTC_RTS_THRESHOLD 2304
-#define HTC_RATES_MAX_LENGTH 30
-
-/**
- * HTC message IDs.
+#define HTC_RTS_THRESHOLD     2304
+#define HTC_RATES_MAX_LENGTH  30
+
+/** HTC message IDs.
+ *
  */
 typedef enum {
 	HTC_MESSAGE_READY = 1,
 	HTC_MESSAGE_CONNECT_SERVICE,
-        HTC_MESSAGE_CONNECT_SERVICE_RESPONSE,
-        HTC_MESSAGE_SETUP_COMPLETE,
-        HTC_MESSAGE_CONFIG
+	HTC_MESSAGE_CONNECT_SERVICE_RESPONSE,
+	HTC_MESSAGE_SETUP_COMPLETE,
+	HTC_MESSAGE_CONFIG
 } htc_message_id_t;
 
-/**
- * HTC response message status codes.
+/** HTC response message status codes.
+ *
  */
 typedef enum {
-        HTC_SERVICE_SUCCESS = 0,
-        HTC_SERVICE_NOT_FOUND,
-        HTC_SERVICE_FAILED,
-        HTC_SERVICE_NO_RESOURCES,
-        HTC_SERVICE_NO_MORE_EP
+	HTC_SERVICE_SUCCESS = 0,
+	HTC_SERVICE_NOT_FOUND,
+	HTC_SERVICE_FAILED,
+	HTC_SERVICE_NO_RESOURCES,
+	HTC_SERVICE_NO_MORE_EP
 } htc_response_status_code_t;
 
-/**
- * HTC operating mode definition.
+/** HTC operating mode definition.
+ *
  */
 typedef enum {
@@ -79,6 +78,6 @@
 } htc_operating_mode_t;
 
-/**
- * HTC data type indicator.
+/** HTC data type indicator.
+ *
  */
 typedef enum {
@@ -89,9 +88,9 @@
 } htc_data_type_t;
 
-/**
- * HTC endpoint numbers.
- */
-typedef struct {
-        int ctrl_endpoint;
+/** HTC endpoint numbers.
+ *
+ */
+typedef struct {
+	int ctrl_endpoint;
 	int wmi_endpoint;
 	int beacon_endpoint;
@@ -105,11 +104,11 @@
 } htc_pipes_t;
 
-/**
- * HTC device data.
- */
-typedef struct {
-        /** WMI message sequence number */
-        uint16_t sequence_number;
-    
+/** HTC device data.
+ *
+ */
+typedef struct {
+	/** WMI message sequence number */
+	uint16_t sequence_number;
+	
 	/** HTC endpoints numbers */
 	htc_pipes_t endpoints;
@@ -128,16 +127,16 @@
 } htc_device_t;
 
-/** 
- * HTC frame header structure.
- */
-typedef struct {
-	uint8_t   endpoint_id;
-	uint8_t   flags;
-	uint16_t  payload_length;	/**< Big Endian value! */
-	uint8_t   control_bytes[4];
+/** HTC frame header structure.
+ *
+ */
+typedef struct {
+	uint8_t endpoint_id;
+	uint8_t flags;
+	uint16_t payload_length;   /**< Big Endian value! */
+	uint8_t control_bytes[4];
 } __attribute__((packed)) htc_frame_header_t;
 
-/** 
- * HTC management TX frame header structure.
+/** HTC management TX frame header structure.
+ *
  */
 typedef struct {
@@ -152,6 +151,6 @@
 } __attribute__((packed)) htc_tx_management_header_t;
 
-/** 
- * HTC data TX frame header structure.
+/** HTC data TX frame header structure.
+ *
  */
 typedef struct {
@@ -160,5 +159,5 @@
 	uint8_t vif_idx;
 	uint8_t tidno;
-	uint32_t flags;			/**< Big Endian value! */
+	uint32_t flags;    /**< Big Endian value! */
 	uint8_t key_type;
 	uint8_t keyix;
@@ -167,23 +166,23 @@
 } __attribute__((packed)) htc_tx_data_header_t;
 
-/** 
- * HTC ready message structure.
- */
-typedef struct {
-        uint16_t message_id;		/**< Big Endian value! */
-        uint16_t credits;		/**< Big Endian value! */
-        uint16_t credit_size;		/**< Big Endian value! */
-        
-        uint8_t max_endpoints;
+/** HTC ready message structure.
+ *
+ */
+typedef struct {
+	uint16_t message_id;   /**< Big Endian value! */
+	uint16_t credits;      /**< Big Endian value! */
+	uint16_t credit_size;  /**< Big Endian value! */
+	
+	uint8_t max_endpoints;
 	uint8_t pad;
 } __attribute__((packed)) htc_ready_msg_t;
 
-/** 
- * HTC service message structure.
- */
-typedef struct {
-	uint16_t message_id;		/**< Big Endian value! */
-	uint16_t service_id;		/**< Big Endian value! */
-	uint16_t connection_flags;	/**< Big Endian value! */
+/** HTC service message structure.
+ *
+ */
+typedef struct {
+	uint16_t message_id;        /**< Big Endian value! */
+	uint16_t service_id;        /**< Big Endian value! */
+	uint16_t connection_flags;  /**< Big Endian value! */
 	
 	uint8_t download_pipe_id;
@@ -193,60 +192,60 @@
 } __attribute__((packed)) htc_service_msg_t;
 
-/** 
- * HTC service response message structure.
- */
-typedef struct {
-        uint16_t message_id;            /**< Big Endian value! */
-        uint16_t service_id;            /**< Big Endian value! */
-        uint8_t status;
-        uint8_t endpoint_id;
-        uint16_t max_message_length;    /**< Big Endian value! */
-        uint8_t service_meta_length;
-        uint8_t pad;
+/** HTC service response message structure.
+ *
+ */
+typedef struct {
+	uint16_t message_id;          /**< Big Endian value! */
+	uint16_t service_id;          /**< Big Endian value! */
+	uint8_t status;
+	uint8_t endpoint_id;
+	uint16_t max_message_length;  /**< Big Endian value! */
+	uint8_t service_meta_length;
+	uint8_t pad;
 } __attribute__((packed)) htc_service_resp_msg_t;
 
-/**
- * HTC credits config message structure.
- */
-typedef struct {
-        uint16_t message_id;            /**< Big Endian value! */
-        uint8_t pipe_id;
-        uint8_t credits;
+/** HTC credits config message structure.
+ *
+ */
+typedef struct {
+	uint16_t message_id;  /**< Big Endian value! */
+	uint8_t pipe_id;
+	uint8_t credits;
 } __attribute__((packed)) htc_config_msg_t;
 
-/**
- * HTC new virtual interface message.
- */
-typedef struct {
-        uint8_t index;
+/** HTC new virtual interface message.
+ *
+ */
+typedef struct {
+	uint8_t index;
 	uint8_t op_mode;
 	uint8_t addr[ETH_ADDR];
 	uint8_t ath_cap;
-	uint16_t rts_thres;		/**< Big Endian value! */
+	uint16_t rts_thres;      /**< Big Endian value! */
 	uint8_t pad;
 } __attribute__((packed)) htc_vif_msg_t;
 
-/**
- * HTC new station message.
+/** HTC new station message.
+ *
  */
 typedef struct {
 	uint8_t addr[ETH_ADDR];
 	uint8_t bssid[ETH_ADDR];
-        uint8_t sta_index;
+	uint8_t sta_index;
 	uint8_t vif_index;
 	uint8_t is_vif_sta;
-		
-	uint16_t flags;		/**< Big Endian value! */
-	uint16_t ht_cap;	/**< Big Endian value! */
-	uint16_t max_ampdu;	/**< Big Endian value! */
+	
+	uint16_t flags;      /**< Big Endian value! */
+	uint16_t ht_cap;     /**< Big Endian value! */
+	uint16_t max_ampdu;  /**< Big Endian value! */
 	
 	uint8_t pad;
 } __attribute__((packed)) htc_sta_msg_t;
 
-/**
- * HTC message to inform target about available capabilities.
- */
-typedef struct {
-	uint32_t ampdu_limit;	/**< Big Endian value! */
+/** HTC message to inform target about available capabilities.
+ *
+ */
+typedef struct {
+	uint32_t ampdu_limit;     /**< Big Endian value! */
 	uint8_t ampdu_subframes;
 	uint8_t enable_coex;
@@ -258,5 +257,5 @@
 	uint8_t sta_index;
 	uint8_t is_new;
-	uint32_t cap_flags;	/**< Big Endian value! */
+	uint32_t cap_flags;  /**< Big Endian value! */
 	uint8_t legacy_rates_count;
 	uint8_t legacy_rates[HTC_RATES_MAX_LENGTH];
@@ -264,10 +263,10 @@
 } htc_rate_msg_t;
 
-/**
- * HTC RX status structure used in incoming HTC data messages.
- */
-typedef struct {
-	uint64_t timestamp;	/**< Big Endian value! */
-	uint16_t data_length;	/**< Big Endian value! */
+/** HTC RX status structure used in incoming HTC data messages.
+ *
+ */
+typedef struct {
+	uint64_t timestamp;    /**< Big Endian value! */
+	uint16_t data_length;  /**< Big Endian value! */
 	uint8_t status;
 	uint8_t phy_err;
@@ -284,29 +283,23 @@
 	uint8_t flags;
 	uint8_t dummy;
-	uint32_t evm0;		/**< Big Endian value! */
-	uint32_t evm1;		/**< Big Endian value! */
-	uint32_t evm2;		/**< Big Endian value! */
+	uint32_t evm0;         /**< Big Endian value! */
+	uint32_t evm1;         /**< Big Endian value! */
+	uint32_t evm2;         /**< Big Endian value! */
 } htc_rx_status_t;
 
-/**
- * HTC setup complete message structure
- */
-typedef struct {
-        uint16_t message_id;            /**< Big Endian value! */
+/** HTC setup complete message structure
+ *
+ */
+typedef struct {
+	uint16_t message_id;  /**< Big Endian value! */
 } __attribute__((packed)) htc_setup_complete_msg_t;
 
-extern int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev, 
-	htc_device_t *htc_device);
-extern int htc_init(htc_device_t *htc_device);
-extern int htc_init_new_vif(htc_device_t *htc_device);
-extern int htc_read_control_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, size_t *transferred_size);
-extern int htc_read_data_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, size_t *transferred_size);
-extern int htc_send_control_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, uint8_t endpoint_id);
-extern int htc_send_data_message(htc_device_t *htc_device, void *buffer, 
-	size_t buffer_size, uint8_t endpoint_id);
-
-#endif	/* ATHEROS_HTC_H */
-
+extern int htc_device_init(ath_t *, ieee80211_dev_t *, htc_device_t *);
+extern int htc_init(htc_device_t *);
+extern int htc_init_new_vif(htc_device_t *);
+extern int htc_read_control_message(htc_device_t *, void *, size_t, size_t *);
+extern int htc_read_data_message(htc_device_t *, void *, size_t, size_t *);
+extern int htc_send_control_message(htc_device_t *, void *, size_t, uint8_t);
+extern int htc_send_data_message(htc_device_t *, void *, size_t, uint8_t);
+
+#endif  /* ATHEROS_HTC_H */
Index: uspace/drv/nic/ar9271/hw.c
===================================================================
--- uspace/drv/nic/ar9271/hw.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/hw.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -38,30 +38,28 @@
 #include <nic.h>
 #include <ieee80211.h>
-
 #include "hw.h"
 #include "wmi.h"
 
-/**
- * Try to wait for register value repeatedly until timeout is reached.
- * 
+/** Try to wait for register value repeatedly until timeout is reached.
+ *
  * @param ar9271 Device structure.
  * @param offset Registry offset (address) to be read.
- * @param mask Mask to apply on read result.
- * @param value Required value we are waiting for.
- * 
- * @return EOK if succeed, ETIMEOUT on timeout, negative error code otherwise.
+ * @param mask   Mask to apply on read result.
+ * @param value  Required value we are waiting for.
+ *
+ * @return EOK if succeed, ETIMEOUT on timeout,
+ *         negative error code otherwise.
+ *
  */
 static int hw_read_wait(ar9271_t *ar9271, uint32_t offset, uint32_t mask,
-	uint32_t value)
-{
-	uint32_t result;
-	
-	for(size_t i = 0; i < HW_WAIT_LOOPS; i++) {
+    uint32_t value)
+{
+	for (size_t i = 0; i < HW_WAIT_LOOPS; i++) {
 		udelay(HW_WAIT_TIME_US);
-
+		
+		uint32_t result;
 		wmi_reg_read(ar9271->htc_device, offset, &result);
-		if((result & mask) == value) {
+		if ((result & mask) == value)
 			return EOK;
-		}
 	}
 	
@@ -74,6 +72,6 @@
 		{
 			.offset = AR9271_RTC_FORCE_WAKE,
-			.value = AR9271_RTC_FORCE_WAKE_ENABLE | 
-				AR9271_RTC_FORCE_WAKE_ON_INT
+			.value = AR9271_RTC_FORCE_WAKE_ENABLE |
+			    AR9271_RTC_FORCE_WAKE_ON_INT
 		},
 		{
@@ -88,5 +86,5 @@
 	
 	wmi_reg_buffer_write(ar9271->htc_device, buffer,
-		sizeof(buffer) / sizeof(wmi_reg_t));
+	    sizeof(buffer) / sizeof(wmi_reg_t));
 	
 	udelay(2);
@@ -95,9 +93,9 @@
 	wmi_reg_write(ar9271->htc_device, AR9271_RTC_RESET, 1);
 	
-	int rc = hw_read_wait(ar9271, 
-		AR9271_RTC_STATUS, 
-		AR9271_RTC_STATUS_MASK, 
-		AR9271_RTC_STATUS_ON);
-	if(rc != EOK) {
+	int rc = hw_read_wait(ar9271,
+	    AR9271_RTC_STATUS,
+	    AR9271_RTC_STATUS_MASK,
+	    AR9271_RTC_STATUS_ON);
+	if (rc != EOK) {
 		usb_log_error("Failed to wait for RTC wake up register.\n");
 		return rc;
@@ -111,13 +109,12 @@
 	uint32_t reset_value = AR9271_RTC_RC_MAC_WARM;
 	
-	if(cold) {
+	if (cold)
 		reset_value |= AR9271_RTC_RC_MAC_COLD;
-	}
 	
 	wmi_reg_t buffer[] = {
 		{
 			.offset = AR9271_RTC_FORCE_WAKE,
-			.value = AR9271_RTC_FORCE_WAKE_ENABLE | 
-				AR9271_RTC_FORCE_WAKE_ON_INT
+			.value = AR9271_RTC_FORCE_WAKE_ENABLE |
+			    AR9271_RTC_FORCE_WAKE_ON_INT
 		},
 		{
@@ -131,6 +128,6 @@
 	};
 	
-	wmi_reg_buffer_write(ar9271->htc_device, buffer, 
-		sizeof(buffer) / sizeof(wmi_reg_t));
+	wmi_reg_buffer_write(ar9271->htc_device, buffer,
+	    sizeof(buffer) / sizeof(wmi_reg_t));
 	
 	udelay(100);
@@ -139,5 +136,5 @@
 	
 	int rc = hw_read_wait(ar9271, AR9271_RTC_RC, AR9271_RTC_RC_MASK, 0);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to wait for RTC RC register.\n");
 		return rc;
@@ -145,6 +142,6 @@
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RC, 0);
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_STATION_ID1, 
-		AR9271_STATION_ID1_POWER_SAVING);
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
+	    AR9271_STATION_ID1_POWER_SAVING);
 	
 	return EOK;
@@ -156,8 +153,7 @@
 	nic_address_t ar9271_address;
 	
-	for(int i = 0; i < 3; i++) {
-		wmi_reg_read(ar9271->htc_device, 
-			AR9271_EEPROM_MAC_ADDR_START + i*4,
-			&value);
+	for (unsigned int i = 0; i < 3; i++) {
+		wmi_reg_read(ar9271->htc_device,
+		    AR9271_EEPROM_MAC_ADDR_START + i * 4, &value);
 		
 		uint16_t two_bytes = uint16_t_be2host(value);
@@ -169,5 +165,5 @@
 	
 	int rc = nic_report_address(nic, &ar9271_address);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to report NIC HW address.\n");
 		return rc;
@@ -179,22 +175,22 @@
 static int hw_gpio_set_output(ar9271_t *ar9271, uint32_t gpio, uint32_t type)
 {
-	uint32_t address, gpio_shift, temp;
-	
-	if(gpio > 11) {
+	uint32_t address;
+	
+	if (gpio > 11)
 		address = AR9271_GPIO_OUT_MUX3;
-	} else if(gpio > 5) {
+	else if (gpio > 5)
 		address = AR9271_GPIO_OUT_MUX2;
-	} else {
+	else
 		address = AR9271_GPIO_OUT_MUX1;
-	}
-	
-	gpio_shift = (gpio % 6) * 5;
-	
+	
+	uint32_t gpio_shift = (gpio % 6) * 5;
+	
+	uint32_t temp;
 	wmi_reg_read(ar9271->htc_device, address, &temp);
-
-	temp = ((temp & 0x1F0) << 1) | (temp & ~0x1F0);
+	
+	temp = ((temp & 0x1f0) << 1) | (temp & ~0x1f0);
 	temp &= ~(0x1f << gpio_shift);
 	temp |= (type << gpio_shift);
-
+	
 	wmi_reg_write(ar9271->htc_device, address, temp);
 	
@@ -202,6 +198,6 @@
 	
 	wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT,
-		AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift, 
-		AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift);
+	    AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift,
+	    AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift);
 	
 	return EOK;
@@ -211,19 +207,19 @@
 {
 	wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_IN_OUT,
-		(~value & 1) << gpio, 1 << gpio);
-	return EOK;
-}
-
-/**
- * Hardware init procedure of AR9271 device.
- * 
+	    (~value & 1) << gpio, 1 << gpio);
+	return EOK;
+}
+
+/**Hardware init procedure of AR9271 device.
+ *
  * @param ar9271 Device structure.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int hw_init_proc(ar9271_t *ar9271)
 {
 	int rc = hw_reset_power_on(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW reset power on.\n");
 		return rc;
@@ -231,5 +227,5 @@
 	
 	rc = hw_set_reset(ar9271, false);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW warm reset.\n");
 		return rc;
@@ -237,5 +233,5 @@
 	
 	rc = hw_addr_init(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to init HW addr.\n");
 		return rc;
@@ -247,7 +243,7 @@
 static int hw_init_led(ar9271_t *ar9271)
 {
-	int rc = hw_gpio_set_output(ar9271, AR9271_LED_PIN, 
-		AR9271_GPIO_OUT_MUX_AS_OUT);
-	if(rc != EOK) {
+	int rc = hw_gpio_set_output(ar9271, AR9271_LED_PIN,
+	    AR9271_GPIO_OUT_MUX_AS_OUT);
+	if (rc != EOK) {
 		usb_log_error("Failed to set led GPIO to output.\n");
 		return rc;
@@ -255,5 +251,5 @@
 	
 	rc = hw_gpio_set_value(ar9271, AR9271_LED_PIN, 0);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to init bring up GPIO led.\n");
 		return rc;
@@ -271,26 +267,25 @@
 }
 
-static int hw_set_operating_mode(ar9271_t *ar9271, 
-	ieee80211_operating_mode_t op_mode)
+static int hw_set_operating_mode(ar9271_t *ar9271,
+    ieee80211_operating_mode_t op_mode)
 {
 	uint32_t set_bit = 0x10000000;
 	
 	switch(op_mode) {
-		case IEEE80211_OPMODE_ADHOC:
-			set_bit |= AR9271_OPMODE_ADHOC_MASK;
-			wmi_reg_set_bit(ar9271->htc_device, AR9271_CONFIG,
-				AR9271_CONFIG_ADHOC);
-			break;
-		case IEEE80211_OPMODE_MESH:
-		case IEEE80211_OPMODE_AP:
-			set_bit |= AR9271_OPMODE_STATION_AP_MASK;
-		case IEEE80211_OPMODE_STATION:
-			wmi_reg_clear_bit(ar9271->htc_device, AR9271_CONFIG,
-				AR9271_CONFIG_ADHOC);
+	case IEEE80211_OPMODE_ADHOC:
+		set_bit |= AR9271_OPMODE_ADHOC_MASK;
+		wmi_reg_set_bit(ar9271->htc_device, AR9271_CONFIG,
+		    AR9271_CONFIG_ADHOC);
+		break;
+	case IEEE80211_OPMODE_MESH:
+	case IEEE80211_OPMODE_AP:
+		set_bit |= AR9271_OPMODE_STATION_AP_MASK;
+	case IEEE80211_OPMODE_STATION:
+		wmi_reg_clear_bit(ar9271->htc_device, AR9271_CONFIG,
+		    AR9271_CONFIG_ADHOC);
 	}
 	
 	wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
-		set_bit, 
-		AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK);
+	    set_bit, AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK);
 	
 	ieee80211_report_current_op_mode(ar9271->ieee80211_dev, op_mode);
@@ -302,5 +297,5 @@
 {
 	int rc = hw_set_operating_mode(ar9271, IEEE80211_OPMODE_STATION);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to set opmode to station.\n");
 		return rc;
@@ -314,32 +309,34 @@
 	uint32_t value;
 	wmi_reg_read(ar9271->htc_device, AR9271_PHY_CAL, &value);
-	value &= 0xFFFFFE00;
-	value |= (((uint32_t) AR9271_CALIB_NOMINAL_VALUE_2GHZ << 1) & 0x1FF);
+	
+	value &= 0xfffffe00;
+	value |= (((uint32_t) AR9271_CALIB_NOMINAL_VALUE_2GHZ << 1) & 0x1ff);
+	
 	wmi_reg_write(ar9271->htc_device, AR9271_PHY_CAL, value);
 	
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB_EN);
-	
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_NOT_UPDATE);
-	
-	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB);
-	
-	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB, 0);
-	if(rc != EOK) {
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB_EN);
+	
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_NOT_UPDATE);
+	
+	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB);
+	
+	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB, 0);
+	if (rc != EOK) {
 		usb_log_error("Failed to wait for NF calibration.\n");
 		return rc;
 	}
 	
-	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB_EN);
-	
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_NOT_UPDATE);
-	
-	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB);
+	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB_EN);
+	
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_NOT_UPDATE);
+	
+	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB);
 	
 	return EOK;
@@ -349,22 +346,20 @@
 {
 	/* Not supported channel frequency. */
-	if(freq < IEEE80211_FIRST_FREQ || freq > IEEE80211_MAX_FREQ) {
+	if ((freq < IEEE80211_FIRST_FREQ) || (freq > IEEE80211_MAX_FREQ))
 		return EINVAL;
-	}
 	
 	/* Not supported channel frequency. */
-	if((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0) {
+	if ((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0)
 		return EINVAL;
-	}
 	
 	uint32_t tx_control;
 	wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &tx_control);
 	wmi_reg_write(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL,
-		tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
+	    tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
 	
 	/* Some magic here. */
 	uint32_t synth_ctl;
 	wmi_reg_read(ar9271->htc_device, AR9271_PHY_SYNTH_CONTROL, &synth_ctl);
-	synth_ctl &= 0xC0000000;
+	synth_ctl &= 0xc0000000;
 	uint32_t channel_select = (freq * 0x10000) / 15;
 	synth_ctl = synth_ctl | (1 << 29) | (1 << 28) | channel_select;
@@ -382,5 +377,5 @@
 	
 	int rc = hw_read_wait(ar9271, AR9271_PHY_RFBUS_GRANT, 0x1, 0x1);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to kill RF bus.\n");
 		return rc;
@@ -388,5 +383,5 @@
 	
 	rc = hw_set_freq(ar9271, freq);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW set frequency.\n");
 		return rc;
@@ -394,5 +389,5 @@
 	
 	rc = hw_activate_phy(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to activate physical layer.\n");
 		return rc;
@@ -403,5 +398,5 @@
 	
 	rc = hw_noise_floor_calibration(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to do NF calibration.\n");
 		return rc;
@@ -413,16 +408,14 @@
 int hw_set_rx_filter(ar9271_t *ar9271, bool assoc)
 {
-	uint32_t filter_bits;
-	
 	uint32_t additional_bits = 0;
 	
-	if(assoc) {
+	if (assoc)
 		additional_bits |= AR9271_RX_FILTER_MYBEACON;
-	} else {
+	else
 		additional_bits |= AR9271_RX_FILTER_BEACON;
-	}
-	
-	filter_bits = AR9271_RX_FILTER_UNI | AR9271_RX_FILTER_MULTI | 
-		AR9271_RX_FILTER_BROAD | additional_bits;
+	
+	uint32_t filter_bits = AR9271_RX_FILTER_UNI |
+	    AR9271_RX_FILTER_MULTI | AR9271_RX_FILTER_BROAD |
+	    additional_bits;
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits);
@@ -441,10 +434,10 @@
 	uint16_t *last_2bytes = (uint16_t *) &bssid.address[4];
 	
-	wmi_reg_write(ar9271->htc_device, AR9271_BSSID0, 
-		uint32_t_le2host(*first_4bytes));
-	
-	wmi_reg_write(ar9271->htc_device, AR9271_BSSID1, 
-		uint16_t_le2host(*last_2bytes) | 
-		((ieee80211_get_aid(ieee80211_dev) & 0x3FFF) << 16));
+	wmi_reg_write(ar9271->htc_device, AR9271_BSSID0,
+	    uint32_t_le2host(*first_4bytes));
+	
+	wmi_reg_write(ar9271->htc_device, AR9271_BSSID1,
+	    uint16_t_le2host(*last_2bytes) |
+	    ((ieee80211_get_aid(ieee80211_dev) & 0x3fff) << 16));
 	
 	return EOK;
@@ -453,9 +446,9 @@
 int hw_rx_init(ar9271_t *ar9271)
 {
-	wmi_reg_write(ar9271->htc_device, AR9271_COMMAND, 
-		AR9271_COMMAND_RX_ENABLE);
+	wmi_reg_write(ar9271->htc_device, AR9271_COMMAND,
+	    AR9271_COMMAND_RX_ENABLE);
 	
 	int rc = hw_set_rx_filter(ar9271, false);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to set RX filtering.\n");
 		return rc;
@@ -473,15 +466,13 @@
 static int hw_init_pll(ar9271_t *ar9271)
 {
-	uint32_t pll;
-	
 	/* Some magic here (set for 2GHz channels). But VERY important :-) */
-	pll = (0x5 << 10) | 0x2C;
+	uint32_t pll = (0x5 << 10) | 0x2c;
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll);
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RTC_SLEEP_CLOCK,
-		AR9271_RTC_SLEEP_CLOCK_FORCE_DERIVED);
+	    AR9271_RTC_SLEEP_CLOCK_FORCE_DERIVED);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_RTC_FORCE_WAKE,
-		AR9271_RTC_FORCE_WAKE_ENABLE);
+	    AR9271_RTC_FORCE_WAKE_ENABLE);
 	
 	return EOK;
@@ -490,9 +481,10 @@
 static void hw_set_init_values(ar9271_t *ar9271)
 {
-	uint32_t reg_offset, reg_value;
-	
-	int size = ARRAY_SIZE(ar9271_2g_mode_array);
-	
-	for(int i = 0; i < size; i++) {
+	uint32_t reg_offset;
+	uint32_t reg_value;
+	
+	size_t size = ARRAY_SIZE(ar9271_2g_mode_array);
+	
+	for (size_t i = 0; i < size; i++) {
 		reg_offset = ar9271_2g_mode_array[i][0];
 		reg_value = ar9271_2g_mode_array[i][1];
@@ -502,5 +494,5 @@
 	size = ARRAY_SIZE(ar9271_2g_tx_array);
 	
-	for(int i = 0; i < size; i++) {
+	for (size_t i = 0; i < size; i++) {
 		reg_offset = ar9271_2g_tx_array[i][0];
 		reg_value = ar9271_2g_tx_array[i][1];
@@ -510,5 +502,5 @@
 	size = ARRAY_SIZE(ar9271_init_array);
 	
-	for(int i = 0; i < size; i++) {
+	for (size_t i = 0; i < size; i++) {
 		reg_offset = ar9271_init_array[i][0];
 		reg_value = ar9271_init_array[i][1];
@@ -520,17 +512,17 @@
 {
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
-		AR9271_CARRIER_LEAK_CALIB);
+	    AR9271_CARRIER_LEAK_CALIB);
 	wmi_reg_clear_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
-		AR9271_ADC_CONTROL_OFF_PWDADC);
+	    AR9271_ADC_CONTROL_OFF_PWDADC);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
-		AR9271_AGC_CONTROL_TX_CALIB);
+	    AR9271_AGC_CONTROL_TX_CALIB);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_PHY_TPCRG1,
-		AR9271_PHY_TPCRG1_PD_CALIB);
+	    AR9271_PHY_TPCRG1_PD_CALIB);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
-		AR9271_AGC_CONTROL_CALIB);
-	
-	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_CALIB, 0);
-	if(rc != EOK) {
+	    AR9271_AGC_CONTROL_CALIB);
+	
+	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_CALIB, 0);
+	if (rc != EOK) {
 		usb_log_error("Failed to wait on calibrate completion.\n");
 		return rc;
@@ -538,14 +530,14 @@
 	
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
-		AR9271_ADC_CONTROL_OFF_PWDADC);
+	    AR9271_ADC_CONTROL_OFF_PWDADC);
 	wmi_reg_clear_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
-		AR9271_CARRIER_LEAK_CALIB);
+	    AR9271_CARRIER_LEAK_CALIB);
 	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
-		AR9271_AGC_CONTROL_TX_CALIB);
-	
-	return EOK;
-}
-
-int hw_reset(ar9271_t *ar9271) 
+	    AR9271_AGC_CONTROL_TX_CALIB);
+	
+	return EOK;
+}
+
+int hw_reset(ar9271_t *ar9271)
 {
 	/* Set physical layer as deactivated. */
@@ -553,8 +545,8 @@
 	
 	if(ar9271->starting_up) {
-		wmi_reg_write(ar9271->htc_device, 
-			AR9271_RESET_POWER_DOWN_CONTROL,
-			AR9271_RADIO_RF_RESET);
-
+		wmi_reg_write(ar9271->htc_device,
+		    AR9271_RESET_POWER_DOWN_CONTROL,
+		    AR9271_RADIO_RF_RESET);
+		
 		udelay(50);
 	}
@@ -563,10 +555,9 @@
 	uint32_t config_reg;
 	wmi_reg_read(ar9271->htc_device, AR9271_COMMAND, &config_reg);
-	if(config_reg & AR9271_COMMAND_RX_ENABLE) {
+	if (config_reg & AR9271_COMMAND_RX_ENABLE)
 		hw_set_reset(ar9271, true);
-	}
 	
 	int rc = hw_init_pll(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to init PLL.\n");
 		return rc;
@@ -575,14 +566,14 @@
 	udelay(500);
 	
-	wmi_reg_write(ar9271->htc_device, AR9271_CLOCK_CONTROL,	
-		AR9271_MAX_CPU_CLOCK);
+	wmi_reg_write(ar9271->htc_device, AR9271_CLOCK_CONTROL,
+	    AR9271_MAX_CPU_CLOCK);
 	
 	udelay(100);
 	
-	if(ar9271->starting_up) {
-		wmi_reg_write(ar9271->htc_device, 
-			AR9271_RESET_POWER_DOWN_CONTROL,
-			AR9271_GATE_MAC_CONTROL);
-
+	if (ar9271->starting_up) {
+		wmi_reg_write(ar9271->htc_device,
+		    AR9271_RESET_POWER_DOWN_CONTROL,
+		    AR9271_GATE_MAC_CONTROL);
+		
 		udelay(50);
 	}
@@ -591,10 +582,10 @@
 	
 	/* Set physical layer mode. */
-	wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE, 
-		AR9271_PHY_MODE_DYNAMIC);
+	wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE,
+	    AR9271_PHY_MODE_DYNAMIC);
 	
 	/* Reset device operating mode. */
 	rc = hw_reset_operating_mode(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to reset operating mode.\n");
 		return rc;
@@ -603,5 +594,5 @@
 	/* Set initial channel frequency. */
 	rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to set channel.\n");
 		return rc;
@@ -609,13 +600,12 @@
 	
 	/* Initialize transmission queues. */
-	for(int i = 0; i < AR9271_QUEUES_COUNT; i++) {
-		wmi_reg_write(ar9271->htc_device, 
-			AR9271_QUEUE_BASE_MASK + (i << 2),
-			1 << i);
+	for (unsigned int i = 0; i < AR9271_QUEUES_COUNT; i++) {
+		wmi_reg_write(ar9271->htc_device,
+		    AR9271_QUEUE_BASE_MASK + (i << 2), 1 << i);
 	}
 	
 	/* Activate physical layer. */
 	rc = hw_activate_phy(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to activate physical layer.\n");
 		return rc;
@@ -624,5 +614,5 @@
 	/* Calibration. */
 	rc = hw_calibration(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to calibrate device.\n");
 		return rc;
@@ -630,5 +620,5 @@
 	
 	rc = hw_noise_floor_calibration(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to calibrate noise floor.\n");
 		return rc;
@@ -641,9 +631,8 @@
 }
 
-/**
- * Initialize hardware of AR9271 device.
- * 
+/** Initialize hardware of AR9271 device.
+ *
  * @param ar9271 Device structure.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
  */
@@ -651,5 +640,5 @@
 {
 	int rc = hw_init_proc(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW reset device.\n");
 		return rc;
@@ -657,5 +646,5 @@
 	
 	rc = hw_init_led(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW init led.\n");
 		return rc;
Index: uspace/drv/nic/ar9271/hw.h
===================================================================
--- uspace/drv/nic/ar9271/hw.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/hw.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -34,17 +34,17 @@
 
 #ifndef ATHEROS_HW_H
-#define	ATHEROS_HW_H
+#define ATHEROS_HW_H
 
 #include "ar9271.h"
 
-#define HW_WAIT_LOOPS 1000
-#define HW_WAIT_TIME_US 10
+#define HW_WAIT_LOOPS    1000
+#define HW_WAIT_TIME_US  10
 
-extern int hw_init(ar9271_t *ar9271);
-extern int hw_freq_switch(ar9271_t *, uint16_t freq);
-extern int hw_rx_init(ar9271_t *ar9271);
-extern int hw_reset(ar9271_t *ar9271);
-extern int hw_set_bssid(ar9271_t *ar9271);
-extern int hw_set_rx_filter(ar9271_t *ar9271, bool assoc);
+extern int hw_init(ar9271_t *);
+extern int hw_freq_switch(ar9271_t *, uint16_t);
+extern int hw_rx_init(ar9271_t *);
+extern int hw_reset(ar9271_t *);
+extern int hw_set_bssid(ar9271_t *);
+extern int hw_set_rx_filter(ar9271_t *, bool);
 
-#endif	/* ATHEROS_HW_H */
+#endif  /* ATHEROS_HW_H */
Index: uspace/drv/nic/ar9271/wmi.c
===================================================================
--- uspace/drv/nic/ar9271/wmi.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/wmi.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -34,19 +34,17 @@
 
 #include <usb/debug.h>
-
 #include <malloc.h>
 #include <mem.h>
 #include <byteorder.h>
-
 #include "wmi.h"
 
-/**
- * WMI registry read.
- * 
+/** WMI registry read.
+ *
  * @param htc_device HTC device structure.
  * @param reg_offset Registry offset (address) to be read.
- * @param res Stored result.
- * 
- * @return EOK if succeed, negative error code otherwise.
+ * @param res        Stored result.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int wmi_reg_read(htc_device_t *htc_device, uint32_t reg_offset, uint32_t *res)
@@ -54,18 +52,17 @@
 	uint32_t cmd_value = host2uint32_t_be(reg_offset);
 	
-	void *resp_buffer = 
-		malloc(htc_device->ath_device->ctrl_response_length);
-	
-	int rc = wmi_send_command(htc_device, WMI_REG_READ, 
-		(uint8_t *) &cmd_value, sizeof(cmd_value), resp_buffer);
-	
-	if(rc != EOK) {
+	void *resp_buffer =
+	    malloc(htc_device->ath_device->ctrl_response_length);
+	
+	int rc = wmi_send_command(htc_device, WMI_REG_READ,
+	    (uint8_t *) &cmd_value, sizeof(cmd_value), resp_buffer);
+	
+	if (rc != EOK) {
 		usb_log_error("Failed to read registry value.\n");
 		return rc;
 	}
 	
-	uint32_t *resp_value = (uint32_t *) ((void*) resp_buffer + 
-		sizeof(htc_frame_header_t) +
-		sizeof(wmi_command_header_t));
+	uint32_t *resp_value = (uint32_t *) ((void *) resp_buffer +
+	    sizeof(htc_frame_header_t) + sizeof(wmi_command_header_t));
 	
 	*res = uint32_t_be2host(*resp_value);
@@ -74,29 +71,29 @@
 }
 
-/**
- * WMI registry write.
- * 
- * @param htc_device HTC device structure.
- * @param reg_offset Registry offset (address) to be written.
- * @param val Value to be written
- * 
- * @return EOK if succeed, negative error code otherwise.
+/** WMI registry write.
+ *
+ * @param htc_device HTC device structure.
+ * @param reg_offset Registry offset (address) to be written.
+ * @param val        Value to be written
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int wmi_reg_write(htc_device_t *htc_device, uint32_t reg_offset, uint32_t val)
 {
 	uint32_t cmd_buffer[] = {
-	    host2uint32_t_be(reg_offset),
-	    host2uint32_t_be(val)
+		host2uint32_t_be(reg_offset),
+		host2uint32_t_be(val)
 	};
 	
-	void *resp_buffer = 
-		malloc(htc_device->ath_device->ctrl_response_length);
-	
-	int rc = wmi_send_command(htc_device, WMI_REG_WRITE, 
-		(uint8_t *) &cmd_buffer, sizeof(cmd_buffer), resp_buffer);
+	void *resp_buffer =
+	    malloc(htc_device->ath_device->ctrl_response_length);
+	
+	int rc = wmi_send_command(htc_device, WMI_REG_WRITE,
+	    (uint8_t *) &cmd_buffer, sizeof(cmd_buffer), resp_buffer);
 	
 	free(resp_buffer);
 	
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to write registry value.\n");
 		return rc;
@@ -106,23 +103,23 @@
 }
 
-/**
- * WMI registry set or clear specified bits.
- * 
- * @param htc_device HTC device structure.
- * @param reg_offset Registry offset (address) to be written.
- * @param set_bit Bit to be set.
- * @param clear_bit Bit to be cleared.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int wmi_reg_set_clear_bit(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t set_bit, uint32_t clear_bit)
+/** WMI registry set or clear specified bits.
+ *
+ * @param htc_device HTC device structure.
+ * @param reg_offset Registry offset (address) to be written.
+ * @param set_bit    Bit to be set.
+ * @param clear_bit  Bit to be cleared.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int wmi_reg_set_clear_bit(htc_device_t *htc_device, uint32_t reg_offset,
+    uint32_t set_bit, uint32_t clear_bit)
 {
 	uint32_t value;
 	
 	int rc = wmi_reg_read(htc_device, reg_offset, &value);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to read registry value in RMW "
-			"function.\n");
+		    "function.\n");
 		return rc;
 	}
@@ -132,78 +129,78 @@
 	
 	rc = wmi_reg_write(htc_device, reg_offset, value);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to write registry value in RMW "
-			"function.\n");
-		return rc;
-	}
-	
-	return rc;
-}
-
-/**
- * WMI registry set specified bit.
- * 
- * @param htc_device HTC device structure.
- * @param reg_offset Registry offset (address) to be written.
- * @param set_bit Bit to be set.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t set_bit)
+		    "function.\n");
+		return rc;
+	}
+	
+	return rc;
+}
+
+/** WMI registry set specified bit.
+ *
+ * @param htc_device HTC device structure.
+ * @param reg_offset Registry offset (address) to be written.
+ * @param set_bit    Bit to be set.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
+    uint32_t set_bit)
 {
 	return wmi_reg_set_clear_bit(htc_device, reg_offset, set_bit, 0);
 }
 
-/**
- * WMI registry clear specified bit.
- * 
- * @param htc_device HTC device structure.
- * @param reg_offset Registry offset (address) to be written.
- * @param clear_bit Bit to be cleared.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int wmi_reg_clear_bit(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t clear_bit)
+/** WMI registry clear specified bit.
+ *
+ * @param htc_device HTC device structure.
+ * @param reg_offset Registry offset (address) to be written.
+ * @param clear_bit  Bit to be cleared.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int wmi_reg_clear_bit(htc_device_t *htc_device, uint32_t reg_offset,
+    uint32_t clear_bit)
 {
 	return wmi_reg_set_clear_bit(htc_device, reg_offset, 0, clear_bit);
 }
 
-/**
- * WMI multi registry write.
- * 
+/** WMI multi registry write.
+ *
  * @param htc_device HTC device structure.
  * @param reg_buffer Array of registry values to be written.
- * @param elements Number of elements in array.
- * 
- * @return EOK if succeed, negative error code otherwise.
+ * @param elements   Number of elements in array.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int wmi_reg_buffer_write(htc_device_t *htc_device, wmi_reg_t *reg_buffer,
-	size_t elements)
+    size_t elements)
 {
 	size_t buffer_size = sizeof(wmi_reg_t) * elements;
 	void *buffer = malloc(buffer_size);
-	void *resp_buffer = 
-		malloc(htc_device->ath_device->ctrl_response_length);
+	void *resp_buffer =
+	    malloc(htc_device->ath_device->ctrl_response_length);
 	
 	/* Convert values to correct endianness. */
-	for(size_t i = 0; i < elements; i++) {
+	for (size_t i = 0; i < elements; i++) {
 		wmi_reg_t *buffer_element = &reg_buffer[i];
 		wmi_reg_t *buffer_it = (wmi_reg_t *)
-			((void *) buffer + i*sizeof(wmi_reg_t));
-		buffer_it->offset = 
-			host2uint32_t_be(buffer_element->offset);
+		    ((void *) buffer + i * sizeof(wmi_reg_t));
+		buffer_it->offset =
+		    host2uint32_t_be(buffer_element->offset);
 		buffer_it->value =
-			host2uint32_t_be(buffer_element->value);
-	}
-	
-	int rc = wmi_send_command(htc_device, WMI_REG_WRITE, 
-		(uint8_t *) buffer, buffer_size, resp_buffer);
+		    host2uint32_t_be(buffer_element->value);
+	}
+	
+	int rc = wmi_send_command(htc_device, WMI_REG_WRITE,
+	    (uint8_t *) buffer, buffer_size, resp_buffer);
 	
 	free(buffer);
 	free(resp_buffer);
 	
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to write multi registry value.\n");
 		return rc;
@@ -213,39 +210,37 @@
 }
 
-/**
- * Send WMI message to HTC device.
- * 
- * @param htc_device HTC device structure.
- * @param command_id Command identification.
- * @param command_buffer Buffer with command data.
- * @param command_length Length of command data.
+/** Send WMI message to HTC device.
+ *
+ * @param htc_device      HTC device structure.
+ * @param command_id      Command identification.
+ * @param command_buffer  Buffer with command data.
+ * @param command_length  Length of command data.
  * @param response_buffer Buffer with response data.
- * 
- * @return EOK if succeed, negative error code otherwise.
- */
-int wmi_send_command(htc_device_t *htc_device, wmi_command_t command_id, 
-    uint8_t *command_buffer, uint32_t command_length, void *response_buffer) 
-{
-	size_t header_size = sizeof(wmi_command_header_t) + 
-		sizeof(htc_frame_header_t);
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
+ */
+int wmi_send_command(htc_device_t *htc_device, wmi_command_t command_id,
+    uint8_t *command_buffer, uint32_t command_length, void *response_buffer)
+{
+	size_t header_size = sizeof(wmi_command_header_t) +
+	    sizeof(htc_frame_header_t);
 	size_t buffer_size = header_size + command_length;
 	void *buffer = malloc(buffer_size);
 	
-	if(command_buffer != NULL) {
+	if (command_buffer != NULL)
 		memcpy(buffer+header_size, command_buffer, command_length);
-	}
 	
 	/* Set up WMI header */
 	wmi_command_header_t *wmi_header = (wmi_command_header_t *)
-		((void *) buffer + sizeof(htc_frame_header_t));
-	wmi_header->command_id = 
-		host2uint16_t_be(command_id);
-	wmi_header->sequence_number = 
-		host2uint16_t_be(++htc_device->sequence_number);
+	    ((void *) buffer + sizeof(htc_frame_header_t));
+	wmi_header->command_id = host2uint16_t_be(command_id);
+	wmi_header->sequence_number =
+	    host2uint16_t_be(++htc_device->sequence_number);
 	
 	/* Send message. */
 	int rc = htc_send_control_message(htc_device, buffer, buffer_size,
-		htc_device->endpoints.wmi_endpoint);
-	if(rc != EOK) {
+	    htc_device->endpoints.wmi_endpoint);
+	if (rc != EOK) {
 		free(buffer);
 		usb_log_error("Failed to send WMI message. Error: %d\n", rc);
@@ -256,7 +251,7 @@
 	
 	bool clean_resp_buffer = false;
-	size_t response_buffer_size = 
-		htc_device->ath_device->ctrl_response_length;
-	if(response_buffer == NULL) {
+	size_t response_buffer_size =
+	    htc_device->ath_device->ctrl_response_length;
+	if (response_buffer == NULL) {
 		response_buffer = malloc(response_buffer_size);
 		clean_resp_buffer = true;
@@ -267,7 +262,7 @@
 	uint16_t cmd_id;
 	do {
-		rc = htc_read_control_message(htc_device, response_buffer, 
-			response_buffer_size, NULL);
-		if(rc != EOK) {
+		rc = htc_read_control_message(htc_device, response_buffer,
+		    response_buffer_size, NULL);
+		if (rc != EOK) {
 			free(buffer);
 			usb_log_error("Failed to receive WMI message response. "
@@ -276,6 +271,6 @@
 		}
 		
-		if(response_buffer_size < sizeof(htc_frame_header_t) + 
-			sizeof(wmi_command_header_t)) {
+		if (response_buffer_size < sizeof(htc_frame_header_t) +
+		    sizeof(wmi_command_header_t)) {
 			free(buffer);
 			usb_log_error("Corrupted response received.\n");
@@ -283,13 +278,12 @@
 		}
 		
-		wmi_command_header_t *wmi_hdr = (wmi_command_header_t *) 
-			((void*) response_buffer + sizeof(htc_frame_header_t));
+		wmi_command_header_t *wmi_hdr = (wmi_command_header_t *)
+		    ((void *) response_buffer + sizeof(htc_frame_header_t));
 		cmd_id = uint16_t_be2host(wmi_hdr->command_id);
 	} while(cmd_id & WMI_MGMT_CMD_MASK);
 	
-	if(clean_resp_buffer) {
+	if (clean_resp_buffer)
 		free(response_buffer);
-	}
-	
-	return rc;
-}
+	
+	return rc;
+}
Index: uspace/drv/nic/ar9271/wmi.h
===================================================================
--- uspace/drv/nic/ar9271/wmi.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/drv/nic/ar9271/wmi.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -35,24 +35,26 @@
 
 #ifndef ATHEROS_WMI_H
-#define	ATHEROS_WMI_H
+#define ATHEROS_WMI_H
 
 #include "htc.h"
 
 /* Macros for creating service identificators. */
-#define WMI_SERVICE_GROUP 1
-#define CREATE_SERVICE_ID(group, i) (int) (((int) group << 8) | (int) (i))
+#define WMI_SERVICE_GROUP  1
 
-#define WMI_MGMT_CMD_MASK 0x1000
+#define CREATE_SERVICE_ID(group, i) \
+	(unsigned int) (((unsigned int) group << 8) | (unsigned int) (i))
 
-/**
- * WMI header structure.
+#define WMI_MGMT_CMD_MASK  0x1000
+
+/** WMI header structure.
+ *
  */
 typedef struct {
-    uint16_t command_id;		/**< Big Endian value! */
-    uint16_t sequence_number;           /**< Big Endian value! */
+	uint16_t command_id;       /**< Big Endian value! */
+	uint16_t sequence_number;  /**< Big Endian value! */
 } __attribute__((packed)) wmi_command_header_t;
 
-/**
- * WMI services IDs
+/** WMI services IDs
+ *
  */
 typedef enum {
@@ -68,11 +70,11 @@
 } wmi_services_t;
 
-/**
- * List of WMI commands
+/** List of WMI commands
+ *
  */
 typedef enum {
 	WMI_ECHO = 0x0001,
 	WMI_ACCESS_MEMORY,
-
+	
 	/* Commands used for HOST -> DEVICE communication */
 	WMI_GET_FW_VERSION,
@@ -107,29 +109,20 @@
 } wmi_command_t;
 
-/**
- * Structure used when sending registry buffer
+/**Structure used when sending registry buffer
+ *
  */
 typedef struct {
-	uint32_t offset;		/**< Big Endian value! */
-	uint32_t value;			/**< Big Endian value! */
+	uint32_t offset;  /**< Big Endian value! */
+	uint32_t value;   /**< Big Endian value! */
 } wmi_reg_t;
 
-extern int wmi_reg_read(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t *res);
-extern int wmi_reg_write(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t val);
-extern int wmi_reg_set_clear_bit(htc_device_t *htc_device, 
-	uint32_t reg_offset, uint32_t set_bit, uint32_t clear_bit);
-extern int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t set_bit);
-extern int wmi_reg_clear_bit(htc_device_t *htc_device, uint32_t reg_offset, 
-	uint32_t clear_bit);
-extern int wmi_reg_buffer_write(htc_device_t *htc_device, 
-	wmi_reg_t *reg_buffer, size_t elements);
-extern int wmi_send_command(htc_device_t *htc_device, 
-	wmi_command_t command_id, 
-	uint8_t *command_buffer, uint32_t command_length, 
-	void *response_buffer);
+extern int wmi_reg_read(htc_device_t *, uint32_t, uint32_t *);
+extern int wmi_reg_write(htc_device_t *, uint32_t, uint32_t);
+extern int wmi_reg_set_clear_bit(htc_device_t *, uint32_t, uint32_t, uint32_t);
+extern int wmi_reg_set_bit(htc_device_t *, uint32_t, uint32_t);
+extern int wmi_reg_clear_bit(htc_device_t *, uint32_t, uint32_t);
+extern int wmi_reg_buffer_write(htc_device_t *, wmi_reg_t *, size_t);
+extern int wmi_send_command(htc_device_t *, wmi_command_t, uint8_t *, uint32_t,
+    void *);
 
-#endif	/* ATHEROS_WMI_H */
-
+#endif  /* ATHEROS_WMI_H */
Index: uspace/lib/c/include/ieee80211/ieee80211.h
===================================================================
--- uspace/lib/c/include/ieee80211/ieee80211.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/c/include/ieee80211/ieee80211.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -44,8 +44,8 @@
 
 /** Max length of scan results array. */
-#define IEEE80211_MAX_RESULTS_LENGTH 32
+#define IEEE80211_MAX_RESULTS_LENGTH  32
 
 /** Max SSID length including null character. */
-#define IEEE80211_MAX_SSID_LENGTH 35
+#define IEEE80211_MAX_SSID_LENGTH  35
 
 /** WiFi security authentication method indicator. */
@@ -97,3 +97,2 @@
 /** @}
  */
-
Index: uspace/lib/crypto/aes.c
===================================================================
--- uspace/lib/crypto/aes.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/crypto/aes.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -28,7 +28,7 @@
 
 /** @file aes.c
- * 
+ *
  * Implementation of AES-128 symmetric cipher cryptographic algorithm.
- * 
+ *
  * Based on FIPS 197.
  */
@@ -37,34 +37,33 @@
 #include <errno.h>
 #include <mem.h>
-
 #include "crypto.h"
 
 /* Number of elements in rows/columns in AES arrays. */
-#define ELEMS 4
+#define ELEMS  4
 
 /* Number of elements (words) in cipher. */
-#define CIPHER_ELEMS 4
+#define CIPHER_ELEMS  4
 
 /* Length of AES block. */
-#define BLOCK_LEN 16
+#define BLOCK_LEN  16
 
 /* Number of iterations in AES algorithm. */
-#define ROUNDS 10
-
-/* 
- * Irreducible polynomial used in AES algorithm. 
- * 
+#define ROUNDS  10
+
+/** Irreducible polynomial used in AES algorithm.
+ *
  * NOTE: x^8 + x^4 + x^3 + x + 1.
- */
-#define AES_IP 0x1B
-
-/* Precomputed values for AES sub_byte transformation. */
+ *
+ */
+#define AES_IP  0x1b
+
+/** Precomputed values for AES sub_byte transformation. */
 static const uint8_t sbox[BLOCK_LEN][BLOCK_LEN] = {
 	{
-		0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 
+		0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
 		0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
 	},
 	{
-		0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 
+		0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
 		0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
 	},
@@ -74,139 +73,139 @@
 	},
 	{
-		0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 
+		0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
 		0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
 	},
 	{
-		0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 
+		0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
 		0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
 	},
 	{
-		0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 
+		0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
 		0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
 	},
 	{
-		0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 
+		0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
 		0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
 	},
 	{
-		0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 
+		0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
 		0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
 	},
 	{
-		0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 
+		0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
 		0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
 	},
 	{
-		0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 
+		0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
 		0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
 	},
 	{
-		0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 
+		0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
 		0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
 	},
 	{
-		0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 
+		0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
 		0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
 	},
 	{
-		0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 
+		0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
 		0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
 	},
 	{
-		0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 
+		0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
 		0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
 	},
 	{
-		0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 
+		0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
 		0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
 	},
 	{
-		0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 
+		0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
 		0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
 	}
 };
 
-/* Precomputed values for AES inv_sub_byte transformation. */
+/** Precomputed values for AES inv_sub_byte transformation. */
 static uint8_t inv_sbox[BLOCK_LEN][BLOCK_LEN] = {
 	{
-		0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 
+		0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38,
 		0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
 	},
 	{
-		0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 
+		0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
 		0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
 	},
 	{
-		0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 
+		0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d,
 		0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
 	},
 	{
-		0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 
+		0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2,
 		0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
 	},
 	{
-		0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 
+		0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
 		0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
 	},
 	{
-		0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 
+		0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda,
 		0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
 	},
 	{
-		0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 
+		0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a,
 		0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
 	},
 	{
-		0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 
+		0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
 		0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
 	},
 	{
-		0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 
+		0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea,
 		0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
 	},
 	{
-		0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 
+		0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85,
 		0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
 	},
 	{
-		0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 
+		0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
 		0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
 	},
 	{
-		0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 
+		0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20,
 		0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
 	},
 	{
-		0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 
+		0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31,
 		0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
 	},
 	{
-		0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 
+		0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
 		0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
 	},
 	{
-		0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 
+		0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0,
 		0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
 	},
 	{
-		0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 
+		0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26,
 		0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
 	}
 };
 
-/* Precomputed values of powers of 2 in GF(2^8) left shifted by 24b. */
+/** Precomputed values of powers of 2 in GF(2^8) left shifted by 24b. */
 static const uint32_t r_con_array[] = {
-	0x01000000, 0x02000000,	0x04000000, 0x08000000, 
+	0x01000000, 0x02000000, 0x04000000, 0x08000000,
 	0x10000000, 0x20000000, 0x40000000, 0x80000000,
-	0x1B000000, 0x36000000
+	0x1b000000, 0x36000000
 };
 
-/**
- * Perform substitution transformation on given byte.
- * 
+/** Perform substitution transformation on given byte.
+ *
  * @param byte Input byte.
- * @param inv Flag indicating whether to use inverse table.
- * 
+ * @param inv  Flag indicating whether to use inverse table.
+ *
  * @return Substituted value.
+ *
  */
 static uint8_t sub_byte(uint8_t byte, bool inv)
@@ -215,16 +214,15 @@
 	uint8_t j = byte & 0xF;
 	
-	if(!inv) {
+	if (!inv)
 		return sbox[i][j];
-	} else {
-		return inv_sbox[i][j];
-	}
-}
-
-/**
- * Perform substitution transformation on state table.
- * 
+	
+	return inv_sbox[i][j];
+}
+
+/** Perform substitution transformation on state table.
+ *
  * @param state State table to be modified.
- * @param inv Flag indicating whether to use inverse table.
+ * @param inv   Flag indicating whether to use inverse table.
+ *
  */
 static void sub_bytes(uint8_t state[ELEMS][ELEMS], bool inv)
@@ -232,6 +230,6 @@
 	uint8_t val;
 	
-	for(size_t i = 0; i < ELEMS; i++) {
-		for(size_t j = 0; j < ELEMS; j++) {
+	for (size_t i = 0; i < ELEMS; i++) {
+		for (size_t j = 0; j < ELEMS; j++) {
 			val = state[i][j];
 			state[i][j] = sub_byte(val, inv);
@@ -240,8 +238,8 @@
 }
 
-/**
- * Perform shift rows transformation on state table.
- * 
+/** Perform shift rows transformation on state table.
+ *
  * @param state State table to be modified.
+ *
  */
 static void shift_rows(uint8_t state[ELEMS][ELEMS])
@@ -249,5 +247,5 @@
 	uint8_t temp[ELEMS];
 	
-	for(size_t i = 1; i < ELEMS; i++) {
+	for (size_t i = 1; i < ELEMS; i++) {
 		memcpy(temp, state[i], i);
 		memcpy(state[i], state[i] + i, ELEMS - i);
@@ -256,8 +254,8 @@
 }
 
-/**
- * Perform inverted shift rows transformation on state table.
- * 
+/** Perform inverted shift rows transformation on state table.
+ *
  * @param state State table to be modified.
+ *
  */
 static void inv_shift_rows(uint8_t state[ELEMS][ELEMS])
@@ -265,5 +263,5 @@
 	uint8_t temp[ELEMS];
 	
-	for(size_t i = 1; i < ELEMS; i++) {
+	for (size_t i = 1; i < ELEMS; i++) {
 		memcpy(temp, state[i], ELEMS - i);
 		memcpy(state[i], state[i] + ELEMS - i, i);
@@ -272,33 +270,37 @@
 }
 
-/**
- * Multiplication in GF(2^8).
- * 
+/** Multiplication in GF(2^8).
+ *
  * @param x First factor.
  * @param y Second factor.
- * 
+ *
  * @return Multiplication of given factors in GF(2^8).
- */
-static uint8_t galois_mult(uint8_t x, uint8_t y) {
-        uint8_t result = 0;
-        uint8_t F_bitH;
-	
-        for(size_t i = 0; i < 8; i++) {
-                if (y & 1) 
+ *
+ */
+static uint8_t galois_mult(uint8_t x, uint8_t y)
+{
+	uint8_t result = 0;
+	uint8_t f_bith;
+	
+	for (size_t i = 0; i < 8; i++) {
+		if (y & 1)
 			result ^= x;
-                F_bitH = (x & 0x80);
-                x <<= 1;
-                if (F_bitH) 
-                        x ^= AES_IP;
-                y >>= 1;
-        }
-	
-        return result;
-}
-
-/**
- * Perform mix columns transformation on state table.
- * 
+		
+		f_bith = (x & 0x80);
+		x <<= 1;
+		
+		if (f_bith)
+			x ^= AES_IP;
+		
+		y >>= 1;
+	}
+	
+	return result;
+}
+
+/** Perform mix columns transformation on state table.
+ *
  * @param state State table to be modified.
+ *
  */
 static void mix_columns(uint8_t state[ELEMS][ELEMS])
@@ -307,32 +309,32 @@
 	memcpy(orig_state, state, BLOCK_LEN);
 	
-	for(size_t j = 0; j < ELEMS; j++) {
-		state[0][j] = 
-			galois_mult(0x2, orig_state[0][j]) ^
-			galois_mult(0x3, orig_state[1][j]) ^
-			orig_state[2][j] ^
-			orig_state[3][j];
-		state[1][j] = 
-			orig_state[0][j] ^
-			galois_mult(0x2, orig_state[1][j]) ^
-			galois_mult(0x3, orig_state[2][j]) ^
-			orig_state[3][j];
-		state[2][j] = 
-			orig_state[0][j] ^
-			orig_state[1][j] ^
-			galois_mult(0x2, orig_state[2][j]) ^
-			galois_mult(0x3, orig_state[3][j]);
-		state[3][j] = 
-			galois_mult(0x3, orig_state[0][j]) ^
-			orig_state[1][j] ^
-			orig_state[2][j] ^
-			galois_mult(0x2, orig_state[3][j]);
-	}
-}
-
-/**
- * Perform inverted mix columns transformation on state table.
- * 
+	for (size_t j = 0; j < ELEMS; j++) {
+		state[0][j] =
+		    galois_mult(0x2, orig_state[0][j]) ^
+		    galois_mult(0x3, orig_state[1][j]) ^
+		    orig_state[2][j] ^
+		    orig_state[3][j];
+		state[1][j] =
+		    orig_state[0][j] ^
+		    galois_mult(0x2, orig_state[1][j]) ^
+		    galois_mult(0x3, orig_state[2][j]) ^
+		    orig_state[3][j];
+		state[2][j] =
+		    orig_state[0][j] ^
+		    orig_state[1][j] ^
+		    galois_mult(0x2, orig_state[2][j]) ^
+		    galois_mult(0x3, orig_state[3][j]);
+		state[3][j] =
+		    galois_mult(0x3, orig_state[0][j]) ^
+		    orig_state[1][j] ^
+		    orig_state[2][j] ^
+		    galois_mult(0x2, orig_state[3][j]);
+	}
+}
+
+/** Perform inverted mix columns transformation on state table.
+ *
  * @param state State table to be modified.
+ *
  */
 static void inv_mix_columns(uint8_t state[ELEMS][ELEMS])
@@ -341,33 +343,33 @@
 	memcpy(orig_state, state, BLOCK_LEN);
 	
-	for(size_t j = 0; j < ELEMS; j++) {
-		state[0][j] = 
-			galois_mult(0x0E, orig_state[0][j]) ^
-			galois_mult(0x0B, orig_state[1][j]) ^
-			galois_mult(0x0D, orig_state[2][j]) ^
-			galois_mult(0x09, orig_state[3][j]);
-		state[1][j] = 
-			galois_mult(0x09, orig_state[0][j]) ^
-			galois_mult(0x0E, orig_state[1][j]) ^
-			galois_mult(0x0B, orig_state[2][j]) ^
-			galois_mult(0x0D, orig_state[3][j]);
-		state[2][j] = 
-			galois_mult(0x0D, orig_state[0][j]) ^
-			galois_mult(0x09, orig_state[1][j]) ^
-			galois_mult(0x0E, orig_state[2][j]) ^
-			galois_mult(0x0B, orig_state[3][j]);
-		state[3][j] = 
-			galois_mult(0x0B, orig_state[0][j]) ^
-			galois_mult(0x0D, orig_state[1][j]) ^
-			galois_mult(0x09, orig_state[2][j]) ^
-			galois_mult(0x0E, orig_state[3][j]);
-	}
-}
-
-/**
- * Perform round key transformation on state table.
- * 
- * @param state State table to be modified.
+	for (size_t j = 0; j < ELEMS; j++) {
+		state[0][j] =
+		    galois_mult(0x0e, orig_state[0][j]) ^
+		    galois_mult(0x0b, orig_state[1][j]) ^
+		    galois_mult(0x0d, orig_state[2][j]) ^
+		    galois_mult(0x09, orig_state[3][j]);
+		state[1][j] =
+		    galois_mult(0x09, orig_state[0][j]) ^
+		    galois_mult(0x0e, orig_state[1][j]) ^
+		    galois_mult(0x0b, orig_state[2][j]) ^
+		    galois_mult(0x0d, orig_state[3][j]);
+		state[2][j] =
+		    galois_mult(0x0d, orig_state[0][j]) ^
+		    galois_mult(0x09, orig_state[1][j]) ^
+		    galois_mult(0x0e, orig_state[2][j]) ^
+		    galois_mult(0x0b, orig_state[3][j]);
+		state[3][j] =
+		    galois_mult(0x0b, orig_state[0][j]) ^
+		    galois_mult(0x0d, orig_state[1][j]) ^
+		    galois_mult(0x09, orig_state[2][j]) ^
+		    galois_mult(0x0e, orig_state[3][j]);
+	}
+}
+
+/** Perform round key transformation on state table.
+ *
+ * @param state     State table to be modified.
  * @param round_key Round key to be applied on state table.
+ *
  */
 static void add_round_key(uint8_t state[ELEMS][ELEMS], uint32_t *round_key)
@@ -375,9 +377,9 @@
 	uint8_t byte_round;
 	uint8_t shift;
-	uint32_t mask = 0xFF;
-	
-	for(size_t j = 0; j < ELEMS; j++) {
-		for(size_t i = 0; i < ELEMS; i++) {
-			shift = 24 - 8*i;
+	uint32_t mask = 0xff;
+	
+	for (size_t j = 0; j < ELEMS; j++) {
+		for (size_t i = 0; i < ELEMS; i++) {
+			shift = 24 - 8 * i;
 			byte_round = (round_key[j] & (mask << shift)) >> shift;
 			state[i][j] = state[i][j] ^ byte_round;
@@ -386,10 +388,10 @@
 }
 
-/**
- * Perform substitution transformation on given word.
- * 
+/** Perform substitution transformation on given word.
+ *
  * @param byte Input word.
- * 
+ *
  * @return Substituted word.
+ *
  */
 static uint32_t sub_word(uint32_t word)
@@ -398,17 +400,16 @@
 	uint8_t *start = (uint8_t *) &temp;
 	
-	for(size_t i = 0; i < 4; i++) {
-		*(start+i) = sub_byte(*(start+i), false);
-	}
+	for (size_t i = 0; i < 4; i++)
+		*(start + i) = sub_byte(*(start + i), false);
 	
 	return temp;
 }
 
-/**
- * Perform left rotation by one byte on given word.
- * 
+/** Perform left rotation by one byte on given word.
+ *
  * @param byte Input word.
- * 
+ *
  * @return Rotated word.
+ *
  */
 static uint32_t rot_word(uint32_t word)
@@ -417,9 +418,9 @@
 }
 
-/**
- * Key expansion procedure for AES algorithm.
- * 
- * @param key Input key.
+/** Key expansion procedure for AES algorithm.
+ *
+ * @param key     Input key.
  * @param key_exp Result key expansion.
+ *
  */
 static void key_expansion(uint8_t *key, uint32_t *key_exp)
@@ -427,18 +428,18 @@
 	uint32_t temp;
 	
-	for(size_t i = 0; i < CIPHER_ELEMS; i++) {
-		key_exp[i] = 
-			(key[4*i] << 24) + 
-			(key[4*i+1] << 16) + 
-			(key[4*i+2] << 8) +
-			(key[4*i+3]);
-	}
-	
-	for(size_t i = CIPHER_ELEMS; i < ELEMS * (ROUNDS + 1); i++) {
-		temp = key_exp[i-1];
-		
-		if((i % CIPHER_ELEMS) == 0) {
-			temp = sub_word(rot_word(temp)) ^ 
-				r_con_array[i/CIPHER_ELEMS - 1];
+	for (size_t i = 0; i < CIPHER_ELEMS; i++) {
+		key_exp[i] =
+		    (key[4 * i] << 24) +
+		    (key[4 * i + 1] << 16) +
+		    (key[4 * i + 2] << 8) +
+		    (key[4 * i + 3]);
+	}
+	
+	for (size_t i = CIPHER_ELEMS; i < ELEMS * (ROUNDS + 1); i++) {
+		temp = key_exp[i - 1];
+		
+		if ((i % CIPHER_ELEMS) == 0) {
+			temp = sub_word(rot_word(temp)) ^
+			    r_con_array[i / CIPHER_ELEMS - 1];
 		}
 		
@@ -447,32 +448,32 @@
 }
 
-/**
- * AES-128 encryption algorithm.
- * 
- * @param key Input key.
- * @param input Input data sequence to be encrypted.
+/** AES-128 encryption algorithm.
+ *
+ * @param key    Input key.
+ * @param input  Input data sequence to be encrypted.
  * @param output Encrypted data sequence.
- * 
- * @return EINVAL when input or key not specified, ENOMEM when pointer for 
- * output is not allocated, otherwise EOK.  
+ *
+ * @return EINVAL when input or key not specified,
+ *         ENOMEM when pointer for output is not allocated,
+ *         otherwise EOK.
+ *
  */
 int aes_encrypt(uint8_t *key, uint8_t *input, uint8_t *output)
 {
-	if(!key || !input)
+	if ((!key) || (!input))
 		return EINVAL;
 	
-	if(!output)
+	if (!output)
 		return ENOMEM;
 	
 	/* Create key expansion. */
-	uint32_t key_exp[ELEMS * (ROUNDS+1)];
+	uint32_t key_exp[ELEMS * (ROUNDS + 1)];
 	key_expansion(key, key_exp);
 	
 	/* Copy input into state array. */
 	uint8_t state[ELEMS][ELEMS];
-	for(size_t i = 0; i < ELEMS; i++) {
-		for(size_t j = 0; j < ELEMS; j++) {
-			state[i][j] = input[i + ELEMS*j];
-		}
+	for (size_t i = 0; i < ELEMS; i++) {
+		for (size_t j = 0; j < ELEMS; j++)
+			state[i][j] = input[i + ELEMS * j];
 	}
 	
@@ -480,17 +481,18 @@
 	add_round_key(state, key_exp);
 	
-	for(size_t k = 1; k <= ROUNDS; k++) {
+	for (size_t k = 1; k <= ROUNDS; k++) {
 		sub_bytes(state, false);
 		shift_rows(state);
-		if(k < ROUNDS)
+		
+		if (k < ROUNDS)
 			mix_columns(state);
-		add_round_key(state, key_exp + k*ELEMS);
+		
+		add_round_key(state, key_exp + k * ELEMS);
 	}
 	
 	/* Copy state array into output. */
-	for(size_t i = 0; i < ELEMS; i++) {
-		for(size_t j = 0; j < ELEMS; j++) {
-			output[i + j*ELEMS] = state[i][j];
-		}
+	for (size_t i = 0; i < ELEMS; i++) {
+		for (size_t j = 0; j < ELEMS; j++)
+			output[i + j * ELEMS] = state[i][j];
 	}
 	
@@ -498,50 +500,50 @@
 }
 
-/**
- * AES-128 decryption algorithm.
- * 
- * @param key Input key.
- * @param input Input data sequence to be decrypted.
+/** AES-128 decryption algorithm.
+ *
+ * @param key    Input key.
+ * @param input  Input data sequence to be decrypted.
  * @param output Decrypted data sequence.
- * 
- * @return EINVAL when input or key not specified, ENOMEM when pointer for 
- * output is not allocated, otherwise EOK.  
+ *
+ * @return EINVAL when input or key not specified,
+ *         ENOMEM when pointer for output is not allocated,
+ *         otherwise EOK.
+ *
  */
 int aes_decrypt(uint8_t *key, uint8_t *input, uint8_t *output)
 {
-	if(!key || !input)
+	if ((!key) || (!input))
 		return EINVAL;
 	
-	if(!output)
+	if (!output)
 		return ENOMEM;
 	
 	/* Create key expansion. */
-	uint32_t key_exp[ELEMS * (ROUNDS+1)];
+	uint32_t key_exp[ELEMS * (ROUNDS + 1)];
 	key_expansion(key, key_exp);
 	
 	/* Copy input into state array. */
 	uint8_t state[ELEMS][ELEMS];
-	for(size_t i = 0; i < ELEMS; i++) {
-		for(size_t j = 0; j < ELEMS; j++) {
-			state[i][j] = input[i + ELEMS*j];
-		}
+	for (size_t i = 0; i < ELEMS; i++) {
+		for (size_t j = 0; j < ELEMS; j++)
+			state[i][j] = input[i + ELEMS * j];
 	}
 	
 	/* Processing loop. */
-	add_round_key(state, key_exp + ROUNDS*ELEMS);
-	
-	for(int k = ROUNDS - 1; k >= 0; k--) {
+	add_round_key(state, key_exp + ROUNDS * ELEMS);
+	
+	for (int k = ROUNDS - 1; k >= 0; k--) {
 		inv_shift_rows(state);
 		sub_bytes(state, true);
-		add_round_key(state, key_exp + k*ELEMS);
-		if(k > 0)
+		add_round_key(state, key_exp + k * ELEMS);
+		
+		if (k > 0)
 			inv_mix_columns(state);
 	}
 	
 	/* Copy state array into output. */
-	for(size_t i = 0; i < ELEMS; i++) {
-		for(size_t j = 0; j < ELEMS; j++) {
-			output[i + j*ELEMS] = state[i][j];
-		}
+	for (size_t i = 0; i < ELEMS; i++) {
+		for (size_t j = 0; j < ELEMS; j++)
+			output[i + j * ELEMS] = state[i][j];
 	}
 	
Index: uspace/lib/crypto/crypto.c
===================================================================
--- uspace/lib/crypto/crypto.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/crypto/crypto.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -28,5 +28,5 @@
 
 /** @file crypto.c
- * 
+ *
  * Cryptographic functions library.
  */
@@ -37,30 +37,32 @@
 #include <errno.h>
 #include <byteorder.h>
-
 #include "crypto.h"
 
-/* Hash function procedure definition. */
-typedef void (*HASH_FUNC)(uint32_t*, uint32_t*);
-
-/* Length of HMAC block. */
-#define HMAC_BLOCK_LENGTH 64
-
-/* Ceiling for UINT32. */
-#define ceil_uint32(val) (((val) - (uint32_t)(val)) > 0 ? \
-	(uint32_t)((val) + 1) : (uint32_t)(val))
-
-/* Floor for UINT32. */
-#define floor_uint32(val) (((val) - (uint32_t)(val)) < 0 ? \
-	(uint32_t)((val) - 1) : (uint32_t)(val))
-
-/* Pick value at specified index from array or zero if out of bounds. */
-#define get_at(input, size, i) (i < size ? input[i] : 0)
-
-/* Init values used in SHA1 and MD5 functions. */
+/** Hash function procedure definition. */
+typedef void (*hash_fnc_t)(uint32_t *, uint32_t *);
+
+/** Length of HMAC block. */
+#define HMAC_BLOCK_LENGTH  64
+
+/** Ceiling for uint32_t. */
+#define ceil_uint32(val) \
+	(((val) - (uint32_t) (val)) > 0 ? \
+	(uint32_t) ((val) + 1) : (uint32_t) (val))
+
+/** Floor for uint32_t. */
+#define floor_uint32(val) \
+	(((val) - (uint32_t) (val)) < 0 ? \
+	(uint32_t) ((val) - 1) : (uint32_t) (val))
+
+/** Pick value at specified index from array or zero if out of bounds. */
+#define get_at(input, size, i) \
+	((i) < (size) ? (input[i]) : 0)
+
+/** Init values used in SHA1 and MD5 functions. */
 static const uint32_t hash_init[] = {
-	0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0
+	0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
 };
 
-/* Shift amount array for MD5 algorithm. */
+/** Shift amount array for MD5 algorithm. */
 static const uint32_t md5_shift[] = {
 	7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,
@@ -70,5 +72,5 @@
 };
 
-/* Substitution box for MD5 algorithm. */
+/** Substitution box for MD5 algorithm. */
 static const uint32_t md5_sbox[] = {
 	0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
@@ -90,83 +92,84 @@
 };
 
-/**
- * Working procedure of MD5 cryptographic hash function.
- * 
- * @param h Working array with interim hash parts values.
+/** Working procedure of MD5 cryptographic hash function.
+ *
+ * @param h         Working array with interim hash parts values.
  * @param sched_arr Input array with scheduled values from input string.
+ *
  */
 static void md5_proc(uint32_t *h, uint32_t *sched_arr)
 {
 	uint32_t f, g, temp;
-	uint32_t w[HASH_MD5/4];
-	
-	memcpy(w, h, (HASH_MD5/4) * sizeof(uint32_t));
-	
-	for(size_t k = 0; k < 64; k++) {
-		if(k < 16) {
+	uint32_t w[HASH_MD5 / 4];
+	
+	memcpy(w, h, (HASH_MD5 / 4) * sizeof(uint32_t));
+	
+	for (size_t k = 0; k < 64; k++) {
+		if (k < 16) {
 			f = (w[1] & w[2]) | (~w[1] & w[3]);
 			g = k;
-		} else if(k >= 16 && k < 32) {
+		} else if ((k >= 16) && (k < 32)) {
 			f = (w[1] & w[3]) | (w[2] & ~w[3]);
-			g = (5*k + 1) % 16;
-		} else if(k >= 32 && k < 48) {
+			g = (5 * k + 1) % 16;
+		} else if ((k >= 32) && (k < 48)) {
 			f = w[1] ^ w[2] ^ w[3];
-			g = (3*k + 5) % 16;
+			g = (3 * k + 5) % 16;
 		} else {
 			f = w[2] ^ (w[1] | ~w[3]);
-			g = 7*k % 16;
+			g = 7 * k % 16;
 		}
+		
 		temp = w[3];
 		w[3] = w[2];
 		w[2] = w[1];
-		w[1] += rotl_uint32(w[0] + f + md5_sbox[k] + 
-			uint32_t_byteorder_swap(sched_arr[g]),	
-			md5_shift[k]);
+		w[1] += rotl_uint32(w[0] + f + md5_sbox[k] +
+		    uint32_t_byteorder_swap(sched_arr[g]),
+		    md5_shift[k]);
 		w[0] = temp;
 	}
 	
-	for(uint8_t k = 0; k < HASH_MD5/4; k++)
+	for (uint8_t k = 0; k < HASH_MD5 / 4; k++)
 		h[k] += w[k];
 }
 
-/**
- * Working procedure of SHA-1 cryptographic hash function.
- * 
- * @param h Working array with interim hash parts values.
+/** Working procedure of SHA-1 cryptographic hash function.
+ *
+ * @param h         Working array with interim hash parts values.
  * @param sched_arr Input array with scheduled values from input string.
+ *
  */
 static void sha1_proc(uint32_t *h, uint32_t *sched_arr)
 {
 	uint32_t f, cf, temp;
-	uint32_t w[HASH_SHA1/4];
-	
-	for(size_t k = 16; k < 80; k++) {
+	uint32_t w[HASH_SHA1 / 4];
+	
+	for (size_t k = 16; k < 80; k++) {
 		sched_arr[k] = rotl_uint32(
-			sched_arr[k-3] ^
-			sched_arr[k-8] ^
-			sched_arr[k-14] ^
-			sched_arr[k-16], 
-			1);
-	}
-
-	memcpy(w, h, (HASH_SHA1/4) * sizeof(uint32_t));
-	
-	for(size_t k = 0; k < 80; k++) {
-		if(k < 20) {
+		    sched_arr[k-3] ^
+		    sched_arr[k-8] ^
+		    sched_arr[k-14] ^
+		    sched_arr[k-16],
+		    1);
+	}
+	
+	memcpy(w, h, (HASH_SHA1 / 4) * sizeof(uint32_t));
+	
+	for (size_t k = 0; k < 80; k++) {
+		if (k < 20) {
 			f = (w[1] & w[2]) | (~w[1] & w[3]);
 			cf = 0x5A827999;
-		} else if(k >= 20 && k < 40) {
+		} else if ((k >= 20) && (k < 40)) {
 			f = w[1] ^ w[2] ^ w[3];
-			cf = 0x6ED9EBA1;
-		} else if(k >= 40 && k < 60) {
+			cf = 0x6ed9eba1;
+		} else if ((k >= 40) && (k < 60)) {
 			f = (w[1] & w[2]) | (w[1] & w[3]) | (w[2] & w[3]);
-			cf = 0x8F1BBCDC;
+			cf = 0x8f1bbcdc;
 		} else {
 			f = w[1] ^ w[2] ^ w[3];
-			cf = 0xCA62C1D6;
+			cf = 0xca62c1d6;
 		}
-
+		
 		temp = rotl_uint32(w[0], 5) + f + w[4] + cf + sched_arr[k];
-
+		
 		w[4] = w[3];
 		w[3] = w[2];
@@ -175,30 +178,31 @@
 		w[0] = temp;
 	}
-
-	for(uint8_t k = 0; k < HASH_SHA1/4; k++)
+	
+	for (uint8_t k = 0; k < HASH_SHA1 / 4; k++)
 		h[k] += w[k];
 }
 
-/**
- * Create hash based on selected algorithm.
- * 
- * @param input Input message byte sequence.
+/** Create hash based on selected algorithm.
+ *
+ * @param input      Input message byte sequence.
  * @param input_size Size of message sequence.
- * @param output Result hash byte sequence.
- * @param hash_sel Hash function selector.
- * 
- * @return EINVAL when input not specified, ENOMEM when pointer for 
- * output hash result is not allocated, otherwise EOK. 
+ * @param output     Result hash byte sequence.
+ * @param hash_sel   Hash function selector.
+ *
+ * @return EINVAL when input not specified,
+ *         ENOMEM when pointer for output hash result
+ *         is not allocated, otherwise EOK.
+ *
  */
 int create_hash(uint8_t *input, size_t input_size, uint8_t *output,
-	hash_func_t hash_sel)
-{
-	if(!input)
+    hash_func_t hash_sel)
+{
+	if (!input)
 		return EINVAL;
 	
-	if(!output)
+	if (!output)
 		return ENOMEM;
 	
-	HASH_FUNC hash_func = (hash_sel == HASH_MD5) ? md5_proc : sha1_proc;
+	hash_fnc_t hash_func = (hash_sel == HASH_MD5) ? md5_proc : sha1_proc;
 	
 	/* Prepare scheduled input. */
@@ -207,31 +211,31 @@
 	work_input[input_size] = 0x80;
 	
-	size_t blocks = ceil_uint32((((double)input_size + 1) / 4 + 2) / 16);
+	// FIXME: double?
+	size_t blocks = ceil_uint32((((double) input_size + 1) / 4 + 2) / 16);
 	uint32_t work_arr[blocks * 16];
-	for(size_t i = 0; i < blocks; i++) {
-		for(size_t j = 0; j < 16; j++) {
-			work_arr[i*16 + j] = 
-			(get_at(work_input, input_size+1, i*64+j*4) << 24) |
-			(get_at(work_input, input_size+1, i*64+j*4+1) << 16) |
-			(get_at(work_input, input_size+1, i*64+j*4+2) << 8) |
-			get_at(work_input, input_size+1, i*64+j*4+3);
+	for (size_t i = 0; i < blocks; i++) {
+		for (size_t j = 0; j < 16; j++) {
+			work_arr[i*16 + j] =
+			    (get_at(work_input, input_size + 1, i * 64 + j * 4) << 24) |
+			    (get_at(work_input, input_size + 1, i * 64 + j * 4 + 1) << 16) |
+			    (get_at(work_input, input_size + 1, i * 64 + j * 4 + 2) << 8) |
+			    get_at(work_input, input_size + 1, i * 64 + j * 4 + 3);
 		}
 	}
 	
-	uint64_t bits_size = (uint64_t)(input_size * 8);
-	if(hash_sel == HASH_MD5)
+	uint64_t bits_size = (uint64_t) (input_size * 8);
+	if (hash_sel == HASH_MD5)
 		bits_size = uint64_t_byteorder_swap(bits_size);
 	
 	work_arr[(blocks - 1) * 16 + 14] = bits_size >> 32;
-	work_arr[(blocks - 1) * 16 + 15] = bits_size & 0xFFFFFFFF;
+	work_arr[(blocks - 1) * 16 + 15] = bits_size & 0xffffffff;
 	
 	/* Hash computation. */
-	uint32_t h[hash_sel/4];
-	memcpy(h, hash_init, (hash_sel/4) * sizeof(uint32_t));
+	uint32_t h[hash_sel / 4];
+	memcpy(h, hash_init, (hash_sel / 4) * sizeof(uint32_t));
 	uint32_t sched_arr[80];
-	for(size_t i = 0; i < blocks; i++) {
-		for(size_t k = 0; k < 16; k++) {
-			sched_arr[k] = work_arr[i*16 + k];
-		}
+	for (size_t i = 0; i < blocks; i++) {
+		for (size_t k = 0; k < 16; k++)
+			sched_arr[k] = work_arr[i * 16 + k];
 		
 		hash_func(h, sched_arr);
@@ -239,8 +243,9 @@
 	
 	/* Copy hash parts into final result. */
-	for(size_t i = 0; i < hash_sel/4; i++) {
-		if(hash_sel == HASH_SHA1)
+	for (size_t i = 0; i < hash_sel / 4; i++) {
+		if (hash_sel == HASH_SHA1)
 			h[i] = uint32_t_byteorder_swap(h[i]);
-		memcpy(output + i*sizeof(uint32_t), &h[i], sizeof(uint32_t));
+		
+		memcpy(output + i * sizeof(uint32_t), &h[i], sizeof(uint32_t));
 	}
 	
@@ -248,24 +253,25 @@
 }
 
-/**
- * Hash-based message authentication code.
- * 
- * @param key Cryptographic key sequence.
+/** Hash-based message authentication code.
+ *
+ * @param key      Cryptographic key sequence.
  * @param key_size Size of key sequence.
- * @param msg Message sequence.
+ * @param msg      Message sequence.
  * @param msg_size Size of message sequence.
- * @param hash Output parameter for result hash.
+ * @param hash     Output parameter for result hash.
  * @param hash_sel Hash function selector.
- * 
- * @return EINVAL when key or message not specified, ENOMEM when pointer for 
- * output hash result is not allocated, otherwise EOK.
+ *
+ * @return EINVAL when key or message not specified,
+ *         ENOMEM when pointer for output hash result
+ *         is not allocated, otherwise EOK.
+ *
  */
 int hmac(uint8_t *key, size_t key_size, uint8_t *msg, size_t msg_size, 
-	uint8_t *hash, hash_func_t hash_sel)
-{
-	if(!key || !msg)
+    uint8_t *hash, hash_func_t hash_sel)
+{
+	if ((!key) || (!msg))
 		return EINVAL;
 	
-	if(!hash)
+	if (!hash)
 		return ENOMEM;
 	
@@ -276,12 +282,11 @@
 	memset(work_key, 0, HMAC_BLOCK_LENGTH);
 	
-	if(key_size > HMAC_BLOCK_LENGTH) {
+	if(key_size > HMAC_BLOCK_LENGTH)
 		create_hash(key, key_size, work_key, hash_sel);
-	} else {
+	else
 		memcpy(work_key, key, key_size);
-	}
-	
-	for(size_t i = 0; i < HMAC_BLOCK_LENGTH; i++) {
-		o_key_pad[i] = work_key[i] ^ 0x5C;
+	
+	for (size_t i = 0; i < HMAC_BLOCK_LENGTH; i++) {
+		o_key_pad[i] = work_key[i] ^ 0x5c;
 		i_key_pad[i] = work_key[i] ^ 0x36;
 	}
@@ -291,6 +296,6 @@
 	memcpy(temp_work + HMAC_BLOCK_LENGTH, msg, msg_size);
 	
-	create_hash(temp_work, HMAC_BLOCK_LENGTH + msg_size, temp_hash, 
-		hash_sel);
+	create_hash(temp_work, HMAC_BLOCK_LENGTH + msg_size, temp_hash,
+	    hash_sel);
 	
 	memcpy(temp_work, o_key_pad, HMAC_BLOCK_LENGTH);
@@ -302,25 +307,27 @@
 }
 
-/**
- * Password-Based Key Derivation Function 2 as defined in RFC 2898,
- * using HMAC-SHA1 with 4096 iterations and 32 bytes key result used
- * for WPA/WPA2.
- * 
- * @param pass Password sequence.
+/** Password-Based Key Derivation Function 2.
+ *
+ * As defined in RFC 2898, using HMAC-SHA1 with 4096 iterations
+ * and 32 bytes key result used for WPA/WPA2.
+ *
+ * @param pass      Password sequence.
  * @param pass_size Password sequence length.
- * @param salt Salt sequence to be used with password.
+ * @param salt      Salt sequence to be used with password.
  * @param salt_size Salt sequence length.
- * @param hash Output parameter for result hash (32 byte value).
- * 
- * @return EINVAL when pass or salt not specified, ENOMEM when pointer for 
- * output hash result is not allocated, otherwise EOK.
- */
-int pbkdf2(uint8_t *pass, size_t pass_size, uint8_t *salt, size_t salt_size, 
-	uint8_t *hash)
-{
-	if(!pass || !salt)
+ * @param hash      Output parameter for result hash (32 byte value).
+ *
+ * @return EINVAL when pass or salt not specified,
+ *         ENOMEM when pointer for output hash result
+ *         is not allocated, otherwise EOK.
+ *
+ */
+int pbkdf2(uint8_t *pass, size_t pass_size, uint8_t *salt, size_t salt_size,
+    uint8_t *hash)
+{
+	if ((!pass) || (!salt))
 		return EINVAL;
 	
-	if(!hash)
+	if (!hash)
 		return ENOMEM;
 	
@@ -330,22 +337,24 @@
 	uint8_t temp_hmac[HASH_SHA1];
 	uint8_t xor_hmac[HASH_SHA1];
-	uint8_t temp_hash[HASH_SHA1*2];
-	
-	for(size_t i = 0; i < 2; i++) {
-		uint32_t be_i = host2uint32_t_be(i+1);
+	uint8_t temp_hash[HASH_SHA1 * 2];
+	
+	for (size_t i = 0; i < 2; i++) {
+		uint32_t be_i = host2uint32_t_be(i + 1);
+		
 		memcpy(work_salt + salt_size, &be_i, 4);
 		hmac(pass, pass_size, work_salt, salt_size + 4,
-			work_hmac, HASH_SHA1);
+		    work_hmac, HASH_SHA1);
 		memcpy(xor_hmac, work_hmac, HASH_SHA1);
 		
-		for(size_t k = 1; k < 4096; k++) {
+		for (size_t k = 1; k < 4096; k++) {
 			memcpy(temp_hmac, work_hmac, HASH_SHA1);
-			hmac(pass, pass_size, temp_hmac, HASH_SHA1, 
-				work_hmac, HASH_SHA1);
-			for(size_t t = 0; t < HASH_SHA1; t++) {
+			hmac(pass, pass_size, temp_hmac, HASH_SHA1,
+			    work_hmac, HASH_SHA1);
+			
+			for (size_t t = 0; t < HASH_SHA1; t++)
 				xor_hmac[t] ^= work_hmac[t];
-			}
 		}
-		memcpy(temp_hash + i*HASH_SHA1, xor_hmac, HASH_SHA1);
+		
+		memcpy(temp_hash + i * HASH_SHA1, xor_hmac, HASH_SHA1);
 	}
 	
Index: uspace/lib/crypto/crypto.h
===================================================================
--- uspace/lib/crypto/crypto.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/crypto/crypto.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -32,29 +32,27 @@
 #include <sys/types.h>
 
-#define AES_CIPHER_LENGTH 16
-#define PBKDF2_KEY_LENGTH 32
+#define AES_CIPHER_LENGTH  16
+#define PBKDF2_KEY_LENGTH  32
 
-/* Left rotation for UINT32. */
-#define rotl_uint32(val, shift) (((val) << shift) | ((val) >> (32 - shift)))
+/* Left rotation for uint32_t. */
+#define rotl_uint32(val, shift) \
+	(((val) << shift) | ((val) >> (32 - shift)))
 
-/* Right rotation for UINT32. */
-#define rotr_uint32(val, shift) (((val) >> shift) | ((val) << (32 - shift)))
+/* Right rotation for uint32_t. */
+#define rotr_uint32(val, shift) \
+	(((val) >> shift) | ((val) << (32 - shift)))
 
 /** Hash function selector and also result hash length indicator. */
 typedef enum {
-	HASH_MD5 =	16,
-	HASH_SHA1 =	20
+	HASH_MD5 =  16,
+	HASH_SHA1 = 20
 } hash_func_t;
 
-extern int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size, 
-	size_t skip, uint8_t *output);
-extern int aes_encrypt(uint8_t *key, uint8_t *input, uint8_t *output);
-extern int aes_decrypt(uint8_t *key, uint8_t *input, uint8_t *output);
-extern int create_hash(uint8_t *input, size_t input_size, uint8_t *output, 
-	hash_func_t hash_sel);
-extern int hmac(uint8_t *key, size_t key_size, uint8_t *msg, size_t msg_size, 
-	uint8_t *hash, hash_func_t hash_sel);
-extern int pbkdf2(uint8_t *pass, size_t pass_size, uint8_t *salt, 
-	size_t salt_size, uint8_t *hash);
+extern int rc4(uint8_t *, size_t, uint8_t *, size_t, size_t, uint8_t *);
+extern int aes_encrypt(uint8_t *, uint8_t *, uint8_t *);
+extern int aes_decrypt(uint8_t *, uint8_t *, uint8_t *);
+extern int create_hash(uint8_t *, size_t, uint8_t *, hash_func_t);
+extern int hmac(uint8_t *, size_t, uint8_t *, size_t, uint8_t *, hash_func_t);
+extern int pbkdf2(uint8_t *, size_t, uint8_t *, size_t, uint8_t *);
 
 #endif
Index: uspace/lib/crypto/rc4.c
===================================================================
--- uspace/lib/crypto/rc4.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/crypto/rc4.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -28,23 +28,22 @@
 
 /** @file rc4.c
- * 
+ *
  * Implementation of ARC4 symmetric cipher cryptographic algorithm.
- * 
+ *
  */
 
 #include <errno.h>
 #include <mem.h>
-
 #include "crypto.h"
 
 /* Sbox table size. */
-#define SBOX_SIZE 256
+#define SBOX_SIZE  256
 
-/**
- * Swap two values in sbox.
- * 
- * @param i First index of value in sbox to be swapped.
- * @param j Second index of value in sbox to be swapped.
+/** Swap two values in sbox.
+ *
+ * @param i    First index of value in sbox to be swapped.
+ * @param j    Second index of value in sbox to be swapped.
  * @param sbox Sbox to be modified.
+ *
  */
 static void swap(size_t i, size_t j, uint8_t *sbox)
@@ -55,19 +54,18 @@
 }
 
-/**
- * Sbox initialization procedure.
- * 
- * @param key Input key.
+/** Sbox initialization procedure.
+ *
+ * @param key      Input key.
  * @param key_size Size of key sequence.
- * @param sbox Place for result sbox.
+ * @param sbox     Place for result sbox.
+ *
  */
 static void create_sbox(uint8_t *key, size_t key_size, uint8_t *sbox)
 {
-	for(size_t i = 0; i < SBOX_SIZE; i++) {
+	for (size_t i = 0; i < SBOX_SIZE; i++)
 		sbox[i] = i;
-	}
 	
 	uint8_t j = 0;
-	for(size_t i = 0; i < SBOX_SIZE; i++) {
+	for (size_t i = 0; i < SBOX_SIZE; i++) {
 		j = j + sbox[i] + key[i % key_size];
 		swap(i, j, sbox);
@@ -75,24 +73,26 @@
 }
 
-/**
- * ARC4 encryption/decryption algorithm.
- * 
- * @param key Input key.
- * @param key_size Size of key sequence.
- * @param input Input data sequence to be processed.
+/** ARC4 encryption/decryption algorithm.
+ *
+ * @param key        Input key.
+ * @param key_size   Size of key sequence.
+ * @param input      Input data sequence to be processed.
  * @param input_size Size of input data sequence.
- * @param skip Number of bytes to be skipped from the beginning of key stream.
- * @param output Result data sequence.
- * 
- * @return EINVAL when input or key not specified, ENOMEM when pointer for 
- * output is not allocated, otherwise EOK.  
+ * @param skip       Number of bytes to be skipped from
+ *                   the beginning of key stream.
+ * @param output     Result data sequence.
+ *
+ * @return EINVAL when input or key not specified,
+ *         ENOMEM when pointer for output is not allocated,
+ *         otherwise EOK.
+ *
  */
-int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size, 
-	size_t skip, uint8_t *output)
+int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size,
+    size_t skip, uint8_t *output)
 {
-	if(!key || !input)
+	if ((!key) || (!input))
 		return EINVAL;
 	
-	if(!output)
+	if (!output)
 		return ENOMEM;
 	
@@ -102,6 +102,7 @@
 	
 	/* Skip first x bytes. */
-	uint8_t i = 0, j = 0;
-	for(size_t k = 0; k < skip; k++) {
+	uint8_t i = 0;
+	uint8_t j = 0;
+	for (size_t k = 0; k < skip; k++) {
 		i = i + 1;
 		j = j + sbox[i];
@@ -111,5 +112,5 @@
 	/* Processing loop. */
 	uint8_t val;
-	for(size_t k = 0; k < input_size; k++) {
+	for (size_t k = 0; k < input_size; k++) {
 		i = i + 1;
 		j = j + sbox[i];
Index: uspace/lib/drv/generic/remote_ieee80211.c
===================================================================
--- uspace/lib/drv/generic/remote_ieee80211.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/drv/generic/remote_ieee80211.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -40,10 +40,9 @@
 #include <inet/dhcp.h>
 #include <inet/inetcfg.h>
-
 #include "ops/ieee80211.h"
 #include "ieee80211_iface.h"
 #include "nic_iface.h"
 
-#define MAX_STRING_SIZE 32
+#define MAX_STRING_SIZE  32
 
 /** IEEE 802.11 RPC functions IDs. */
@@ -56,12 +55,13 @@
 /** Get scan results from IEEE 802.11 device
  *
- * @param[in] dev_sess Device session.
- * @param[out] results Structure where to put scan results.
+ * @param[in]  dev_sess Device session.
+ * @param[out] results  Structure where to put scan results.
  *
  * @return EOK If the operation was successfully completed,
- * negative error code otherwise.
- */
-int ieee80211_get_scan_results(async_sess_t *dev_sess, 
-	ieee80211_scan_results_t *results, bool now)
+ *         negative error code otherwise.
+ *
+ */
+int ieee80211_get_scan_results(async_sess_t *dev_sess,
+    ieee80211_scan_results_t *results, bool now)
 {
 	assert(results);
@@ -71,7 +71,8 @@
 	aid_t aid = async_send_2(exch, DEV_IFACE_ID(IEEE80211_DEV_IFACE),
 	    IEEE80211_GET_SCAN_RESULTS, now, NULL);
-	int rc = async_data_read_start(exch, results, sizeof(ieee80211_scan_results_t));
+	int rc = async_data_read_start(exch, results,
+	    sizeof(ieee80211_scan_results_t));
 	async_exchange_end(exch);
-
+	
 	sysarg_t res;
 	async_wait_for(aid, &res);
@@ -79,12 +80,12 @@
 	if(res != EOK)
 		return (int) res;
-	else
-		return rc;
+	
+	return rc;
 }
 
 static bool mac_matches(uint8_t *mac1, uint8_t *mac2)
 {
-	for(size_t i = 0; i < ETH_ADDR; i++) {
-		if(mac1[i] != mac2[i])
+	for (size_t i = 0; i < ETH_ADDR; i++) {
+		if (mac1[i] != mac2[i])
 			return false;
 	}
@@ -108,7 +109,6 @@
 			return -1;
 		
-		if(mac_matches(mac, link_info.mac_addr)) {
+		if (mac_matches(mac, link_info.mac_addr))
 			return link_list[i];
-		}
 	}
 	
@@ -118,10 +118,11 @@
 /** Connect to specified network.
  *
- * @param[in] dev_sess Device session.
+ * @param[in] dev_sess   Device session.
  * @param[in] ssid_start Network SSID prefix.
- * @param[in] password Network password (pass empty string if not needed).
+ * @param[in] password   Network password (pass empty string if not needed).
  *
  * @return EOK If the operation was successfully completed,
- * negative error code otherwise.
+ *         negative error code otherwise.
+ *
  */
 int ieee80211_connect(async_sess_t *dev_sess, char *ssid_start, char *password)
@@ -136,6 +137,6 @@
 	    IEEE80211_CONNECT, NULL);
 	
-	sysarg_t rc = async_data_write_start(exch, ssid_start, 
-		str_size(ssid_start) + 1);
+	sysarg_t rc = async_data_write_start(exch, ssid_start,
+	    str_size(ssid_start) + 1);
 	if (rc != EOK) {
 		async_exchange_end(exch);
@@ -144,11 +145,11 @@
 		if (rc_orig == EOK)
 			return (int) rc;
-		else
-			return (int) rc_orig;
-	}
-	
-	if(password == NULL) {
+		
+		return (int) rc_orig;
+	}
+	
+	// FIXME: Typecasting string literal
+	if (password == NULL)
 		password = (char *) "";
-	}
 	
 	rc = async_data_write_start(exch, password, str_size(password) + 1);
@@ -159,10 +160,10 @@
 		if (rc_orig == EOK)
 			return (int) rc;
-		else
-			return (int) rc_orig;
+		
+		return (int) rc_orig;
 	}
 	
 	async_exchange_end(exch);
-
+	
 	async_wait_for(aid, &rc);
 	if (rc != EOK)
@@ -176,5 +177,5 @@
 	
 	sysarg_t link_id = get_link_id(wifi_mac.address);
-	if(link_id == ((sysarg_t) -1))
+	if (link_id == ((sysarg_t) -1))
 		return EINVAL;
 	
@@ -189,5 +190,6 @@
  *
  * @return EOK If the operation was successfully completed,
- * negative error code otherwise.
+ *         negative error code otherwise.
+ *
  */
 int ieee80211_disconnect(async_sess_t *dev_sess)
@@ -198,5 +200,5 @@
 	async_exchange_end(exch);
 	
-	if(rc != EOK)
+	if (rc != EOK)
 		return rc;
 	
@@ -227,9 +229,10 @@
 			return rc;
 		
-		if(mac_matches(wifi_mac.address, link_info.mac_addr)) {
-			if(str_test_prefix(addr_info.name, "dhcp")) {
+		if (mac_matches(wifi_mac.address, link_info.mac_addr)) {
+			if (str_test_prefix(addr_info.name, "dhcp")) {
 				rc = inetcfg_addr_delete(addr_list[i]);
-				if(rc != EOK)
+				if (rc != EOK)
 					return rc;
+				
 				break;
 			}
@@ -237,5 +240,5 @@
 	}
 	
-	/* 
+	/*
 	 * TODO: At this moment there can be only one DHCP route,
 	 * so it must be reimplemented after this limitation will be
@@ -252,8 +255,9 @@
 			return rc;
 		
-		if(str_test_prefix(route_info.name, "dhcp")) {
+		if (str_test_prefix(route_info.name, "dhcp")) {
 			rc = inetcfg_sroute_delete(route_list[i]);
-			if(rc != EOK)
+			if (rc != EOK)
 				return rc;
+			
 			break;
 		}
Index: uspace/lib/drv/include/ieee80211_iface.h
===================================================================
--- uspace/lib/drv/include/ieee80211_iface.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/drv/include/ieee80211_iface.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup libc
+/** @addtogroup libc
  * @{
  */
@@ -39,6 +39,6 @@
 #include <async.h>
 
-extern int ieee80211_get_scan_results(async_sess_t *, 
-	ieee80211_scan_results_t *, bool);
+extern int ieee80211_get_scan_results(async_sess_t *,
+    ieee80211_scan_results_t *, bool);
 extern int ieee80211_connect(async_sess_t *, char *, char *);
 extern int ieee80211_disconnect(async_sess_t *);
Index: uspace/lib/drv/include/ops/ieee80211.h
===================================================================
--- uspace/lib/drv/include/ops/ieee80211.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/drv/include/ops/ieee80211.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -42,32 +42,32 @@
 /** IEEE 802.11 interface functions definition. */
 typedef struct ieee80211_iface {
-	/**
-	 * Fetch scan results from IEEE 802.11 device.
-	 * 
-	 * @param fun IEEE 802.11 function.
+	/** Fetch scan results from IEEE 802.11 device.
+	 *
+	 * @param fun     IEEE 802.11 function.
 	 * @param results Structure where to put scan results.
-	 * @param now Whether to initiate scan immediately.
-	 * 
+	 * @param now     Whether to initiate scan immediately.
+	 *
 	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*get_scan_results)(ddf_fun_t *, ieee80211_scan_results_t *, bool);
 	
-	/** 
-	 * Connect IEEE 802.11 device to specified network.
+	/** Connect IEEE 802.11 device to specified network.
 	 *
-	 * @param fun IEEE 802.11 function.
-	 * @param ssid Network SSID.
+	 * @param fun      IEEE 802.11 function.
+	 * @param ssid     Network SSID.
 	 * @param password Network password (empty string if not needed).
-	 * 
+	 *
 	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*connect)(ddf_fun_t *, char *, char *);
 	
-	/** 
-	 * Disconnect IEEE 802.11 device from network.
+	/** Disconnect IEEE 802.11 device from network.
 	 *
 	 * @param fun IEEE 802.11 function.
-	 * 
+	 *
 	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*disconnect)(ddf_fun_t *);
Index: uspace/lib/ieee80211/Makefile
===================================================================
--- uspace/lib/ieee80211/Makefile	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/Makefile	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -45,5 +45,4 @@
 	src/ieee80211_impl.c \
 	src/ieee80211_iface_impl.c \
-	
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/ieee80211/include/ieee80211.h
===================================================================
--- uspace/lib/ieee80211/include/ieee80211.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/include/ieee80211.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -27,5 +27,5 @@
  */
 
-/** 
+/**
  * @addtogroup libieee80211
  * @{
@@ -43,5 +43,5 @@
 #include <ops/ieee80211.h>
 
-#define DEVICE_CATEGORY_IEEE80211 "ieee80211"
+#define DEVICE_CATEGORY_IEEE80211  "ieee80211"
 
 struct ieee80211_dev;
@@ -49,17 +49,17 @@
 
 /** Initial channel frequency. */
-#define IEEE80211_FIRST_FREQ 2412
+#define IEEE80211_FIRST_FREQ  2412
 
 /** Max supported channel frequency. */
-#define IEEE80211_MAX_FREQ 2472
-
-/* Gap between IEEE80211 channels in MHz. */
-#define IEEE80211_CHANNEL_GAP 5
-
-/* Max AMPDU factor. */
-#define IEEE80211_MAX_AMPDU_FACTOR 13
-
-/* Max authentication password length. */
-#define IEEE80211_MAX_PASSW_LEN 64
+#define IEEE80211_MAX_FREQ  2472
+
+/** Gap between IEEE80211 channels in MHz. */
+#define IEEE80211_CHANNEL_GAP  5
+
+/** Max AMPDU factor. */
+#define IEEE80211_MAX_AMPDU_FACTOR  13
+
+/** Max authentication password length. */
+#define IEEE80211_MAX_PASSW_LEN  64
 
 /** IEEE 802.11 b/g supported data rates in units of 500 kb/s. */
@@ -97,113 +97,111 @@
 /** IEEE 802.11 callback functions. */
 typedef struct {
-	/**
-	 * Function that is called at device initalization. This should
-	 * get device into running state.
-	 * 
-	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
-	 * 
-	 * @return EOK if succeed, negative error code otherwise.
+	/** unction that is called at device initalization.
+	 *
+	 * This should get device into running state.
+	 *
+	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
+	 *
+	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*start)(struct ieee80211_dev *);
 	
-	/**
-	 * Scan neighborhood for networks. There should be implemented
-	 * scanning of whole bandwidth. Incoming results are processed by
-	 * IEEE 802.11 framework itself.
-	 * 
-	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
-	 * 
-	 * @return EOK if succeed, negative error code otherwise.
+	/** Scan neighborhood for networks.
+	 *
+	 * There should be implemented scanning of whole bandwidth.
+	 * Incoming results are processed by IEEE 802.11 framework itself.
+	 *
+	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
+	 *
+	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*scan)(struct ieee80211_dev *);
 	
-	/**
-	 * Handler for TX frames to be send from device. This should be
-	 * called for every frame that has to be send from IEEE 802.11 device.
-	 * 
-	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
-	 * @param buffer Buffer with data to be send.
-	 * @param buffer_size Size of buffer.
-	 * 
-	 * @return EOK if succeed, negative error code otherwise.
+	/** Handler for TX frames to be send from device.
+	 *
+	 * This should be called for every frame that has to be send
+	 * from IEEE 802.11 device.
+	 *
+	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
+	 * @param buffer        Buffer with data to be send.
+	 * @param buffer_size   Size of buffer.
+	 *
+	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*tx_handler)(struct ieee80211_dev *, void *, size_t);
 	
-	/**
-	 * Set device operating frequency to given value.
-	 * 
-	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
-	 * @param freq New device operating frequency.
-	 * 
-	 * @return EOK if succeed, negative error code otherwise.
+	/** Set device operating frequency to given value.
+	 *
+	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
+	 * @param freq          New device operating frequency.
+	 *
+	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*set_freq)(struct ieee80211_dev *, uint16_t);
 	
-	/**
-	 * Callback to inform device about BSSID change.
-	 * 
-	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
-	 * @param connected True if connected to new BSSID, otherwise false.
-	 * 
-	 * @return EOK if succeed, negative error code otherwise.
+	/** Callback to inform device about BSSID change.
+	 *
+	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
+	 * @param connected     True if connected to new BSSID, otherwise false.
+	 *
+	 * @return EOK if succeed, negative error code otherwise.
+	 *
 	 */
 	int (*bssid_change)(struct ieee80211_dev *, bool);
 	
-	/**
-	 * Callback to setup encryption key in IEEE 802.11 device.
-	 * 
-	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
-	 * @param key_conf Key config structure.
-	 * @param insert True to insert this key to device, false to remove it.
-	 * 
-	 * @return EOK if succeed, negative error code otherwise.
-	 */
-	int (*key_config)(struct ieee80211_dev *, 
-		ieee80211_key_config_t *key_conf, bool);
+	/** Callback to setup encryption key in IEEE 802.11 device.
+	 *
+	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
+	 * @param key_conf      Key config structure.
+	 * @param insert        True to insert this key to device,
+	 *                      false to remove it.
+	 *
+	 * @return EOK if succeed, negative error code otherwise.
+	 *
+	 */
+	int (*key_config)(struct ieee80211_dev *,
+	    ieee80211_key_config_t *key_conf, bool);
 } ieee80211_ops_t;
 
 /* Initialization functions. */
 extern ieee80211_dev_t *ieee80211_device_create(void);
-extern int ieee80211_device_init(ieee80211_dev_t *ieee80211_dev, 
-	ddf_dev_t *ddf_dev);
-extern int ieee80211_init(ieee80211_dev_t *ieee80211_dev, 
-	ieee80211_ops_t *ieee80211_ops, ieee80211_iface_t *ieee80211_iface,
-	nic_iface_t *ieee80211_nic_iface, ddf_dev_ops_t *ieee80211_dev_ops);
+extern int ieee80211_device_init(ieee80211_dev_t *, ddf_dev_t *);
+extern int ieee80211_init(ieee80211_dev_t *, ieee80211_ops_t *,
+    ieee80211_iface_t *, nic_iface_t *, ddf_dev_ops_t *);
 
 /* Getters & setters, queries & reports. */
-extern void *ieee80211_get_specific(ieee80211_dev_t *ieee80211_dev);
-extern void ieee80211_set_specific(ieee80211_dev_t *ieee80211_dev, 
-	void *specific);
-extern ddf_dev_t *ieee80211_get_ddf_dev(ieee80211_dev_t* ieee80211_dev);
-extern ieee80211_operating_mode_t 
-	ieee80211_query_current_op_mode(ieee80211_dev_t *ieee80211_dev);
-extern uint16_t ieee80211_query_current_freq(ieee80211_dev_t *ieee80211_dev);
-extern void ieee80211_query_bssid(ieee80211_dev_t* ieee80211_dev, 
-	nic_address_t *bssid);
-extern bool ieee80211_is_connected(ieee80211_dev_t* ieee80211_dev);
-extern void ieee80211_report_current_op_mode(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_operating_mode_t op_mode);
-extern void ieee80211_report_current_freq(ieee80211_dev_t *ieee80211_dev,
-	uint16_t freq);
-extern uint16_t ieee80211_get_aid(ieee80211_dev_t* ieee80211_dev);
-extern int ieee80211_get_pairwise_security(ieee80211_dev_t* ieee80211_dev);
-extern bool ieee80211_is_ready(ieee80211_dev_t* ieee80211_dev);
-extern void ieee80211_set_ready(ieee80211_dev_t* ieee80211_dev, bool ready);
-extern bool ieee80211_query_using_key(ieee80211_dev_t* ieee80211_dev);
-extern void ieee80211_setup_key_confirm(ieee80211_dev_t* ieee80211_dev, 
-	bool using_key);
-
-extern bool ieee80211_is_data_frame(uint16_t frame_ctrl);
-extern bool ieee80211_is_mgmt_frame(uint16_t frame_ctrl);
-extern bool ieee80211_is_beacon_frame(uint16_t frame_ctrl);
-extern bool ieee80211_is_probe_response_frame(uint16_t frame_ctrl);
-extern bool ieee80211_is_auth_frame(uint16_t frame_ctrl);
-extern bool ieee80211_is_assoc_response_frame(uint16_t frame_ctrl);
+extern void *ieee80211_get_specific(ieee80211_dev_t *);
+extern void ieee80211_set_specific(ieee80211_dev_t *, void *);
+extern ddf_dev_t *ieee80211_get_ddf_dev(ieee80211_dev_t *);
+extern ieee80211_operating_mode_t
+    ieee80211_query_current_op_mode(ieee80211_dev_t *);
+extern uint16_t ieee80211_query_current_freq(ieee80211_dev_t *);
+extern void ieee80211_query_bssid(ieee80211_dev_t *, nic_address_t *);
+extern bool ieee80211_is_connected(ieee80211_dev_t *);
+extern void ieee80211_report_current_op_mode(ieee80211_dev_t *,
+    ieee80211_operating_mode_t);
+extern void ieee80211_report_current_freq(ieee80211_dev_t *, uint16_t);
+extern uint16_t ieee80211_get_aid(ieee80211_dev_t *);
+extern int ieee80211_get_pairwise_security(ieee80211_dev_t *);
+extern bool ieee80211_is_ready(ieee80211_dev_t *);
+extern void ieee80211_set_ready(ieee80211_dev_t *, bool);
+extern bool ieee80211_query_using_key(ieee80211_dev_t *);
+extern void ieee80211_setup_key_confirm(ieee80211_dev_t *, bool);
+
+extern bool ieee80211_is_data_frame(uint16_t);
+extern bool ieee80211_is_mgmt_frame(uint16_t);
+extern bool ieee80211_is_beacon_frame(uint16_t);
+extern bool ieee80211_is_probe_response_frame(uint16_t);
+extern bool ieee80211_is_auth_frame(uint16_t);
+extern bool ieee80211_is_assoc_response_frame(uint16_t);
 
 /* Worker functions. */
-extern int ieee80211_rx_handler(ieee80211_dev_t *ieee80211_dev, void *buffer,
-	size_t buffer_size);
-
-#endif // LIB_IEEE80211_H
+extern int ieee80211_rx_handler(ieee80211_dev_t *, void *, size_t);
+
+#endif
 
 /** @}
Index: uspace/lib/ieee80211/include/ieee80211_iface_impl.h
===================================================================
--- uspace/lib/ieee80211/include/ieee80211_iface_impl.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/include/ieee80211_iface_impl.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -27,5 +27,5 @@
  */
 
-/** 
+/**
  * @addtogroup libieee80211
  * @{
@@ -33,22 +33,20 @@
 
 /** @file ieee80211_iface_impl.h
- * 
+ *
  * IEEE 802.11 default interface functions definition.
  */
 
 #ifndef LIB_IEEE80211_IFACE_IMPL_H
-#define	LIB_IEEE80211_IFACE_IMPL_H
+#define LIB_IEEE80211_IFACE_IMPL_H
 
 #include <ddf/driver.h>
-
 #include "ieee80211.h"
 
-extern int ieee80211_get_scan_results_impl(ddf_fun_t *fun, 
-	ieee80211_scan_results_t *results, bool now);
-extern int ieee80211_connect_impl(ddf_fun_t *fun, char *ssid_start, 
-	char *password);
-extern int ieee80211_disconnect_impl(ddf_fun_t *fun);
+extern int ieee80211_get_scan_results_impl(ddf_fun_t *,
+    ieee80211_scan_results_t *, bool);
+extern int ieee80211_connect_impl(ddf_fun_t *, char *, char *);
+extern int ieee80211_disconnect_impl(ddf_fun_t *);
 
-#endif	/* LIB_IEEE80211_IFACE_IMPL_H */
+#endif  /* LIB_IEEE80211_IFACE_IMPL_H */
 
 /** @}
Index: uspace/lib/ieee80211/include/ieee80211_impl.h
===================================================================
--- uspace/lib/ieee80211/include/ieee80211_impl.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/include/ieee80211_impl.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -27,5 +27,5 @@
  */
 
-/** 
+/**
  * @addtogroup libieee80211
  * @{
@@ -33,40 +33,33 @@
 
 /** @file ieee80211_impl.h
- * 
+ *
  * IEEE 802.11 default device functions definition.
  */
 
 #ifndef LIB_IEEE80211_IMPL_H
-#define	LIB_IEEE80211_IMPL_H
+#define LIB_IEEE80211_IMPL_H
 
 #include "ieee80211_private.h"
 
-extern int ieee80211_start_impl(ieee80211_dev_t *ieee80211_dev);
-extern int ieee80211_tx_handler_impl(ieee80211_dev_t *ieee80211_dev, 
-	void *buffer, size_t buffer_size);
-extern int ieee80211_set_freq_impl(ieee80211_dev_t *ieee80211_dev, 
-	uint16_t freq);
-extern int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev,
-	bool connected);
-extern int ieee80211_key_config_impl(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_key_config_t *key_conf, bool insert);
-extern int ieee80211_scan_impl(ieee80211_dev_t *ieee80211_dev);
-extern int ieee80211_prf(uint8_t *key, uint8_t *data, uint8_t *hash, 
-	size_t output_size);
-extern int ieee80211_rc4_key_unwrap(uint8_t *key, uint8_t *data, 
-	size_t data_size, uint8_t *output);
-extern int ieee80211_aes_key_unwrap(uint8_t *kek, uint8_t *data, 
-	size_t data_size, uint8_t *output);
-extern int ieee80211_michael_mic(uint8_t *key, uint8_t *data, size_t data_size, 
-	uint8_t *mic);
-extern uint16_t uint16le_from_seq(void *seq);
-extern uint32_t uint32le_from_seq(void *seq);
-extern uint16_t uint16be_from_seq(void *seq);
-extern uint32_t uint32be_from_seq(void *seq);
-extern int rnd_sequence(uint8_t *sequence, size_t length);
-extern uint8_t *min_sequence(uint8_t *seq1, uint8_t *seq2, size_t size);
-extern uint8_t *max_sequence(uint8_t *seq1, uint8_t *seq2, size_t size);
+extern int ieee80211_start_impl(ieee80211_dev_t *);
+extern int ieee80211_tx_handler_impl(ieee80211_dev_t *, void *, size_t);
+extern int ieee80211_set_freq_impl(ieee80211_dev_t *, uint16_t);
+extern int ieee80211_bssid_change_impl(ieee80211_dev_t *, bool);
+extern int ieee80211_key_config_impl(ieee80211_dev_t *,
+    ieee80211_key_config_t *, bool);
+extern int ieee80211_scan_impl(ieee80211_dev_t *);
+extern int ieee80211_prf(uint8_t *, uint8_t *, uint8_t *, size_t);
+extern int ieee80211_rc4_key_unwrap(uint8_t *, uint8_t *, size_t, uint8_t *);
+extern int ieee80211_aes_key_unwrap(uint8_t *, uint8_t *, size_t, uint8_t *);
+extern int ieee80211_michael_mic(uint8_t *, uint8_t *, size_t, uint8_t *);
+extern uint16_t uint16le_from_seq(void *);
+extern uint32_t uint32le_from_seq(void *);
+extern uint16_t uint16be_from_seq(void *);
+extern uint32_t uint32be_from_seq(void *);
+extern int rnd_sequence(uint8_t *, size_t);
+extern uint8_t *min_sequence(uint8_t *, uint8_t *, size_t);
+extern uint8_t *max_sequence(uint8_t *, uint8_t *, size_t);
 
-#endif	/* LIB_IEEE80211_IMPL_H */
+#endif  /* LIB_IEEE80211_IMPL_H */
 
 /** @}
Index: uspace/lib/ieee80211/include/ieee80211_private.h
===================================================================
--- uspace/lib/ieee80211/include/ieee80211_private.h	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/include/ieee80211_private.h	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -27,5 +27,5 @@
  */
 
-/** 
+/**
  * @addtogroup libieee80211
  * @{
@@ -33,10 +33,10 @@
 
 /** @file ieee80211.h
- * 
+ *
  * Internal IEEE 802.11 header that should not be included.
  */
 
-#ifndef LIBNET_IEEE80211_PRIVATE_H
-#define LIBNET_IEEE80211_PRIVATE_H
+#ifndef LIB_IEEE80211_PRIVATE_H
+#define LIB_IEEE80211_PRIVATE_H
 
 #include <fibril_synch.h>
@@ -44,57 +44,57 @@
 #include <ddf/driver.h>
 #include <sys/types.h>
-
 #include <ieee80211/ieee80211.h>
 #include "ieee80211.h"
 
-/* Timeout in us for waiting to authentication/association response. */
-#define AUTH_TIMEOUT 200000
-
-/* Timeout in us for waiting to finish 4-way handshake process. */
-#define HANDSHAKE_TIMEOUT 5000000
-
-/* Scanning period. */
-#define SCAN_PERIOD_USEC 35000000
-
-/* Time to wait for beacons on channel. */
-#define SCAN_CHANNEL_WAIT_USEC 200000
-
-/* Max time to keep scan result. */
-#define MAX_KEEP_SCAN_SPAN_SEC 120
-
-/* Security bit in capability info field. */
-#define CAP_SECURITY 0x10
-
-/* Protocol type used in EAPOL frames. */
-#define ETH_TYPE_PAE 0x888E
-
-/* WPA OUI used in vendor specific IE. */
-#define WPA_OUI 0x0050F201
-
-/* GTK OUI used in vendor specific IE. */
-#define GTK_OUI 0x000FAC01
-
-/* Max PTK key length. */
-#define MAX_PTK_LENGTH 64
-
-/* Max GTK key length. */
-#define MAX_GTK_LENGTH 64
-
-/* KEK offset inside PTK. */
-#define KEK_OFFSET 16
-
-/* TK offset inside PTK. */
-#define TK_OFFSET 32
-
-/* Length of Michael MIC code used in TKIP security suite. */
-#define MIC_LENGTH 8
-
-/* 
- * Length of data to be encrypted by PRF function:
- * NONCE + SNONCE (2 * 32) + DEST_MAC + SOURCE_MAC (2 * ETH_ADDR) 
+/** Timeout in us for waiting to authentication/association response. */
+#define AUTH_TIMEOUT  200000
+
+/** Timeout in us for waiting to finish 4-way handshake process. */
+#define HANDSHAKE_TIMEOUT  5000000
+
+/** Scanning period. */
+#define SCAN_PERIOD_USEC  35000000
+
+/** Time to wait for beacons on channel. */
+#define SCAN_CHANNEL_WAIT_USEC  200000
+
+/** Max time to keep scan result. */
+#define MAX_KEEP_SCAN_SPAN_SEC  120
+
+/** Security bit in capability info field. */
+#define CAP_SECURITY  0x10
+
+/** Protocol type used in EAPOL frames. */
+#define ETH_TYPE_PAE  0x888e
+
+/** WPA OUI used in vendor specific IE. */
+#define WPA_OUI  0x0050f201
+
+/** GTK OUI used in vendor specific IE. */
+#define GTK_OUI  0x000fac01
+
+/** Max PTK key length. */
+#define MAX_PTK_LENGTH  64
+
+/** Max GTK key length. */
+#define MAX_GTK_LENGTH  64
+
+/** KEK offset inside PTK. */
+#define KEK_OFFSET  16
+
+/** TK offset inside PTK. */
+#define TK_OFFSET  32
+
+/** Length of Michael MIC code used in TKIP security suite. */
+#define MIC_LENGTH  8
+
+/** Length of data to be encrypted by PRF function.
+ *
+ * NONCE + SNONCE (2 * 32) + DEST_MAC + SOURCE_MAC (2 * ETH_ADDR)
+ *
  */
-#define PRF_CRYPT_DATA_LENGTH 2*32 + 2*ETH_ADDR
-
-/* Special room in header reserved for encryption. */
+#define PRF_CRYPT_DATA_LENGTH  (2 * 32 + 2 * ETH_ADDR)
+
+/** Special room in header reserved for encryption. */
 typedef enum {
 	IEEE80211_TKIP_HEADER_LENGTH = 8,
@@ -184,11 +184,11 @@
 /** IEEE 802.11 information element types. */
 typedef enum {
-	IEEE80211_SSID_IE = 0,		/**< Target SSID. */
-	IEEE80211_RATES_IE = 1,		/**< Supported data rates. */
-	IEEE80211_CHANNEL_IE = 3,	/**< Current channel number. */
-	IEEE80211_CHALLENGE_IE = 16,	/**< Challenge text. */
-	IEEE80211_RSN_IE = 48,		/**< RSN. */
-	IEEE80211_EXT_RATES_IE = 50,	/**< Extended data rates. */
-	IEEE80211_VENDOR_IE = 221	/**< Vendor specific IE. */
+	IEEE80211_SSID_IE = 0,        /**< Target SSID. */
+	IEEE80211_RATES_IE = 1,       /**< Supported data rates. */
+	IEEE80211_CHANNEL_IE = 3,     /**< Current channel number. */
+	IEEE80211_CHALLENGE_IE = 16,  /**< Challenge text. */
+	IEEE80211_RSN_IE = 48,        /**< RSN. */
+	IEEE80211_EXT_RATES_IE = 50,  /**< Extended data rates. */
+	IEEE80211_VENDOR_IE = 221     /**< Vendor specific IE. */
 } ieee80211_ie_type_t;
 
@@ -249,7 +249,7 @@
 	ieee80211_bssid_info_t bssid_info;
 	
-	/** 
+	/**
 	 * Flag indicating that data traffic is encrypted by HW key
-	 * that is set up in device. 
+	 * that is set up in device.
 	 */
 	bool using_hw_key;
@@ -290,29 +290,29 @@
 	uint8_t dest_addr[ETH_ADDR];
 	uint8_t src_addr[ETH_ADDR];
-	uint16_t proto;			/**< Big Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	eth_header_t;
+	uint16_t proto;  /**< Big Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    eth_header_t;
 
 /** IEEE 802.11 management header structure. */
 typedef struct {
-	uint16_t frame_ctrl;		/**< Little Endian value! */
-	uint16_t duration_id;		/**< Little Endian value! */
+	uint16_t frame_ctrl;          /**< Little Endian value! */
+	uint16_t duration_id;         /**< Little Endian value! */
 	uint8_t dest_addr[ETH_ADDR];
 	uint8_t src_addr[ETH_ADDR];
 	uint8_t bssid[ETH_ADDR];
-	uint16_t seq_ctrl;		/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_mgmt_header_t;
+	uint16_t seq_ctrl;            /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_mgmt_header_t;
 
 /** IEEE 802.11 data header structure. */
 typedef struct {
-	uint16_t frame_ctrl;		/**< Little Endian value! */
-	uint16_t duration_id;		/**< Little Endian value! */
+	uint16_t frame_ctrl;         /**< Little Endian value! */
+	uint16_t duration_id;        /**< Little Endian value! */
 	uint8_t address1[ETH_ADDR];
 	uint8_t address2[ETH_ADDR];
 	uint8_t address3[ETH_ADDR];
-	uint16_t seq_ctrl;		/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_data_header_t;
+	uint16_t seq_ctrl;           /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_data_header_t;
 
 /** IEEE 802.11 information element header. */
@@ -320,43 +320,43 @@
 	uint8_t element_id;
 	uint8_t length;
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_ie_header_t;
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_ie_header_t;
 
 /** IEEE 802.11 authentication frame body. */
 typedef struct {
-	uint16_t auth_alg;		/**< Little Endian value! */
-	uint16_t auth_trans_no;		/**< Little Endian value! */
-	uint16_t status;		/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_auth_body_t;
+	uint16_t auth_alg;       /**< Little Endian value! */
+	uint16_t auth_trans_no;  /**< Little Endian value! */
+	uint16_t status;         /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_auth_body_t;
 
 /** IEEE 802.11 deauthentication frame body. */
 typedef struct {
-	uint16_t reason;		/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_deauth_body_t;
+	uint16_t reason;    /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_deauth_body_t;
 
 /** IEEE 802.11 association request frame body. */
 typedef struct {
-	uint16_t capability;		/**< Little Endian value! */
-	uint16_t listen_interval;	/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_assoc_req_body_t;
+	uint16_t capability;       /**< Little Endian value! */
+	uint16_t listen_interval;  /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_assoc_req_body_t;
 
 /** IEEE 802.11 association response frame body. */
 typedef struct {
-	uint16_t capability;		/**< Little Endian value! */
-	uint16_t status;		/**< Little Endian value! */
-	uint16_t aid;			/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_assoc_resp_body_t;
+	uint16_t capability;  /**< Little Endian value! */
+	uint16_t status;      /**< Little Endian value! */
+	uint16_t aid;         /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_assoc_resp_body_t;
 
 /** IEEE 802.11 beacon frame body start. */
 typedef struct {
 	uint8_t timestamp[8];
-	uint16_t beacon_interval;	/**< Little Endian value! */
-	uint16_t capability;		/**< Little Endian value! */
-} __attribute__((packed)) __attribute__ ((aligned(2))) 
-	ieee80211_beacon_start_t;
+	uint16_t beacon_interval;  /**< Little Endian value! */
+	uint16_t capability;       /**< Little Endian value! */
+} __attribute__((packed)) __attribute__((aligned(2)))
+    ieee80211_beacon_start_t;
 
 /** IEEE 802.11i EAPOL-Key frame format. */
@@ -364,8 +364,8 @@
 	uint8_t proto_version;
 	uint8_t packet_type;
-	uint16_t body_length;		/**< Big Endian value! */
+	uint16_t body_length;      /**< Big Endian value! */
 	uint8_t descriptor_type;
-	uint16_t key_info;		/**< Big Endian value! */
-	uint16_t key_length;		/**< Big Endian value! */
+	uint16_t key_info;         /**< Big Endian value! */
+	uint16_t key_length;       /**< Big Endian value! */
 	uint8_t key_replay_counter[8];
 	uint8_t key_nonce[32];
@@ -374,12 +374,12 @@
 	uint8_t reserved[8];
 	uint8_t key_mic[16];
-	uint16_t key_data_length;	/**< Big Endian value! */
+	uint16_t key_data_length;  /**< Big Endian value! */
 } __attribute__((packed)) ieee80211_eapol_key_frame_t;
 
 #define ieee80211_scan_result_list_foreach(results, iter) \
-    list_foreach((results).list, link, ieee80211_scan_result_link_t, (iter))
-
-static inline void ieee80211_scan_result_list_init(
-	ieee80211_scan_result_list_t *results) 
+	list_foreach((results).list, link, ieee80211_scan_result_link_t, (iter))
+
+static inline void
+    ieee80211_scan_result_list_init(ieee80211_scan_result_list_t *results)
 {
 	list_initialize(&results->list);
@@ -387,7 +387,7 @@
 }
 
-static inline void ieee80211_scan_result_list_remove(
-	ieee80211_scan_result_list_t *results,
-	ieee80211_scan_result_link_t *result)
+static inline void
+    ieee80211_scan_result_list_remove(ieee80211_scan_result_list_t *results,
+    ieee80211_scan_result_link_t *result)
 {
 	list_remove(&result->link);
@@ -395,7 +395,7 @@
 }
 
-static inline void ieee80211_scan_result_list_append(
-	ieee80211_scan_result_list_t *results,
-	ieee80211_scan_result_link_t *result)
+static inline void
+    ieee80211_scan_result_list_append(ieee80211_scan_result_list_t *results,
+    ieee80211_scan_result_link_t *result)
 {
 	list_append(&result->link, &results->list);
@@ -403,20 +403,16 @@
 }
 
-extern bool ieee80211_is_fromds_frame(uint16_t frame_ctrl);
-extern bool ieee80211_is_tods_frame(uint16_t frame_ctrl);
-extern void ieee80211_set_connect_request(ieee80211_dev_t *ieee80211_dev);
-extern bool ieee80211_pending_connect_request(ieee80211_dev_t *ieee80211_dev);
-extern ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t 
-	*ieee80211_dev);
-extern void ieee80211_set_auth_phase(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_auth_phase_t auth_phase);
-extern int ieee80211_probe_request(ieee80211_dev_t *ieee80211_dev, 
-	char *ssid);
-extern int ieee80211_authenticate(ieee80211_dev_t *ieee80211_dev);
-extern int ieee80211_associate(ieee80211_dev_t *ieee80211_dev, 
-	char *password);
-extern int ieee80211_deauthenticate(ieee80211_dev_t *ieee80211_dev);
-
-#endif /* LIBN_IEEE80211_H */
+extern bool ieee80211_is_fromds_frame(uint16_t);
+extern bool ieee80211_is_tods_frame(uint16_t);
+extern void ieee80211_set_connect_request(ieee80211_dev_t *);
+extern bool ieee80211_pending_connect_request(ieee80211_dev_t *);
+extern ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t *);
+extern void ieee80211_set_auth_phase(ieee80211_dev_t *, ieee80211_auth_phase_t);
+extern int ieee80211_probe_request(ieee80211_dev_t *, char *);
+extern int ieee80211_authenticate(ieee80211_dev_t *);
+extern int ieee80211_associate(ieee80211_dev_t *, char *);
+extern int ieee80211_deauthenticate(ieee80211_dev_t *);
+
+#endif
 
 /** @}
Index: uspace/lib/ieee80211/src/ieee80211.c
===================================================================
--- uspace/lib/ieee80211/src/ieee80211.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/src/ieee80211.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -32,5 +32,5 @@
 
 /** @file ieee80211.c
- * 
+ *
  * IEEE 802.11 interface implementation.
  */
@@ -41,5 +41,4 @@
 #include <macros.h>
 #include <errno.h>
-
 #include <ieee80211.h>
 #include <ieee80211_impl.h>
@@ -48,25 +47,25 @@
 #include <ops/ieee80211.h>
 
-#define IEEE80211_DATA_RATES_SIZE 8
-#define IEEE80211_EXT_DATA_RATES_SIZE 4
+#define IEEE80211_DATA_RATES_SIZE      8
+#define IEEE80211_EXT_DATA_RATES_SIZE  4
 
 #define ATOMIC_GET(state)
 
 /** Frame encapsulation used in IEEE 802.11. */
-static const uint8_t rfc1042_header[] = { 
-	0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00 
+static const uint8_t rfc1042_header[] = {
+	0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 
 };
 
 /** Broadcast MAC address. */
 static const uint8_t ieee80211_broadcast_mac_addr[] = {
-	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 };
 
-/**
- * Check data frame.
- * 
+/** Check data frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is data frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_data_frame(uint16_t frame_ctrl)
@@ -74,14 +73,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_TYPE)
-		== IEEE80211_DATA_FRAME;
-}
-
-/**
- * Check management frame.
- * 
+	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_TYPE) ==
+	    IEEE80211_DATA_FRAME;
+}
+
+/** Check management frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is management frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_mgmt_frame(uint16_t frame_ctrl)
@@ -89,14 +88,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_TYPE)
-		== IEEE80211_MGMT_FRAME;
-}
-
-/**
- * Check management beacon frame.
- * 
+	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_TYPE) ==
+	    IEEE80211_MGMT_FRAME;
+}
+
+/** Check management beacon frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is beacon frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_beacon_frame(uint16_t frame_ctrl)
@@ -104,14 +103,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE)
-		== IEEE80211_MGMT_BEACON_FRAME;
-}
-
-/**
- * Check management probe response frame.
- * 
+	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE) ==
+	    IEEE80211_MGMT_BEACON_FRAME;
+}
+
+/** Check management probe response frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is probe resp frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_probe_response_frame(uint16_t frame_ctrl)
@@ -119,14 +118,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE)
-		== IEEE80211_MGMT_PROBE_RESP_FRAME;
-}
-
-/**
- * Check management authentication frame.
- * 
+	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE) ==
+	    IEEE80211_MGMT_PROBE_RESP_FRAME;
+}
+
+/** Check management authentication frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is auth frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_auth_frame(uint16_t frame_ctrl)
@@ -134,14 +133,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE)
-		== IEEE80211_MGMT_AUTH_FRAME;
-}
-
-/**
- * Check management association response frame.
- * 
+	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE) ==
+	    IEEE80211_MGMT_AUTH_FRAME;
+}
+
+/** Check management association response frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is assoc resp frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_assoc_response_frame(uint16_t frame_ctrl)
@@ -149,14 +148,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE)
-		== IEEE80211_MGMT_ASSOC_RESP_FRAME;
-}
-
-/**
- * Check data frame "to distribution system" direction.
- * 
+	return (frame_ctrl & IEEE80211_FRAME_CTRL_FRAME_SUBTYPE) ==
+	    IEEE80211_MGMT_ASSOC_RESP_FRAME;
+}
+
+/** Check data frame "to distribution system" direction.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is TODS frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_tods_frame(uint16_t frame_ctrl)
@@ -167,10 +166,10 @@
 }
 
-/**
- * Check data frame "from distribution system" direction.
- * 
+/** Check data frame "from distribution system" direction.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it is FROMDS frame, otherwise false.
+ *
  */
 inline bool ieee80211_is_fromds_frame(uint16_t frame_ctrl)
@@ -181,10 +180,10 @@
 }
 
-/**
- * Check if it is data frame containing payload data.
- * 
+/** Check if it is data frame containing payload data.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if it has payload data, otherwise false.
+ *
  */
 static inline bool ieee80211_has_data_frame(uint16_t frame_ctrl)
@@ -192,14 +191,14 @@
 	frame_ctrl = uint16_t_le2host(frame_ctrl);
 	
-	return (frame_ctrl & (IEEE80211_FRAME_CTRL_FRAME_TYPE | 0x40))
-		== IEEE80211_DATA_FRAME;
-}
-
-/**
- * Check if it is encrypted frame.
- * 
+	return (frame_ctrl & (IEEE80211_FRAME_CTRL_FRAME_TYPE | 0x40)) ==
+	    IEEE80211_DATA_FRAME;
+}
+
+/** Check if it is encrypted frame.
+ *
  * @param frame_ctrl Frame control field in little endian (!).
- * 
+ *
  * @return True if the frame is encrypted, otherwise false.
+ *
  */
 static inline bool ieee80211_is_encrypted_frame(uint16_t frame_ctrl)
@@ -210,24 +209,23 @@
 }
 
-/**
- * Check if PAE packet is EAPOL-Key frame.
- * 
+/** Check if PAE packet is EAPOL-Key frame.
+ *
  * @param key_frame Pointer to start of EAPOL frame.
- * 
+ *
  * @return True if it is EAPOL-Key frame, otherwise false.
- */
-static inline bool ieee80211_is_eapol_key_frame(ieee80211_eapol_key_frame_t 
-	*key_frame)
+ *
+ */
+static inline bool
+    ieee80211_is_eapol_key_frame(ieee80211_eapol_key_frame_t *key_frame)
 {
 	return (key_frame->packet_type == IEEE80211_EAPOL_KEY);
 }
 
-
-/**
- * Generate packet sequence number.
- * 
+/** Generate packet sequence number.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return True if it has payload data, otherwise false.
+ *
  */
 static uint16_t ieee80211_get_sequence_number(ieee80211_dev_t *ieee80211_dev)
@@ -235,52 +233,53 @@
 	uint16_t ret_val = ieee80211_dev->sequence_number;
 	ieee80211_dev->sequence_number += (1 << 4);
+	
 	return ret_val;
 }
 
-/**
- * Get driver-specific structure for IEEE 802.11 device.
- * 
+/** Get driver-specific structure for IEEE 802.11 device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return Driver-specific structure.
- */
-void *ieee80211_get_specific(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+void *ieee80211_get_specific(ieee80211_dev_t *ieee80211_dev)
 {
 	return ieee80211_dev->specific;
 }
 
-/**
- * Set driver-specific structure for IEEE 802.11 device.
- * 
+/** Set driver-specific structure for IEEE 802.11 device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * @param specific Driver-specific structure.
- */
-void ieee80211_set_specific(ieee80211_dev_t* ieee80211_dev,
-	void *specific)
+ * @param specific      Driver-specific structure.
+ *
+ */
+void ieee80211_set_specific(ieee80211_dev_t *ieee80211_dev,
+    void *specific)
 {
 	ieee80211_dev->specific = specific;
 }
 
-/**
- * Get related DDF device.
- * 
+/** Get related DDF device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return DDF device.
- */
-ddf_dev_t *ieee80211_get_ddf_dev(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+ddf_dev_t *ieee80211_get_ddf_dev(ieee80211_dev_t *ieee80211_dev)
 {
 	return ieee80211_dev->ddf_dev;
 }
 
-/**
- * Query current operating mode of IEEE 802.11 device.
- * 
+/** Query current operating mode of IEEE 802.11 device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return Current IEEE 802.11 operating mode.
- */
-ieee80211_operating_mode_t ieee80211_query_current_op_mode(ieee80211_dev_t* 
-	ieee80211_dev)
+ *
+ */
+ieee80211_operating_mode_t
+    ieee80211_query_current_op_mode(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -291,12 +290,12 @@
 }
 
-/**
- * Query current frequency of IEEE 802.11 device.
- * 
+/** Query current frequency of IEEE 802.11 device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return Current device operating frequency.
- */
-uint16_t ieee80211_query_current_freq(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+uint16_t ieee80211_query_current_freq(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -307,29 +306,28 @@
 }
 
-/**
- * Query BSSID the device is connected to.
- * 
+/** Query BSSID the device is connected to.
+ *
  * Note: Expecting locked results_mutex.
- * 
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * @param bssid Pointer to structure where should be stored BSSID.
- */
-void ieee80211_query_bssid(ieee80211_dev_t* ieee80211_dev, 
-	nic_address_t *bssid)
+ * @param bssid         Pointer to structure where should be stored BSSID.
+ *
+ */
+void ieee80211_query_bssid(ieee80211_dev_t *ieee80211_dev,
+    nic_address_t *bssid)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
 	
-	if(bssid) {
-		ieee80211_scan_result_link_t *res_link = 
-			ieee80211_dev->bssid_info.res_link;
-		
-		if(res_link) {
-			memcpy(bssid, &res_link->scan_result.bssid, 
-				sizeof(nic_address_t));
+	if (bssid) {
+		ieee80211_scan_result_link_t *res_link =
+		    ieee80211_dev->bssid_info.res_link;
+		
+		if (res_link) {
+			memcpy(bssid, &res_link->scan_result.bssid,
+			    sizeof(nic_address_t));
 		} else {
 			nic_address_t broadcast_addr;
 			memcpy(broadcast_addr.address,
-				ieee80211_broadcast_mac_addr,
-				ETH_ADDR);
+			    ieee80211_broadcast_mac_addr, ETH_ADDR);
 			memcpy(bssid, &broadcast_addr, sizeof(nic_address_t));
 		}
@@ -339,12 +337,12 @@
 }
 
-/**
- * Get AID of network we are connected to.
- * 
+/** Get AID of network we are connected to.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return AID.
- */
-uint16_t ieee80211_get_aid(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+uint16_t ieee80211_get_aid(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -355,16 +353,16 @@
 }
 
-/**
- * Get pairwise security suite used for HW encryption. 
- * 
+/** Get pairwise security suite used for HW encryption. 
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return Security suite indicator.
- */
-int ieee80211_get_pairwise_security(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+int ieee80211_get_pairwise_security(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
-	ieee80211_scan_result_link_t *auth_link = 
-		ieee80211_dev->bssid_info.res_link;
+	ieee80211_scan_result_link_t *auth_link =
+	    ieee80211_dev->bssid_info.res_link;
 	int suite = auth_link->scan_result.security.pair_alg;
 	fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
@@ -373,22 +371,23 @@
 }
 
-/**
- * Check if IEEE 802.11 device is connected to network.
- * 
+/** Check if IEEE 802.11 device is connected to network.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return True if device is connected to network, otherwise false.
- */
-bool ieee80211_is_connected(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+bool ieee80211_is_connected(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
-	bool conn_state = 
-		ieee80211_dev->current_auth_phase == IEEE80211_AUTH_CONNECTED;
+	bool conn_state =
+	    ieee80211_dev->current_auth_phase == IEEE80211_AUTH_CONNECTED;
 	fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
+	
 	return conn_state;
 }
 
 void ieee80211_set_auth_phase(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_auth_phase_t auth_phase)
+    ieee80211_auth_phase_t auth_phase)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -397,10 +396,10 @@
 }
 
-ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t 
-	*ieee80211_dev)
+ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
 	ieee80211_auth_phase_t conn_state = ieee80211_dev->current_auth_phase;
 	fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
+	
 	return conn_state;
 }
@@ -419,15 +418,16 @@
 	ieee80211_dev->pending_conn_req = false;
 	fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
+	
 	return conn_request;
 }
 
-/**
- * Report current operating mode for IEEE 802.11 device.
- * 
+/** Report current operating mode for IEEE 802.11 device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * @param op_mode Current IEEE 802.11 operating mode.
- */
-void ieee80211_report_current_op_mode(ieee80211_dev_t* ieee80211_dev,
-	ieee80211_operating_mode_t op_mode)
+ * @param op_mode       Current IEEE 802.11 operating mode.
+ *
+ */
+void ieee80211_report_current_op_mode(ieee80211_dev_t *ieee80211_dev,
+    ieee80211_operating_mode_t op_mode)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -436,12 +436,12 @@
 }
 
-/**
- * Report current frequency for IEEE 802.11 device.
- * 
+/** Report current frequency for IEEE 802.11 device.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * @param freq Current device operating frequency.
- */
-void ieee80211_report_current_freq(ieee80211_dev_t* ieee80211_dev,
-	uint16_t freq)
+ * @param freq          Current device operating frequency.
+ *
+ */
+void ieee80211_report_current_freq(ieee80211_dev_t *ieee80211_dev,
+    uint16_t freq)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -450,12 +450,12 @@
 }
 
-/**
- * Check if IEEE 802.11 device is ready (fully initialized).
- * 
+/** Check if IEEE 802.11 device is ready (fully initialized).
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * 
+ *
  * @return True if device is ready to work, otherwise false.
- */
-bool ieee80211_is_ready(ieee80211_dev_t* ieee80211_dev)
+ *
+ */
+bool ieee80211_is_ready(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -466,11 +466,11 @@
 }
 
-/**
- * Set IEEE 802.11 device to ready state.
- * 
+/** Set IEEE 802.11 device to ready state.
+ *
  * @param ieee80211_dev IEEE 802.11 device.
- * @param ready Ready state to be set.
- */
-void ieee80211_set_ready(ieee80211_dev_t* ieee80211_dev, bool ready)
+ * @param ready         Ready state to be set.
+ *
+ */
+void ieee80211_set_ready(ieee80211_dev_t *ieee80211_dev, bool ready)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -479,5 +479,5 @@
 }
 
-extern bool ieee80211_query_using_key(ieee80211_dev_t* ieee80211_dev)
+extern bool ieee80211_query_using_key(ieee80211_dev_t *ieee80211_dev)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -488,6 +488,6 @@
 }
 
-void ieee80211_setup_key_confirm(ieee80211_dev_t* ieee80211_dev, 
-	bool using_key)
+void ieee80211_setup_key_confirm(ieee80211_dev_t *ieee80211_dev,
+    bool using_key)
 {
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -502,5 +502,5 @@
 	ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) arg;
 	
-	while(true) {
+	while (true) {
 		ieee80211_dev->ops->scan(ieee80211_dev);
 		async_usleep(SCAN_PERIOD_USEC);
@@ -510,10 +510,10 @@
 }
 
-/**
- * Implementation of NIC open callback for IEEE 802.11 devices.
- * 
+/** Implementation of NIC open callback for IEEE 802.11 devices.
+ *
  * @param fun NIC function.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int ieee80211_open(ddf_fun_t *fun)
@@ -522,19 +522,18 @@
 	ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
 	
-	if(ieee80211_dev->started) {
+	if (ieee80211_dev->started)
 		return EOK;
-	} else {
-		ieee80211_dev->started = true;
-	}
+	
+	ieee80211_dev->started = true;
 	
 	int rc = ieee80211_dev->ops->start(ieee80211_dev);
-	if(rc != EOK)
+	if (rc != EOK)
 		return rc;
 	
 	/* Add scanning fibril. */
 	fid_t fibril = fibril_create(ieee80211_scan, ieee80211_dev);
-	if (fibril == 0) {
+	if (fibril == 0)
 		return ENOMEM;
-	}
+	
 	fibril_add_ready(fibril);
 	
@@ -542,32 +541,31 @@
 }
 
-/**
- * Send frame handler.
- * 
- * @param nic Pointer to NIC device.
+/** Send frame handler.
+ *
+ * @param nic  Pointer to NIC device.
  * @param data Data buffer.
  * @param size Data buffer size.
+ *
  */
 static void ieee80211_send_frame(nic_t *nic, void *data, size_t size)
 {
-	ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) 
-		nic_get_specific(nic);
-	
-	ieee80211_auth_phase_t auth_phase = 
-		ieee80211_get_auth_phase(ieee80211_dev);
-	if(auth_phase != IEEE80211_AUTH_ASSOCIATED && 
-		auth_phase != IEEE80211_AUTH_CONNECTED) {
+	ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *)
+	    nic_get_specific(nic);
+	
+	ieee80211_auth_phase_t auth_phase =
+	    ieee80211_get_auth_phase(ieee80211_dev);
+	if ((auth_phase != IEEE80211_AUTH_ASSOCIATED) &&
+	    (auth_phase != IEEE80211_AUTH_CONNECTED))
 		return;
-	}
 	
 	ieee80211_scan_result_t *auth_data =
-			&ieee80211_dev->bssid_info.res_link->scan_result;
+	    &ieee80211_dev->bssid_info.res_link->scan_result;
 	
 	/* We drop part of IEEE 802.3 ethernet header. */
 	size_t drop_bytes = sizeof(eth_header_t) - 2;
 	
-	size_t complete_size = (size - drop_bytes) + 
-		sizeof(ieee80211_data_header_t) +
-		ARRAY_SIZE(rfc1042_header);
+	size_t complete_size = (size - drop_bytes) +
+	    sizeof(ieee80211_data_header_t) +
+	    ARRAY_SIZE(rfc1042_header);
 	
 	/* Init crypto data. */
@@ -579,20 +577,20 @@
 	
 	// TODO: Distinguish used key (pair/group) by dest address ?
-	if(ieee80211_query_using_key(ieee80211_dev)) {
+	if (ieee80211_query_using_key(ieee80211_dev)) {
 		int sec_suite = auth_data->security.pair_alg;
-		switch(sec_suite) {
-			case IEEE80211_SECURITY_SUITE_TKIP:
-				head_space = IEEE80211_TKIP_HEADER_LENGTH;
-				mic_space = MIC_LENGTH;
-				add_mic = true;
-				break;
-			case IEEE80211_SECURITY_SUITE_CCMP:
-				head_space = IEEE80211_CCMP_HEADER_LENGTH;
-				head_data[3] = 0x20;
-				break;
-			default:
-				break;
+		switch (sec_suite) {
+		case IEEE80211_SECURITY_SUITE_TKIP:
+			head_space = IEEE80211_TKIP_HEADER_LENGTH;
+			mic_space = MIC_LENGTH;
+			add_mic = true;
+			break;
+		case IEEE80211_SECURITY_SUITE_CCMP:
+			head_space = IEEE80211_CCMP_HEADER_LENGTH;
+			head_data[3] = 0x20;
+			break;
+		default:
+			break;
 		}
-
+		
 		crypto = uint16_t_le2host(IEEE80211_FRAME_CTRL_PROTECTED);
 	}
@@ -601,116 +599,110 @@
 	
 	void *complete_buffer = malloc(complete_size);
+	if (!complete_buffer)
+		return;
+	
 	memset(complete_buffer, 0, complete_size);
 	
-	if(head_space) {
+	if (head_space)
 		memcpy(complete_buffer + sizeof(ieee80211_data_header_t),
-			head_data, head_space);
-	}
+		    head_data, head_space);
 	
 	memcpy(complete_buffer + sizeof(ieee80211_data_header_t) + head_space,
-		rfc1042_header,
-		ARRAY_SIZE(rfc1042_header));
-	
-	memcpy(complete_buffer + 
-		sizeof(ieee80211_data_header_t) +
-		ARRAY_SIZE(rfc1042_header) + head_space, 
-		data + drop_bytes, size - drop_bytes);
+	    rfc1042_header, ARRAY_SIZE(rfc1042_header));
+	
+	memcpy(complete_buffer + sizeof(ieee80211_data_header_t) +
+	    ARRAY_SIZE(rfc1042_header) + head_space,
+	    data + drop_bytes, size - drop_bytes);
 	
 	ieee80211_data_header_t *data_header =
-		(ieee80211_data_header_t *) complete_buffer;
-	data_header->frame_ctrl = 
-		uint16_t_le2host(IEEE80211_DATA_FRAME) |
-		uint16_t_le2host(IEEE80211_DATA_DATA_FRAME) |
-		uint16_t_le2host(IEEE80211_FRAME_CTRL_TODS) |
-		crypto;
+	    (ieee80211_data_header_t *) complete_buffer;
+	data_header->frame_ctrl =
+	    uint16_t_le2host(IEEE80211_DATA_FRAME) |
+	    uint16_t_le2host(IEEE80211_DATA_DATA_FRAME) |
+	    uint16_t_le2host(IEEE80211_FRAME_CTRL_TODS) |
+	    crypto;
 	data_header->seq_ctrl = ieee80211_get_sequence_number(ieee80211_dev);
 	
 	/* BSSID, SA, DA. */
-	memcpy(data_header->address1, auth_data->bssid.address,	ETH_ADDR);
+	memcpy(data_header->address1, auth_data->bssid.address, ETH_ADDR);
 	memcpy(data_header->address2, data + ETH_ADDR, ETH_ADDR);
 	memcpy(data_header->address3, data, ETH_ADDR);
 	
-	if(add_mic) {
+	if (add_mic) {
 		size_t size_wo_mic = complete_size - MIC_LENGTH;
 		uint8_t *tx_mic = ieee80211_dev->bssid_info.ptk +
-			TK_OFFSET +
-			IEEE80211_TKIP_TX_MIC_OFFSET;
+		    TK_OFFSET + IEEE80211_TKIP_TX_MIC_OFFSET;
 		ieee80211_michael_mic(tx_mic, complete_buffer, size_wo_mic,
-			complete_buffer + size_wo_mic);
-	}
-	
-	ieee80211_dev->ops->tx_handler(ieee80211_dev, 
-		complete_buffer, 
-		complete_size);
+		    complete_buffer + size_wo_mic);
+	}
+	
+	ieee80211_dev->ops->tx_handler(ieee80211_dev,
+	    complete_buffer, complete_size);
 	
 	free(complete_buffer);
 }
 
-/**
- * Fill out IEEE 802.11 device functions implementations.
- * 
- * @param ieee80211_dev IEEE 802.11 device.
- * @param ieee80211_ops Callbacks implementation.
+/** Fill out IEEE 802.11 device functions implementations.
+ *
+ * @param ieee80211_dev   IEEE 802.11 device.
+ * @param ieee80211_ops   Callbacks implementation.
  * @param ieee80211_iface Interface functions implementation.
- * @param nic_iface NIC interface functions implementation.
- * @param nic_dev_ops NIC device functions implementation.
- * 
- * @return EINVAL when missing pointer to ieee80211_ops or ieee80211_iface,
- * otherwise EOK.
- */
-static int ieee80211_implement(ieee80211_dev_t *ieee80211_dev, 
-	ieee80211_ops_t *ieee80211_ops, ieee80211_iface_t *ieee80211_iface,
-	nic_iface_t *nic_iface, ddf_dev_ops_t *nic_dev_ops)
-{
-	if(ieee80211_ops) {
-		if(!ieee80211_ops->start)
+ * @param nic_iface       NIC interface functions implementation.
+ * @param nic_dev_ops     NIC device functions implementation.
+ *
+ * @return EINVAL when missing pointer to ieee80211_ops
+ *         or ieee80211_iface, otherwise EOK.
+ *
+ */
+static int ieee80211_implement(ieee80211_dev_t *ieee80211_dev,
+    ieee80211_ops_t *ieee80211_ops, ieee80211_iface_t *ieee80211_iface,
+    nic_iface_t *nic_iface, ddf_dev_ops_t *nic_dev_ops)
+{
+	if (ieee80211_ops) {
+		if (!ieee80211_ops->start)
 			ieee80211_ops->start = ieee80211_start_impl;
-
-		if(!ieee80211_ops->tx_handler)
+		
+		if (!ieee80211_ops->tx_handler)
 			ieee80211_ops->tx_handler = ieee80211_tx_handler_impl;
-
-		if(!ieee80211_ops->set_freq)
+		
+		if (!ieee80211_ops->set_freq)
 			ieee80211_ops->set_freq = ieee80211_set_freq_impl;
 		
-		if(!ieee80211_ops->bssid_change)
-			ieee80211_ops->bssid_change = 
-				ieee80211_bssid_change_impl;
-		
-		if(!ieee80211_ops->key_config)
+		if (!ieee80211_ops->bssid_change)
+			ieee80211_ops->bssid_change = ieee80211_bssid_change_impl;
+		
+		if (!ieee80211_ops->key_config)
 			ieee80211_ops->key_config = ieee80211_key_config_impl;
 		
-		if(!ieee80211_ops->scan)
+		if (!ieee80211_ops->scan)
 			ieee80211_ops->scan = ieee80211_scan_impl;
-	} else {
+	} else
 		return EINVAL;
-	}
 	
 	ieee80211_dev->ops = ieee80211_ops;
 	
-	if(ieee80211_iface) {
-		if(nic_dev_ops)
+	if (ieee80211_iface) {
+		if (nic_dev_ops)
 			if (!nic_dev_ops->interfaces[IEEE80211_DEV_IFACE])
-				nic_dev_ops->interfaces[IEEE80211_DEV_IFACE] = 
-					ieee80211_iface;
-		
-		if(!ieee80211_iface->get_scan_results)
-			ieee80211_iface->get_scan_results = 
-				ieee80211_get_scan_results_impl;
-		
-		if(!ieee80211_iface->connect)
+				nic_dev_ops->interfaces[IEEE80211_DEV_IFACE] =
+				    ieee80211_iface;
+		
+		if (!ieee80211_iface->get_scan_results)
+			ieee80211_iface->get_scan_results =
+			    ieee80211_get_scan_results_impl;
+		
+		if (!ieee80211_iface->connect)
 			ieee80211_iface->connect = ieee80211_connect_impl;
 		
-		if(!ieee80211_iface->disconnect)
+		if (!ieee80211_iface->disconnect)
 			ieee80211_iface->disconnect = ieee80211_disconnect_impl;
-	} else {
+	} else
 		return EINVAL;
-	}
-	
-	if(nic_dev_ops) {
-		if(!nic_dev_ops->open)
+	
+	if (nic_dev_ops) {
+		if (!nic_dev_ops->open)
 			nic_dev_ops->open = ieee80211_open;
-	} else {
+	} else
 		return EINVAL;
-	}
 	
 	ieee80211_dev->iface = ieee80211_iface;
@@ -721,8 +713,8 @@
 }
 
-/**
- * Allocate IEEE802.11 device structure.
- * 
+/** Allocate IEEE802.11 device structure.
+ *
  * @return Pointer to allocated IEEE802.11 device structure.
+ *
  */
 ieee80211_dev_t *ieee80211_device_create()
@@ -731,11 +723,11 @@
 }
 
-/**
- * Initialize an IEEE802.11 framework structure.
- * 
+/** Initialize an IEEE802.11 framework structure.
+ *
  * @param ieee80211_dev Device structure to initialize.
- * @param ddf_dev Pointer to backing DDF device structure.
- * 
+ * @param ddf_dev       Pointer to backing DDF device structure.
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ieee80211_device_init(ieee80211_dev_t *ieee80211_dev, ddf_dev_t *ddf_dev)
@@ -748,6 +740,7 @@
 	ieee80211_dev->current_op_mode = IEEE80211_OPMODE_STATION;
 	ieee80211_dev->current_auth_phase = IEEE80211_AUTH_DISCONNECTED;
-	memcpy(ieee80211_dev->bssid_mask.address, ieee80211_broadcast_mac_addr, 
-		ETH_ADDR);
+	
+	memcpy(ieee80211_dev->bssid_mask.address, ieee80211_broadcast_mac_addr,
+	    ETH_ADDR);
 	
 	ieee80211_scan_result_list_init(&ieee80211_dev->ap_list);
@@ -759,7 +752,6 @@
 	/* Bind NIC to device */
 	nic_t *nic = nic_create_and_bind(ddf_dev);
-	if (!nic) {
+	if (!nic)
 		return ENOMEM;
-	}
 	
 	nic_set_specific(nic, ieee80211_dev);
@@ -768,35 +760,34 @@
 }
 
-/**
- * IEEE802.11 WiFi framework initialization.
- * 
- * @param ieee80211_dev Device structure to initialize.
- * @param ieee80211_ops Structure with implemented IEEE802.11 device operations.
- * @param ieee80211_iface Structure with implemented IEEE802.11 interface 
- * operations.
- * 
+/** IEEE802.11 WiFi framework initialization.
+ *
+ * @param ieee80211_dev   Device structure to initialize.
+ * @param ieee80211_ops   Structure with implemented IEEE802.11
+ *                        device operations.
+ * @param ieee80211_iface Structure with implemented IEEE802.11
+ *                        interface operations.
+ *
  * @return EOK if succeed, negative error code otherwise.
- */
-int ieee80211_init(ieee80211_dev_t *ieee80211_dev, 
-	ieee80211_ops_t *ieee80211_ops, ieee80211_iface_t *ieee80211_iface,
-	nic_iface_t *ieee80211_nic_iface, ddf_dev_ops_t *ieee80211_nic_dev_ops)
-{
-	int rc = ieee80211_implement(ieee80211_dev, 
-		ieee80211_ops, ieee80211_iface,
-		ieee80211_nic_iface, ieee80211_nic_dev_ops);
-	if(rc != EOK) {
+ *
+ */
+int ieee80211_init(ieee80211_dev_t *ieee80211_dev,
+    ieee80211_ops_t *ieee80211_ops, ieee80211_iface_t *ieee80211_iface,
+    nic_iface_t *ieee80211_nic_iface, ddf_dev_ops_t *ieee80211_nic_dev_ops)
+{
+	int rc = ieee80211_implement(ieee80211_dev,
+	    ieee80211_ops, ieee80211_iface,
+	    ieee80211_nic_iface, ieee80211_nic_dev_ops);
+	if (rc != EOK)
 		return rc;
-	}
 	
 	nic_t *nic = nic_get_from_ddf_dev(ieee80211_dev->ddf_dev);
 	
-	/** TODO: Set NIC handlers here. */
+	/* TODO: Set NIC handlers here. */
 	nic_set_send_frame_handler(nic, ieee80211_send_frame);
 	
-	ddf_fun_t *fun = ddf_fun_create(ieee80211_dev->ddf_dev, fun_exposed, 
-		"port0");
-	if (fun == NULL) {
+	ddf_fun_t *fun = ddf_fun_create(ieee80211_dev->ddf_dev, fun_exposed,
+	    "port0");
+	if (fun == NULL)
 		return EINVAL;
-	}
 	
 	nic_set_ddf_fun(nic, fun);
@@ -808,4 +799,5 @@
 		return rc;
 	}
+	
 	rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
 	if (rc != EOK) {
@@ -813,4 +805,5 @@
 		return rc;
 	}
+	
 	rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_IEEE80211);
 	if (rc != EOK) {
@@ -822,10 +815,10 @@
 }
 
-/**
- * Convert frequency value to channel number.
- * 
+/** Convert frequency value to channel number.
+ *
  * @param freq IEEE 802.11 operating frequency.
- * 
+ *
  * @return Operating channel number.
+ *
  */
 static uint8_t ieee80211_freq_to_channel(uint16_t freq)
@@ -835,8 +828,8 @@
 
 static void ieee80211_prepare_ie_header(void **ie_header,
-	uint8_t id, uint8_t length, void *data)
+    uint8_t id, uint8_t length, void *data)
 {
 	ieee80211_ie_header_t *header =
-		(ieee80211_ie_header_t *) *ie_header;
+	    (ieee80211_ie_header_t *) *ie_header;
 	
 	header->element_id = id;
@@ -845,15 +838,15 @@
 	memcpy(*ie_header + sizeof(ieee80211_ie_header_t), data, length);
 	
-	*ie_header = (void *) ((void *) header + 
-		sizeof(ieee80211_ie_header_t) + length);
-}
-
-/**
- * Probe request implementation.
- * 
+	*ie_header = (void *) ((void *) header +
+	    sizeof(ieee80211_ie_header_t) + length);
+}
+
+/** Probe request implementation.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param ssid Probing SSID or NULL if broadcast.
- * 
+ * @param ssid          Probing SSID or NULL if broadcast.
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ieee80211_probe_request(ieee80211_dev_t *ieee80211_dev, char *ssid)
@@ -866,45 +859,47 @@
 	size_t channel_data_size = 1;
 	
-	uint8_t channel = 
-		ieee80211_freq_to_channel(ieee80211_dev->current_freq);
-	
-	/* 4 headers - (ssid, rates, ext rates, current channel) and their data
-	 * lengths. 
+	uint8_t channel =
+	    ieee80211_freq_to_channel(ieee80211_dev->current_freq);
+	
+	/*
+	 * 4 headers - (ssid, rates, ext rates, current channel)
+	 * and their data lengths.
 	 */
-	size_t payload_size = 
-		sizeof(ieee80211_ie_header_t) * 4 +
-		ssid_data_size + 
-		IEEE80211_DATA_RATES_SIZE + IEEE80211_EXT_DATA_RATES_SIZE + 
-		channel_data_size;
+	size_t payload_size =
+	    sizeof(ieee80211_ie_header_t) * 4 +
+	    ssid_data_size +
+	    IEEE80211_DATA_RATES_SIZE + IEEE80211_EXT_DATA_RATES_SIZE +
+	    channel_data_size;
 	
 	size_t buffer_size = sizeof(ieee80211_mgmt_header_t) + payload_size;
 	void *buffer = malloc(buffer_size);
+	if (!buffer)
+		return ENOMEM;
+	
 	memset(buffer, 0, buffer_size);
 	
-	ieee80211_mgmt_header_t *mgmt_header = 
-		(ieee80211_mgmt_header_t *) buffer;
-	
-	mgmt_header->frame_ctrl = host2uint16_t_le(
-		IEEE80211_MGMT_FRAME | 
-		IEEE80211_MGMT_PROBE_REQ_FRAME
-		);
+	ieee80211_mgmt_header_t *mgmt_header =
+	    (ieee80211_mgmt_header_t *) buffer;
+	
+	mgmt_header->frame_ctrl =
+	    host2uint16_t_le(IEEE80211_MGMT_FRAME |
+	    IEEE80211_MGMT_PROBE_REQ_FRAME);
 	memcpy(mgmt_header->dest_addr, ieee80211_broadcast_mac_addr, ETH_ADDR);
 	memcpy(mgmt_header->src_addr, nic_address.address, ETH_ADDR);
 	memcpy(mgmt_header->bssid, ieee80211_broadcast_mac_addr, ETH_ADDR);
-	mgmt_header->seq_ctrl = 
-		host2uint16_t_le(ieee80211_get_sequence_number(ieee80211_dev));
+	mgmt_header->seq_ctrl =
+	    host2uint16_t_le(ieee80211_get_sequence_number(ieee80211_dev));
 	
 	/* Jump to payload. */
 	void *it = (void *) buffer + sizeof(ieee80211_mgmt_header_t);
-	ieee80211_prepare_ie_header(&it, IEEE80211_SSID_IE, ssid_data_size, 
-		(void *) ssid);
-	ieee80211_prepare_ie_header(&it, IEEE80211_RATES_IE, 
-		IEEE80211_DATA_RATES_SIZE, 
-		(void *) &ieee80211bg_data_rates);
-	ieee80211_prepare_ie_header(&it, IEEE80211_EXT_RATES_IE, 
-		IEEE80211_EXT_DATA_RATES_SIZE, 
-		(void *) &ieee80211bg_data_rates[IEEE80211_DATA_RATES_SIZE]);
-	ieee80211_prepare_ie_header(&it, IEEE80211_CHANNEL_IE, 
-		channel_data_size, (void *) &channel);
+	ieee80211_prepare_ie_header(&it, IEEE80211_SSID_IE, ssid_data_size,
+	    (void *) ssid);
+	ieee80211_prepare_ie_header(&it, IEEE80211_RATES_IE,
+	    IEEE80211_DATA_RATES_SIZE, (void *) &ieee80211bg_data_rates);
+	ieee80211_prepare_ie_header(&it, IEEE80211_EXT_RATES_IE,
+	    IEEE80211_EXT_DATA_RATES_SIZE,
+	    (void *) &ieee80211bg_data_rates[IEEE80211_DATA_RATES_SIZE]);
+	ieee80211_prepare_ie_header(&it, IEEE80211_CHANNEL_IE,
+	    channel_data_size, (void *) &channel);
 	
 	ieee80211_dev->ops->tx_handler(ieee80211_dev, buffer, buffer_size);
@@ -915,10 +910,10 @@
 }
 
-/**
- * IEEE 802.11 authentication implementation.
- * 
+/** IEEE 802.11 authentication implementation.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ieee80211_authenticate(ieee80211_dev_t *ieee80211_dev)
@@ -929,19 +924,21 @@
 	
 	ieee80211_scan_result_t *auth_data =
-		&ieee80211_dev->bssid_info.res_link->scan_result;
-	
-	size_t buffer_size = sizeof(ieee80211_mgmt_header_t) + 
-		sizeof(ieee80211_auth_body_t);
+	    &ieee80211_dev->bssid_info.res_link->scan_result;
+	
+	size_t buffer_size = sizeof(ieee80211_mgmt_header_t) +
+	    sizeof(ieee80211_auth_body_t);
 	
 	void *buffer = malloc(buffer_size);
+	if (!buffer)
+		return ENOMEM;
+	
 	memset(buffer, 0, buffer_size);
 	
-	ieee80211_mgmt_header_t *mgmt_header = 
-		(ieee80211_mgmt_header_t *) buffer;
-	
-	mgmt_header->frame_ctrl = host2uint16_t_le(
-		IEEE80211_MGMT_FRAME | 
-		IEEE80211_MGMT_AUTH_FRAME
-		);
+	ieee80211_mgmt_header_t *mgmt_header =
+	    (ieee80211_mgmt_header_t *) buffer;
+	
+	mgmt_header->frame_ctrl =
+	    host2uint16_t_le(IEEE80211_MGMT_FRAME |
+	    IEEE80211_MGMT_AUTH_FRAME);
 	memcpy(mgmt_header->dest_addr, auth_data->bssid.address, ETH_ADDR);
 	memcpy(mgmt_header->src_addr, nic_address.address, ETH_ADDR);
@@ -949,6 +946,6 @@
 	
 	ieee80211_auth_body_t *auth_body =
-		(ieee80211_auth_body_t *) 
-		(buffer + sizeof(ieee80211_mgmt_header_t));
+	    (ieee80211_auth_body_t *)
+	    (buffer + sizeof(ieee80211_mgmt_header_t));
 	auth_body->auth_alg = host2uint16_t_le(0);
 	auth_body->auth_trans_no = host2uint16_t_le(1);
@@ -961,14 +958,14 @@
 }
 
-/** 
- * IEEE 802.11 association implementation.
- * 
+/** IEEE 802.11 association implementation.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param password Passphrase to be used in encrypted communication or NULL
- * for open networks.
- * 
+ * @param password      Passphrase to be used in encrypted communication
+ *                      or NULL for open networks.
+ *
  * @return EOK if succeed, negative error code otherwise.
- */
-int ieee80211_associate(ieee80211_dev_t *ieee80211_dev, char *password) 
+ *
+ */
+int ieee80211_associate(ieee80211_dev_t *ieee80211_dev, char *password)
 {
 	nic_t *nic = nic_get_from_ddf_dev(ieee80211_dev->ddf_dev);
@@ -977,5 +974,5 @@
 	
 	ieee80211_scan_result_link_t *auth_link =
-		ieee80211_dev->bssid_info.res_link;
+	    ieee80211_dev->bssid_info.res_link;
 	
 	ieee80211_scan_result_t *auth_data = &auth_link->scan_result;
@@ -983,30 +980,31 @@
 	size_t ssid_data_size = str_size(auth_data->ssid);
 	
-	size_t payload_size = 
-		sizeof(ieee80211_ie_header_t) * 3 +
-		ssid_data_size + 
-		IEEE80211_DATA_RATES_SIZE + 
-		IEEE80211_EXT_DATA_RATES_SIZE;
-	
-	size_t buffer_size = 
-		sizeof(ieee80211_mgmt_header_t) + 
-		sizeof(ieee80211_assoc_req_body_t) +
-		payload_size;
-	
-	if(auth_data->security.type == IEEE80211_SECURITY_WPA || 
-		auth_data->security.type == IEEE80211_SECURITY_WPA2) {
+	size_t payload_size =
+	    sizeof(ieee80211_ie_header_t) * 3 +
+	    ssid_data_size +
+	    IEEE80211_DATA_RATES_SIZE +
+	    IEEE80211_EXT_DATA_RATES_SIZE;
+	
+	size_t buffer_size =
+	    sizeof(ieee80211_mgmt_header_t) +
+	    sizeof(ieee80211_assoc_req_body_t) +
+	    payload_size;
+	
+	if ((auth_data->security.type == IEEE80211_SECURITY_WPA) ||
+	    (auth_data->security.type == IEEE80211_SECURITY_WPA2))
 		buffer_size += auth_link->auth_ie_len;
-	}
 	
 	void *buffer = malloc(buffer_size);
+	if (!buffer)
+		return ENOMEM;
+	
 	memset(buffer, 0, buffer_size);
 	
-	ieee80211_mgmt_header_t *mgmt_header = 
-		(ieee80211_mgmt_header_t *) buffer;
-	
-	mgmt_header->frame_ctrl = host2uint16_t_le(
-		IEEE80211_MGMT_FRAME | 
-		IEEE80211_MGMT_ASSOC_REQ_FRAME
-		);
+	ieee80211_mgmt_header_t *mgmt_header =
+	    (ieee80211_mgmt_header_t *) buffer;
+	
+	mgmt_header->frame_ctrl =
+	    host2uint16_t_le(IEEE80211_MGMT_FRAME |
+	    IEEE80211_MGMT_ASSOC_REQ_FRAME);
 	memcpy(mgmt_header->dest_addr, auth_data->bssid.address, ETH_ADDR);
 	memcpy(mgmt_header->src_addr, nic_address.address, ETH_ADDR);
@@ -1014,37 +1012,34 @@
 	
 	ieee80211_assoc_req_body_t *assoc_body =
-		(ieee80211_assoc_req_body_t *) 
-		(buffer + sizeof(ieee80211_mgmt_header_t));
+	    (ieee80211_assoc_req_body_t *)
+	    (buffer + sizeof(ieee80211_mgmt_header_t));
 	assoc_body->listen_interval = host2uint16_t_le(1);
 	
 	/* Jump to payload. */
 	void *it = buffer + sizeof(ieee80211_mgmt_header_t) +
-		sizeof(ieee80211_assoc_req_body_t);
-	ieee80211_prepare_ie_header(&it, IEEE80211_SSID_IE, 
-		ssid_data_size, (void *) auth_data->ssid);
-	ieee80211_prepare_ie_header(&it, IEEE80211_RATES_IE, 
-		IEEE80211_DATA_RATES_SIZE, 
-		(void *) &ieee80211bg_data_rates);
-	ieee80211_prepare_ie_header(&it, IEEE80211_EXT_RATES_IE, 
-		IEEE80211_EXT_DATA_RATES_SIZE, 
-		(void *) &ieee80211bg_data_rates[IEEE80211_DATA_RATES_SIZE]);
-	
-	if(auth_data->security.type != IEEE80211_SECURITY_OPEN) {
+	    sizeof(ieee80211_assoc_req_body_t);
+	ieee80211_prepare_ie_header(&it, IEEE80211_SSID_IE,
+	    ssid_data_size, (void *) auth_data->ssid);
+	ieee80211_prepare_ie_header(&it, IEEE80211_RATES_IE,
+	    IEEE80211_DATA_RATES_SIZE, (void *) &ieee80211bg_data_rates);
+	ieee80211_prepare_ie_header(&it, IEEE80211_EXT_RATES_IE,
+	    IEEE80211_EXT_DATA_RATES_SIZE,
+	    (void *) &ieee80211bg_data_rates[IEEE80211_DATA_RATES_SIZE]);
+	
+	if (auth_data->security.type != IEEE80211_SECURITY_OPEN)
 		assoc_body->capability |= host2uint16_t_le(CAP_SECURITY);
-	}
-	
-	if(auth_data->security.type == IEEE80211_SECURITY_WPA || 
-		auth_data->security.type == IEEE80211_SECURITY_WPA2) {
-		memcpy(it, auth_link->auth_ie,	auth_link->auth_ie_len);
-	}
+	
+	if ((auth_data->security.type == IEEE80211_SECURITY_WPA) ||
+	    (auth_data->security.type == IEEE80211_SECURITY_WPA2))
+		memcpy(it, auth_link->auth_ie, auth_link->auth_ie_len);
 	
 	ieee80211_dev->ops->tx_handler(ieee80211_dev, buffer, buffer_size);
 	
-	/* 
-	 * Save password to be used in eventual authentication handshake. 
+	/*
+	 * Save password to be used in eventual authentication handshake.
 	 */
 	memset(ieee80211_dev->bssid_info.password, 0, IEEE80211_MAX_PASSW_LEN);
-	memcpy(ieee80211_dev->bssid_info.password, password, 
-		str_size(password));
+	memcpy(ieee80211_dev->bssid_info.password, password,
+	    str_size(password));
 	
 	free(buffer);
@@ -1053,17 +1048,17 @@
 }
 
-/** 
- * IEEE 802.11 deauthentication implementation.
- * 
+/** IEEE 802.11 deauthentication implementation.
+ *
  * Note: Expecting locked results_mutex or scan_mutex.
- * 
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ieee80211_deauthenticate(ieee80211_dev_t *ieee80211_dev)
 {
 	ieee80211_scan_result_t *auth_data =
-		&ieee80211_dev->bssid_info.res_link->scan_result;
+	    &ieee80211_dev->bssid_info.res_link->scan_result;
 	
 	nic_t *nic = nic_get_from_ddf_dev(ieee80211_dev->ddf_dev);
@@ -1071,16 +1066,19 @@
 	nic_query_address(nic, &nic_address);
 	
-	size_t buffer_size = sizeof(ieee80211_mgmt_header_t) + 
-		sizeof(ieee80211_deauth_body_t);
+	size_t buffer_size = sizeof(ieee80211_mgmt_header_t) +
+	    sizeof(ieee80211_deauth_body_t);
+	
 	void *buffer = malloc(buffer_size);
+	if (!buffer)
+		return ENOMEM;
+	
 	memset(buffer, 0, buffer_size);
 	
-	ieee80211_mgmt_header_t *mgmt_header = 
-		(ieee80211_mgmt_header_t *) buffer;
-	
-	mgmt_header->frame_ctrl = host2uint16_t_le(
-		IEEE80211_MGMT_FRAME | 
-		IEEE80211_MGMT_DEAUTH_FRAME
-		);
+	ieee80211_mgmt_header_t *mgmt_header =
+	    (ieee80211_mgmt_header_t *) buffer;
+	
+	mgmt_header->frame_ctrl =
+	    host2uint16_t_le(IEEE80211_MGMT_FRAME |
+	    IEEE80211_MGMT_DEAUTH_FRAME);
 	memcpy(mgmt_header->dest_addr, auth_data->bssid.address, ETH_ADDR);
 	memcpy(mgmt_header->src_addr, nic_address.address, ETH_ADDR);
@@ -1094,5 +1092,5 @@
 	ieee80211_dev->ops->bssid_change(ieee80211_dev, false);
 	
-	if(ieee80211_query_using_key(ieee80211_dev))
+	if (ieee80211_query_using_key(ieee80211_dev))
 		ieee80211_dev->ops->key_config(ieee80211_dev, NULL, false);
 	
@@ -1103,10 +1101,10 @@
 
 static void ieee80211_process_auth_info(ieee80211_scan_result_link_t *ap_data,
-	void *buffer)
+    void *buffer)
 {
 	uint8_t *it = (uint8_t *) buffer;
 	
 	uint16_t *version = (uint16_t *) it;
-	if(uint16_t_le2host(*version) != 0x1) {
+	if (uint16_t_le2host(*version) != 0x1) {
 		ap_data->scan_result.security.type = -1;
 		return;
@@ -1115,58 +1113,58 @@
 	it += sizeof(uint16_t);
 	
-	uint32_t group_cipher = *(it+3);
-	switch(group_cipher) {
-		case IEEE80211_AUTH_CIPHER_TKIP:
-			ap_data->scan_result.security.group_alg =
-				IEEE80211_SECURITY_SUITE_TKIP;
-			break;
-		case IEEE80211_AUTH_CIPHER_CCMP:
-			ap_data->scan_result.security.group_alg =
-				IEEE80211_SECURITY_SUITE_CCMP;
-			break;
-		default:
-			ap_data->scan_result.security.group_alg = -1;
-	}
-	
-	it += 4*sizeof(uint8_t);
+	uint32_t group_cipher = *(it + 3);
+	switch (group_cipher) {
+	case IEEE80211_AUTH_CIPHER_TKIP:
+		ap_data->scan_result.security.group_alg =
+		    IEEE80211_SECURITY_SUITE_TKIP;
+		break;
+	case IEEE80211_AUTH_CIPHER_CCMP:
+		ap_data->scan_result.security.group_alg =
+		    IEEE80211_SECURITY_SUITE_CCMP;
+		break;
+	default:
+		ap_data->scan_result.security.group_alg = -1;
+	}
+	
+	it += 4 * sizeof(uint8_t);
 	
 	uint16_t *pairwise_count = (uint16_t *) it;
-	uint32_t pairwise_cipher = *(it+sizeof(uint16_t)+3);
-	switch(pairwise_cipher) {
-		case IEEE80211_AUTH_CIPHER_TKIP:
-			ap_data->scan_result.security.pair_alg =
-				IEEE80211_SECURITY_SUITE_TKIP;
-			break;
-		case IEEE80211_AUTH_CIPHER_CCMP:
-			ap_data->scan_result.security.pair_alg =
-				IEEE80211_SECURITY_SUITE_CCMP;
-			break;
-		default:
-			ap_data->scan_result.security.pair_alg = -1;
-	}
-	
-	it += 2*sizeof(uint16_t) + 
-		uint16_t_le2host(*pairwise_count)*sizeof(uint32_t);
-	
-	uint32_t auth_suite = *(it+3);
-	switch(auth_suite) {
-		case IEEE80211_AUTH_AKM_PSK:
-			ap_data->scan_result.security.auth =
-				IEEE80211_SECURITY_AUTH_PSK;
-			break;
-		case IEEE80211_AUTH_AKM_8021X:
-			ap_data->scan_result.security.auth =
-				IEEE80211_SECURITY_AUTH_8021X;
-			break;
-		default:
-			ap_data->scan_result.security.auth = -1;
+	uint32_t pairwise_cipher = *(it + sizeof(uint16_t) + 3);
+	switch (pairwise_cipher) {
+	case IEEE80211_AUTH_CIPHER_TKIP:
+		ap_data->scan_result.security.pair_alg =
+		    IEEE80211_SECURITY_SUITE_TKIP;
+		break;
+	case IEEE80211_AUTH_CIPHER_CCMP:
+		ap_data->scan_result.security.pair_alg =
+		    IEEE80211_SECURITY_SUITE_CCMP;
+		break;
+	default:
+		ap_data->scan_result.security.pair_alg = -1;
+	}
+	
+	it += 2 * sizeof(uint16_t) +
+	    uint16_t_le2host(*pairwise_count) * sizeof(uint32_t);
+	
+	uint32_t auth_suite = *(it + 3);
+	switch (auth_suite) {
+	case IEEE80211_AUTH_AKM_PSK:
+		ap_data->scan_result.security.auth =
+		    IEEE80211_SECURITY_AUTH_PSK;
+		break;
+	case IEEE80211_AUTH_AKM_8021X:
+		ap_data->scan_result.security.auth =
+		    IEEE80211_SECURITY_AUTH_8021X;
+		break;
+	default:
+		ap_data->scan_result.security.auth = -1;
 	}
 }
 
 static void copy_auth_ie(ieee80211_ie_header_t *ie_header,
-	ieee80211_scan_result_link_t *ap_data, void *it)
-{
-	ap_data->auth_ie_len = ie_header->length + 
-		sizeof(ieee80211_ie_header_t);
+    ieee80211_scan_result_link_t *ap_data, void *it)
+{
+	ap_data->auth_ie_len = ie_header->length +
+	    sizeof(ieee80211_ie_header_t);
 	
 	memcpy(ap_data->auth_ie, it, ap_data->auth_ie_len);
@@ -1174,53 +1172,59 @@
 
 static uint8_t *ieee80211_process_ies(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_scan_result_link_t *ap_data, void *buffer, size_t buffer_size)
+    ieee80211_scan_result_link_t *ap_data, void *buffer, size_t buffer_size)
 {
 	void *it = buffer;
-	while((it + sizeof(ieee80211_ie_header_t)) < buffer + buffer_size) {
-		ieee80211_ie_header_t *ie_header = 
-			(ieee80211_ie_header_t *) it;
+	while ((it + sizeof(ieee80211_ie_header_t)) < buffer + buffer_size) {
+		ieee80211_ie_header_t *ie_header =
+		    (ieee80211_ie_header_t *) it;
 		uint8_t *channel;
 		uint32_t oui;
-		switch(ie_header->element_id) {
-			case IEEE80211_CHANNEL_IE:
-				if(!ap_data)
+		
+		switch (ie_header->element_id) {
+		case IEEE80211_CHANNEL_IE:
+			if (!ap_data)
+				break;
+			
+			channel = (uint8_t *)
+			    (it + sizeof(ieee80211_ie_header_t));
+			ap_data->scan_result.channel = *channel;
+			break;
+		case IEEE80211_RSN_IE:
+			if (!ap_data)
+				break;
+			
+			ap_data->scan_result.security.type =
+			    IEEE80211_SECURITY_WPA2;
+			ieee80211_process_auth_info(ap_data,
+			    it + sizeof(ieee80211_ie_header_t));
+			copy_auth_ie(ie_header, ap_data, it);
+			break;
+		case IEEE80211_VENDOR_IE:
+			oui = uint32be_from_seq(it +
+			    sizeof(ieee80211_ie_header_t));
+			
+			if (oui == WPA_OUI) {
+				if (!ap_data)
 					break;
-				channel = (uint8_t *) 
-					(it + sizeof(ieee80211_ie_header_t));
-				ap_data->scan_result.channel = *channel;
-				break;
-			case IEEE80211_RSN_IE:
-				if(!ap_data)
+				
+				/* Prefering WPA2. */
+				if (ap_data->scan_result.security.type ==
+				    IEEE80211_SECURITY_WPA2)
 					break;
+				
 				ap_data->scan_result.security.type =
-					IEEE80211_SECURITY_WPA2;
-				ieee80211_process_auth_info(ap_data, 
-					it + sizeof(ieee80211_ie_header_t));
+				    IEEE80211_SECURITY_WPA;
+				
+				ieee80211_process_auth_info(ap_data,
+				    it + sizeof(ieee80211_ie_header_t) +
+				    sizeof(uint32_t));
 				copy_auth_ie(ie_header, ap_data, it);
-				break;
-			case IEEE80211_VENDOR_IE:
-				oui = uint32be_from_seq(it + 
-					sizeof(ieee80211_ie_header_t));
-				if(oui == WPA_OUI) {
-					if(!ap_data)
-						break;
-					/* Prefering WPA2. */
-					if(ap_data->scan_result.security.type ==
-						IEEE80211_SECURITY_WPA2) {
-						break;
-					}
-					ap_data->scan_result.security.type =
-						IEEE80211_SECURITY_WPA;
-					ieee80211_process_auth_info(ap_data,
-						it + 
-						sizeof(ieee80211_ie_header_t) +
-						sizeof(uint32_t));
-					copy_auth_ie(ie_header, ap_data, it);
-				} else if(oui == GTK_OUI) {
-					return it + 
-						sizeof(ieee80211_ie_header_t) +
-						sizeof(uint32_t);
-				}
+			} else if (oui == GTK_OUI) {
+				return it +
+				    sizeof(ieee80211_ie_header_t) +
+				    sizeof(uint32_t);
+			}
 		}
+		
 		it += sizeof(ieee80211_ie_header_t) + ie_header->length;
 	}
@@ -1229,29 +1233,30 @@
 }
 
-/**
- * Process probe response and store results.
- * 
+/** Process probe response and store results.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param mgmt_header Pointer to start of management frame header.
- * 
+ * @param mgmt_header   Pointer to start of management frame header.
+ *
  * @return EOK if succeed, negative error code otherwise.
- */
-static int ieee80211_process_probe_response(ieee80211_dev_t *ieee80211_dev, 
-	ieee80211_mgmt_header_t *mgmt_header, size_t buffer_size)
-{
-	ieee80211_beacon_start_t *beacon_body = (ieee80211_beacon_start_t *) 
-		((void *)mgmt_header + sizeof(ieee80211_mgmt_header_t));
-	
-	ieee80211_ie_header_t *ssid_ie_header = (ieee80211_ie_header_t *) 
-		((void *)beacon_body + sizeof(ieee80211_beacon_start_t));
+ *
+ */
+static int ieee80211_process_probe_response(ieee80211_dev_t *ieee80211_dev,
+    ieee80211_mgmt_header_t *mgmt_header, size_t buffer_size)
+{
+	ieee80211_beacon_start_t *beacon_body = (ieee80211_beacon_start_t *)
+	    ((void *) mgmt_header + sizeof(ieee80211_mgmt_header_t));
+	
+	ieee80211_ie_header_t *ssid_ie_header = (ieee80211_ie_header_t *)
+	    ((void *) beacon_body + sizeof(ieee80211_beacon_start_t));
 	
 	/* Not empty SSID. */
-	if(ssid_ie_header->length > 0) {
+	if (ssid_ie_header->length > 0) {
 		ieee80211_scan_result_list_t *result_list =
-			&ieee80211_dev->ap_list;
-		
-		uint8_t *ssid_start = (uint8_t *) ((void *)ssid_ie_header + 
-			sizeof(ieee80211_ie_header_t));
+		    &ieee80211_dev->ap_list;
+		
+		uint8_t *ssid_start = (uint8_t *) ((void *) ssid_ie_header +
+		    sizeof(ieee80211_ie_header_t));
 		char ssid[IEEE80211_MAX_SSID_LENGTH];
+		
 		memcpy(ssid, ssid_start, ssid_ie_header->length);
 		ssid[ssid_ie_header->length] = '\0';
@@ -1259,5 +1264,5 @@
 		/* Check whether SSID is already in results. */
 		ieee80211_scan_result_list_foreach(*result_list, result) {
-			if(!str_cmp(ssid, result->scan_result.ssid)) {
+			if (!str_cmp(ssid, result->scan_result.ssid)) {
 				result->last_beacon = time(NULL);
 				return EOK;
@@ -1266,24 +1271,26 @@
 		
 		/* Results are full. */
-		if(result_list->size == IEEE80211_MAX_RESULTS_LENGTH - 1) {
+		if (result_list->size == IEEE80211_MAX_RESULTS_LENGTH - 1)
 			return EOK;
-		}
-		
-		ieee80211_scan_result_link_t *ap_data = 
-			malloc(sizeof(ieee80211_scan_result_link_t));
+		
+		ieee80211_scan_result_link_t *ap_data =
+		    malloc(sizeof(ieee80211_scan_result_link_t));
+		if (!ap_data)
+			return ENOMEM;
+		
 		memset(ap_data, 0, sizeof(ieee80211_scan_result_link_t));
 		link_initialize(&ap_data->link);
 		
-		memcpy(ap_data->scan_result.bssid.address, 
-			mgmt_header->bssid, ETH_ADDR);
-		memcpy(ap_data->scan_result.ssid, ssid, 
-			ssid_ie_header->length + 1);
-		
-		if(uint16_t_le2host(beacon_body->capability) & CAP_SECURITY) {
-			ap_data->scan_result.security.type = 
-				IEEE80211_SECURITY_WEP;
+		memcpy(ap_data->scan_result.bssid.address,
+		    mgmt_header->bssid, ETH_ADDR);
+		memcpy(ap_data->scan_result.ssid, ssid,
+		    ssid_ie_header->length + 1);
+		
+		if (uint16_t_le2host(beacon_body->capability) & CAP_SECURITY) {
+			ap_data->scan_result.security.type =
+			    IEEE80211_SECURITY_WEP;
 		} else {
-			ap_data->scan_result.security.type = 
-				IEEE80211_SECURITY_OPEN;
+			ap_data->scan_result.security.type =
+			    IEEE80211_SECURITY_OPEN;
 			ap_data->scan_result.security.auth = -1;
 			ap_data->scan_result.security.pair_alg = -1;
@@ -1292,13 +1299,13 @@
 		
 		void *rest_ies_start = ssid_start + ssid_ie_header->length;
-		size_t rest_buffer_size = 
-			buffer_size - 
-			sizeof(ieee80211_mgmt_header_t) -
-			sizeof(ieee80211_beacon_start_t) -
-			sizeof(ieee80211_ie_header_t) -
-			ssid_ie_header->length;
-		
-		ieee80211_process_ies(ieee80211_dev, ap_data, rest_ies_start, 
-			rest_buffer_size);
+		size_t rest_buffer_size =
+		    buffer_size -
+		    sizeof(ieee80211_mgmt_header_t) -
+		    sizeof(ieee80211_beacon_start_t) -
+		    sizeof(ieee80211_ie_header_t) -
+		    ssid_ie_header->length;
+		
+		ieee80211_process_ies(ieee80211_dev, ap_data, rest_ies_start,
+		    rest_buffer_size);
 		
 		ap_data->last_beacon = time(NULL);
@@ -1312,26 +1319,25 @@
 }
 
-/**
- * Process authentication response.
- * 
+/** Process authentication response.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param mgmt_header Pointer to start of management frame header.
- * 
+ * @param mgmt_header   Pointer to start of management frame header.
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int ieee80211_process_auth_response(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_mgmt_header_t *mgmt_header)
+    ieee80211_mgmt_header_t *mgmt_header)
 {
 	ieee80211_auth_body_t *auth_body =
-		(ieee80211_auth_body_t *)
-		((void *)mgmt_header + sizeof(ieee80211_mgmt_header_t));
-	
-	if(auth_body->status != 0) {
-		ieee80211_set_auth_phase(ieee80211_dev, 
-			IEEE80211_AUTH_DISCONNECTED);
-	} else {
-		ieee80211_set_auth_phase(ieee80211_dev, 
-			IEEE80211_AUTH_AUTHENTICATED);
-	}
+	    (ieee80211_auth_body_t *)
+	    ((void *) mgmt_header + sizeof(ieee80211_mgmt_header_t));
+	
+	if (auth_body->status != 0)
+		ieee80211_set_auth_phase(ieee80211_dev,
+		    IEEE80211_AUTH_DISCONNECTED);
+	else
+		ieee80211_set_auth_phase(ieee80211_dev,
+		    IEEE80211_AUTH_AUTHENTICATED);
 	
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
@@ -1342,27 +1348,27 @@
 }
 
-/**
- * Process association response.
- * 
+/** Process association response.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param mgmt_header Pointer to start of management frame header.
- * 
+ * @param mgmt_header   Pointer to start of management frame header.
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int ieee80211_process_assoc_response(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_mgmt_header_t *mgmt_header)
+    ieee80211_mgmt_header_t *mgmt_header)
 {
 	ieee80211_assoc_resp_body_t *assoc_resp =
-		(ieee80211_assoc_resp_body_t *) ((void *)mgmt_header +
-		sizeof(ieee80211_mgmt_header_t));
-	
-	if(assoc_resp->status != 0) {
-		ieee80211_set_auth_phase(ieee80211_dev, 
-			IEEE80211_AUTH_DISCONNECTED);
-	} else {
-		ieee80211_dev->bssid_info.aid = 
-			uint16_t_le2host(assoc_resp->aid);
-		ieee80211_set_auth_phase(ieee80211_dev, 
-			IEEE80211_AUTH_ASSOCIATED);
+	    (ieee80211_assoc_resp_body_t *) ((void *) mgmt_header +
+	    sizeof(ieee80211_mgmt_header_t));
+	
+	if (assoc_resp->status != 0)
+		ieee80211_set_auth_phase(ieee80211_dev,
+		    IEEE80211_AUTH_DISCONNECTED);
+	else {
+		ieee80211_dev->bssid_info.aid =
+		    uint16_t_le2host(assoc_resp->aid);
+		ieee80211_set_auth_phase(ieee80211_dev,
+		    IEEE80211_AUTH_ASSOCIATED);
 		ieee80211_dev->ops->bssid_change(ieee80211_dev, true);
 	}
@@ -1376,107 +1382,99 @@
 
 static int ieee80211_process_4way_handshake(ieee80211_dev_t *ieee80211_dev,
-	void *buffer, size_t buffer_size)
-{
-	ieee80211_eapol_key_frame_t *key_frame = 
-		(ieee80211_eapol_key_frame_t *) buffer;
-	
-	ieee80211_scan_result_link_t *auth_link = 
-		ieee80211_dev->bssid_info.res_link;
-
+    void *buffer, size_t buffer_size)
+{
+	ieee80211_eapol_key_frame_t *key_frame =
+	    (ieee80211_eapol_key_frame_t *) buffer;
+	
+	ieee80211_scan_result_link_t *auth_link =
+	    ieee80211_dev->bssid_info.res_link;
+	
 	ieee80211_scan_result_t *auth_data = &auth_link->scan_result;
 	
 	/* We don't support 802.1X authentication yet. */
-	if(auth_data->security.auth == IEEE80211_AUTH_AKM_8021X) {
+	if (auth_data->security.auth == IEEE80211_AUTH_AKM_8021X)
 		return ENOTSUP;
-	}
 	
 	uint8_t *ptk = ieee80211_dev->bssid_info.ptk;
 	uint8_t *gtk = ieee80211_dev->bssid_info.gtk;
 	uint8_t gtk_id = 1;
-
+	
 	bool handshake_done = false;
 	
-	bool old_wpa = 
-		auth_data->security.type == IEEE80211_SECURITY_WPA;
+	bool old_wpa =
+	    auth_data->security.type == IEEE80211_SECURITY_WPA;
 	
 	bool key_phase =
-		uint16_t_be2host(key_frame->key_info) & 
-		IEEE80211_EAPOL_KEY_KEYINFO_MIC;
-	
-	bool final_phase = 
-		uint16_t_be2host(key_frame->key_info) & 
-		IEEE80211_EAPOL_KEY_KEYINFO_SECURE;
-	
-	bool ccmp_used = 
-		auth_data->security.pair_alg == IEEE80211_SECURITY_SUITE_CCMP ||
-		auth_data->security.group_alg == IEEE80211_SECURITY_SUITE_CCMP;
+	    uint16_t_be2host(key_frame->key_info) &
+	    IEEE80211_EAPOL_KEY_KEYINFO_MIC;
+	
+	bool final_phase =
+	    uint16_t_be2host(key_frame->key_info) &
+	    IEEE80211_EAPOL_KEY_KEYINFO_SECURE;
+	
+	bool ccmp_used =
+	    (auth_data->security.pair_alg == IEEE80211_SECURITY_SUITE_CCMP) ||
+	    (auth_data->security.group_alg == IEEE80211_SECURITY_SUITE_CCMP);
 	
 	size_t ptk_key_length, gtk_key_length;
 	hash_func_t mic_hash;
-	if(ccmp_used) {
+	if (ccmp_used)
 		mic_hash = HASH_SHA1;
-	} else {
+	else
 		mic_hash = HASH_MD5;
-	}
-	
-	if(auth_data->security.pair_alg == IEEE80211_SECURITY_SUITE_CCMP) {
+	
+	if (auth_data->security.pair_alg == IEEE80211_SECURITY_SUITE_CCMP)
 		ptk_key_length = IEEE80211_PTK_CCMP_LENGTH;
-	} else {
+	else
 		ptk_key_length = IEEE80211_PTK_TKIP_LENGTH;
-	}
-	
-	if(auth_data->security.group_alg == IEEE80211_SECURITY_SUITE_CCMP) {
+	
+	if (auth_data->security.group_alg == IEEE80211_SECURITY_SUITE_CCMP)
 		gtk_key_length = IEEE80211_GTK_CCMP_LENGTH;
-	} else {
+	else
 		gtk_key_length = IEEE80211_GTK_TKIP_LENGTH;
-	}
-	
-	size_t output_size = 
-		sizeof(eth_header_t) +
-		sizeof(ieee80211_eapol_key_frame_t);
-
-	if(!(uint16_t_be2host(key_frame->key_info) & 
-		IEEE80211_EAPOL_KEY_KEYINFO_MIC)) {
+	
+	size_t output_size =
+	    sizeof(eth_header_t) +
+	    sizeof(ieee80211_eapol_key_frame_t);
+	
+	if (!(uint16_t_be2host(key_frame->key_info) &
+	    IEEE80211_EAPOL_KEY_KEYINFO_MIC))
 		output_size += auth_link->auth_ie_len;
-	}
-
+	
 	nic_t *nic = nic_get_from_ddf_dev(ieee80211_dev->ddf_dev);
 	nic_address_t nic_address;
 	nic_query_address(nic, &nic_address);
-
+	
 	void *output_buffer = malloc(output_size);
+	if (!output_buffer)
+		return ENOMEM;
+	
 	memset(output_buffer, 0, output_size);
-
+	
 	/* Setup ethernet header. */
 	eth_header_t *eth_header = (eth_header_t *) output_buffer;
-	memcpy(eth_header->dest_addr, auth_data->bssid.address,	ETH_ADDR);
+	memcpy(eth_header->dest_addr, auth_data->bssid.address, ETH_ADDR);
 	memcpy(eth_header->src_addr, nic_address.address, ETH_ADDR);
 	eth_header->proto = host2uint16_t_be(ETH_TYPE_PAE);
-
+	
 	ieee80211_eapol_key_frame_t *output_key_frame =
-		(ieee80211_eapol_key_frame_t *) 
-		(output_buffer + sizeof(eth_header_t));
-
+	    (ieee80211_eapol_key_frame_t *)
+	    (output_buffer + sizeof(eth_header_t));
+	
 	/* Copy content of incoming EAPOL-Key frame. */
-	memcpy((void *) output_key_frame, buffer, 
-		sizeof(ieee80211_eapol_key_frame_t));
-
+	memcpy((void *) output_key_frame, buffer,
+	    sizeof(ieee80211_eapol_key_frame_t));
+	
 	output_key_frame->proto_version = 0x1;
 	output_key_frame->body_length =
-		host2uint16_t_be(output_size - sizeof(eth_header_t) - 4);
-	output_key_frame->key_info &= 
-		~host2uint16_t_be(
-			IEEE80211_EAPOL_KEY_KEYINFO_ACK
-		);
-
-	if(key_phase) {
-		output_key_frame->key_info &= 
-			~host2uint16_t_be(
-				IEEE80211_EAPOL_KEY_KEYINFO_ENCDATA
-			);
-		output_key_frame->key_info &= 
-			~host2uint16_t_be(
-				IEEE80211_EAPOL_KEY_KEYINFO_INSTALL
-			);
+	    host2uint16_t_be(output_size - sizeof(eth_header_t) - 4);
+	output_key_frame->key_info &=
+	    ~host2uint16_t_be(IEEE80211_EAPOL_KEY_KEYINFO_ACK);
+	
+	if (key_phase) {
+		output_key_frame->key_info &=
+		    ~host2uint16_t_be(IEEE80211_EAPOL_KEY_KEYINFO_ENCDATA);
+		output_key_frame->key_info &=
+		    ~host2uint16_t_be(IEEE80211_EAPOL_KEY_KEYINFO_INSTALL);
 		output_key_frame->key_data_length = 0;
 		memset(output_key_frame->key_nonce, 0, 32);
@@ -1484,40 +1482,41 @@
 		memset(output_key_frame->key_rsc, 0, 8);
 		memset(output_key_frame->eapol_key_iv, 0, 16);
-
+		
 		/* Derive GTK and save it. */
-		if(final_phase) {
-			uint16_t key_data_length = 
-				uint16_t_be2host(key_frame->key_data_length);
+		if (final_phase) {
+			uint16_t key_data_length =
+			    uint16_t_be2host(key_frame->key_data_length);
 			uint8_t key_data[key_data_length];
-			uint8_t *data_ptr = (uint8_t *) (buffer + 
-				sizeof(ieee80211_eapol_key_frame_t));
-
+			uint8_t *data_ptr = (uint8_t *)
+			    (buffer + sizeof(ieee80211_eapol_key_frame_t));
+			
 			int rc;
 			uint8_t work_key[32];
-		
-			if(ccmp_used) {
-				rc = ieee80211_aes_key_unwrap(ptk + KEK_OFFSET, 
-					data_ptr, key_data_length, key_data);
+			
+			if (ccmp_used) {
+				rc = ieee80211_aes_key_unwrap(ptk + KEK_OFFSET,
+				    data_ptr, key_data_length, key_data);
 			} else {
 				memcpy(work_key, key_frame->eapol_key_iv, 16);
 				memcpy(work_key + 16, ptk + KEK_OFFSET, 16);
-				rc = ieee80211_rc4_key_unwrap(work_key, 
-					data_ptr, key_data_length, key_data);
+				rc = ieee80211_rc4_key_unwrap(work_key,
+				    data_ptr, key_data_length, key_data);
 			}
 			
-			if(rc == EOK) {
+			if (rc == EOK) {
 				uint8_t *key_data_ptr = old_wpa ? key_data :
-					ieee80211_process_ies(ieee80211_dev,
-					NULL, key_data, key_data_length);
-
-				if(key_data_ptr) {
+				    ieee80211_process_ies(ieee80211_dev,
+				    NULL, key_data, key_data_length);
+				
+				if (key_data_ptr) {
 					uint8_t *key_ptr;
-					if(old_wpa) {
+					
+					if (old_wpa)
 						key_ptr = key_data_ptr;
-					} else {
+					else {
 						gtk_id = *key_data_ptr & 0x3;
 						key_ptr = key_data_ptr + 2;
 					}
-						
+					
 					memcpy(gtk, key_ptr, gtk_key_length);
 					handshake_done = true;
@@ -1526,90 +1525,81 @@
 		}
 	} else {
-		output_key_frame->key_info |= 
-			host2uint16_t_be(
-				IEEE80211_EAPOL_KEY_KEYINFO_MIC
-			);
+		output_key_frame->key_info |=
+		    host2uint16_t_be(IEEE80211_EAPOL_KEY_KEYINFO_MIC);
 		output_key_frame->key_data_length =
-			host2uint16_t_be(auth_link->auth_ie_len);
-		memcpy((void *)output_key_frame + 
-			sizeof(ieee80211_eapol_key_frame_t),
-			auth_link->auth_ie,
-			auth_link->auth_ie_len);
-
+		    host2uint16_t_be(auth_link->auth_ie_len);
+		memcpy((void *) output_key_frame +
+		    sizeof(ieee80211_eapol_key_frame_t),
+		    auth_link->auth_ie, auth_link->auth_ie_len);
+		
 		/* Compute PMK. */
 		uint8_t pmk[PBKDF2_KEY_LENGTH];
 		pbkdf2((uint8_t *) ieee80211_dev->bssid_info.password,
-			str_size(ieee80211_dev->bssid_info.password),
-			(uint8_t *) auth_data->ssid,
-			str_size(auth_data->ssid), pmk);
-
+		    str_size(ieee80211_dev->bssid_info.password),
+		    (uint8_t *) auth_data->ssid,
+		    str_size(auth_data->ssid), pmk);
+		
 		uint8_t *anonce = key_frame->key_nonce;
-
+		
 		/* Generate SNONCE. */
 		uint8_t snonce[32];
 		rnd_sequence(snonce, 32);
-
+		
 		memcpy(output_key_frame->key_nonce, snonce, 32);
-
+		
 		uint8_t *dest_addr = eth_header->dest_addr;
 		uint8_t *src_addr = eth_header->src_addr;
-
+		
 		/* Derive PTK and save it. */
 		uint8_t crypt_data[PRF_CRYPT_DATA_LENGTH];
-		memcpy(crypt_data, 
-			min_sequence(dest_addr, src_addr, ETH_ADDR), 
-			ETH_ADDR);
-		memcpy(crypt_data + ETH_ADDR, 
-			max_sequence(dest_addr, src_addr, ETH_ADDR), 
-			ETH_ADDR);
-		memcpy(crypt_data + 2*ETH_ADDR, 
-			min_sequence(anonce, snonce, 32), 
-			32);
-		memcpy(crypt_data + 2*ETH_ADDR + 32, 
-			max_sequence(anonce, snonce, 32),
-			32);
+		memcpy(crypt_data,
+		    min_sequence(dest_addr, src_addr, ETH_ADDR), ETH_ADDR);
+		memcpy(crypt_data + ETH_ADDR,
+		    max_sequence(dest_addr, src_addr, ETH_ADDR), ETH_ADDR);
+		memcpy(crypt_data + 2*ETH_ADDR,
+		    min_sequence(anonce, snonce, 32), 32);
+		memcpy(crypt_data + 2*ETH_ADDR + 32,
+		    max_sequence(anonce, snonce, 32), 32);
 		ieee80211_prf(pmk, crypt_data, ptk, ptk_key_length);
 	}
-
+	
 	/* Compute MIC of key frame data from KCK part of PTK. */
 	uint8_t mic[mic_hash];
-	hmac(ptk, 16, (uint8_t *) output_key_frame, 
-		output_size - sizeof(eth_header_t), mic, mic_hash);
-
+	hmac(ptk, 16, (uint8_t *) output_key_frame,
+	    output_size - sizeof(eth_header_t), mic, mic_hash);
+	
 	memcpy(output_key_frame->key_mic, mic, 16);
-
+	
 	ieee80211_send_frame(nic, output_buffer, output_size);
-
+	
 	free(output_buffer);
-
+	
 	ieee80211_key_config_t key_config;
 	
 	/* Insert Pairwise key. */
-	if((key_phase && old_wpa) || (final_phase && !old_wpa)) {
+	if ((key_phase && old_wpa) || (final_phase && !old_wpa)) {
 		key_config.suite = auth_data->security.pair_alg;
 		key_config.flags =
-			IEEE80211_KEY_FLAG_TYPE_PAIRWISE;
-		memcpy(key_config.data, 
-			ptk + TK_OFFSET,
-			ptk_key_length - TK_OFFSET);
-
+		    IEEE80211_KEY_FLAG_TYPE_PAIRWISE;
+		memcpy(key_config.data,
+		    ptk + TK_OFFSET, ptk_key_length - TK_OFFSET);
+		
 		ieee80211_dev->ops->key_config(ieee80211_dev,
-			&key_config, true);
+		    &key_config, true);
 	}
 	
 	/* Insert Group key. */
-	if(final_phase) {
+	if (final_phase) {
 		key_config.id = gtk_id;
 		key_config.suite = auth_data->security.group_alg;
-		key_config.flags =
-			IEEE80211_KEY_FLAG_TYPE_GROUP;
+		key_config.flags = IEEE80211_KEY_FLAG_TYPE_GROUP;
 		memcpy(key_config.data, gtk, gtk_key_length);
-
+		
 		ieee80211_dev->ops->key_config(ieee80211_dev,
-			&key_config, true);
-	}
-
+		    &key_config, true);
+	}
+	
 	/* Signal successful handshake completion. */
-	if(handshake_done) {
+	if (handshake_done) {
 		fibril_mutex_lock(&ieee80211_dev->gen_mutex);
 		fibril_condvar_signal(&ieee80211_dev->gen_cond);
@@ -1621,77 +1611,74 @@
 
 static int ieee80211_process_eapol_frame(ieee80211_dev_t *ieee80211_dev,
-	void *buffer, size_t buffer_size)
-{
-	ieee80211_eapol_key_frame_t *key_frame = 
-		(ieee80211_eapol_key_frame_t *) buffer;
-	if(ieee80211_is_eapol_key_frame(key_frame)) {
+    void *buffer, size_t buffer_size)
+{
+	ieee80211_eapol_key_frame_t *key_frame =
+	    (ieee80211_eapol_key_frame_t *) buffer;
+	
+	if (ieee80211_is_eapol_key_frame(key_frame))
 		return ieee80211_process_4way_handshake(ieee80211_dev, buffer,
-			buffer_size);
-	}
+		    buffer_size);
 	
 	return EOK;
 }
 
-/**
- * Process data frame.
- * 
+/** Process data frame.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param buffer Data buffer starting with IEEE 802.11 data header.
- * @param buffer_size Size of buffer.
- * 
+ * @param buffer        Data buffer starting with IEEE 802.11 data header.
+ * @param buffer_size   Size of buffer.
+ *
  * @return EOK if succeed, negative error code otherwise.
- */
-static int ieee80211_process_data(ieee80211_dev_t *ieee80211_dev, 
-	void *buffer, size_t buffer_size)
-{
-	ieee80211_data_header_t *data_header = 
-		(ieee80211_data_header_t *) buffer;
-	
-	if(ieee80211_has_data_frame(data_header->frame_ctrl)) {
+ *
+ */
+static int ieee80211_process_data(ieee80211_dev_t *ieee80211_dev,
+    void *buffer, size_t buffer_size)
+{
+	ieee80211_data_header_t *data_header =
+	    (ieee80211_data_header_t *) buffer;
+	
+	if (ieee80211_has_data_frame(data_header->frame_ctrl)) {
 		nic_t *nic = nic_get_from_ddf_dev(ieee80211_dev->ddf_dev);
-		size_t strip_length = sizeof(ieee80211_data_header_t) + 
-			ARRAY_SIZE(rfc1042_header);
+		size_t strip_length = sizeof(ieee80211_data_header_t) +
+		    ARRAY_SIZE(rfc1042_header);
 		
 		/* TODO: Different by used security alg. */
 		/* TODO: Trim frame by used security alg. */
 		// TODO: Distinguish used key (pair/group) by dest address ?
-		if(ieee80211_is_encrypted_frame(data_header->frame_ctrl)) {
+		if (ieee80211_is_encrypted_frame(data_header->frame_ctrl))
 			strip_length += 8;
-		}
 		
 		/* Process 4-way authentication handshake. */
 		uint16_t *proto = (uint16_t *) (buffer + strip_length);
-		if(uint16_t_be2host(*proto) == ETH_TYPE_PAE) {
+		if (uint16_t_be2host(*proto) == ETH_TYPE_PAE)
 			return ieee80211_process_eapol_frame(ieee80211_dev,
-				buffer + strip_length + sizeof(uint16_t),
-				buffer_size - strip_length - sizeof(uint16_t));
-		}
-		
-		/* Note: ETH protocol ID is already there, so we don't create 
-		 * whole ETH header. */
-		size_t frame_size = 
-			buffer_size - strip_length + sizeof(eth_header_t)-2;
+			    buffer + strip_length + sizeof(uint16_t),
+			    buffer_size - strip_length - sizeof(uint16_t));
+		
+		/*
+		 * Note: ETH protocol ID is already there, so we don't create
+		 * whole ETH header.
+		 */
+		size_t frame_size =
+		    buffer_size - strip_length + sizeof(eth_header_t) - 2;
 		nic_frame_t *frame = nic_alloc_frame(nic, frame_size);
-
-		if(frame == NULL) {
+		
+		if(frame == NULL)
 			return ENOMEM;
-		}
-
-		uint8_t *src_addr = 
-			ieee80211_is_fromds_frame(data_header->frame_ctrl) ?
-				data_header->address3 : data_header->address2;
-		uint8_t *dest_addr = 
-			ieee80211_is_tods_frame(data_header->frame_ctrl) ?
-				data_header->address3 : data_header->address1;
-
-		eth_header_t *eth_header =
-			(eth_header_t *) frame->data;
+		
+		uint8_t *src_addr =
+		    ieee80211_is_fromds_frame(data_header->frame_ctrl) ?
+		    data_header->address3 : data_header->address2;
+		uint8_t *dest_addr =
+		    ieee80211_is_tods_frame(data_header->frame_ctrl) ?
+		    data_header->address3 : data_header->address1;
+		
+		eth_header_t *eth_header = (eth_header_t *) frame->data;
 		memcpy(eth_header->src_addr, src_addr, ETH_ADDR);
 		memcpy(eth_header->dest_addr, dest_addr, ETH_ADDR);
-
-		memcpy(frame->data + sizeof(eth_header_t)-2, 
-			buffer + strip_length, 
-			buffer_size - strip_length);
-
+		
+		memcpy(frame->data + sizeof(eth_header_t) - 2,
+		    buffer + strip_length, buffer_size - strip_length);
+		
 		nic_received_frame(nic, frame);
 	}
@@ -1700,40 +1687,37 @@
 }
 
-/**
- * IEEE 802.11 RX frames handler.
- * 
+/** IEEE 802.11 RX frames handler.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
- * @param buffer Buffer with data.
- * @param buffer_size Size of buffer.
- * 
+ * @param buffer        Buffer with data.
+ * @param buffer_size   Size of buffer.
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ieee80211_rx_handler(ieee80211_dev_t *ieee80211_dev, void *buffer,
-	size_t buffer_size)
+    size_t buffer_size)
 {
 	uint16_t frame_ctrl = *((uint16_t *) buffer);
-	if(ieee80211_is_mgmt_frame(frame_ctrl)) {
+	
+	if (ieee80211_is_mgmt_frame(frame_ctrl)) {
 		ieee80211_mgmt_header_t *mgmt_header =
-			(ieee80211_mgmt_header_t *) buffer;
-		
-		if(ieee80211_is_probe_response_frame(mgmt_header->frame_ctrl) ||
-			ieee80211_is_beacon_frame(mgmt_header->frame_ctrl)) {
+		    (ieee80211_mgmt_header_t *) buffer;
+		
+		if ((ieee80211_is_probe_response_frame(mgmt_header->frame_ctrl)) ||
+		    (ieee80211_is_beacon_frame(mgmt_header->frame_ctrl)))
 			return ieee80211_process_probe_response(ieee80211_dev,
-				mgmt_header, buffer_size);
-		}
-		
-		if(ieee80211_is_auth_frame(mgmt_header->frame_ctrl)) {
+			    mgmt_header, buffer_size);
+		
+		if (ieee80211_is_auth_frame(mgmt_header->frame_ctrl))
 			return ieee80211_process_auth_response(ieee80211_dev,
-				mgmt_header);
-		}
-		
-		if(ieee80211_is_assoc_response_frame(mgmt_header->frame_ctrl)) {
+			    mgmt_header);
+		
+		if (ieee80211_is_assoc_response_frame(mgmt_header->frame_ctrl))
 			return ieee80211_process_assoc_response(ieee80211_dev,
-				mgmt_header);
-		}
-	} else if(ieee80211_is_data_frame(frame_ctrl)) {
-		return ieee80211_process_data(ieee80211_dev, buffer, 
-			buffer_size);
-	}
+			    mgmt_header);
+	} else if (ieee80211_is_data_frame(frame_ctrl))
+		return ieee80211_process_data(ieee80211_dev, buffer,
+		    buffer_size);
 	
 	return EOK;
Index: uspace/lib/ieee80211/src/ieee80211_iface_impl.c
===================================================================
--- uspace/lib/ieee80211/src/ieee80211_iface_impl.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/src/ieee80211_iface_impl.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -27,50 +27,50 @@
  */
 
+/** @addtogroup libieee80211
+ * @{
+ */
+
+/** @file ieee80211_iface_impl.c
+ *
+ * IEEE 802.11 default interface functions implementation.
+ */
+
 #include <str.h>
 #include <errno.h>
-
 #include <ieee80211_private.h>
 #include <ieee80211_iface_impl.h>
 
-/** @addtogroup libieee80211
- * @{
- */
-
-/** @file ieee80211_iface_impl.c
- * 
- * IEEE 802.11 default interface functions implementation.
- */
-
-/**
- * Implementation of fetching scan results.
- * 
- * @param fun Device function.
+/** Implementation of fetching scan results.
+ *
+ * @param fun     Device function.
  * @param results Structure where should be stored scan results.
- * 
- * @return EOK if everything went OK, EREFUSED when device is not ready yet.
- */
-int ieee80211_get_scan_results_impl(ddf_fun_t *fun, 
-	ieee80211_scan_results_t *results, bool now)
+ *
+ * @return EOK if everything went OK,
+ *         EREFUSED when device is not ready yet.
+ *
+ */
+int ieee80211_get_scan_results_impl(ddf_fun_t *fun,
+    ieee80211_scan_results_t *results, bool now)
 {
 	nic_t *nic_data = nic_get_from_ddf_fun(fun);
 	ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
 	
-	if(!ieee80211_is_ready(ieee80211_dev))
+	if (!ieee80211_is_ready(ieee80211_dev))
 		return EREFUSED;
 	
-	if(now) {
+	if (now)
 		ieee80211_dev->ops->scan(ieee80211_dev);
-	}
 	
 	fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
-	if(results) {
+	
+	if (results) {
 		ieee80211_scan_result_list_t *result_list =
-			&ieee80211_dev->ap_list;
-		
-		int i = 0;
+		    &ieee80211_dev->ap_list;
+		
+		unsigned int i = 0;
 		ieee80211_scan_result_list_foreach(*result_list, result) {
-			memcpy(&results->results[i], 
-				&result->scan_result, 
-				sizeof(ieee80211_scan_result_t));
+			memcpy(&results->results[i],
+			    &result->scan_result,
+			    sizeof(ieee80211_scan_result_t));
 			i++;
 		}
@@ -78,4 +78,5 @@
 		results->length = i;
 	}
+	
 	fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
 	
@@ -88,36 +89,39 @@
 }
 
-/**
- * Working procedure of connect function.
- * 
+/** Working procedure of connect function.
+ *
  * @param ieee80211_dev Pointer to IEEE 802.11 device.
- * @param auth_data Selected AP data we want to connect to.
- * 
- * @return EOK if everything OK, ETIMEOUT when timeout during authenticating.
+ * @param auth_data     Selected AP data we want to connect to.
+ *
+ * @return EOK if everything OK,
+ *         ETIMEOUT when timeout during authenticating.
+ *
  */
 static int ieee80211_connect_proc(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_scan_result_link_t *auth_data, char *password)
+    ieee80211_scan_result_link_t *auth_data, char *password)
 {
 	ieee80211_dev->bssid_info.res_link = auth_data;
 	
 	/* Set channel. */
-	int rc = ieee80211_dev->ops->set_freq(ieee80211_dev, 
-		ieee80211_channel_to_freq(auth_data->scan_result.channel));
-	if(rc != EOK)
+	int rc = ieee80211_dev->ops->set_freq(ieee80211_dev,
+	    ieee80211_channel_to_freq(auth_data->scan_result.channel));
+	if (rc != EOK)
 		return rc;
 	
 	/* Try to authenticate. */
 	ieee80211_authenticate(ieee80211_dev);
+	
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
 	rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond,
-			&ieee80211_dev->gen_mutex,
-			AUTH_TIMEOUT);
+	    &ieee80211_dev->gen_mutex, AUTH_TIMEOUT);
 	fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
-	if(rc != EOK)
+	
+	if (rc != EOK)
 		return rc;
-	if(ieee80211_get_auth_phase(ieee80211_dev) != 
-		IEEE80211_AUTH_AUTHENTICATED) {
-		ieee80211_set_auth_phase(ieee80211_dev, 
-			IEEE80211_AUTH_DISCONNECTED);
+	
+	if (ieee80211_get_auth_phase(ieee80211_dev) !=
+	    IEEE80211_AUTH_AUTHENTICATED) {
+		ieee80211_set_auth_phase(ieee80211_dev,
+		    IEEE80211_AUTH_DISCONNECTED);
 		return EINVAL;
 	}
@@ -125,27 +129,31 @@
 	/* Try to associate. */
 	ieee80211_associate(ieee80211_dev, password);
+	
 	fibril_mutex_lock(&ieee80211_dev->gen_mutex);
 	rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond,
-			&ieee80211_dev->gen_mutex,
-			AUTH_TIMEOUT);
+	    &ieee80211_dev->gen_mutex, AUTH_TIMEOUT);
 	fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
-	if(rc != EOK)
+	
+	if (rc != EOK)
 		return rc;
-	if(ieee80211_get_auth_phase(ieee80211_dev) != 
-		IEEE80211_AUTH_ASSOCIATED) {
-		ieee80211_set_auth_phase(ieee80211_dev, 
-			IEEE80211_AUTH_DISCONNECTED);
+	
+	if (ieee80211_get_auth_phase(ieee80211_dev) !=
+	    IEEE80211_AUTH_ASSOCIATED) {
+		ieee80211_set_auth_phase(ieee80211_dev,
+		    IEEE80211_AUTH_DISCONNECTED);
 		return EINVAL;
 	}
 	
 	/* On open network, we are finished. */
-	if(auth_data->scan_result.security.type != IEEE80211_SECURITY_OPEN) {
+	if (auth_data->scan_result.security.type !=
+	    IEEE80211_SECURITY_OPEN) {
 		/* Otherwise wait for 4-way handshake to complete. */
+		
 		fibril_mutex_lock(&ieee80211_dev->gen_mutex);
 		rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond,
-				&ieee80211_dev->gen_mutex,
-				HANDSHAKE_TIMEOUT);
+		    &ieee80211_dev->gen_mutex, HANDSHAKE_TIMEOUT);
 		fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
-		if(rc != EOK) {
+		
+		if (rc != EOK) {
 			ieee80211_deauthenticate(ieee80211_dev);
 			return rc;
@@ -158,13 +166,15 @@
 }
 
-/**
- * Implementation of connecting to specified SSID.
- * 
- * @param fun Device function.
+/** Implementation of connecting to specified SSID.
+ *
+ * @param fun        Device function.
  * @param ssid_start SSID prefix of access point we want to connect to.
- * 
- * @return EOK if everything OK, ETIMEOUT when timeout during authenticating,
- * EINVAL when SSID not in scan results list, EPERM when incorrect password
- * passed, EREFUSED when device is not ready yet.
+ *
+ * @return EOK if everything OK,
+ *         ETIMEOUT when timeout during authenticating,
+ *         EINVAL when SSID not in scan results list,
+ *         EPERM when incorrect password passed,
+ *         EREFUSED when device is not ready yet.
+ *
  */
 int ieee80211_connect_impl(ddf_fun_t *fun, char *ssid_start, char *password)
@@ -173,15 +183,13 @@
 	assert(password);
 	
-	int rc;
-	
 	nic_t *nic_data = nic_get_from_ddf_fun(fun);
 	ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
 	
-	if(!ieee80211_is_ready(ieee80211_dev))
+	if (!ieee80211_is_ready(ieee80211_dev))
 		return EREFUSED;
 	
-	if(ieee80211_is_connected(ieee80211_dev)) {
-		rc = ieee80211_dev->iface->disconnect(fun);
-		if(rc != EOK)
+	if (ieee80211_is_connected(ieee80211_dev)) {
+		int rc = ieee80211_dev->iface->disconnect(fun);
+		if (rc != EOK)
 			return rc;
 	}
@@ -189,15 +197,14 @@
 	ieee80211_set_connect_request(ieee80211_dev);
 	
-	rc = ENOENT;
+	int rc = ENOENT;
 	fibril_mutex_lock(&ieee80211_dev->scan_mutex);
 	
 	ieee80211_dev->pending_conn_req = false;
-
+	
 	ieee80211_scan_result_list_foreach(ieee80211_dev->ap_list, result) {
-		if(!str_lcmp(ssid_start, 
-			result->scan_result.ssid, 
-			str_size(ssid_start))) {
+		if (!str_lcmp(ssid_start, result->scan_result.ssid,
+		    str_size(ssid_start))) {
 			rc = ieee80211_connect_proc(ieee80211_dev, result,
-				password);
+			    password);
 			break;
 		}
@@ -209,10 +216,11 @@
 }
 
-/**
- * Implementation of disconnecting device from network.
- * 
+/** Implementation of disconnecting device from network.
+ *
  * @param fun Device function.
- * 
- * @return EOK if everything OK, EREFUSED if device is not ready yet.
+ *
+ * @return EOK if everything OK,
+ *         EREFUSED if device is not ready yet.
+ *
  */
 int ieee80211_disconnect_impl(ddf_fun_t *fun)
@@ -221,15 +229,15 @@
 	ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
 	
-	if(!ieee80211_is_ready(ieee80211_dev))
+	if (!ieee80211_is_ready(ieee80211_dev))
 		return EREFUSED;
 	
-	if(!ieee80211_is_connected(ieee80211_dev)) {
+	if (!ieee80211_is_connected(ieee80211_dev))
 		return EOK;
-	} else {
-		fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
-		int rc = ieee80211_deauthenticate(ieee80211_dev);
-		fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
-		return rc;
-	}
+	
+	fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
+	int rc = ieee80211_deauthenticate(ieee80211_dev);
+	fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
+	
+	return rc;
 }
 
Index: uspace/lib/ieee80211/src/ieee80211_impl.c
===================================================================
--- uspace/lib/ieee80211/src/ieee80211_impl.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/lib/ieee80211/src/ieee80211_impl.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -32,5 +32,5 @@
 
 /** @file ieee80211_impl.c
- * 
+ *
  * IEEE 802.11 default device functions implementation.
  */
@@ -40,13 +40,12 @@
 #include <stdlib.h>
 #include <errno.h>
-
 #include <ieee80211_impl.h>
 
-/**
- * Default implementation of IEEE802.11 start function.
- * 
- * @param ieee80211_dev Structure of IEEE802.11 device.
- * 
- * @return EOK. 
+/** Default implementation of IEEE802.11 start function.
+ *
+ * @param ieee80211_dev Structure of IEEE802.11 device.
+ *
+ * @return EOK.
+ *
  */
 int ieee80211_start_impl(ieee80211_dev_t *ieee80211_dev)
@@ -55,26 +54,26 @@
 }
 
-/**
- * Default implementation of IEEE802.11 TX handler function.
- * 
- * @param ieee80211_dev Structure of IEEE802.11 device.
- * @param buffer Buffer with data to send.
- * @param buffer_size Size of buffer.
- * 
- * @return EOK. 
- */
-int ieee80211_tx_handler_impl(ieee80211_dev_t *ieee80211_dev, void *buffer, 
-	size_t buffer_size)
-{
-	return EOK;
-}
-
-/**
- * Default implementation of IEEE802.11 set frequency function.
- * 
- * @param ieee80211_dev Structure of IEEE802.11 device.
- * @param freq Value of frequency to be switched on.
- * 
- * @return EOK. 
+/** Default implementation of IEEE802.11 TX handler function.
+ *
+ * @param ieee80211_dev Structure of IEEE802.11 device.
+ * @param buffer        Buffer with data to send.
+ * @param buffer_size   Size of buffer.
+ *
+ * @return EOK.
+ *
+ */
+int ieee80211_tx_handler_impl(ieee80211_dev_t *ieee80211_dev, void *buffer,
+    size_t buffer_size)
+{
+	return EOK;
+}
+
+/** Default implementation of IEEE802.11 set frequency function.
+ *
+ * @param ieee80211_dev Structure of IEEE802.11 device.
+ * @param freq          Value of frequency to be switched on.
+ *
+ * @return EOK.
+ *
  */
 int ieee80211_set_freq_impl(ieee80211_dev_t *ieee80211_dev, uint16_t freq)
@@ -83,37 +82,37 @@
 }
 
-/**
- * Default implementation of IEEE802.11 BSSID change function.
- * 
- * @param ieee80211_dev Structure of IEEE802.11 device.
- * 
- * @return EOK. 
- */
-int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev, 
-	bool connected)
-{
-	return EOK;
-}
-
-/**
- * Default implementation of IEEE802.11 key config function.
- * 
- * @param ieee80211_dev Structure of IEEE802.11 device.
- * 
- * @return EOK. 
+/** Default implementation of IEEE802.11 BSSID change function.
+ *
+ * @param ieee80211_dev Structure of IEEE802.11 device.
+ *
+ * @return EOK.
+ *
+ */
+int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev,
+    bool connected)
+{
+	return EOK;
+}
+
+/** Default implementation of IEEE802.11 key config function.
+ *
+ * @param ieee80211_dev Structure of IEEE802.11 device.
+ *
+ * @return EOK.
+ *
  */
 int ieee80211_key_config_impl(ieee80211_dev_t *ieee80211_dev,
-	ieee80211_key_config_t *key_conf, bool insert)
-{
-	return EOK;
-}
-
-/**
- * Default implementation of IEEE802.11 scan function.
- * 
- * @param ieee80211_dev Structure of IEEE802.11 device.
- * @param clear Whether to clear current scan results.
- * 
- * @return EOK if succeed, negative error code otherwise. 
+    ieee80211_key_config_t *key_conf, bool insert)
+{
+	return EOK;
+}
+
+/** Default implementation of IEEE802.11 scan function.
+ *
+ * @param ieee80211_dev Structure of IEEE802.11 device.
+ * @param clear         Whether to clear current scan results.
+ *
+ * @return EOK if succeed, negative error code otherwise.
+ *
  */
 int ieee80211_scan_impl(ieee80211_dev_t *ieee80211_dev)
@@ -121,39 +120,39 @@
 	fibril_mutex_lock(&ieee80211_dev->scan_mutex);
 	
-	if(ieee80211_get_auth_phase(ieee80211_dev) == 
-		IEEE80211_AUTH_DISCONNECTED) {
+	if (ieee80211_get_auth_phase(ieee80211_dev) ==
+	    IEEE80211_AUTH_DISCONNECTED) {
 		fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
+		
 		/* Remove old entries we don't receive beacons from. */
-		ieee80211_scan_result_list_t *result_list = 
-			&ieee80211_dev->ap_list;
+		ieee80211_scan_result_list_t *result_list =
+		    &ieee80211_dev->ap_list;
+		
 		list_foreach_safe(result_list->list, cur_link, next_link) {
-			ieee80211_scan_result_link_t *cur_result = 
-				list_get_instance(cur_link,
-				ieee80211_scan_result_link_t, 
-				link);
-			if((time(NULL) - cur_result->last_beacon) > 
-				MAX_KEEP_SCAN_SPAN_SEC) {
-				ieee80211_scan_result_list_remove(result_list, 
-					cur_result);
-			}
+			ieee80211_scan_result_link_t *cur_result =
+			    list_get_instance(cur_link,
+			    ieee80211_scan_result_link_t, link);
+			
+			if ((time(NULL) - cur_result->last_beacon) >
+			    MAX_KEEP_SCAN_SPAN_SEC)
+				ieee80211_scan_result_list_remove(result_list,
+				    cur_result);
 		}
+		
 		fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
-
+		
 		uint16_t orig_freq = ieee80211_dev->current_freq;
-
-		for(uint16_t freq = IEEE80211_FIRST_FREQ;
-			freq <= IEEE80211_MAX_FREQ; 
-			freq += IEEE80211_CHANNEL_GAP) {
-			if(ieee80211_pending_connect_request(ieee80211_dev)) {
+		
+		for (uint16_t freq = IEEE80211_FIRST_FREQ;
+		    freq <= IEEE80211_MAX_FREQ; freq += IEEE80211_CHANNEL_GAP) {
+			if (ieee80211_pending_connect_request(ieee80211_dev))
 				break;
-			}
 			
 			ieee80211_dev->ops->set_freq(ieee80211_dev, freq);
 			ieee80211_probe_request(ieee80211_dev, NULL);
-
+			
 			/* Wait for probe responses. */
 			async_usleep(SCAN_CHANNEL_WAIT_USEC);
 		}
-
+		
 		ieee80211_dev->ops->set_freq(ieee80211_dev, orig_freq);
 	}
@@ -164,23 +163,26 @@
 }
 
-/**
- * Pseudorandom function used for IEEE 802.11 pairwise key computation
- * using SHA1 hash algorithm.
- * 
- * @param key Key with PBKDF2 encrypted passphrase.
- * @param data Concatenated sequence of both mac addresses and nonces.
- * @param hash Output parameter for result hash.
+/** Pseudorandom function used for IEEE 802.11 pairwise key computation.
+ *
+ * Using SHA1 hash algorithm.
+ *
+ * @param key         Key with PBKDF2 encrypted passphrase.
+ * @param data        Concatenated sequence of both MAC
+ *                    addresses and nonces.
+ * @param hash        Output parameter for result hash.
  * @param output_size Length of output sequence to be generated.
- * 
- * @return EINVAL when key or data not specified, ENOMEM when pointer for 
- * output hash result is not allocated, otherwise EOK. 
- */
-int ieee80211_prf(uint8_t *key, uint8_t *data, uint8_t *hash, 
-	size_t output_size)
-{
-	if(!key || !data)
+ *
+ * @return EINVAL when key or data not specified,
+ *         ENOMEM when pointer for output hash result
+ *         is not allocated, otherwise EOK.
+ *
+ */
+int ieee80211_prf(uint8_t *key, uint8_t *data, uint8_t *hash,
+    size_t output_size)
+{
+	if ((!key) || (!data))
 		return EINVAL;
 	
-	if(!hash)
+	if (!hash)
 		return ENOMEM;
 	
@@ -188,6 +190,7 @@
 	
 	const char *a = "Pairwise key expansion";
-	uint8_t result[HASH_SHA1*iters];
+	uint8_t result[HASH_SHA1 * iters];
 	uint8_t temp[HASH_SHA1];
+	
 	size_t data_size = PRF_CRYPT_DATA_LENGTH + str_size(a) + 2;
 	uint8_t work_arr[data_size];
@@ -196,9 +199,9 @@
 	memcpy(work_arr, a, str_size(a));
 	memcpy(work_arr + str_size(a) + 1, data, PRF_CRYPT_DATA_LENGTH);
-
-	for(uint8_t i = 0; i < iters; i++) {
+	
+	for (uint8_t i = 0; i < iters; i++) {
 		memcpy(work_arr + data_size - 1, &i, 1);
-		hmac(key, PBKDF2_KEY_LENGTH, work_arr, data_size, temp, 
-			HASH_SHA1);
+		hmac(key, PBKDF2_KEY_LENGTH, work_arr, data_size, temp,
+		    HASH_SHA1);
 		memcpy(result + i*HASH_SHA1, temp, HASH_SHA1);
 	}
@@ -210,5 +213,5 @@
 
 int ieee80211_rc4_key_unwrap(uint8_t *key, uint8_t *data, size_t data_size,
-	uint8_t *output)
+    uint8_t *output)
 {
 	return rc4(key, 32, data, data_size, 256, output);
@@ -216,60 +219,63 @@
 
 int ieee80211_aes_key_unwrap(uint8_t *kek, uint8_t *data, size_t data_size,
-	uint8_t *output)
-{
-	if(!kek || !data)
+    uint8_t *output)
+{
+	if ((!kek) || (!data))
 		return EINVAL;
 	
-	if(!output)
+	if (!output)
 		return ENOMEM;
-
-	uint32_t n = data_size/8 - 1;
-	uint8_t work_data[n*8];
+	
+	uint32_t n = data_size / 8 - 1;
+	uint8_t work_data[n * 8];
 	uint8_t work_input[AES_CIPHER_LENGTH];
 	uint8_t work_output[AES_CIPHER_LENGTH];
 	uint8_t *work_block;
 	uint8_t a[8];
+	
 	memcpy(a, data, 8);
-	uint64_t mask = 0xFF;
+	
+	uint64_t mask = 0xff;
 	uint8_t shift, shb;
 	
-	memcpy(work_data, data + 8, n*8);
-	for(int j = 5; j >= 0; j--) {
-		for(int i = n; i > 0; i--) {
-			for(size_t k = 0; k < 8; k++) {
-				shift = 56 - 8*k;
-				shb = ((n*j+i) & (mask << shift)) >> shift;
+	memcpy(work_data, data + 8, n * 8);
+	for (int j = 5; j >= 0; j--) {
+		for (int i = n; i > 0; i--) {
+			for (size_t k = 0; k < 8; k++) {
+				shift = 56 - 8 * k;
+				shb = ((n * j + i) & (mask << shift)) >> shift;
 				a[k] ^= shb;
 			}
-			work_block = work_data + (i-1)*8;
+			
+			work_block = work_data + (i - 1) * 8;
 			memcpy(work_input, a, 8);
 			memcpy(work_input + 8, work_block, 8);
 			aes_decrypt(kek, work_input, work_output);
 			memcpy(a, work_output, 8);
-			memcpy(work_data + (i-1)*8, work_output + 8, 8);
+			memcpy(work_data + (i - 1) * 8, work_output + 8, 8);
 		}
 	}
 	
 	size_t it;
-	for(it = 0; it < 8; it++) {
-		if(a[it] != 0xA6)
+	for (it = 0; it < 8; it++) {
+		if (a[it] != 0xa6)
 			break;
 	}
 	
-	if(it == 8) {
-		memcpy(output, work_data, n*8);
+	if (it == 8) {
+		memcpy(output, work_data, n * 8);
 		return EOK;
-	} else {
-		return EINVAL;
-	}
-}
-
-static void ieee80211_michael_mic_block(uint32_t *l, uint32_t *r, 
-	uint32_t value)
+	}
+	
+	return EINVAL;
+}
+
+static void ieee80211_michael_mic_block(uint32_t *l, uint32_t *r,
+    uint32_t value)
 {
 	*l ^= value;
 	*r ^= rotl_uint32(*l, 17);
 	*l += *r;
-	*r ^= ((*l & 0x00FF00FF) << 8) | ((*l & 0xFF00FF00) >> 8);
+	*r ^= ((*l & 0x00ff00ff) << 8) | ((*l & 0xff00ff00) >> 8);
 	*l += *r;
 	*r ^= rotl_uint32(*l, 3);
@@ -279,11 +285,11 @@
 }
 
-int ieee80211_michael_mic(uint8_t *key, uint8_t *buffer, size_t size, 
-	uint8_t *mic)
-{
-	if(!key || !buffer)
+int ieee80211_michael_mic(uint8_t *key, uint8_t *buffer, size_t size,
+    uint8_t *mic)
+{
+	if ((!key) || (!buffer))
 		return EINVAL;
 	
-	if(!mic)
+	if (!mic)
 		return ENOMEM;
 	
@@ -292,23 +298,23 @@
 	
 	ieee80211_data_header_t *data_header =
-		(ieee80211_data_header_t *) buffer;
-	
-	uint8_t *data = buffer + sizeof(ieee80211_data_header_t) + 
-		IEEE80211_TKIP_HEADER_LENGTH;
+	    (ieee80211_data_header_t *) buffer;
+	
+	uint8_t *data = buffer + sizeof(ieee80211_data_header_t) +
+	    IEEE80211_TKIP_HEADER_LENGTH;
 	size_t data_size = size - sizeof(ieee80211_data_header_t) -
-		IEEE80211_TKIP_HEADER_LENGTH;
+	    IEEE80211_TKIP_HEADER_LENGTH;
 	
 	/* Process header. */
-	uint8_t *src_addr = 
-		ieee80211_is_fromds_frame(data_header->frame_ctrl) ?
-			data_header->address3 : data_header->address2;
-	uint8_t *dest_addr = 
-		ieee80211_is_tods_frame(data_header->frame_ctrl) ?
-			data_header->address3 : data_header->address1;
+	uint8_t *src_addr =
+	    ieee80211_is_fromds_frame(data_header->frame_ctrl) ?
+	    data_header->address3 : data_header->address2;
+	uint8_t *dest_addr =
+	    ieee80211_is_tods_frame(data_header->frame_ctrl) ?
+	    data_header->address3 : data_header->address1;
 	
 	ieee80211_michael_mic_block(&l, &r, uint32le_from_seq(dest_addr));
-	ieee80211_michael_mic_block(&l, &r, 
-		uint16le_from_seq(dest_addr + 4) |
-		(uint16le_from_seq(src_addr) << 16));
+	ieee80211_michael_mic_block(&l, &r,
+	    uint16le_from_seq(dest_addr + 4) |
+	    (uint16le_from_seq(src_addr) << 16));
 	ieee80211_michael_mic_block(&l, &r, uint32le_from_seq(src_addr + 2));
 	ieee80211_michael_mic_block(&l, &r, 0);
@@ -318,14 +324,14 @@
 	size_t pad = data_size % 4;
 	
-	for(size_t k = 0; k < blocks; k++) {
-		ieee80211_michael_mic_block(&l, &r, 
-			uint32le_from_seq(&data[k*4]));
+	for (size_t k = 0; k < blocks; k++) {
+		ieee80211_michael_mic_block(&l, &r,
+		    uint32le_from_seq(&data[k * 4]));
 	}
 	
 	/* Add padding. */
-	uint32_t value = 0x5A;
-	for(size_t i = pad; i > 0; i--) {
+	uint32_t value = 0x5a;
+	for (size_t i = pad; i > 0; i--) {
 		value <<= 8;
-		value |= data[blocks*4 + (i-1)];
+		value |= data[blocks * 4 + (i - 1)];
 	}
 	
@@ -345,5 +351,5 @@
 {
 	uint16_t *u16 = (uint16_t *) seq;
-	return uint16_t_le2host(*u16); 
+	return uint16_t_le2host(*u16);
 }
 
@@ -351,5 +357,5 @@
 {
 	uint32_t *u32 = (uint32_t *) seq;
-	return uint32_t_le2host(*u32); 
+	return uint32_t_le2host(*u32);
 }
 
@@ -357,5 +363,5 @@
 {
 	uint16_t *u16 = (uint16_t *) seq;
-	return uint16_t_be2host(*u16); 
+	return uint16_t_be2host(*u16);
 }
 
@@ -363,15 +369,14 @@
 {
 	uint32_t *u32 = (uint32_t *) seq;
-	return uint32_t_be2host(*u32); 
+	return uint32_t_be2host(*u32);
 }
 
 int rnd_sequence(uint8_t *sequence, size_t length)
 {
-	if(!sequence)
+	if (!sequence)
 		return ENOMEM;
 	
-	for(size_t i = 0; i < length; i++) {
+	for (size_t i = 0; i < length; i++)
 		sequence[i] = (uint8_t) rand();
-	}
 	
 	return EOK;
@@ -380,13 +385,12 @@
 uint8_t *min_sequence(uint8_t *seq1, uint8_t *seq2, size_t size)
 {
-	if(!seq1 || !seq2)
+	if ((!seq1) || (!seq2))
 		return NULL;
 	
-	for(size_t i = 0; i < size; i++) {
-		if(seq1[i] < seq2[i]) {
+	for (size_t i = 0; i < size; i++) {
+		if (seq1[i] < seq2[i])
 			return seq1;
-		} else if(seq1[i] > seq2[i]) {
+		else if (seq1[i] > seq2[i])
 			return seq2;
-		}
 	}
 	
@@ -397,9 +401,8 @@
 {
 	uint8_t *min = min_sequence(seq1, seq2, size);
-	if(min == seq1) {
+	if (min == seq1)
 		return seq2;
-	} else {
-		return seq1;
-	}
+	
+	return seq1;
 }
 
Index: uspace/srv/net/dhcp/dhcp.c
===================================================================
--- uspace/srv/net/dhcp/dhcp.c	(revision 09044cb23535bd9cffcad94397a217746432ba44)
+++ uspace/srv/net/dhcp/dhcp.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -428,9 +428,8 @@
 	dlink->retries_left = dhcp_discover_retries;
 	
-	if(dlink->timeout->state == fts_not_set || 
-		dlink->timeout->state == fts_fired) {
+	if ((dlink->timeout->state == fts_not_set) ||
+	    (dlink->timeout->state == fts_fired))
 		fibril_timer_set(dlink->timeout, dhcp_discover_timeout_val,
-			dhcpsrv_discover_timeout, dlink);
-	}
+		    dhcpsrv_discover_timeout, dlink);
 	
 	return rc;
@@ -507,5 +506,5 @@
 	
 	dhcp_link_t *dlink = dhcpsrv_link_find(link_id);
-
+	
 	if (dlink == NULL) {
 		log_msg(LOG_DEFAULT, LVL_NOTE, "Link %zu doesn't exist",
