Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from this space and version 3.01.00

...

Code Block
languagecpp
linenumberstrue
#include  <cpu_core.h>
#include  <lib_mem.h>
#include  <Source/net.h>
#include  <Source/net_ascii.h>
#include  <IF/net_if.h>
#include  <IF/net_if_wifi.h>

#ifdef NET_IPv4_MODULE_EN
#include  <IP/IPv4/net_ipv4.h>
#endif

#ifdef NET_IPv6_MODULE_EN
#include  <IP/IPv6/net_ipv6.h>
#endif

#include  <Cfg/Template/net_dev_cfg.h>                      /* Device configuration header.           */
#include  <Dev/Ether/Template/net_dev_ether_template_dma.h> /* Device driver header.                  */
#include  <Dev/WiFi/Template/net_dev_wifi_template_spi.h>   /* Device driver header.                  */
#include  <Dev/Ether/PHY/Generic/net_phy.h>                 /* PHY driver header.                     */
#include  <Dev/WiFi/Manager/Generic/net_wifi_mgr.h>
#include  <BSP/Template/net_bsp_ether.h>                    /* BSP header.                            */
#include  <BSP/Template/net_bsp_wifi.h>                     /* BSP header.                            */
 
 

CPU_BOOLEAN  AppInit_TCPIP_MultipleIF (void)
{
#ifdef NET_IPv4_MODULE_EN
    NET_IPv4_ADDR       addr_ipv4;
    NET_IPv4_ADDR       msk_ipv4;
    NET_IPv4_ADDR       gateway_ipv4;
#endif
#ifdef NET_IPv6_MODULE_EN
    CPU_BOOLEAN         cfg_result;
#if (NET_IPv6_CFG_ADDR_AUTO_CFG_EN == DEF_DISABLED)
    NET_FLAGS           ipv6_flags;
    NET_IPv6_ADDR       addr_ipv6;
#endif
#endif
    NET_IF_NBR          if_nbr_ether;
    NET_IF_NBR          if_nbr_wifi;
    NET_IF_WIFI_AP      ap[10];
    NET_IF_WIFI_SSID   *p_ssid;
    NET_IF_WIFI_SSID    ssid;
    NET_IF_WIFI_PSK     psk;
    CPU_INT16U          ctn;
    CPU_INT16U          i;
    CPU_INT16S          result;
    CPU_BOOLEAN         found;
    NET_ERR             err_net;

                                                                /* -------- INITIALIZE NETWORK TASKS & OBJECTS -------- */
    err_net = Net_Init(&NetRxTaskCfg,
                       &NetTxDeallocTaskCfg,
                       &NetTmrTaskCfg);
    if (err_net != NET_ERR_NONE) {
        return (DEF_FAIL);
    }

                                                                /* -------------- ADD ETHERNET INTERFACE -------------- */
    if_nbr_ether = NetIF_Add((void    *)&NetIF_API_Ether,       
                             (void    *)&NetDev_API_TemplateEtherDMA, /* Device driver API                              */
                             (void    *)&NetDev_BSP_BoardDev_Nbr,     /* BSP API                                        */
                             (void    *)&NetDev_Cfg_Ether_1,          /* Device configuration                           */
                             (void    *)&NetPhy_API_Generic,          /* PHY driver API                                 */
                             (void    *)&NetPhy_Cfg_Ether_1,          /* PHY configuration                              */
                                        &err_net);
    if (err_net != NET_IF_ERR_NONE) {
        return (DEF_FAIL);
    }
                                                                /* ------------- START ETHERNET INTERFACE ------------- */
    NetIF_Start(if_nbr_ether, &err_net);                        /* Makes the interface ready to receive and transmit.   */
    if (err_net != NET_IF_ERR_NONE) {
        return (DEF_FAIL);
    }

#ifdef NET_IPv4_MODULE_EN
                                                                /* --------- CONFIGURE IPV4 STATIC ADDRESSES ---------- */
                                                                /* For Dynamic IPv4 configuration, µC/DHCPc is required */
                                                                /* Update IPv4 Addresses following your network ...     */
                                                                /* ... requirements.                                    */
    NetASCII_Str_to_IP("10.10.10.64",                           /* Convert Host IPv4 string address to 32 bit address.  */
                       &addr_ipv4,
                        NET_IPv4_ADDR_SIZE,
                       &err_net);
    NetASCII_Str_to_IP("255.255.255.0",                         /* Convert IPv4 mask string to 32 bit address.          */
                       &msk_ipv4,
                        NET_IPv4_ADDR_SIZE,
                       &err_net);
    NetASCII_Str_to_IP("10.10.10.1",                            /* Convert Gateway string address to 32 bit address.    */
                       &gateway_ipv4,
                        NET_IPv4_ADDR_SIZE,
                       &err_net);
    NetIPv4_CfgAddrAdd(if_nbr_ether,                            /* Add a statically-configured IPv4 host address,   ... */
                       addr_ipv4,                               /* ... subnet mask, & default gateway to the        ... */
                       msk_ipv4,                                /* ... interface.                                       */
                       gateway_ipv4,
                      &err_net);
    if (err_net != NET_IPv4_ERR_NONE) {
        return (DEF_FAIL);
    }
#endif

#ifdef NET_IPv6_MODULE_EN
#if (NET_IPv6_CFG_ADDR_AUTO_CFG_EN == DEF_ENABLED)
                                                                /* ----- CONFIGURESTART IPV6 STATICSTATELESS LINK LOCAL ADDRESS AUTO-CONFIGURATION ------ */
    NetIPv6_AddrAutoCfgHookSet(if_nbr_ether,                    /* Set Hook function to received Auto-Cfg result.       */
                         /* IPv6 Autoconfiguration is not yet supported.&App_AutoCfgResult,
         */                     &err_net);
    
    cfg_result = NetIPv6_AddrAutoCfgEn(if_nbr_ether,            /* Enable and Start Auto-Configuration process.         */
     /* DHCPv6c is not yet available.                        */     DEF_YES,
                                      &err_net);
    if (cfg_result == DEF_FAIL) {
        return (DEF_FAIL);
 /* TODO Update IPv6}
Address following your network ... 
*/#else
                                                                /* ... requirements.       ----- CONFIGURE IPV6 STATIC LINK LOCAL ADDRESS ----- */
                             */     NetASCII_Str_to_IP("fe80::1111:1111",                       /* Convert IPv6 string address to 128 bit/* address.DHCPv6c is not yet available.  */                      */
 &addr_ipv6,                         NET_IPv6_ADDR_SIZE,                        &err_net);     NetIPv6_CfgAddrAdd(if_nbr_ether,         /* TODO Update IPv6 Address following your network ...  */
        /* Add a statically-configured IPv6 host address to ... */
                      &addr_ipv6,                               /* ... therequirements. interface.                                   */
    NetASCII_Str_to_IP("fe80::1111:1111",                   64,    /* Convert IPv6 string address to 128 bit address.      */
     &err_net);     if (err_net != NET_IPv6_ERR_NONE) {         return (DEF_FAIL);&addr_ipv6,
    } #endif                   NET_IPv6_ADDR_SIZE,
                       &err_net);
 
    ipv6_flags = 0;               /* -------------- ADD WIRELESS INTERFACE -------------- */     if_nbr_wifi = NetIF_Add((void    *)&NetIF_API_WiFi,             
    DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_BLOCK_EN);            (void/* Set Address  *)&NetDev_API_TemplateWiFiSpi,  /* Change following your Device driver API.Configuration as blocking.               */
    DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_DAD_EN);              /* Enable DAD with Address Configuration.    (void    *)&NetDev_BSP_WiFi,       */
 
    /* Change for your BSP API.cfg_result = NetIPv6_CfgAddrAdd(if_nbr_ether,               /* Add a statically-configured IPv6 host address to ... */
  */                             (void    *)&NetDev_Cfg_WiFi_1addr_ipv6,                  /* Change... forthe Device configurationinterface.                */                   */
         (void     *)&NetWiFiMgr_API_Generic,                      64,
                  DEF_NULL,                  ipv6_flags,
                     &err_net);     if (         &err_net !);
    if (cfg_result == NET_IF_ERR_NONEDEF_FAIL) {
        return (DEF_FAIL);
    }
#endif
#endif

                                                                /* -------------- STARTADD WIRELESS INTERFACE -------------- */
    NetIF_Start(if_nbr_wifi, = &err_net);NetIF_Add((void    *)&NetIF_API_WiFi,
                     /* Makes the interface ready to receive and(void transmit.   *)&NetDev_API_TemplateWiFiSpi,  /* Change following your Device if (err_net != NET_IF_ERR_NONE) {driver API.        */
   return (DEF_FAIL);     }                   (void    *)&NetDev_BSP_WiFi,             /* Change for your BSP API.                         */*
------------ SCAN FOR WIRELESS NETWORKS ------------ */     ctn = NetIF_WiFi_Scan(if_nbr_wifi,               (void    *)&NetDev_Cfg_WiFi_1,        ap,   /* Change for Device configuration.                */
           /* Access point table.              (void    *)&NetWiFiMgr_API_Generic,
               */                           10DEF_NULL,
                                  /* Access point table size.  &err_net);
    if (err_net != NET_IF_ERR_NONE) {
        return (DEF_FAIL);
    }
   */                           DEF_NULL,                             /* Hidden SSID.   /* ------------- START WIRELESS    INTERFACE ------------- */
    NetIF_Start(if_nbr_wifi, &err_net);                         /*/ Makes the interface ready to receive and transmit.   */
    if           (err_net != NET_IF_WIFI_CH_ALL,ERR_NONE) {
        return (DEF_FAIL);
    }

  /* Channel to scan.                                     */                      /* ------------ SCAN  &err_net);
FOR WIRELESS NETWORKS ------------ */
   if (err_netctn != NETNetIF_IFWiFi_WIFIScan(if_ERRnbr_NONE)wifi,
{         return (DEF_FAIL);     }           ap,                                   /* Access point table.                 /* --------- ANALYSE WIRELESS NETWORKS FOUND ---------- */     found = DEF_NO;   */
 for (i = 0; i < ctn - 1; i++) {                 10,            /* Browse table of access point found.                  /*/ Access point table size.     p_ssid = &ap[i].SSID;         result = Str_Cmp_N((CPU_CHAR *)p_ssid,          */
       /* Search for a specific Wireless Network SSID.         */   DEF_NULL,                             /* Hidden SSID.     "Wifi_AP_SSID",           /* Change for your WiFi Network SSID.                   */
                               NET_IF_WIFI_CH_ALL,                   /* Channel to scan.        NET_IF_WIFI_STR_LEN_MAX_SSID);         if (result == 0) {             found = DEF_YES; */
           break;         }     }&err_net);
    if (founderr_net !== DEF_NO NET_IF_WIFI_ERR_NONE) {
        return (DEF_FAIL);
    }

                                                                /* ------------- JOINANALYSE AWIRELESS WIRELESSNETWORKS NETWORKFOUND --------------  */
    Mem_Clr(&ssid, sizeof(ssid));found = DEF_NO;
    for Mem_Clr(&psk,  sizeof(psk));
    Str_Copy_N((CPU_CHAR *)&ssid,
(i = 0; i < ctn - 1; i++) {                           "Wifi_AP_SSID",  /* Browse table of access point found.              /* Change for your WiFi*/
Network SSID.       p_ssid = &ap[i].SSID;
        result */
 = Str_Cmp_N((CPU_CHAR *)p_ssid,                  /* Search for a specific Wireless Network SSID.  12);       */
                        /* SSID string length.           "Wifi_AP_SSID",           /* Change for your WiFi Network SSID.      */     Str_Copy_N((CPU_CHAR *)&psk,       */
                    "Password",                   NET_IF_WIFI_STR_LEN_MAX_SSID);
      /* Change forif your WiFi Network Password.(result == 0) {
            found = DEF_YES;
 */           break;
        }
    }
   8); if (found == DEF_NO) {
        return (DEF_FAIL);
    }

           /* PSK string length.                                   */     NetIF_WiFi_Join(if_nbr_wifi,          /* ------------- JOIN A WIRELESS NETWORK -------------- */
    ap[i].NetType, Mem_Clr(&ssid, sizeof(ssid));
    Mem_Clr(&psk,  sizeof(psk));
    Str_Copy_N((CPU_CHAR *)&ssid,
               /* WiFi Network type.         "Wifi_AP_SSID",                      /* Change for your */WiFi Network SSID.                   NET_IF_WIFI_DATA_RATE_AUTO,*/
                /* Data rate.          12);                                 /*/ SSID string length.                  ap[i].SecurityType,                */
    Str_Copy_N((CPU_CHAR *)&psk,
  /* WiFi Network security type.                     "Password",     */                     NET_IF_WIFI_PWR_LEVEL_HI,      /* Change for your WiFi Network Password.             /* Power level.*/
                            8);            */                     ssid,/* PSK string length.                                    */*
WiFi Network SSID.  NetIF_WiFi_Join(if_nbr_wifi, 
                    ap[i].NetType,           */                   /* WiFi psk,Network type.                                   */
   /* WiFi Network PSK.              NET_IF_WIFI_DATA_RATE_AUTO,                 /* Data rate.   */                    &err_net);     if (err_net != NET_IF_WIFI_ERR_NONE) {         return (DEF_FAIL);
 */
   }  #ifdef NET_IPv4_MODULE_EN              ap[i].SecurityType,                         /* WiFi Network security type.                      /* --------- CONFIGURE IPV4 STATIC*/
ADDRESSES ---------- */                    NET_IF_WIFI_PWR_LEVEL_HI,                   /* Power level.                            /* For Dynamic IPv4 configuration, µC/DHCPc is required */     */
                    ssid,                                       /* UpdateWiFi IPv4Network AddressesSSID. following your network ...     */                          */
                    psk,                  /* ... requirements.                    /* WiFi Network PSK.             */     NetASCII_Str_to_IP("192.168.1.10",                  */
       /* Convert Host IPv4 string address to 32 bit address.  */
 &err_net);
    if (err_net != NET_IF_WIFI_ERR_NONE) {
             &addr_ipv4,return (DEF_FAIL);
    }

#ifdef NET_IPv4_MODULE_EN
                NET_IPv4_ADDR_SIZE,                        &err_net);     NetASCII_Str_to_IP("255.255.255.0",                         /* Convert IPv4 mask string to 32 bit address.--------- CONFIGURE IPV4 STATIC ADDRESSES ---------- */
          */                        &msk_ipv4,                         NET_IPv4_ADDR_SIZE,     /* For Dynamic IPv4 configuration, µC/DHCPc is required */
          &err_net);     NetASCII_Str_to_IP("192.168.1.1",                           /* Convert Gateway string address to 32 bit address.    */          /* Update IPv4 Addresses following your network ...     */
         &gateway_ipv4,                         NET_IPv4_ADDR_SIZE,                        &err_net);     NetIPv4_CfgAddrAdd(if_nbr_wifi,    /* ... requirements.                          /* Add a statically-configured IPv4 host address,   ... */
    NetASCII_Str_to_IP("192.168.1.10",                   addr_ipv4,       /* Convert Host IPv4 string address to 32 bit address.  */
            /* ... subnet mask, & default gateway to the   &addr_ipv4,
    ... */                        msk_ipv4NET_IPv4_ADDR_SIZE,
                       &err_net);
    NetASCII_Str_to_IP("255.255.255.0",   /* ... interface.                     /* Convert IPv4 mask string to 32 bit address.          */
                       gateway&msk_ipv4,
                       &err_net); NET_IPv4_ADDR_SIZE,
     if (err_net != NET_IPv4_ERR_NONE) {         return (DEF_FAIL);    &err_net);
} #endif  #ifdef NETNetASCII_IPv6Str_MODULE_ENto_IP("192.168.1.1",                           /* Convert Gateway string address to 32 bit address.    */
                       &gateway_ipv4,
 /* ----- CONFIGURE IPV6 STATIC LINK LOCAL ADDRESS ----- */              NET_IPv4_ADDR_SIZE,
                       &err_net);
        NetIPv4_CfgAddrAdd(if_nbr_wifi,                  /* IPv6 Autoconfiguration is not yet supported.         /*/ Add a statically-configured IPv4 host address,   ... */
                       addr_ipv4,                               /* DHCPv6c is not yet available... subnet mask, & default gateway to the        ... */
       */                msk_ipv4,                                /* ... interface.               /* Update IPv6 Address following your network ...       */          */
                       gateway_ipv4,
                      &err_net);
    if (err_net  /* ... requirements.!= NET_IPv4_ERR_NONE) {
        return (DEF_FAIL);
    }
#endif

#ifdef NET_IPv6_MODULE_EN
#if (NET_IPv6_CFG_ADDR_AUTO_CFG_EN == DEF_ENABLED)
             */                                                   /* ----- START IPV6 STATELESS AUTO-CONFIGURATION ------ */
    NetIPv6_AddrAutoCfgHookSet(if_nbr_wifi,  /* See Note #5.                /* Set hook function to received Auto-Cfg result.       */
           */     NetASCII_Str_to_IP("fe80::4444:1111",              &App_AutoCfgResult,				/* TODO update pointer to hook fnct implemented in /* Convert IPv6 string address to 128 bit address.App.	*/
                 */             &err_net);
    
     &addr_ipv6,
    cfg_result = NetIPv6_AddrAutoCfgEn(if_nbr_wifi,             /* Enable and Start Auto-Configuration process.         */
                                       DEF_YES,
                                      &err_net);
    if (cfg_result == DEF_FAIL) {
        return (DEF_FAIL);
    }
    
#else
                                                                /* ----- CONFIGURE IPV6 STATIC LINK LOCAL ADDRESS ----- */
                                                                /* DHCPv6c is not yet available.                        */
                                                                /* Update IPv6 Address following your network ...       */
                                                                /* ... requirements.                                    */
      
    NetASCII_Str_to_IP("fe80::4444:1111",                       /* Convert IPv6 string address to 128 bit address.      */
                       &addr_ipv6,
                        NET_IPv6_ADDR_SIZE,
                       &err_net);
 
    ipv6_flags = 0;
    DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_BLOCK_EN);            /* Set Address Configuration as blocking.               */
    DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_DAD_EN);              /* Enable DAD with Address Configuration.               */
 
    cfg_result = NetIPv6_CfgAddrAdd(if_nbr_wifi,                /* Add a statically-configured NET_IPv6_ADDR_SIZE,
   IPv6 host address to ... */
                   &err_net);     NetIPv6_CfgAddrAdd(if_nbr_wifi,           &addr_ipv6,                  /* Add... a statically-configured IPv6 host address to ... */the interface.                             &addr_ipv6,      */
                        /* ... the interface.         64,
                         */           ipv6_flags,
            64,                       &err_net);
    if (errcfg_netresult !== NET_IPv6_ERR_NONEDEF_FAIL) {
        return (DEF_FAIL);
    }
#endif

    return (DEF_OK);
}

...