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

Improve wificfg #732

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Improve wificfg #732

wants to merge 4 commits into from

Conversation

zub2
Copy link

@zub2 zub2 commented Oct 3, 2019

Several small improvements of extras/wificfg:

  • add missing #includes to wificfg.h
  • use #if instead of #ifdef when checking for configUSE_TRACE_FACILITY
  • make default ssid, password and hostname overridable by making the definitions in wificfg.c weak
  • fix typo in comment

Without these, wificfg.h can fail to compile because types like uint32_t,
size_t or ssize_t are not available.
FreeRTOS/Source/include/FreeRTOSConfig.h makes sure configUSE_TRACE_FACILITY
is always defined. But it's defined to 0 when TRACE_FACILITY is disabled.

When #ifdef is used, the guarded blocks of code are always compiled and
this results in link failure when TRACE_FACILITY is in fact not enabled.
wificfg.c defines the default values for ssid, password and hostname. But
because these are not weak, trying to redefine these causes a link error.

This change marks the definitions in wificfg.c weak, thus making it
possible for a program using the wificfg component to redefine these w/o
having to touch wificfg.c.
const char *wificfg_default_hostname = "eor-%02x%02x%02x";
const char *wificfg_default_ssid __attribute__ ((weak)) = "EOR_%02X%02X%02X";
const char *wificfg_default_password __attribute__ ((weak)) = "esp-open-rtos";
const char *wificfg_default_hostname __attribute__ ((weak)) = "eor-%02x%02x%02x";
Copy link
Contributor

Choose a reason for hiding this comment

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

These don't need to be 'weak', they are variables that can be trivially modified, just set them in your app initialization code.

Copy link
Author

Choose a reason for hiding this comment

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

You are right. I didn't realize it's a const char*, not a const char[].

I was motivated by several things:

  • I thought I can't really change it (which was wrong)
  • I didn't want the literals from the wificfg.c to be present in the binary at all (just a few bytes, but still needless if I'm using my own strings)
  • when re-defining a weak symbol, there is no need to do anything at runtime, linker just handles that (yes, just 3 assignments, but when just a declaration can suffice, it seems nicer)

Because the type is const char*, even the second point was not fulfilled. If the type is changed to const char[], then it seems to do what I wanted.

What do you think about keeping these weak and making them const char[]? Or are the last two points from the list above not interesting to you?

@@ -1540,7 +1540,7 @@ static int handle_wificfg_challenge_post(int s, wificfg_method method,
return wificfg_write_string(s, http_redirect_header);
}

#ifdef configUSE_TRACE_FACILITY
#if configUSE_TRACE_FACILITY
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that looks right, thanks.

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

2 participants