Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the initial version of Wi-Fi Manager #528

Merged
merged 1 commit into from
Sep 7, 2017

Conversation

davidfather
Copy link
Contributor

Wi-Fi Manager is introduced to provide easy APIs for applications to easily manipulate Wi-Fi features

Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many violations of coding rule.

@@ -42,6 +42,11 @@ ifeq ($(CONFIG_NETUTILS_MQTT), y)
include src$(DELIM)mqtt$(DELIM)Make.defs
endif

ifeq ($(CONFIG_WIFI_MANAGER), y)
#CFLAGS += -I$(TOPDIR)$(DELIM)..$(DELIM)framework$(DELIM)src$(DELIM)wifi_manager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove unnecessary codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,129 @@
/****************************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Year of copyright should be 2017.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// SOFT AP mode status
CLIENT_CONNECTED,
CLIENT_DISCONNECTED
} connect_status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about add _e postfix to know easily what this is an enum structure?

connect_status_e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

void (*sta_disconnected) (void);
void (*softap_sta_join) (void);
void (*softap_sta_leave) (void);
} wifi_manager_cb;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous.

wifi_manager_cb_s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

typedef struct {
char ip4_address[18];
char ssid[32];
int rssi;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are violations of coding rule. Please use tab as an indention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did apply fomatter.sh


wifi_utils_result wifi_mutex_create(wifi_mutex* mutex)
{
return wifi_semaphore_create((wifi_semaphore *) mutex, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let' remove space after type casting.

(wifi_semaphore *)mutex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did go through fomatter.sh

#include "wifi_mutex.h"
#include "wifi_semaphore.h"

wifi_utils_result wifi_mutex_create(wifi_mutex* mutex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(wifi_mutex *mutex)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did go through fomatter.sh

* @return WIFI_UTILS_FAIL : fail
* @return WIFI_UTILS_INVALID_ARGS : input parameter invalid
*/
wifi_utils_result wifi_mutex_create( wifi_mutex* mutex );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xxx yyy(wifi_mutex *mutex);

Need same at belows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did go through fomatter.sh

#include "wifi_net.h"

#define ptr2uint32(ptr) (uint32_t)ptr[3] | \
((uint32_t)ptr[2] << 8) | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tabs intead of spaces as an indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did go through fomatter.sh

} wifi_manager_ap_config;


wifi_manager_result wifi_manager_init(wifi_manager_cb *wmcb);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this file shows public APIs, you didn't add comments for doxygen. But you added doxygen comments at local header file. Please check it.
And when you add doxygen comments at public APIs, since option should be there at end of comments.

 * @since Tizen RT v1.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added api description

Wi-Fi Manager is introduced to provide easy APIs for applications to easily manipulate Wi-Fi features
@@ -0,0 +1,23 @@
###########################################################################
#
# Copyright 2016 Samsung Electronics All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016 -> 2017

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

os/net/Kconfig Outdated
@@ -133,6 +133,20 @@ endif #NET_SECURITY_TLS

endmenu #Protocols

menu "Wireless"

config WIFI_MANAGER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not under network folder so that let's make a new Kconfig at wifi_manager and include it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wifi_manager/Kconfig is created

@@ -148,7 +148,7 @@ int cmd_dhcpd(int argc, char *argv[])
}
}

if (dhcpd_start(argv[2]) != 0) {
if (dhcpd_start(argv[2], NULL) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any releation between WiFi Manager and DHCPD stubs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, wifi manager needs to be informed of join of a new station in softap mode.


ret = select(sockfd+1, &sockfd_set, NULL, NULL, &g_select_timeout);
if ((ret > 0) && FD_ISSET(sockfd, &sockfd_set)) {
ret = select(g_dhcpd_sockfd+1, &sockfd_set, NULL, NULL, &g_select_timeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add spaces around +.

g_dhcpd_sockfd + 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I go through fomatter.

}
/* Create a socket to listen for requests from DHCP clients */
/* TODO : Need to add cancellation point */
if (g_dhcpd_sockfd < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always put -1 to g_dhcpd_sockfd at line 1552. This if condition is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. if statement is removed.

*
****************************************************************************/

#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#pragma once is not a standard so that some compiler can not understand this command.
Let's change this like belows.

#ifndef XXX
#define
...
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return WIFI_UTILS_INVALID_ARGS;
}

if (sem_destroy((sem_t *) semaphore)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sem_t *) semaphore => (sem_t *)semaphore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatter doesn't fix this problem. I mannually fix it.

}
}

ret = WiFiNetworkJoin((uint8_t *) ap_connect_config->ssid, ap_connect_config->ssid_length, NULL, config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

config = (slsi_security_config_t *)zalloc(sizeof(slsi_security_config_t));
if (!config) {
ndbg("Memory allocation failed!\n");
goto connect_ap_fail;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we don't need to check config so that let's change this to "return result;"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the viewpoint of readability, this statement seems to be fine.

WIFI_UTILS_AUTH_WPA2_PSK, /**< WPA2_PSK mode */
WIFI_UTILS_AUTH_WPA_AND_WPA2_PSK, /**< WPA_PSK and WPA_PSK mixed mode */
WIFI_UTILS_AUTH_UNKNOWN, /**< unknown type */
} wifi_utils_ap_auth_type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about _e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} wifi_manager_ap_config_s;

/**
* @brief Initialize Wi-Fi Manager including starting Wi-Fi interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our public APIs should be in group.
If those APIs need new group, you should do "@defgroup " , and include all APIs to that group with "@InGroup"

You can refer to below
/**

  • @defgroup DHCP DHCP
  • @InGroup NETWORK
  • @{
    */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

wifi_manager_result_e wifi_manager_init(wifi_manager_cb_s *wmcb);

/**
* @brief Deinitialize Wi-Fi Manager including stoping Wi-Fi interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the indent for doxygen comment(space is needed before *)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
@}
*/// end mutex group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary tab


/**
@}
*/// end net work utility group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the indent

return WIFI_UTILS_INVALID_ARGS;
}

