Skip to content

Commit

Permalink
lwip upgrade to 2.2.0, added mDNS, various small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vysocan committed Oct 11, 2024
1 parent d1b79d1 commit 1b37bc7
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-releases-to-discord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: discord_on_release

on:
release:
types: [published, released, created]
types: [published, released]
workflow_dispatch:

jobs:
Expand Down
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk
#include $(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/stcrypt.mk
#include $(CHIBIOS)/ext/STM32_Cryptographic_Library/stcryptolib.mk
#include $(CHIBIOS)/os/various/wolfssl_bindings/wolfssl.mk
include $(CHIBIOS)/ext/mbedtls/mbedtls.mk
#include $(CHIBIOS)/ext/mbedtls/mbedtls.mk

# Define linker script file here
LDSCRIPT= $(CONFDIR)/STM32F437xG.ld
Expand All @@ -132,12 +132,10 @@ CSRC = $(ALLCSRC) \
$(TESTSRC) \
$(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/syscalls.c \
$(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c \
$(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rng.c \
$(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp.c \
main.c
# $(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c \
# $(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rng.c \
# $(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp.c \


# C++ sources that can be compiled in ARM or THUMB mode depending on the global
Expand All @@ -157,10 +155,7 @@ ALLXASMSRC += $(CONFDIR)/DFU.S
ASMXSRC = $(ALLXASMSRC)

# Inclusion directories.
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC) \
$(CHIBIOS)/ext/STM32F4xx_StdPeriph_Driver/inc \
$(CHIBIOS)/ext/STM32_Cryptographic_Library/inc \

INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)

# Define C warning options here.
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
Expand Down Expand Up @@ -189,7 +184,8 @@ UINCDIR =
ULIBDIR =

# List all user libraries here
ULIBS = $(CHIBIOS)/ext/STM32_Cryptographic_Library/binary/EWARM/M4_CryptoFW_RngHW_2_0_6.a
ULIBS =
#$(CHIBIOS)/ext/STM32_Cryptographic_Library/binary/EWARM/M4_CryptoFW_RngHW_2_0_6.a

#
# End of user section
Expand Down
13 changes: 9 additions & 4 deletions lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,17 @@
#define DNS_DOES_NAME_CHECK 1 /** DNS do a name checking between the query and the response. */
// DHCP
#define LWIP_DHCP 1
// IGMP
#define LWIP_IGMP 0
// MDNS
// IGMP multicast in hal_mac_lld.c
#define LWIP_MDNS_RESPONDER 0
#define LWIP_MDNS_RESPONDER 1
#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_MDNS_RESPONDER) // +1 MDSN
#if LWIP_MDNS_RESPONDER
// IGMP
#define LWIP_IGMP 1
#else
// IGMP
#define LWIP_IGMP 0
#endif
// Rename thread name
#define TCPIP_THREAD_NAME "tcpip"

Expand Down Expand Up @@ -200,7 +205,7 @@
#define SNTP_UPDATE_DELAY 3600000 // SNTP update every # milliseconds

// Maximum segment size
#define TCP_MSS 1024 // TODO OHS change to Ethernet size 1460 and test memory constraints
#define TCP_MSS 1460

// Number of rx pbufs to enqueue to parse an incoming request (up to the first newline)
#define LWIP_HTTPD_REQ_QUEUELEN 7
Expand Down
42 changes: 12 additions & 30 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
// ChibiOS
#include "ch.h"
#include "hal.h"
// ChibiOS tests
#include "rt_test_root.h"
#include "oslib_test_root.h"
// Added from ChibiOS
#include "shell.h"
#include "chprintf.h"
Expand Down Expand Up @@ -97,13 +94,18 @@ char gprsSmsText[128] __attribute__((section(".ram4")));
#include "lwip/apps/httpd.h"
#include "lwip/apps/sntp.h"
#include "lwip/apps/smtp.h"
#if LWIP_MDNS_RESPONDER
#define MDNS_HOSTANME "ohs"
#include "lwip/apps/mdns.h"
#endif
// HTTPD OHS handler
#include "ohs_httpdhandler.h"
// MQTT
#include "lwip/apps/mqtt_priv.h" // Needed for conf.mqtt
#include "lwip/apps/mqtt.h"
#include "ohs_mqtt_functions.h"
// mDNS
#include "ohs_mdns_functions.h"

// Shell functions
#include "ohs_shell.h"
Expand All @@ -124,23 +126,6 @@ char gprsSmsText[128] __attribute__((section(".ram4")));
#include "ohs_th_mqtt.h"
#include "ohs_th_heartbeat.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2*1024)

#if LWIP_MDNS_RESPONDER
static void srv_txt(struct mdns_service *service, void *txt_userdata){
err_t res;
LWIP_UNUSED_ARG(txt_userdata);

res = mdns_resp_add_service_txtitem(service, "path=/", 6);
chprintf(console, "mdns add service txt status %d.\r\n", res);
}
#endif

#if LWIP_MDNS_RESPONDER
static void mdns_example_report(struct netif* netif, u8_t result, s8_t service){
chprintf(console,"mdns status[netif %d][service %d]: %d\r\n", netif->num, service, result);
}
#endif

/*
* Application entry point.
*/
Expand Down Expand Up @@ -173,7 +158,7 @@ int main(void) {
struct lwipthread_opts lwip_opts =
{ &macAddr[0], 0, 0, 0, NET_ADDRESS_DHCP
#if LWIP_NETIF_HOSTNAME
, OHS_NAME "2"
, OHS_NAME
#endif
,NULL, NULL
};
Expand Down Expand Up @@ -262,21 +247,18 @@ int main(void) {

// LWIP
stats_init();
//ETH->MACFFR |= ETH_MACFFR_PAM;
LOCK_TCPIP_CORE();
httpd_init();
sntp_init();
UNLOCK_TCPIP_CORE();
// TODO OHS implement IGMP and MDNS
#if LWIP_MDNS_RESPONDER
chThdSleepMilliseconds(100);
mdns_resp_register_name_result_cb(mdns_example_report);
ETH->MACFFR |= ETH_MACFFR_PAM; // Allow multicast
mdns_resp_register_name_result_cb(mdnsStatusReport);
LOCK_TCPIP_CORE();
mdns_resp_init();
mdns_resp_add_netif(netif_default, "ohs");
//chprintf(console, "netif_default %x\r\n", netif_default);
mdns_resp_add_service(netif_default, "ohs", "_http", DNSSD_PROTO_TCP, 80, srv_txt, NULL);
//mdns_resp_announce(netif_default);
chThdSleepMilliseconds(100);
mdns_resp_add_netif(netif_default, MDNS_HOSTANME);
mdns_resp_add_service(netif_default, MDNS_HOSTANME, "_http", DNSSD_PROTO_TCP, 80, mdnsSrvTxt, NULL);
UNLOCK_TCPIP_CORE();
#endif

// Read last groups state
Expand Down
4 changes: 3 additions & 1 deletion ohs_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#define OHS_NAME "OHS"
#define OHS_MAJOR 1
#define OHS_MINOR 5
#define OHS_MOD 2
#define OHS_MOD 3

#define BACKUP_SRAM_SIZE 0x1000 // 4kB SRAM size

// A change on following define(s) will corrupt backup SRAM integrity.
// It will need to be setDefault.
#define ALARM_GROUPS 10 // # of groups
#define ALARM_ZONES 30 // # of zones
#define HW_ZONES 11 // # of hardware zones on gateway
Expand Down
2 changes: 1 addition & 1 deletion ohs_httpdhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ int fs_open_custom(struct fs_file *file, const char *name){
text_0x, text_1x, text_2x, text_3x, 0);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_publish, html_e_td_td);
printOnOffButton(chp, "d", GET_CONF_ZONE_MQTT_PUB(conf.zone[webZone]));
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_HAD, text_Discovery, html_e_td_td);
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_HA, text_Discovery, html_e_td_td);
printOnOffButton(chp, "c", GET_CONF_ZONE_MQTT_HAD(conf.zone[webZone]));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Group, html_e_td_td);
selectGroup(chp, GET_CONF_ZONE_GROUP(conf.zone[webZone]), 'g');
Expand Down
38 changes: 38 additions & 0 deletions ohs_mdns_functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* ohs_mdns_functions.h
*
* Created on: Oct 11, 2024
* Author: vysocan
*/

