uint evlog_bump_head(evlog_t *e) { uint index = e->head; e->head = INCPTR(e, e->head, e->unitsize); return index; }
/* * upap_sauthreq - Send an Authenticate-Request. */ static void upap_sauthreq(upap_state *u) { u_char *outp; int outlen; outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) + u->us_userlen + u->us_passwdlen; outp = outpacket_buf[u->us_unit]; MAKEHEADER(outp, PPP_PAP); PUTCHAR(UPAP_AUTHREQ, outp); PUTCHAR(++u->us_id, outp); PUTSHORT(outlen, outp); PUTCHAR(u->us_userlen, outp); BCOPY(u->us_user, outp, u->us_userlen); INCPTR(u->us_userlen, outp); PUTCHAR(u->us_passwdlen, outp); BCOPY(u->us_passwd, outp, u->us_passwdlen); pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN); UPAPDEBUG((LOG_INFO, "pap_sauth: Sent id %d\n", u->us_id)); TIMEOUT(upap_timeout, u, u->us_timeouttime); ++u->us_transmits; u->us_clientstate = UPAPCS_AUTHREQ; }
/* * upap_sauthreq - Send an Authenticate-Request. */ static void upap_sauthreq(ppp_pcb *pcb) { struct pbuf *p; u_char *outp; int outlen; outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) + pcb->upap.us_userlen + pcb->upap.us_passwdlen; p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { pbuf_free(p); return; } outp = (u_char*)p->payload; MAKEHEADER(outp, PPP_PAP); PUTCHAR(UPAP_AUTHREQ, outp); PUTCHAR(++pcb->upap.us_id, outp); PUTSHORT(outlen, outp); PUTCHAR(pcb->upap.us_userlen, outp); MEMCPY(outp, pcb->upap.us_user, pcb->upap.us_userlen); INCPTR(pcb->upap.us_userlen, outp); PUTCHAR(pcb->upap.us_passwdlen, outp); MEMCPY(outp, pcb->upap.us_passwd, pcb->upap.us_passwdlen); ppp_write(pcb, p); TIMEOUT(upap_timeout, pcb, pcb->settings.pap_timeout_time); ++pcb->upap.us_transmits; pcb->upap.us_clientstate = UPAPCS_AUTHREQ; }
//****************************************************************************** // Generate PAP options ( username + password) //****************************************************************************** void UPAPGenWapAuth(PAP_CnfgOptions_t *po, char * user, char * password) { char *us_user; /* User */ int us_userlen; /* User length */ char *us_passwd; /* Password */ int us_passwdlen; /* Password length */ int outlen; u_char *outp; /* Save the username and password we're given */ us_user = user; us_userlen = strlen(user); us_passwd = password; us_passwdlen = strlen(password); outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) + us_userlen + us_passwdlen; outp = po->content; PUTCHAR(UPAP_AUTHREQ, outp); PUTCHAR(gChid, outp); PUTSHORT(outlen, outp); PUTCHAR(us_userlen, outp); memcpy(outp, us_user, us_userlen); INCPTR(us_userlen, outp); PUTCHAR(us_passwdlen, outp); memcpy(outp, us_passwd, us_passwdlen); po->len = outlen; po->flag = 1; }
/* * ChapSendChallenge - Send an Authenticate challenge. */ static void ChapSendChallenge( chap_state *cstate) { u_char *outp; int chal_len, name_len; int outlen; chal_len = cstate->chal_len; name_len = strlen(cstate->chal_name); outlen = CHAP_HEADERLEN + sizeof (u_char) + chal_len + name_len; outp = outpacket_buf; MAKEHEADER(outp, PPP_CHAP); /* paste in a CHAP header */ PUTCHAR(CHAP_CHALLENGE, outp); PUTCHAR(cstate->chal_id, outp); PUTSHORT(outlen, outp); PUTCHAR(chal_len, outp); /* put length of challenge */ BCOPY(cstate->challenge, outp, chal_len); INCPTR(chal_len, outp); BCOPY(cstate->chal_name, outp, name_len); /* append hostname */ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN); TIMEOUT(ChapChallengeTimeout, cstate, cstate->timeouttime); ++cstate->chal_transmits; }
/* ARGSUSED */ static void ChapSendResponse( chap_state *cstate) { u_char *outp; int outlen, md_len, name_len; md_len = cstate->resp_length; name_len = strlen(cstate->resp_name); outlen = CHAP_HEADERLEN + sizeof (u_char) + md_len + name_len; outp = outpacket_buf; MAKEHEADER(outp, PPP_CHAP); PUTCHAR(CHAP_RESPONSE, outp); /* we are a response */ PUTCHAR(cstate->resp_id, outp); /* copy id from challenge packet */ PUTSHORT(outlen, outp); /* packet length */ PUTCHAR(md_len, outp); /* length of MD */ BCOPY(cstate->response, outp, md_len); /* copy MD to buffer */ INCPTR(md_len, outp); BCOPY(cstate->resp_name, outp, name_len); /* append our name */ /* send the packet */ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN); cstate->clientstate = CHAPCS_RESPONSE; TIMEOUT(ChapResponseTimeout, cstate, cstate->timeouttime); ++cstate->resp_transmits; }
static vframe_t *local_vf_get(void) { vframe_t *vf; if (get_ptr == fill_ptr) return NULL; vf = &vfpool[get_ptr]; INCPTR(get_ptr); return vf; }
static int prepare_vframe(vframe_t *vf) { vframe_t* new_vf; int index ; index = get_unused_vm_index(); if(index < 0 ){ return -1; } new_vf = &vfpool[fill_ptr]; memcpy(new_vf , vf, sizeof(vframe_t)); vfbuf_use[index]++; INCPTR(fill_ptr); return 0; }
static void local_vf_put(vframe_t *vf) { int i; int canvas_addr; if(!vf) return; INCPTR(putting_ptr); for (i = 0; i < VF_POOL_SIZE; i++) { canvas_addr = index2canvas(i); if(vf->canvas0Addr == canvas_addr ){ vfbuf_use[i] = 0; vm_vf_put_from_provider(vf); } } }
/* * upap_rauth - Receive Authenticate. */ static void upap_rauthreq(upap_state *u, u_char *inp, int id, int len) { u_char ruserlen, rpasswdlen; char *ruser, *rpasswd; int retcode; char *msg; int msglen; UPAPDEBUG((LOG_INFO, "pap_rauth: Rcvd id %d.\n", id)); if (u->us_serverstate < UPAPSS_LISTEN) { return; } /* * If we receive a duplicate authenticate-request, we are * supposed to return the same status as for the first request. */ if (u->us_serverstate == UPAPSS_OPEN) { upap_sresp(u, UPAP_AUTHACK, id, "", 0); /* return auth-ack */ return; } if (u->us_serverstate == UPAPSS_BADAUTH) { upap_sresp(u, UPAP_AUTHNAK, id, "", 0); /* return auth-nak */ return; } /* * Parse user/passwd. */ if (len < sizeof (u_char)) { UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet.\n")); return; } GETCHAR(ruserlen, inp); len -= sizeof (u_char) + ruserlen + sizeof (u_char); if (len < 0) { UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet.\n")); return; } ruser = (char *) inp; INCPTR(ruserlen, inp); GETCHAR(rpasswdlen, inp); if (len < rpasswdlen) { UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet.\n")); return; } rpasswd = (char *) inp; /* * Check the username and password given. */ retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen); BZERO(rpasswd, rpasswdlen); upap_sresp(u, retcode, id, msg, msglen); if (retcode == UPAP_AUTHACK) { u->us_serverstate = UPAPSS_OPEN; auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen); } else { u->us_serverstate = UPAPSS_BADAUTH; auth_peer_fail(u->us_unit, PPP_PAP); } if (u->us_reqtimeout > 0) { UNTIMEOUT(upap_reqtimeout, u); } }
void evlog_dump(evlog_t *e, evlog_dump_cb cb) { for (uint index = INCPTR(e, e->head, e->unitsize); index != e->head; index = INCPTR(e, index, e->unitsize)) { cb(&e->items[index]); } }
/* * upap_rauth - Receive Authenticate. */ static void upap_rauthreq(ppp_pcb *pcb, u_char *inp, int id, int len) { u_char ruserlen, rpasswdlen; char *ruser; char *rpasswd; char rhostname[256]; int retcode; const char *msg; int msglen; if (pcb->upap.us_serverstate < UPAPSS_LISTEN) return; /* * If we receive a duplicate authenticate-request, we are * supposed to return the same status as for the first request. */ if (pcb->upap.us_serverstate == UPAPSS_OPEN) { upap_sresp(pcb, UPAP_AUTHACK, id, "", 0); /* return auth-ack */ return; } if (pcb->upap.us_serverstate == UPAPSS_BADAUTH) { upap_sresp(pcb, UPAP_AUTHNAK, id, "", 0); /* return auth-nak */ return; } /* * Parse user/passwd. */ if (len < 1) { UPAPDEBUG(("pap_rauth: rcvd short packet.")); return; } GETCHAR(ruserlen, inp); len -= sizeof (u_char) + ruserlen + sizeof (u_char); if (len < 0) { UPAPDEBUG(("pap_rauth: rcvd short packet.")); return; } ruser = (char *) inp; INCPTR(ruserlen, inp); GETCHAR(rpasswdlen, inp); if (len < rpasswdlen) { UPAPDEBUG(("pap_rauth: rcvd short packet.")); return; } rpasswd = (char *) inp; /* * Check the username and password given. */ retcode = UPAP_AUTHNAK; if (auth_check_passwd(pcb, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen)) { retcode = UPAP_AUTHACK; } BZERO(rpasswd, rpasswdlen); #if 0 /* UNUSED */ /* * Check remote number authorization. A plugin may have filled in * the remote number or added an allowed number, and rather than * return an authenticate failure, is leaving it for us to verify. */ if (retcode == UPAP_AUTHACK) { if (!auth_number()) { /* We do not want to leak info about the pap result. */ retcode = UPAP_AUTHNAK; /* XXX exit value will be "wrong" */ warn("calling number %q is not authorized", remote_number); } } msglen = strlen(msg); if (msglen > 255) msglen = 255; #endif /* UNUSED */ upap_sresp(pcb, retcode, id, msg, msglen); /* Null terminate and clean remote name. */ ppp_slprintf(rhostname, sizeof(rhostname), "%.*v", ruserlen, ruser); if (retcode == UPAP_AUTHACK) { pcb->upap.us_serverstate = UPAPSS_OPEN; ppp_notice("PAP peer authentication succeeded for %q", rhostname); auth_peer_success(pcb, PPP_PAP, 0, ruser, ruserlen); } else { pcb->upap.us_serverstate = UPAPSS_BADAUTH; ppp_warn("PAP peer authentication failed for %q", rhostname); auth_peer_fail(pcb, PPP_PAP); } if (pcb->settings.pap_req_timeout > 0) UNTIMEOUT(upap_reqtimeout, pcb); }
/* * ChapReceiveResponse - Receive and process response. */ static void ChapReceiveResponse( chap_state *cstate, u_char *inp, int id, int len) { u_char *remmd, remmd_len; int secret_len, old_state; int code; char rhostname[256]; MD5_CTX mdContext; unsigned char secret[MAXSECRETLEN]; u_char hash[MD5_SIGNATURE_SIZE]; if (cstate->serverstate == CHAPSS_CLOSED || cstate->serverstate == CHAPSS_PENDING) { CHAPDEBUG(("ChapReceiveResponse: in state %d", cstate->serverstate)); return; } if (id != cstate->chal_id) return; /* doesn't match ID of last challenge */ /* * If we have received a duplicate or bogus Response, * we have to send the same answer (Success/Failure) * as we did for the first Response we saw. */ if (cstate->serverstate == CHAPSS_OPEN) { ChapSendStatus(cstate, CHAP_SUCCESS); return; } if (cstate->serverstate == CHAPSS_BADAUTH) { ChapSendStatus(cstate, CHAP_FAILURE); return; } if (len < 2) { CHAPDEBUG(("ChapReceiveResponse: rcvd short packet.")); return; } GETCHAR(remmd_len, inp); /* get length of MD */ remmd = inp; /* get pointer to MD */ INCPTR(remmd_len, inp); len -= sizeof (u_char) + remmd_len; if (len < 0) { CHAPDEBUG(("ChapReceiveResponse: rcvd short packet.")); return; } UNTIMEOUT(ChapChallengeTimeout, cstate); if (len >= sizeof(rhostname)) len = sizeof(rhostname) - 1; BCOPY(inp, rhostname, len); rhostname[len] = '\000'; /* * Get secret for authenticating them with us, * do the hash ourselves, and compare the result. */ code = CHAP_FAILURE; if (!get_secret(cstate->unit, (explicit_remote? remote_name: rhostname), cstate->chal_name, secret, &secret_len, 1)) { warn("No CHAP secret found for authenticating %q", rhostname); } else { /* generate MD based on negotiated type */ switch (cstate->chal_type) { case CHAP_DIGEST_MD5: /* only MD5 is defined for now */ if (remmd_len != MD5_SIGNATURE_SIZE) break; /* it's not even the right length */ MD5Init(&mdContext); MD5Update(&mdContext, &cstate->chal_id, 1); MD5Update(&mdContext, secret, secret_len); MD5Update(&mdContext, cstate->challenge, cstate->chal_len); MD5Final(hash, &mdContext); /* compare local and remote MDs and send the appropriate status */ if (memcmp (hash, remmd, MD5_SIGNATURE_SIZE) == 0) code = CHAP_SUCCESS; /* they are the same! */ break; default: CHAPDEBUG(("unknown digest type %d", cstate->chal_type)); } } BZERO(secret, sizeof(secret)); ChapSendStatus(cstate, code); if (code == CHAP_SUCCESS) { old_state = cstate->serverstate; cstate->serverstate = CHAPSS_OPEN; if (old_state == CHAPSS_INITIAL_CHAL) { auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len); } if (cstate->chal_interval != 0) TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval); notice("CHAP peer authentication succeeded for %q", rhostname); } else { error("CHAP peer authentication failed for remote host %q", rhostname); cstate->serverstate = CHAPSS_BADAUTH; auth_peer_fail(cstate->unit, PPP_CHAP); } }
/* * ChapReceiveChallenge - Receive Challenge and send Response. */ static void ChapReceiveChallenge( chap_state *cstate, u_char *inp, int id, int len) { int rchallenge_len; u_char *rchallenge; int secret_len; unsigned char secret[MAXSECRETLEN]; char rhostname[256]; MD5_CTX mdContext; u_char hash[MD5_SIGNATURE_SIZE]; if (cstate->clientstate == CHAPCS_CLOSED || cstate->clientstate == CHAPCS_PENDING) { CHAPDEBUG(("ChapReceiveChallenge: in state %d", cstate->clientstate)); return; } if (len < 2) { CHAPDEBUG(("ChapReceiveChallenge: rcvd short packet.")); return; } GETCHAR(rchallenge_len, inp); len -= sizeof (u_char) + rchallenge_len; /* now name field length */ if (len < 0) { CHAPDEBUG(("ChapReceiveChallenge: rcvd short packet.")); return; } rchallenge = inp; INCPTR(rchallenge_len, inp); if (len >= sizeof(rhostname)) len = sizeof(rhostname) - 1; BCOPY(inp, rhostname, len); rhostname[len] = '\000'; /* Microsoft doesn't send their name back in the PPP packet */ if (explicit_remote || (remote_name[0] != 0 && rhostname[0] == 0)) { strlcpy(rhostname, remote_name, sizeof(rhostname)); CHAPDEBUG(("ChapReceiveChallenge: using '%q' as remote name", rhostname)); } /* get secret for authenticating ourselves with the specified host */ if (!get_secret(cstate->unit, cstate->resp_name, rhostname, secret, &secret_len, 0)) { secret_len = 0; /* assume null secret if can't find one */ warn("No CHAP secret found for authenticating us to %q", rhostname); } /* cancel response send timeout if necessary */ if (cstate->clientstate == CHAPCS_RESPONSE) UNTIMEOUT(ChapResponseTimeout, cstate); cstate->resp_id = id; cstate->resp_transmits = 0; /* generate MD based on negotiated type */ switch (cstate->resp_type) { case CHAP_DIGEST_MD5: MD5Init(&mdContext); MD5Update(&mdContext, &cstate->resp_id, 1); MD5Update(&mdContext, secret, secret_len); MD5Update(&mdContext, rchallenge, rchallenge_len); MD5Final(hash, &mdContext); BCOPY(hash, cstate->response, MD5_SIGNATURE_SIZE); cstate->resp_length = MD5_SIGNATURE_SIZE; break; #ifdef CHAPMS case CHAP_MICROSOFT: ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len); break; #endif default: CHAPDEBUG(("unknown digest type %d", cstate->resp_type)); return; } BZERO(secret, sizeof(secret)); ChapSendResponse(cstate); }
static irqreturn_t vmjpeg_isr(int irq, void *dev_id) { u32 reg, offset, pts, pts_valid = 0; vframe_t *vf; WRITE_MPEG_REG(ASSIST_MBOX1_CLR_REG, 1); reg = READ_MPEG_REG(MREG_FROM_AMRISC); if (reg & PICINFO_BUF_IDX_MASK) { offset = READ_MPEG_REG(MREG_FRAME_OFFSET); if (pts_lookup_offset(PTS_TYPE_VIDEO, offset, &pts, 0) == 0) { pts_valid = 1; } if ((reg & PICINFO_INTERLACE) == 0) { u32 index = ((reg & PICINFO_BUF_IDX_MASK) - 1) & 3; vfpool_idx[fill_ptr] = index; vf = &vfpool[fill_ptr]; set_frame_info(vf); vf->type = VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_FIELD; vf->canvas0Addr = vf->canvas1Addr = index2canvas0(index); vf->pts = (pts_valid) ? pts : 0; vfbuf_use[index]++; INCPTR(fill_ptr); vf_notify_receiver(PROVIDER_NAME,VFRAME_EVENT_PROVIDER_VFRAME_READY,NULL); } else { u32 index = ((reg & PICINFO_BUF_IDX_MASK) - 1) & 3; vfpool_idx[fill_ptr] = index; vf = &vfpool[fill_ptr]; set_frame_info(vf); #if 0 if (reg & PICINFO_AVI1) { /* AVI1 format */ if (reg & PICINFO_INTERLACE_AVI1_BOT) { vf->type = VIDTYPE_INTERLACE_BOTTOM | VIDTYPE_INTERLACE_FIRST; } else { vf->type = VIDTYPE_INTERLACE_TOP; } } else { if (reg & PICINFO_INTERLACE_FIRST) { vf->type = VIDTYPE_INTERLACE_TOP | VIDTYPE_INTERLACE_FIRST; } else { vf->type = VIDTYPE_INTERLACE_BOTTOM; } } vf->type |= VIDTYPE_VIU_FIELD; vf->duration >>= 1; vf->canvas0Addr = vf->canvas1Addr = index2canvas0(index); if ((vf->type & VIDTYPE_INTERLACE_FIRST) && (pts_valid)) { vf->pts = pts; } else { vf->pts = 0; } vfbuf_use[index]++; INCPTR(fill_ptr); #else /* send whole frame by weaving top & bottom field */ vf->type = VIDTYPE_PROGRESSIVE; vf->canvas0Addr = index2canvas0(index); vf->canvas1Addr = index2canvas1(index); if (pts_valid) { vf->pts = pts; } else { vf->pts = 0; } vfbuf_use[index]++; INCPTR(fill_ptr); vf_notify_receiver(PROVIDER_NAME,VFRAME_EVENT_PROVIDER_VFRAME_READY,NULL); #endif } WRITE_MPEG_REG(MREG_FROM_AMRISC, 0); }