void physical_SetupStack(struct physical *p, const char *who, int how) { link_EmptyStack(&p->link); if (how == PHYSICAL_FORCE_SYNC || how == PHYSICAL_FORCE_SYNCNOACF || (how == PHYSICAL_NOFORCE && physical_IsSync(p))) link_Stack(&p->link, &synclayer); else { link_Stack(&p->link, &asynclayer); link_Stack(&p->link, &hdlclayer); } if (how != PHYSICAL_FORCE_SYNCNOACF) link_Stack(&p->link, &acflayer); link_Stack(&p->link, &protolayer); link_Stack(&p->link, &lqrlayer); link_Stack(&p->link, &ccplayer); link_Stack(&p->link, &vjlayer); link_Stack(&p->link, &tcpmsslayer); #ifndef NONAT link_Stack(&p->link, &natlayer); #endif if (how == PHYSICAL_FORCE_ASYNC && physical_IsSync(p)) { log_Printf(LogWARN, "Sync device setting ignored for ``%s'' device\n", who); p->cfg.speed = MODEM_SPEED; } else if (how == PHYSICAL_FORCE_SYNC && !physical_IsSync(p)) { log_Printf(LogWARN, "Async device setting ignored for ``%s'' device\n", who); physical_SetSync(p); } }
struct physical * physical_Create(struct datalink *dl, int type) { struct physical *p; p = (struct physical *)malloc(sizeof(struct physical)); if (!p) return NULL; p->link.type = PHYSICAL_LINK; p->link.name = dl->name; p->link.len = sizeof *p; /* The sample period is fixed - see physical2iov() & iov2physical() */ throughput_init(&p->link.stats.total, SAMPLE_PERIOD); p->link.stats.parent = dl->bundle->ncp.mp.active ? &dl->bundle->ncp.mp.link.stats.total : NULL; p->link.stats.gather = 1; memset(p->link.Queue, '\0', sizeof p->link.Queue); memset(p->link.proto_in, '\0', sizeof p->link.proto_in); memset(p->link.proto_out, '\0', sizeof p->link.proto_out); link_EmptyStack(&p->link); p->handler = NULL; physical_SetDescriptor(p); p->type = type; hdlc_Init(&p->hdlc, &p->link.lcp); async_Init(&p->async); p->fd = -1; p->out = NULL; p->connect_count = 0; p->dl = dl; p->input.sz = 0; *p->name.full = '\0'; p->name.base = p->name.full; p->Utmp = 0; p->session_owner = (pid_t)-1; p->cfg.rts_cts = MODEM_CTSRTS; p->cfg.speed = MODEM_SPEED; p->cfg.parity = CS8; memcpy(p->cfg.devlist, MODEM_LIST, sizeof MODEM_LIST); p->cfg.ndev = NMODEMS; p->cfg.cd.necessity = CD_DEFAULT; p->cfg.cd.delay = 0; /* reconfigured or device specific default */ lcp_Init(&p->link.lcp, dl->bundle, &p->link, &dl->fsmp); ccp_Init(&p->link.ccp, dl->bundle, &p->link, &dl->fsmp); return p; }
VOS_VOID link_Init(struct link *l) { l->phase = PHASE_DEAD; l->type = PHYSICAL_LINK; l->name = VOS_NULL; l->len = sizeof(*l); /* The sample period is fixed - see physical2iov() & iov2physical() */ throughput_init(&l->stats.total, SAMPLE_PERIOD); #if 0/*fanzhibin f49086 delete it*/ p->link.stats.parent = dl->bundle->ncp.mp.active ? &dl->bundle->ncp.mp.link.stats.total : VOS_NULL_PTR; #endif l->stats.gather = 1; l->DropedPacketFromGgsn = 0; PS_MEM_SET(l->Queue, '\0', sizeof l->Queue); PS_MEM_SET(l->proto_in, '\0', sizeof l->proto_in); PS_MEM_SET(l->proto_out, '\0', sizeof l->proto_out); link_EmptyStack(l); /*依次压入PPP协议的各个处理层*/ #if (PPP_FEATURE == PPP_FEATURE_PPP) link_Stack(l, &asynclayer); link_Stack(l, &hdlclayer); link_Stack(l, &acflayer); #endif link_Stack(l, &protolayer); async_Init(&(l->async)); hdlc_Init(&(l->hdlc),&(l->lcp)); /*参数const struct fsm_parent * parent不能为空*/ lcp_Init(&(l->lcp), l, &parent); ipcp_Init(&(l->ipcp), l, &parent); pap_Init(&(l->pap)); chap_Init(&(l->chap)); }