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;
 }
 
