📄 wdbportsvr.c
字号:
/* wdbportsvr.c - portServer backend library */ /* Copyright 1984-1998 Wind River Systems, Inc. */#include "copyright_wrs.h" /*modification history--------------------01b,01jul98,c_c Ported to backend V2 API.01a,29Jan98,rlp written*/ /*DESCRIPTIONThis file is a target server backend using the RPC mechanism to dialog witha WDB target agent. This backend is attached when the target server is started with the option -B followed by "wdbportsvr". The communication protocol used is TCP/IP. To increase the reliability of thisprotocol a simple mechanism of timeout and re-sending is implemented. When aservice is called a timer (implemented in the RPC client mechanism) isalso started. If the timeout arrived before the service has replied then therequest is re-sent. The number of time a same request can be re-sent is limited.When this limit is reached and the service call fails one more in timeout thelink is declared as broken. The default timeout value is handled by WDB_TIMEOUTbut this value can be changed by the user. He must start the target server withthe option -Bt followed by a number. This number is the timeout value to use(in second). The user can also modify the maxinum number of time that a samerequest can be re-sent. In this case the option -Br must be used. The defaultvalue of this option is handled by WDB_MAX_RESEND.The TCP/IP was not used because it requests timer. This feature is not alwaysavailable on all target boards. Moreover the implementation of this protocolrequer more memory space as the UDP protocol. As the WDB target agent mustbe the smallest possible the UDP protocol is the obligatory choise. This backend file handles all functions that a target server backend request.The diagram below gives the function link. The wdbRpcClntCall () isthe root function. It allows to call any WDB service and performs the linkreliability control as describe before. This function is called by 7 functions:5 are backend functions and 2 are internal to this backend. This 2 functions(wdbRpcCallRStatus() and wdbRpcCallStatus()) are used by the otherbackend functions that don't call wdbRpcClntCall() directly. They allow tocall a WDB service but this service must return either a RESULT_STATUS (forwdbRpcCallRStatus()) or a STATUS (for wdbRpcCallStatus()). */ /* includes */ #include <stdio.h>#include <netdb.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <rpc/rpc.h>#include <sys/time.h>#include <fcntl.h> #include "tgtlib.h"#include "tgtsvr.h"#include "tssvcmgt.h"#include "host.h"#include "wdb.h"#include "wdbP.h"#include "bkendlib.h"#include "bkendlog.h"#include "wpwrutil.h" #ifdef WIN32extern int dbg_on;#endif /* WIN32 */ /* defines */ #define BASE_RAW_PORT 2100 /* forward declarations */ extern STATUS rpcCoreInit (CLIENT *, u_int, u_int, TGT_OPS *);extern CLIENT * clntttysvr_create (struct sockaddr_in *, u_long, u_long, struct timeval, int, int);/* locals */LOCAL int baudRate = 9600; /* Serial line speed */LOCAL int timeout = BKEND_TIMEOUT;/* timeout value */LOCAL int recallNum = BKEND_RESEND; /* how much calls allowed */LOCAL int portNum = 0; /* portserver port number */static FLAG_DESC wdbportsvrFlags [] = { { "-device", "-d", (PARSE_RTN) flagInt, &portNum, "-d[evice] device\tPortServer serial port Number to use." }, { "-bps", "-b", (PARSE_RTN) flagInt, &baudRate, "-b[ps] bit/s\t\tPortServer serial port speed (default 9600)." }, {"-Btimeout","-Bt", (PARSE_RTN) flagInt, &timeout, "-Bt[imeout] value\tPortServer Backend timeout (default 1 sec)." }, {"-Bresend", "-Br", (PARSE_RTN) flagInt, &recallNum, "-Br[esend] number\tPortServer Backend request re-send number (default 3)." },#ifdef WIN32 /* hidden flag for debugging purpose */ { "-BTtyDebug", "-BT", (PARSE_RTN) flagInt, &dbg_on, NULL },#endif {NULL, NULL, NULL, NULL, NULL} /* End Of Record delimiter */ }; /********************************************************************************* wdbportsvrFlagsGet - Get the supported flags for this backend** This function is called by the target server when it wants to get the flags* which are supported by the currently attached backend. The following options* can be set trough command line parameters.** <timeout> is the time out duration to use for the communication with the* WDB target agent. This input argument is set when the target server is* started with the option -Bt. Otherwise set to zero.** <recallNum> is the maximun number of time that a request is re-sent before* to admit the communication link is broken. Set when the target server is* started with the option -Br, otherwise reset to zero.** <portNum> is the port to open on the portserver to deal with the target. It* can be set with the -d(evice) parameter (default 0).** <baudRate> is the speed of the used serial line. It can be set with the* -b(ps) parameter (defaults to 9600).** * Here we return our supported flags.**/DLL_EXPORT FLAG_DESC * wdbportsvrFlagsGet (void) { return (FLAG_DESC *) wdbportsvrFlags; }/********************************************************************************* wdbportsvrInitialize - initialize the backend interface.** This function is called by the target server when it wants to attach this* backend. Four input arguments are accepted:** <tgtName> is a pointer to a string that handles either the name or the* internet address (in dotted-decimal * format) of the target board. ** <pTgtOps> is a pointer to TGT_OPS structure (defines in tgtlib.h file).* This structure handles function pointers used by the target server to call* a backend function. The backend attachment is performed by filling this* structure with the backend function address. ** <pBkInfo> is a structure to fill for the target server to know if the backend* exports a selectable file descriptor, a select-like function, or nothing for* the asynchronous event notification. * Remember that the target server now dedicates a thread to the event* notification.** This function initializes the backend. It creates the backend client, resets* the udp datagram sequence number and fills the TGT_OPS structure with* the information describing the backend and returns a pointer to this * structure.** CAVEAT: its name is built from the file name concatenated with the string* "Initialize". This is compulsory.* * RETURNS: TRUE if the backend is properly initialized, otherwise FALSE.*/DLL_EXPORT STATUS wdbportsvrInitialize ( char * tgtName, /* target name to connect to */ TGT_OPS * pTgtOps, /* backend function */ BKEND_INFO * pBkInfo /* Backend info and select method */ ) { CLIENT * pClnt; /* target client */ u_long addr; /* target address: long int format */ struct sockaddr_in dest_addr; /* portServer address information */ struct hostent * dest_host; /* target address */ struct timeval tv; /* connection timeout */ u_int resendCnt; /* connection re-send counter */ /* clear dest_addr */ memset ((void *) &dest_addr, 0x00, sizeof (dest_addr)); /* convert <tgtName> into the target board Internet address */ if ((dest_host = (struct hostent *) gethostbyname (tgtName)) == NULL) { if ((addr = inet_addr (tgtName)) == (u_long) ERROR) { errno = WTX_ERR_SVR_TARGET_UNKNOWN; wpwrLogErr ("Target %s unknown. Attach failed.\n", tgtName); return (ERROR); } dest_addr.sin_addr.s_addr = addr; } else dest_addr.sin_addr.s_addr = * ((u_long *) dest_host->h_addr_list[0]); /* * set the socket with the input informaton * we store the tty port as the IP port number to connect */ dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons((short) (BASE_RAW_PORT + portNum)); /* set the connection timeout to the current value */ tv.tv_sec = timeout; tv.tv_usec = 0; /* * set the resendCnt counter with the maximun of time the client creation * will be re-tried. */ resendCnt = recallNum; do { /* create the backend client and connect the target deamon */ pClnt = clntttysvr_create (&dest_addr, WDBPROG, WDBVERS, tv, baudRate, portNum); } while ((pClnt == NULL) && (--resendCnt > 0)); /* * check the client creation : If the creation failed, log a message with * the RPC error and return ERROR to stop the target server initialization * otherwise initialize the portServer. */ if (pClnt == NULL) { wpwrLogErr ("%s\n", clnt_spcreateerror("wdbportsvr backend client create")); return (ERROR); } /* initialize the rpc core */ rpcCoreInit (pClnt, timeout, recallNum, pTgtOps); /* describe the link used between the backend and the target */ pTgtOps->tgtLink.name = "WDB Agent across portServer"; pTgtOps->tgtLink.type = TGT_LINK_SERIAL_RPC; pTgtOps->tgtLink.speed = baudRate; pBkInfo->tgtBkVersion = BKEND_VERSION_2; /* Backend version 2 */ /* We give here our polling method : a selectable socket */ pBkInfo->INFO.POLLING_METHOD.bkEndPollingMethod = POLL_SELECT_MODE; pBkInfo->INFO.POLLING_METHOD.BKEND_NOTIF_METHOD.pollingFd = pTgtOps->tgtEventFd; return (OK); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -