⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sunlink.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    }    TRACE_OUT    return TRUE;}/* *********** * quick_check:  The test duration is approximately 8mins/port.  If all four * ports are being tested in one pass, (the ports are being tested sequentially) * it would be a lengthy period of time to wait just to find out wether the  * loopbacks are in place.  Quick_check allows a quick check of the specified * ports.   * ***********/quick_check(){    func_name = "quick_check";    TRACE_IN    init_parm();    loop_count    = 1;    min_frame_len = 10;    max_frame_len = 11;    proc_msg();    proc_sund_ports();    TRACE_OUT;    return (return_code);}/* *********** * exec_test * ***********//* Execute selected test */exec_test(){    func_name = "exec_test";    TRACE_IN    init_parm();        /* initialize sunlink parameters */    proc_msg();         /* handle messages to be sent out */    proc_sund_ports();	/* test selected ports for sundiag */    TRACE_OUT    return(return_code);}/* ********** * proc_msg * **********//* Display exec_test messages */proc_msg(){    func_name = "proc_msg";    TRACE_IN    sprintf(msg, "pattern= 0x%x, count= %d, min frame= %d, max frame= %d, ",            pattern, loop_count, min_frame_len, max_frame_len);    switch (protocol) {    case SDLC_PROTOCOL:        strcat(msg, "protocol= SDLC\n");        break;    case BSC_PROTOCOL:        strcat(msg, "protocol= BSC\n");        break;    case ASYNC_PROTOCOL:        strcat(msg, "protocol= ASYNC\n");        break;    case LOOPBACK:        strcat(msg, "protocol= LOOPBACK\n");        break;    default:        strcat(msg, "protocol= ILLEGAL\n");    }    send_message (0, DEBUG, msg);    TRACE_OUT }/* ***************** * proc_sund_ports * ****************//* Test selected ports for sundiag */proc_sund_ports(){    int from_ptr = 0, to_ptr = 0;    func_name = "proc_sund_ports";    TRACE_IN    while (sund_ports_to_test(&from_ptr, &to_ptr))     {        set_ports_test();		/* setup env and test ports */        if (!either_quick_test && !verbose && !ttyb_test && !status_dcp)	    sleep(3);    }    TRACE_OUT}/* **************** * set_ports_test * ***************//* Control environment setup for ports test */set_ports_test(){    func_name = "set_ports_test";    TRACE_IN    xmit_device = &testing[0];    rec_device = &testing[1];    if (strcmp(xmit_device->device, rec_device->device)) {	port_to_port = TRUE;    } else {	port_to_port = FALSE;	rec_device = &testing[0];    }    if (!ttyb_test) {	using_device = xmit_device;	set_environment();	if (port_to_port) {	    using_device = rec_device;	    set_environment();	}    }    test_ports(FALSE);    if (port_to_port && !status_dcp) {	rec_device = &testing[0];	xmit_device = &testing[1];	test_ports(TRUE);    }    TRACE_OUT}/* ******************** * sund_ports_to_test * ********************/sund_ports_to_test(from_ptr, to_ptr)int *from_ptr;int *to_ptr;{    func_name = "sund_ports_to_test";     TRACE_IN     using_device = &testing[0];						/* source port exists */    if (get_sund_port(from_ports, from_ptr)) {		using_device = &testing[1];						/* dest port does not exist */	if (!get_sund_port(to_ports, to_ptr))  		    testing[1] = testing[0];		/* set for single port loopbk */        TRACE_OUT	return TRUE;    }     TRACE_OUT    return FALSE;}/* *************** * get_sund_port * ***************/get_sund_port(ports, ptr)char *ports;					/* list of ports */int  *ptr;					/* current position in list */{#define GETTOKEN(from,to,f_indx,t_indx) while(from[f_indx] != ',' &&\	from[f_indx] != '\0') to[t_indx++] = from[f_indx++];\	if (from[f_indx]==',') f_indx++;\	to[t_indx]='\0';    char temp_str[20];    int  str_ptr;    int  port_ptr;    int  dummy;					/* dummy return value */    func_name = "get_sund_port";     TRACE_IN     if (ports == 0 || ports[*ptr] == '\0')	/* if no more source ports */    { 	TRACE_OUT	return FALSE;    }        match = FALSE;    port_ptr = *ptr;				/* current ptr of ports list */    if (cur_test == DCP)     {	temp_str[0] = ports[0];			/* get board type */	str_ptr = 1;        if (!port_ptr)	    port_ptr++;	GETTOKEN(ports, temp_str, port_ptr, str_ptr)	if (det_sd_dcp(temp_str, &dummy))  	{		TRACE_OUT		return(FALSE);	}    }    else {	if (cur_test == MCP) {	    str_ptr = 0;  	    GETTOKEN(ports, temp_str, port_ptr, str_ptr) 	    det_sd_mcp(temp_str, &dummy);	}	else {	    str_ptr = 0;	    GETTOKEN(ports, temp_str, port_ptr, str_ptr)	    if ( (its_hih) || (its_his) )	/* if Sbus HSI devices */	    	det_sd_hih(temp_str, &dummy);	    else				/* else VME hsi */	    	det_sd_hss(temp_str, &dummy);	}    }    if (!match) {        send_message(-BAD_SD_PORTS_SPEC, ERROR, "Invalid port specification.");    }    *ptr = port_ptr;    TRACE_OUT    return(match);}/* ************ * det_sd_dcp * ************//* Determine DCP device values */int	det_sd_dcp(arg, return_ptr)char *arg;int  *return_ptr;{    func_name = "det_sd_dcp";     TRACE_IN     if (arg[0] >= 'a' && arg[0]  <= 'd')    {      if (arg[1] >= '0' && arg[1] < '4' && (arg[2] == '-' || arg[2] == '\0'))       {        match = TRUE;        using_device->dcp = TRUE;        using_device->board = arg[0];        using_device->port = arg[1];        sprintf(using_device->device, "dcp%c%c", arg[0], arg[1] );        using_device->int_port = atoi(&using_device->device[4]);        if (arg[2] == '-')            *return_ptr = 3;         send_message(0, VERBOSE, "Testing '%s', board %c, port %c.", 		using_device->device, using_device->board, using_device->port);      }      else	if (arg[1] == '\0')         {		TRACE_OUT		return(TRUE);	}    }    TRACE_OUT    return(FALSE);} /* ************ * det_sd_hss * ************//* Determine HSS device values */ det_sd_hss(arg, return_ptr)char *arg;int  *return_ptr;{     if ((arg[0]=='e' || arg[0]=='o') && arg[1]>='0' && arg[1]<='3' &&        (arg[2]=='r' || arg[2]=='v') && (arg[3] == '-' || arg[3] == '\0'))    {        match = TRUE;        using_device->dcp = FALSE;        sprintf(using_device->device, "hss%c", arg[1]);        using_device->int_port = atoi(&using_device->device[3]);         if (using_device->int_port < 2)            using_device->board = 'm';        else if (using_device->int_port < 4)            using_device->board = 'n';        using_device->hp_obclk = FALSE;        using_device->hp_v35   = FALSE;        if (arg[0] == 'o')      /* if on-board clock */            using_device->hp_obclk = TRUE;        if (arg[2] == 'v')      /* if V.35 */            using_device->hp_v35 =TRUE;        if (arg[3] == '-')            *return_ptr = 4;        send_message(0, VERBOSE, "Testing '%s', board %c, port %d.",          using_device->device, using_device->board, using_device->int_port);    }}/* ************ * det_sd_hih * ************/ /* Determine Sbus HSI device values */ det_sd_hih(arg, return_ptr)char *arg;int  *return_ptr;{     func_name = "det_sd_hih";     TRACE_IN     if ((arg[0]=='e' || arg[0]=='o') && (arg[1]>='0' && arg[1]<='9') &&        ((arg[2]>='0' && arg[2]<='9') || arg[2] == '-' || arg[2] == '\0'))    {        match = TRUE;        using_device->dcp = FALSE;        using_device->int_port = atoi(&arg[1]);	if (!((using_device->int_port >=0) && (using_device->int_port < 20)))		send_message (-PORT_NUM_OUT_OF_RANGE, ERROR, "Port number specified is out of range.");	if (its_hih)        	sprintf(using_device->device, "hih%d", using_device->int_port);	else 		/* if (its_his) */ 	      	sprintf(using_device->device, "his%d", using_device->int_port);         if (using_device->int_port < 4)            using_device->board = '1';        else if (using_device->int_port < 8)            using_device->board = '2';        else if (using_device->int_port < 12)            using_device->board = '3';        else if (using_device->int_port < 16)            using_device->board = '4';        else            using_device->board = '5';         using_device->hp_obclk = FALSE;        using_device->hp_v35   = FALSE;         if (arg[0] == 'o')      /* if on-board clock */            using_device->hp_obclk = TRUE;          if (arg[2] == '-')            *return_ptr = 3;  	if (quick_check_flag)	{    	    send_message(0, VERBOSE, "Quick check of port connection(s): device '%s', board %c, port %d.",              using_device->device,using_device->board, using_device->int_port);        }	else	{	    send_message(0, VERBOSE, "Testing '%s', board %c, port %d.",	      using_device->device,using_device->board, using_device->int_port);	}    }    TRACE_OUT}     /* ************ * det_sd_mcp * ************/ /* Determine MCP device values */  det_sd_mcp(arg, return_ptr)char *arg;int  *return_ptr;{    func_name = "det_sd_mcp";     TRACE_IN     if (isdigit(arg[0]))     {        if (isdigit(arg[1]) || arg[1]=='-' || arg[1]=='\0')         {            sprintf(using_device->device, "mcph%c%c", arg[0], arg[1] != '-' ? arg[1] : '\0');            using_device->int_port = atoi(&using_device->device[4]);            if (using_device->int_port >= 0 && using_device->int_port < 16) 	    {                match = TRUE;                using_device->dcp = FALSE;                 if (using_device->int_port < 4)                    using_device->board = 'h';                else if (using_device->int_port < 8)                    using_device->board = 'i';                else if (using_device->int_port < 12)                    using_device->board = 'j';                else                    using_device->board = 'k';                 if (arg[1] == '-')                    *return_ptr = 2;                else if (arg[2] == '-')                    *return_ptr = 3;      		send_message(0, VERBOSE, "Testing '%s', board %c, port %d.", 			using_device->device, using_device->board, 			using_device->int_port);            }        }    }     TRACE_OUT}set_environment(){    /*     * ---------------------------------------------------------------- set     * the environment of the DCP board by the system function call. 1)     * download the DCP kernel, by dcpload command (dcpload dcpmon.image). 2)     * initialize the selected channel, by dcpattach command (dcpattach     * /dev/dcpXX). 3) configure the selected channel to the selected     * protocol, by dcplayer command (dcplayer dcpXX YYY ZZZ).     * -----------------------------------------------------------------     */    int             load_kernal = FALSE, attach_dcp = FALSE;    func_name = "set_environment";     TRACE_IN     set_dcp_parms(&load_kernal,&attach_dcp); /* define parm values for dcp */    load_dcp_kern(load_kernal);              /* download dcp kernal */    init_dcp_chnel(attach_dcp);              /* init selected channel for dcp *//* Setup conditions for selected protocol. *//* MCP and HSS are concerned only with SDLC */    switch (protocol) {    case SDLC_PROTOCOL:        config_dcp_chnel(attach_dcp);        /* config selected channel with */                                             /* selected protocol */        init_brd_sdlc();                     /* syncinit board */	break;    case BSC_PROTOCOL:	send_message(-NO_BSC, ERROR,"BSC protocol is not implemented for '%s'.",                using_device->device);	break;    case ASYNC_PROTOCOL:	send_message(-NO_ASYNC, ERROR, 		"ASYNC protocol is not implemented for '%s'.",		 using_device->device);	break;    case LOOPBACK:	if (using_device->dcp) {	    if (simulate_error == NO_LAYER_LOOPBACK)		sprintf(tmpbuf, "/no/dcplayer %s lo%c", using_device->device, using_device->port);	    else		sprintf(tmpbuf, "/usr/sunlink/dcp/dcplayer %s lo%c",			using_device->device, using_device->port);	    send_message(0, DEBUG, "Executing %s\n", tmpbuf);            if (system(tmpbuf))		couldnt_execute(NO_LAYER_LOOPBACK);	}	break;    default:	send_message(-ILLEGAL_PROTOCOL, ERROR, 		"Illegal protocol specified for '%s'.", using_device->device);	break;    }    TRACE_OUT}/* *************** * set_dcp_parms * ***************//* Define parameter values if testing dcp board */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -