LWIP & DHCP/Static addressing

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: LWIP & DHCP/Static addressing

Post by JoVM »

steved wrote:I've added the recent lwip initialisation changes to my working project, and all seems to be OK. Updated files attached.

As I've added to the comment, various bits need to be initialised before calling lwipInit(), especially if using SNMP.

Most users will have to call lwipInit() with some parameters set; it may be clearer to add that to the example:

Code: Select all

const uint8_t localMACAddress[6] = {0x00, 0x0E, 0x32, 0x00, 0x00, 0x01 };

struct lwipthread_opts netOptions = { (uint8_t *)localMACAddress,
                                      IP4_ADDR_VALUE(192, 168, 143, 25),
                                      IP4_ADDR_VALUE(255, 255, 255, 0),
                                      IP4_ADDR_VALUE(192, 168, 143, 220),
                                      NET_ADDRESS_STATIC
//                                      NET_ADDRESS_DHCP
};

// To initialise:
   lwipInit(&netOptions);




In my restricted knowledge I think this is done in netadd() were it stands perfect. No?
I use the lwip binds to chibiOS and that is also perfect. You can add more netif's as you pleases.

I prefer to use the zero copy buf's. The IP stack is albout Pbuf's. And I use lot's of memory to get as much allocations as possible. At least as much memory for the whole TCP segment. TCPin and TCPout.
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

Re: LWIP & DHCP/Static addressing

Post by gallegojm »

Hi steved
In case we want to obtain the IP from DHCP, what is the correct configuration for lwipInit()?
Something like this?

Code: Select all

const uint8_t localMACAddress[6] = {0x00, 0x0E, 0x32, 0x00, 0x00, 0x01 };

struct lwipthread_opts netOptions = { (uint8_t *)localMACAddress,
                                      NULL, NULL, NULL,
                                      NET_ADDRESS_DHCP };


Jean-Michel
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

Yes, that will work fine.

The IP/Subnet mask fields are ignored if DHCP is selected, so they could be any value.

I've always regarded NULL as being a pointer type, so being pedantic, the IP and subnet mask fields should be zero rather than NULL. (I'm sure I read somewhere that NULL could map to a compiler/platform-specific non-zero value, although I've never come across it myself)
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

Re: LWIP & DHCP/Static addressing

Post by gallegojm »

Hi steved
Thank you for your reply.
Sorry, I do not see that IP4_ADDR_VALUE was an uin32_t
Jean-Michel
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

Re: LWIP & DHCP/Static addressing

Post by gallegojm »

I like the steved' patch because it allow to switch easily between 2 or more cases for the configuration of the IP.
For example in my case, I have an 'almost' definitive version of my ftp server connected to the DMZ of my firewall. And on an other board connected via DHCP to the internal net, I test some upgrades.
So, in main.c , I just have to comment one configuration or the other:

Code: Select all

const uint8_t localMACAddress[6] = { 0xC2, 0xAF, 0x51, 0x03, 0xCF, 0x46 };
struct lwipthread_opts netOptions = { (uint8_t *) localMACAddress,
                                      0, 0, 0, NET_ADDRESS_DHCP };

/*
const uint8_t localMACAddress[6] = { 0xC2, 0xAF, 0x51, 0x03, 0xCF, 0x45 };
struct lwipthread_opts netOptions = { (uint8_t *) localMACAddress,
                                      IP4_ADDR_VALUE( 192, 168, 3, 12 ),
                                      IP4_ADDR_VALUE( 255, 255, 255, 0 ),
                                      IP4_ADDR_VALUE( 192, 168, 3, 1 ),
                                      NET_ADDRESS_STATIC };
*/

I wonder why version 3.0 of ChibiOS introduce a 'reduced' lwipInit() function for the initialisation of lwip.
This 'reduced' lwipInit() function do not allow to select DHCP or static.
And macro IP4_ADDR_VALUE is not defined. So it is necessary to use macro IP4_ADDR which is heavier and less elegant.
So, is there a reason for not including this patch in next release of ChibiOS?

On the other hand, I admit I do not understand the comment of JoVM and I had not found any function called netadd()
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

gallegojm wrote:I wonder why version 3.0 of ChibiOS introduce a 'reduced' lwipInit() function for the initialisation of lwip.
This 'reduced' lwipInit() function do not allow to select DHCP or static.
And macro IP4_ADDR_VALUE is not defined. So it is necessary to use macro IP4_ADDR which is heavier and less elegant.
So, is there a reason for not including this patch in next release of ChibiOS?

On the other hand, I admit I do not understand the comment of JoVM and I had not found any function called netadd()

My second upload (July 6th) uses the new lwipInit() function, passing the options structure.

The IP4_ADDR_VALUE macro is one I added in lwipthread.h
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

Re: LWIP & DHCP/Static addressing

Post by gallegojm »

Hi steved
I am afraid my english is too approximate.
I shall try to be more concise:

1- I use your 'second upload' ,I appreciate it and thank you for it
2- I would like the next version of ChibiOS includes it instead of the lwipInit() function actually included in ChibiOS 3.0
3- I wonder what is the opinion of other users. (that is why I say do not understand the comment of JoVM)
4- I would like to know the opinion of Giovanni, the conductor(*) of the ChibiOS symphony

Jean-Michel

(*) Well, not only conductor, but too composer and major performer :D
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: LWIP & DHCP/Static addressing

Post by Giovanni »

Hi,

The idea is good, the code breaks some coding rules so I will have to adjust few things here and there, this will have to wait because I am working on other things (new STM32s).

@gallegojm, if you knew the sounds that I can make emit to my poor guitar you would not have called me with any of those terms :)

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

I've added support for setting a host name, much as per UliKoehler's suggestion here
Attachments
lwip_bindings.zip
(15.45 KiB) Downloaded 547 times
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

Re: LWIP & DHCP/Static addressing

Post by gallegojm »

Hi steved
Thank you for this new patch.
I hope it would be part of next ChibiOs release!

As an example, in order to specify a host name, there is only two things to do:

1) in lwipopts.h modify

Code: Select all

#define LWIP_NETIF_HOSTNAME             0
to

Code: Select all

#define LWIP_NETIF_HOSTNAME             1

2) in main.c add the host name to the lwipthread_opts structure like this: (for example)

Code: Select all

const uint8_t localMACAddress[6] = { 0xC2, 0xAF, 0x51, 0x03, 0x02, 0x01 };
static struct lwipthread_opts netOptions = { (uint8_t *) localMACAddress,
                                             "STM32-E407",
                                             0, 0, 0, NET_ADDRESS_DHCP };


Jean-Michel
Post Reply