#ifndef OHS_MDNS_FUNCTIONS_H_
#define OHS_MDNS_FUNCTIONS_H_

/*
* MDNS responder callback Service Status
*/
#if LWIP_MDNS_RESPONDER
static void mdnsSrvTxt(struct mdns_service *service, void *txt_userdata) {
err_t resp;
LWIP_UNUSED_ARG(txt_userdata);

resp = mdns_resp_add_service_txtitem(service, "path=/", 6);
if (resp != ERR_OK) {
chprintf(console, "MDNS: Add service txt status %d.\r\n", resp);
}
}
#endif
/*
* MDNS responder callback Status Report
*/
#if LWIP_MDNS_RESPONDER
static void mdnsStatusReport(struct netif* netif, u8_t result, s8_t service) {
(void)netif;
(void)result;
(void)service;

//chprintf(console,"mdns status[netif %d][service %d]: %d\r\n", netif->num, service, result);
}
#endif

#endif /* OHS_MDNS_FUNCTIONS_H_ */
3 changes: 3 additions & 0 deletions ohs_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ static void cmd_net(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;

chprintf(chp, "Hostname : " OHS_NAME SHELL_NEWLINE_STR);
#if LWIP_MDNS_RESPONDER
chprintf(chp, "mDNS : http://%s.local" SHELL_NEWLINE_STR, MDNS_HOSTANME);
#endif
chprintf(chp, "IP address : %s" SHELL_NEWLINE_STR, ip4addr_ntoa((ip4_addr_t *)&netInfo.ip));
chprintf(chp, "Netmask : %s" SHELL_NEWLINE_STR, ip4addr_ntoa((ip4_addr_t *)&netInfo.mask));
chprintf(chp, "Gateway : %s" SHELL_NEWLINE_STR, ip4addr_ntoa((ip4_addr_t *)&netInfo.gw));
Expand Down

0 comments on commit 1b37bc7

Please sign in to comment.