diff --git a/src/include/broadcastsocket.h b/src/include/broadcastsocket.h index 0aa1ddc..bd93409 100644 --- a/src/include/broadcastsocket.h +++ b/src/include/broadcastsocket.h @@ -1,6 +1,14 @@ #ifndef __DAWN_BROADCASTSOCKET_H #define __DAWN_BROADCASTSOCKET_H + +/** + * Function that setups a broadcast socket. + * @param _broadcast_ip - The broadcast ip to use. + * @param _broadcast_port - The broadcast port to use. + * @param addr The sockaddr_in struct. + * @return the socket that was created. + */ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_port, struct sockaddr_in *addr); #endif diff --git a/src/include/crypto.h b/src/include/crypto.h index 46dba90..178e7a9 100644 --- a/src/include/crypto.h +++ b/src/include/crypto.h @@ -3,12 +3,36 @@ #include +/** + * Initialize gcrypt. + * Has to be called before using the other functions! + */ void gcrypt_init(); +/** + * Set the Key and the iv. + * @param key + * @param iv + */ void gcrypt_set_key_and_iv(const char *key, const char *iv); +/** + * Function that encrypts the message. + * Free the string after using it! + * @param msg + * @param msg_length + * @param out_length + * @return the encrypted string. + */ char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length); +/** + * FUnction that decrypts a message. + * Free the string after using it! + * @param msg + * @param msg_length + * @return the decrypted string. + */ char *gcrypt_decrypt_msg(char *msg, size_t msg_length); #endif //DAWN_CRYPTO_H diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 089f0f7..adf6dfb 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -6,14 +6,47 @@ #include #include +/** + * Get RSSI using the mac adress of the client. + * Function uses libiwinfo and searches through all interfaces that are existing. + * @param client_addr - mac adress of the client + * @return The RSSI of the client if successful. INT_MIN if client was not found. + */ int get_rssi_iwinfo(__uint8_t *client_addr); +/** + * Get expected throughut using the mac adress of the client. + * Function uses libiwinfo and searches through all interfaces that are existing. + * @param client_addr - mac adress of the client + * @return The expected throughput of the client if successful. INT_MIN if client was not found. + */ int get_expected_throughput_iwinfo(uint8_t *client_addr); +/** + * Get rx and tx bandwidth using the mac of the client. + * Function uses libiwinfo and searches through all interfaces that are existing. + * @param client_addr - mac adress of the client + * @param rx_rate - float pointer for returning the rx rate + * @param tx_rate - float pointer for returning the tx rate + * @return 0 if successful 1 otherwise. + */ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); +/** + * Function checks if two bssid adresses have the same essid. + * Function uses libiwinfo and searches through all interfaces that are existing. + * @param bssid_addr + * @param bssid_addr_to_compares + * @return 1 if the bssid adresses have the same essid. + */ int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare); +/** + * Function returns the expected throughput using the interface and the client address. + * @param ifname + * @param client_addr + * @return - The expected throughput of the client if successful. INT_MIN if client was not found. + */ int get_expected_throughput(const char *ifname, uint8_t *client_addr); #endif //DAWN_RSSI_H diff --git a/src/include/dawn_uci.h b/src/include/dawn_uci.h index 547f278..3cd3ebb 100644 --- a/src/include/dawn_uci.h +++ b/src/include/dawn_uci.h @@ -1,18 +1,46 @@ #ifndef DAWN_UCI_H #define DAWN_UCI_H -struct probe_metric_s uci_get_dawn_metric(); - -struct time_config_s uci_get_time_config(); - -struct network_config_s uci_get_dawn_network(); - -const char *uci_get_dawn_hostapd_dir(); - -const char *uci_get_dawn_sort_order(); - +/** + * Init uci. Call this function before using the other functions! + * @return if call was successful. + */ int uci_init(); +/** + * Clear uci. Call this function after using uci! + * @return if call was successful. + */ int uci_clear(); +/** + * Function that returns the metric for the load balancing sheme using uci. + * @return the load balancing metric. + */ +struct probe_metric_s uci_get_dawn_metric(); + +/** + * Function that returns a struct with all the time config values. + * @return the time config values. + */ +struct time_config_s uci_get_time_config(); + +/** + * Function that returns all the network informations. + * @return the network config values. + */ +struct network_config_s uci_get_dawn_network(); + +/** + * Function that returns the hostapd directory reading from the config file. + * @return the hostapd directory. + */ +const char *uci_get_dawn_hostapd_dir(); + +/** + * Function that returns the sort order. + * @return the sort order. + */ +const char *uci_get_dawn_sort_order(); + #endif //DAWN_UCI_H_H diff --git a/src/include/ieee80211_utils.h b/src/include/ieee80211_utils.h index 2c16fff..66b7312 100644 --- a/src/include/ieee80211_utils.h +++ b/src/include/ieee80211_utils.h @@ -3,6 +3,11 @@ #include +/** + * Calculate bitrate using the supported rates values. + * @param supp_rate_val + * @return the bitrate. + */ double iee80211_calculate_bitrate(uint8_t supp_rate_val); #endif //DAWN_IEEE80211_UTILS_H diff --git a/src/include/multicastsocket.h b/src/include/multicastsocket.h index 3b8e86d..dab0547 100644 --- a/src/include/multicastsocket.h +++ b/src/include/multicastsocket.h @@ -1,8 +1,21 @@ #ifndef __DAWN_MULTICASTSTSOCKET_H #define __DAWN_MULTICASTSSOCKET_H +/** + * Setup a multicast socket. + * Setup permissions. Join the multicast group, etc. ... + * @param _multicast_ip - multicast ip to use. + * @param _multicast_port - multicast port to use. + * @param addr + * @return the multicast socket. + */ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_port, struct sockaddr_in *addr); +/** + * Removes the multicast socket. + * @param socket + * @return + */ int remove_multicast_socket(int socket); #endif diff --git a/src/include/networksocket.h b/src/include/networksocket.h index 4ab5a23..2b26bfd 100644 --- a/src/include/networksocket.h +++ b/src/include/networksocket.h @@ -5,12 +5,32 @@ pthread_mutex_t send_mutex; +/** + * Init a socket using the runopts. + * @param _ip - ip to use. + * @param _port - port to use. + * @param _multicast_socket - if socket should be multicast or broadcast. + * @return the socket. + */ int init_socket_runopts(const char *_ip, int _port, int _multicast_socket); +/** + * Send message via network. + * @param msg + * @return + */ int send_string(char *msg); +/** + * Send encrypted message via network. + * @param msg + * @return + */ int send_string_enc(char *msg); +/** + * Close socket. + */ void close_socket(); // save connections diff --git a/src/include/tcpsocket.h b/src/include/tcpsocket.h index 7236fae..8284e61 100644 --- a/src/include/tcpsocket.h +++ b/src/include/tcpsocket.h @@ -5,29 +5,57 @@ #include #include +#define ARRAY_NETWORK_LEN 50 + struct network_con_s { int sockfd; struct sockaddr_in sock_addr; struct ustream_fd s; }; -void *run_tcp_socket(void *arg); - -int add_tcp_conncection(char *ipv4, int port); - -int run_server(int port); - -void print_tcp_array(); +struct network_con_s network_array[ARRAY_NETWORK_LEN]; pthread_mutex_t tcp_array_mutex; +/** + * Add tcp connection. + * @param ipv4 + * @param port + * @return + */ +int add_tcp_conncection(char *ipv4, int port); + +/** + * Opens a tcp server and adds it to the uloop. + * @param port + * @return + */ +int run_server(int port); + +/** + * Insert tcp connection to tcp array. + * @param entry + * @return + */ int insert_to_tcp_array(struct network_con_s entry); +/** + * Checks if a tcp address is already contained in the database. + * @param entry + * @return + */ int tcp_array_contains_address(struct sockaddr_in entry); +/** + * Send message via tcp to all other hosts. + * @param msg + */ void send_tcp(char *msg); -#define ARRAY_NETWORK_LEN 50 -struct network_con_s network_array[ARRAY_NETWORK_LEN]; +/** + * Debug message. + */ +void print_tcp_array(); + #endif //DAWN_TCPSOCKET_H diff --git a/src/include/ubus.h b/src/include/ubus.h index be5a128..c563593 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -16,46 +16,148 @@ #define UNSPECIFIED_REASON 0 #define NO_MORE_STAS 5 -void start_umdns_update(); - -int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir); - -int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req); - -int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req); - -int parse_to_assoc_req(struct blob_attr *msg, assoc_entry *assoc_req); - -int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id); - -int parse_to_hostapd_notify(struct blob_attr *msg, hostapd_notify_entry *notify_req); - -void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); - -void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); - -void *update_clients_thread(void *arg); - -void *update_connections_thread(void *arg); - const char *hostapd_dir_glob; +/** + * Init ubus. + * Setup tcp socket. + * Start ubus timer. + * @param ubus_socket + * @param hostapd_dir + * @return + */ +int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir); + +/** + * Start the umdns timer for updating the zeroconfiguration properties. + */ +void start_umdns_update(); + +/** + * Call umdns update to update the TCP connections. + * @return + */ int ubus_call_umdns(); +/** + * Parse to probe request. + * @param msg + * @param prob_req + * @return + */ +int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req); + +/** + * Parse to authentication request. + * @param msg + * @param auth_req + * @return + */ +int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req); + +/** + * Parse to association request. + * @param msg + * @param assoc_req + * @return + */ +int parse_to_assoc_req(struct blob_attr *msg, assoc_entry *assoc_req); + +/** + * Dump a client array into the database. + * @param msg - message to parse. + * @param do_kick - use the automatic kick function when updating the clients. + * @param id - ubus id. + * @return + */ +int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id); + +/** + * Parse to hostapd notify. + * Notify are such notifications like: + * + Disassociation + * + Deauthentication + * + ... + * @param msg + * @param notify_req + * @return + */ +int parse_to_hostapd_notify(struct blob_attr *msg, hostapd_notify_entry *notify_req); + +/** + * Kick client from hostapd interface. + * @param id - the ubus id. + * @param client_addr - the client adress of the client to kick. + * @param reason - the reason to kick the client. + * @param deauth - if the client should be deauthenticated. + * @param ban_time - the ban time the client is not allowed to connect again. + */ +void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); + +/** + * Kick client from all hostapd interfaces. + * @param client_addr - the client adress of the client to kick. + * @param reason - the reason to kick the client. + * @param deauth - if the client should be deauthenticated. + * @param ban_time - the ban time the client is not allowed to connect again. + */ +void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); + +/** + * Send probe message via the network. + * @param probe_entry + * @return + */ int ubus_send_probe_via_network(struct probe_entry_s probe_entry); +/** + * Update the hostapd sockets. + * @param t + */ void update_hostapd_sockets(struct uloop_timeout *t); +/** + * Set client timer for updating the clients. + * @param time + */ void add_client_update_timer(time_t time); +/** + * Handle network messages. + * @param msg + * @return + */ int handle_network_msg(char* msg); +/** + * Send message via network. + * @param msg + * @param method + * @return + */ int send_blob_attr_via_network(struct blob_attr *msg, char* method); +/** + * Add mac to a list that contains addresses of clients that can not be controlled. + * @param buf + * @param name + * @param addr + */ void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr); +/** + * Function to set the probe counter to the min probe request. + * This allows that the client is able to connect directly without sending multiple probe requests to the Access Point. + * @param client_addr + * @return + */ int send_set_probe(uint8_t client_addr[]); +/** + * Send control message to all hosts to add the mac to a don't control list. + * @param client_addr + * @return + */ int send_add_mac(uint8_t* client_addr); #endif diff --git a/src/include/utils.h b/src/include/utils.h index efc874b..2a9bc8b 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -9,14 +9,42 @@ #define MACSTR "%02X:%02X:%02X:%02X:%02X:%02X" +/** + * Convert char to binary. + * @param ch + * @return + */ int hex_to_bin(char ch); +/** + * Convert mac adress string to mac adress. + * @param txt + * @param addr + * @return + */ int hwaddr_aton(const char *txt, uint8_t *addr); +/** + * Convert mac to use big characters. + * @param in + * @param out + * @return + */ int convert_mac(char *in, char *out); +/** + * Write mac to a file. + * @param path + * @param addr + */ void write_mac_to_file(char* path, uint8_t addr[]); +/** + * Check if a string is greater than another one. + * @param str + * @param str_2 + * @return + */ int string_is_greater(uint8_t* str, uint8_t* str_2); #endif \ No newline at end of file