openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

cfmlm.c (3113B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * Linemodule CLI access
      8  */
      9 
     10 #if defined(VXWORKS)
     11 #if defined(BMW) || defined(NSX) || defined(METROCORE)
     12 
     13 #include "vxWorks.h"
     14 #include "stdio.h"
     15 #include "sys/socket.h"
     16 #include "net/socketvar.h"
     17 #include "sockLib.h"
     18 #include "ioLib.h"
     19 #include "netinet/in.h"
     20 #include <appl/diag/cmdlist.h>
     21 #include <shared/bsl.h>
     22 
     23 #define TELNET_PORT 23
     24 
     25 extern int sysSlotIdGet();
     26 extern int atoi(const char *);
     27 
     28 /* Debug Stuff */
     29 UINT32 saddr = (192 << 24) | (168 << 16) | (0 << 8) | (1 << 0);
     30 int useslotid = 1;
     31 
     32 char lm_console_usage[] =
     33     "Parameters: <lm slot>\n\tConnect to LM slot.\n";
     34 
     35 cmd_result_t
     36 lm_console(int unit, args_t *a)
     37 {
     38     int retval;
     39     char   buf[4];
     40     struct sockaddr_in  sa;
     41     int lineModSock;
     42     fd_set rfds;
     43     char *c;
     44     UINT32 laddr = (192 << 24) | (168 << 16) | (0 << 8) | (0 << 0);
     45 
     46     if ((c = ARG_GET(a)) == NULL) {
     47         return(ERROR);
     48     } else {
     49         printf("IP addr %d.%d.%d.%d\n",
     50         (saddr >> 24 ) & 0x000000FF,
     51         (saddr >> 16 ) & 0x000000FF,
     52         (saddr >> 8 ) & 0x000000FF,
     53         (saddr >> 0 ) & 0x000000FF
     54         );
     55 
     56         laddr |= (sysSlotIdGet() ? (1 << 8) : 0);
     57         laddr |= ((atoi(c)) & 0x000000FF);
     58         printf("slot %s IP addr %d.%d.%d.%d\n", c,
     59         (laddr >> 24 ) & 0x000000FF,
     60         (laddr >> 16 ) & 0x000000FF,
     61         (laddr >> 8 ) & 0x000000FF,
     62         (laddr >> 0 ) & 0x000000FF
     63         );
     64         if (useslotid) {
     65             saddr = laddr;
     66         }
     67         if (((laddr & 0x000000FF) < 3 ) || ((laddr & 0x000000FF) > 10 )) {
     68                 cli_out("Slot ID should be 3 .. 10\n");
     69                 return(ERROR);
     70         }
     71     }
     72 
     73 
     74     if ((lineModSock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
     75     {
     76         printf("Socket Create failed\n");
     77         return (ERROR);
     78     }
     79 
     80     /* connect to Telnet port */
     81     bzero ((char *)&sa, sizeof(sa));
     82     sa.sin_family      = AF_INET;
     83     sa.sin_port        = htons(TELNET_PORT);
     84     sa.sin_addr.s_addr = htonl(saddr);
     85     if (connect(lineModSock, (struct sockaddr *)&sa, sizeof(sa)) < 0 )
     86     {
     87         printf("connect failed\n");
     88         return (ERROR);
     89     }
     90 
     91     printf("connect success %d\n", lineModSock);
     92 
     93 
     94     while(1) {
     95         FD_ZERO(&rfds);
     96         FD_SET(0, &rfds);
     97         FD_SET(lineModSock, &rfds);
     98         retval = select(lineModSock + 1, &rfds, NULL, NULL, NULL);
     99 
    100         if (retval < 0) break;
    101 
    102         if (FD_ISSET(0, &rfds)) {
    103             if (read(0, buf, 1)) {
    104                 write(lineModSock, buf, 1);
    105             } else {
    106                 break;
    107             }
    108         } else if (FD_ISSET(lineModSock, &rfds)) {
    109             if (read(lineModSock, buf, 1)) {
    110                 write(0, buf, 1);
    111             } else {
    112                 break;
    113             }
    114         }
    115     }
    116 
    117     close(lineModSock);
    118 
    119     return(OK);
    120 }
    121 
    122 #endif /* defined(BMW) || defined(NSX) || defined(METROCORE) */
    123 #endif /* defined(VXWORKS) */
    124 
    125 int _bcm_diag_cfmlm_not_empty;