AnsweredAssumed Answered

MQX 4.1 RTCS AF

Question asked by Stuart Baker on Jun 20, 2014
Latest reply on Jun 20, 2014 by Martin Latal

I am trying to make a INADDR_LOOPBACK connection using RTCS.  When I make a connect() call, the connect() blocks forwever (perhaps it would timeout if I waited long enough).  When I follow the connect() operation through the stack, it goes all the way to the lowest layers where it finally makes an ARP request.  This leads me to believe that I do not have a loopback interface installed as I would expect that if I did, the ARP would be in a static table and not need to be resolved over the network.

 

I'm having difficulting determining if:

  1. Do I have a loopback interface installed?
  2. If I don't have a loopback interface installed, how do I install it?

 

It seems the documentation that came with RTCS is out of date and does not match up with the actuall source code.  For instance, the documented method of initializing the stack does not match what is actually being done successfully in my source code.

 

My connection code:

            struct sockaddr saddr;
            saddr.sin_family = PF_INET;
            saddr.sin_port = 80; //htons(80);
            saddr.sin_addr.s_addr = INADDR_LOOPBACK;

 

            uint32_t s = socket(PF_INET, SOCK_STREAM, 0);
            assert(s != RTCS_SOCKET_ERROR);

 

            setsockopt(s, SOL_TCP, OPT_NO_NAGLE_ALGORITHM, &yes, sizeof(int));
            setsockopt(s, SOL_TCP, OPT_RECEIVE_NOWAIT, &yes, sizeof(int));

 

            result = connect(s, (sockaddr*)&saddr, sizeof(struct sockaddr));
            assert(result == RTCS_OK);

 

 

 

My network stack initialization code:

 

    int32_t                 error;
    IPCFG_IP_ADDRESS_DATA   ip_data;
    uint8_t                 mac_id[6];    // 6 byte MAC ID

   // runtime RTCS configuration
   _RTCSPCB_init          = 4;
   _RTCSPCB_grow          = 2;
   _RTCSPCB_max           = 32; //8;
   _RTCSTASK_stacksize    = 4096;
   _RTCS_socket_part_init = 4;
   _RTCS_socket_part_grow = 2;
   _RTCS_socket_part_max  = 20;

    error = RTCS_create();
    if( error != RTCS_OK )
    {
        _task_block();
    }

    _IP_forward = TRUE;

    mac_id[0] = 0;     // Use a fixed MAC ID: 0 . 16 . 141 . 1 . 194 . 93
    mac_id[1] = 16; 
    mac_id[2] = 141;
    mac_id[3] = 1;
    mac_id[4] = 194;
    mac_id[5] = 93;

    error = ipcfg_init_device( BSP_DEFAULT_ENET_DEVICE,  // Ethernet device ID
                               mac_id);                  // MAC address

    // Set user config'd IP address, subnet mask, and gateway address.
    ip_data.ip      = IPADDR( 192, 168,   1,   4 );
    ip_data.mask    = IPADDR( 255, 255, 255,   0 );
    ip_data.gateway = IPADDR( 192, 168,   1,   1 );

    ipcfg_bind_staticip( BSP_DEFAULT_ENET_DEVICE, &ip_data );


#ifdef  JCI_HARDWARE

    // Ethernet IO Configuration - in addition to the hardware / register
    //   configuration steps that occur as part of the previous call
    //   to "initialize_networking()", Enable the Slew rate and the
    //   High Drive on all of the ENET RMI Lines.
    //
    PORTA_PCR15 |= (PORT_PCR_SRE_MASK | PORT_PCR_DSE_MASK);   // TXEN
    PORTA_PCR16 |= (PORT_PCR_SRE_MASK | PORT_PCR_DSE_MASK);   // TXD0
    PORTA_PCR17 |= (PORT_PCR_SRE_MASK | PORT_PCR_DSE_MASK);   // TXD1
    PORTB_PCR0  |= (PORT_PCR_SRE_MASK | PORT_PCR_DSE_MASK);   // MDIO - Phy serial data
    PORTB_PCR1  |= (PORT_PCR_SRE_MASK | PORT_PCR_DSE_MASK);   // MDC - Phy serial clock
#endif

    // The "Trivial File System" (tfs) is used to hold the web pages. These
    //   files are encoded as constant arrays, and are located in program
    //   memory. They are hard coded.
    //
    if( (error = _io_tfs_install("tfs:", tfs_data)) )
    {
        printf("\ninstall returned: %08x\n", error);
    }

    HTTPSRV_PARAM_STRUCT  srv_param;   // Web server parameters

    _mem_zero( &srv_param, sizeof(HTTPSRV_PARAM_STRUCT) );

    srv_param.port                = 80;
    srv_param.ipv4_address.s_addr = INADDR_ANY;
    srv_param.max_uri             = HTTPSRVCFG_DEF_URL_LEN;
    srv_param.max_ses             = HTTPSRVCFG_DEF_SES_CNT;
    srv_param.cgi_lnk_tbl         = (HTTPSRV_CGI_LINK_STRUCT *) cgi_lnk_tbl;
    srv_param.ssi_lnk_tbl         = (HTTPSRV_SSI_LINK_STRUCT *) fn_lnk_tbl;
    srv_param.server_prio         = HTTPSRVCFG_DEF_SERVER_PRIO;

    //  Increased "script_stack" to deal with CGI, SSI problems when moving
    //  "large" amounts of data; ie. loading the error web page.
    //
    srv_param.script_stack        = 4096;   //16384;
    srv_param.root_dir            = "tfs:";
    srv_param.index_page          = "\\overview.shtm";
    srv_param.auth_table          = NULL;
    srv_param.af                  = AF_INET;

    hWebServer = HTTPSRV_init( &srv_param );

 

I'm using IAR as my toolchain.

 

Thanks,

Stuart

Outcomes