Ignore:
Timestamp:
Jul 3, 2020, 7:19:17 PM (4 years ago)
Author:
coas-nagasima
Message:

ASP3, TINET, mbed を更新

Location:
EcnlProtoTool/trunk/asp3_dcre/tinet/net
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/ethernet.c

    r331 r429  
    195195
    196196/**
    197  * Called by a driver when its link goes up
    198  */
    199 void ether_set_link_up(T_IFNET *ether)
    200 {
    201   if (!(ether->flags & IF_FLAG_LINK_UP)) {
    202     ether->flags |= IF_FLAG_LINK_UP;
    203 
    204     if (ether->flags & IF_FLAG_UP) {
    205 #if LWIP_ARP
    206       /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */
    207       if (ether->flags & IF_FLAG_ETHARP) {
    208         etharp_gratuitous(ether);
    209       }
    210 #endif /* LWIP_ARP */
    211 
    212 #if LWIP_IGMP
    213       /* resend IGMP memberships */
    214       if (ether->_flags & IF_FLAG_IGMP) {
    215         igmp_report_groups(ether);
    216       }
    217 #endif /* LWIP_IGMP */
    218     }
    219     if (ether->link_callback) {
    220       (ether->link_callback)(ether);
    221     }
    222   }
    223 }
     197 * ether_set_link_up -- リンクしたときにNICから呼び出される
     198 */
     199void
     200ether_set_link_up()
     201{
     202        if (!(ether_ifnet.flags & IF_FLAG_LINK_UP)) {
     203                ether_ifnet.flags |= IF_FLAG_LINK_UP;
     204
     205                if (ether_ifnet.flags & IF_FLAG_UP) {
     206#if defined(_IP4_CFG) && defined(SUPPORT_ETHER)
     207                        /* ARP再構築? */
     208#endif /* #if defined(_IP4_CFG) && defined(SUPPORT_ETHER) */
     209
     210#ifdef SUPPORT_IGMP
     211                        /* IGMP参加 */
     212#endif /* #ifdef SUPPORT_IGMP */
     213                        }
     214                if (ether_ifnet.link_callback) {
     215                        (ether_ifnet.link_callback)(&ether_ifnet);
     216                        }
     217                }
     218        }
    224219
    225220/**
    226  * Called by a driver when its link goes down
    227  */
    228 void ether_set_link_down(T_IFNET *ether)
    229 {
    230   if (ether->flags & IF_FLAG_LINK_UP) {
    231     ether->flags &= ~IF_FLAG_LINK_UP;
    232     if (ether->link_callback) {
    233       (ether->link_callback)(ether);
    234     }
    235   }
    236 }
    237 
    238 /**
    239  * Set callback to be called when link is brought up/down
    240  */
    241 void ether_set_link_callback(ether_status_callback_fn link_callback)
     221 * ether_set_link_up -- リンクが切断したときにNICから呼び出される
     222 */
     223void
     224ether_set_link_down()
     225{
     226        if (ether_ifnet.flags & IF_FLAG_LINK_UP) {
     227                ether_ifnet.flags &= ~IF_FLAG_LINK_UP;
     228                if (ether_ifnet.link_callback) {
     229                        (ether_ifnet.link_callback)(&ether_ifnet);
     230                        }
     231                }
     232        }
     233
     234/*
     235 * ether_set_up -- DHCPでアドレスが設定されたとき呼び出される
     236 */
     237
     238void
     239ether_set_up()
     240{
     241        if (!(ether_ifnet.flags & IF_FLAG_UP)) {
     242                ether_ifnet.flags |= IF_FLAG_UP;
     243                if (ether_ifnet.link_callback) {
     244                        (ether_ifnet.link_callback)(&ether_ifnet);
     245                        }
     246                }
     247        }
     248
     249/*
     250 * ether_set_down -- DHCPでアドレスが解放されたとき呼び出される
     251 */
     252
     253void
     254ether_set_down()
     255{
     256        if (ether_ifnet.flags & IF_FLAG_UP) {
     257                ether_ifnet.flags &= ~IF_FLAG_UP;
     258                if (ether_ifnet.link_callback) {
     259                        (ether_ifnet.link_callback)(&ether_ifnet);
     260                        }
     261                }
     262        }
     263
     264/*
     265 * ether_set_link_callback -- リンク状態変化時のコールバック登録
     266 */
     267
     268void
     269ether_set_link_callback(ether_status_callback_fn link_callback)
    242270{
    243271        ether_ifnet.link_callback = link_callback;
    244 }
     272        if (ether_ifnet.link_callback) {
     273                (ether_ifnet.link_callback)(&ether_ifnet);
     274                }
     275        }
    245276
    246277/*
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/ethernet.h

    r331 r429  
    9999
    100100#if defined(__RX)
    101 
    102101#pragma pack
     102#elif defined(_MSC_VER)
     103#pragma pack(push, 1)
     104#endif
     105
     106#if defined(__RX) || defined(_MSC_VER)
     107
    103108typedef struct t_ether_header {
    104109
     
    113118        uint16_t        type;
    114119        } T_ETHER_HDR;
    115 #pragma packoption
    116120
    117121#elif defined(TOPPERS_S810_CLG3_85)     /* of #if defined(__RX) */
     
    143147        uint8_t         shost[ETHER_ADDR_LEN];
    144148        uint16_t        type;
    145         } __attribute__((packed, aligned(2)))T_ETHER_HDR;
     149        } __attribute__((packed, aligned(2))) T_ETHER_HDR;
    146150
    147151#endif  /* of #if defined(__RX) */
     
    158162typedef struct t_ether_addr {
    159163        uint8_t         lladdr[ETHER_ADDR_LEN];
    160         } __attribute__((packed, aligned(2)))T_ETHER_ADDR;
     164        } __attribute__((packed, aligned(2))) T_ETHER_ADDR;
     165
     166#if defined(__RX)
     167#pragma packoption
     168#elif defined(_MSC_VER)
     169#pragma pack(pop)
     170#endif
    161171
    162172/*
     
    208218                                                        /* インタフェースのマルチキャストアドレスへの変換              */
    209219
     220#define IF_FLAG_UP                              0x01U
     221#define IF_FLAG_LINK_UP                 0x10U
     222
    210223/*
    211224 *  前方参照
     
    266279#endif  /* of #ifdef T_IF_ETHER_NIC_SOFTC */
    267280
    268 #define IF_FLAG_UP                              0x01U
    269 #define IF_FLAG_LINK_UP                 0x10U
    270 
    271281/*
    272282 *  変数
     
    304314extern uint32_t ether_srand (void);
    305315
    306 /** Function prototype for netif status- or link-callback functions. */
    307316typedef void (*ether_status_callback_fn)(T_IFNET *ether);
    308317extern void ether_set_link_callback(ether_status_callback_fn link_callback);
    309 extern void ether_set_link_up(T_IFNET *ether);
    310 extern void ether_set_link_down(T_IFNET *ether);
     318extern void ether_set_link_up();
     319extern void ether_set_link_down();
     320extern void ether_set_up();
     321extern void ether_set_down();
    311322
    312323#endif  /* of #ifdef SUPPORT_ETHER */
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/if_arp.h

    r331 r429  
    9191        uint8_t         proto_len;      /* プロトコル長                       */
    9292        uint16_t        opcode;         /* 命令コード                        */
    93         } __attribute__((packed, aligned(2)))T_ARP_HDR;
     93        } __attribute__((packed, aligned(2))) T_ARP_HDR;
    9494
    9595#define ARP_HDR_SIZE                    (sizeof(T_ARP_HDR))
     
    119119typedef struct arpcom {
    120120        uint8_t         mac_addr[ETHER_ADDR_LEN];
    121         } __attribute__((packed, aligned(2)))T_ARPCOM;
     121        } __attribute__((packed, aligned(2))) T_ARPCOM;
    122122
    123123/*
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/net_asp.cfg

    r331 r429  
    4141
    4242INCLUDE("net/net.cfg");
     43
     44#ifndef NOUSE_MPF_NET_BUF
    4345
    4446/*
     
    169171                });
    170172#endif  /* of #if defined(NUM_MPF_NET_BUF6_65536) && NUM_MPF_NET_BUF6_65536 > 0 */
     173
     174#endif
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/net_buf.c

    r331 r429  
    6868#include <netinet/tcp_var.h>
    6969
     70#ifndef NOUSE_MPF_NET_BUF
     71
    7072/*
    7173 *  関数
     
    226228#endif  /* of #if defined(NUM_MPF_NET_BUF_128) && NUM_MPF_NET_BUF_128 > 0 */
    227229
    228 #if defined(_IP4_CFG)
     230#if defined(_IP6_CFG)
     231
     232#if defined(NUM_MPF_NET_BUF_CSEG) && NUM_MPF_NET_BUF_CSEG > 0
     233        {
     234                MPF_NET_BUF_CSEG,
     235                IF_HDR_SIZE + IP_HDR_SIZE + TCP_HDR_SIZE,
     236
     237#if NET_COUNT_ENABLE & PROTO_FLG_NET_BUF
     238
     239                NUM_MPF_NET_BUF_CSEG,
     240
     241#endif  /* of #if NET_COUNT_ENABLE & PROTO_FLG_NET_BUF */
     242
     243                },
     244#endif  /* of #if defined(NUM_MPF_NET_BUF_CSEG) && NUM_MPF_NET_BUF_CSEG > 0 */
     245
     246#endif  /* of #if defined(_IP6_CFG) */
    229247
    230248#if defined(NUM_MPF_NET_BUF_64) && NUM_MPF_NET_BUF_64 > 0
     
    242260#endif  /* of #if defined(NUM_MPF_NET_BUF_64) && NUM_MPF_NET_BUF_64 > 0 */
    243261
    244 #endif  /* of #if defined(_IP4_CFG) */
     262#if defined(_IP4_CFG) && !defined(_IP6_CFG)
    245263
    246264#if defined(NUM_MPF_NET_BUF_CSEG) && NUM_MPF_NET_BUF_CSEG > 0
     
    257275                },
    258276#endif  /* of #if defined(NUM_MPF_NET_BUF_CSEG) && NUM_MPF_NET_BUF_CSEG > 0 */
     277
     278#endif  /* of #if defined(_IP4_CFG) && !defined(_IP6_CFG) */
    259279
    260280        };
     
    307327
    308328        while (1) {
    309                 if ((error = tget_mpf((ID)net_buf_table[ix].index, (void*)buf, ix == 0 ? tmout : TMO_POL)) == E_OK) {
     329                if ((error = tget_mpf((ID)net_buf_table[ix].index, (void **)buf, ix == 0 ? tmout : TMO_POL)) == E_OK) {
    310330                        (*buf)->idix  = (uint8_t)ix;
    311331                        (*buf)->len   = (uint16_t)minlen;
    312332                        (*buf)->flags = 0;
    313 
     333#ifdef IF_ETHER_MULTI_NIC
     334                        (*buf)->conn_pos = 0;
     335#endif
    314336#if NET_COUNT_ENABLE & PROTO_FLG_NET_BUF
    315337                        NET_COUNT_NET_BUF(net_buf_table[ix].allocs, 1);
     
    318340                        return error;
    319341                        }
    320                 else if (ix == 0 || net_buf_table[ix].size > maxlen)
     342                ix --;
     343                if (ix < 0 || net_buf_table[ix].size > maxlen)
    321344                        break;
    322                 ix --;
    323345                }
    324346
     
    349371
    350372        while (1) {
    351                 if ((error = tget_mpf((ID)net_buf_table[ix].index, (void*)buf,
     373                if ((error = tget_mpf((ID)net_buf_table[ix].index, (void **)buf,
    352374                                      ix == sizeof(net_buf_table) / sizeof(T_NET_BUF_ENTRY) - 1 ? tmout : TMO_POL)) == E_OK) {
    353375                        (*buf)->idix  = (uint8_t)ix;
    354376                        (*buf)->len   = net_buf_table[ix].size;
    355377                        (*buf)->flags = 0;
     378#ifdef IF_ETHER_MULTI_NIC
     379                        (*buf)->conn_pos = 0;
     380#endif
    356381
    357382#if NET_COUNT_ENABLE & PROTO_FLG_NET_BUF
     
    450475                /* 固定メモリプールに返す。*/
    451476
    452 #if NET_COUNT_ENABLE & PROTO_FLG_NET_BUF
    453                 net_buf_table[buf->idix].busies --;
    454 #endif
    455                 if ((error = rel_mpf((ID)net_buf_table[buf->idix].index, buf)) != E_OK) {
    456                         syslog(LOG_WARNING, "[NET BUF] %s, ID=%d.", itron_strerror(error), buf->idix);
     477                int idix = buf->idix;
     478#if NET_COUNT_ENABLE & PROTO_FLG_NET_BUF
     479                net_buf_table[idix].busies --;
     480#endif
     481                if ((error = rel_mpf((ID)net_buf_table[idix].index, buf)) != E_OK) {
     482                        syslog(LOG_WARNING, "[NET BUF] %s, ID=%d.", itron_strerror(error), idix);
    457483                        }
    458484                }
     
    505531        return (uint_t)net_buf_table[0].size;
    506532        }
     533
     534#else
     535#include <stdlib.h>
     536
     537/*
     538 *  tget_net_buf_ex -- ネットワークバッファを獲得する(拡張機能)。
     539 */
     540
     541ER
     542tget_net_buf_ex (T_NET_BUF **buf, uint_t minlen, uint_t maxlen, ATR nbatr, TMO tmout)
     543{
     544        uint_t len = (minlen > maxlen) ? minlen : maxlen;
     545        *buf = (T_NET_BUF *)malloc(sizeof(T_NET_BUF) - sizeof(((T_NET_BUF *)0)->buf) + len);
     546        if (*buf == NULL)
     547                return E_NOMEM;
     548
     549        (*buf)->idix = 0;
     550        (*buf)->len = (uint16_t)len;
     551        (*buf)->flags = 0;
     552#ifdef IF_ETHER_MULTI_NIC
     553        (*buf)->conn_pos = 0;
     554#endif
     555
     556        return E_OK;
     557        }
     558
     559/*
     560 *  tget_net_buf -- ネットワークバッファを獲得する(互換)。
     561 */
     562
     563ER
     564tget_net_buf (T_NET_BUF **buf, uint_t len, TMO tmout)
     565{
     566        return tget_net_buf_ex(buf, len, len, NBA_SEARCH_ASCENT, tmout);
     567        }
     568
     569
     570/*
     571 * rel_net_buf -- ネットワークバッファを返却する。
     572 */
     573
     574ER
     575rel_net_buf (T_NET_BUF *buf)
     576{
     577        free(buf);
     578
     579        return E_OK;
     580        }
     581
     582
     583/*
     584 * net_buf_max_siz -- ネットワークバッファの最大サイズを返す。
     585 */
     586
     587uint_t
     588net_buf_max_siz (void)
     589{
     590        return (uint_t)IF_PDU_SIZE;
     591        }
     592
     593#endif
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/net_buf.h

    r331 r429  
    5555        uint8_t         idix;   /* mpfid のインデックス        */
    5656        uint8_t         flags;  /* フラグ          */
     57#ifdef IF_ETHER_MULTI_NIC
     58        uint8_t         conn_pos;
     59#endif
    5760#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    5861        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
     
    8083        uint8_t         idix;   /* mpfid のインデックス        */
    8184        uint8_t         flags;  /* フラグ          */
     85#ifdef IF_ETHER_MULTI_NIC
     86        uint8_t         conn_pos;
     87#endif
    8288#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    8389        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
     
    97103        uint8_t         idix;   /* mpfid のインデックス        */
    98104        uint8_t         flags;  /* フラグ          */
     105#ifdef IF_ETHER_MULTI_NIC
     106        uint8_t         conn_pos;
     107#endif
    99108#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    100109        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
     
    114123        uint8_t         idix;   /* mpfid のインデックス        */
    115124        uint8_t         flags;  /* フラグ          */
     125#ifdef IF_ETHER_MULTI_NIC
     126        uint8_t         conn_pos;
     127#endif
    116128#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    117129        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
     
    131143        uint8_t         idix;   /* mpfid のインデックス        */
    132144        uint8_t         flags;  /* フラグ          */
     145#ifdef IF_ETHER_MULTI_NIC
     146        uint8_t         conn_pos;
     147#endif
    133148#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    134149        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
     
    148163        uint8_t         idix;   /* mpfid のインデックス        */
    149164        uint8_t         flags;  /* フラグ          */
     165#ifdef IF_ETHER_MULTI_NIC
     166        uint8_t         conn_pos;
     167#endif
    150168#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    151169        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
     
    167185        uint8_t         idix;   /* mpfid のインデックス        */
    168186        uint8_t         flags;  /* フラグ          */
     187#ifdef IF_ETHER_MULTI_NIC
     188        uint8_t         conn_pos;
     189#endif
    169190#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
    170191        uint8_t         nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/net_count.c

    r331 r429  
    222222T_NET_COUNT     net_count_igmp;
    223223
    224 #endif  /* of #if NET_COUNT_ENABLE & PROTO_FLG_ICMP4 */
     224#endif  /* of #if NET_COUNT_ENABLE & PROTO_FLG_IGMP */
    225225
    226226#endif  /* of #if defined(_IP4_CFG) */
  • EcnlProtoTool/trunk/asp3_dcre/tinet/net/net_rename.h

    r331 r429  
    7171#define tget_net_buf_ex         _tinet_tget_net_buf_ex
    7272#define tget_net_buf            _tinet_tget_net_buf
    73 #define rel_net_buf             _tinet_rel_net_buf
    74 #define rus_net_buf             _tinet_rus_net_buf
    75 #define net_buf_siz             _tinet_net_buf_siz
     73#define rel_net_buf                     _tinet_rel_net_buf
     74#define rus_net_buf                     _tinet_rus_net_buf
     75#define net_buf_siz                     _tinet_net_buf_siz
    7676#define net_buf_max_siz         _tinet_net_buf_max_siz
    7777#define nbuf_get_tbl            _tinet_nbuf_get_tbl
Note: See TracChangeset for help on using the changeset viewer.