if (sem_post((sem_t *) semaphore)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove space after type casting

*/

/**
* @defgroup semaphore semaphore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those APIs are related with wifi semaphore.
but if you define this group to "semaphore", then category name in doxygen is set to semaphore.
that makes some confusion to users. isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not public APIs. Anyway, change to Wi-Fi Manager group.


/**
@}
*/// end semaphore group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the indent

@davidfather davidfather force-pushed the wifi_manager branch 2 times, most recently from 6044413 to deb69fb Compare September 6, 2017 08:52
* @since Tizen RT v1.1
*/
wifi_manager_result_e wifi_manager_set_softap_config(wifi_manager_softap_config_s *config);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you opened the "Wi-Fi_Manager ingroup" brace, but not close.
please add below.
/**

  • @}
    */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you didn't close the }. please check this

*/

/**
* @defgroup Wi-Fi_Manager Wi-Fi_Manager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already made defgroup Wi-Fi_Manager in wifi_manager.h
if you want to add below APIs to that group, you can just do ingroup, not making again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file doesn't include public apis so that related comments are removed.

@@ -610,15 +622,15 @@ static inline bool dhcpd_parseoptions(void)
optlen = ptr[DHCPD_OPTION_LENGTH] + 2;
if (optlen >= 4 && optlen < remaining) {
memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4);
g_state.ds_optreqip = (in_addr_t)ntohl(tmp);
g_state.ds_optreqip = (in_addr_t) ntohl(tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
break;

case DHCP_OPTION_LEASE_TIME: /* IP address lease time */
optlen = ptr[DHCPD_OPTION_LENGTH] + 2;
if (optlen >= 4 && optlen < remaining) {
memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4);
g_state.ds_optleasetime = (time_t)ntohl(tmp);
g_state.ds_optleasetime = (time_t) ntohl(tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -633,7 +645,7 @@ static inline bool dhcpd_parseoptions(void)
optlen = ptr[DHCPD_OPTION_LENGTH] + 2;
if (optlen >= 4 && optlen < remaining) {
memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4);
g_state.ds_optserverip = (in_addr_t)ntohl(tmp);
g_state.ds_optserverip = (in_addr_t) ntohl(tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -942,38 +917,35 @@ static int dhcpd_sendpacket(int bbroadcast)
if (bbroadcast) {
ipaddr = INADDR_BROADCAST;
} else if (memcmp(g_state.ds_outpacket.ciaddr, g_anyipaddr, 4) != 0) {
dhcpd_arpupdate((uint16_t *)g_state.ds_outpacket.ciaddr, g_state.ds_outpacket.chaddr);
dhcpd_arpupdate((uint16_t *) g_state.ds_outpacket.ciaddr, g_state.ds_outpacket.chaddr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

memcpy(&ipaddr, g_state.ds_outpacket.ciaddr, 4);
} else if (g_state.ds_outpacket.flags & HTONS(BOOTP_BROADCAST)) {
ipaddr = INADDR_BROADCAST;
} else {
dhcpd_arpupdate((uint16_t *)g_state.ds_outpacket.yiaddr, g_state.ds_outpacket.chaddr);
dhcpd_arpupdate((uint16_t *) g_state.ds_outpacket.yiaddr, g_state.ds_outpacket.chaddr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

g_dhcp_sta_joined = dhcp_join_cb;
}

status = pthread_create(&g_tid, &attr, (pthread_startroutine_t) dhcpd_run, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove space after type casting.

(pthread_startroutine_t) dhcpd_run => (pthread_startroutine_t)dhcpd_run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

if (!g_wifi_softap_config) {
g_wifi_softap_config = (wifi_manager_softap_config_s *)malloc(sizeof(wifi_manager_softap_config_s));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find codes to free g_wifi_softap_config. Only allocation is here. Is it intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good comment!
Actually this api is not required if softap configuration information is delivered when wifi_manager_set_mode() is called.

@@ -88,6 +88,8 @@ extern "C" {
#define EXTERN extern
#endif

typedef void (*dhcp_sta_joined) (void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the space between (*dhcp_sta_joined) and (void);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


static wifi_utils_result_e stop_dhcp_server(void)
{
struct in_addr in = {.s_addr = INADDR_NONE };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space is needed after '{'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
@}
*/// end mutex group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary tab

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file doesn't include public apis so that related comments are removed.

wifi_utils_result_e wifi_mutex_destroy(wifi_mutex *mutex);

/**
@}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add '*' infront of @

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file doesn't include public apis so that related comments are removed.

@davidfather davidfather force-pushed the wifi_manager branch 2 times, most recently from 28b0101 to cd3eb9a Compare September 7, 2017 01:56
@sunghan-chang sunghan-chang merged commit db3685b into Samsung:master Sep 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants