int pof_write_buffer(hysdn_card * card, int datlen) { struct boot_data *boot = card->boot; /* pointer to boot specific data */ if (!boot) return (-EFAULT); /* invalid call */ if (boot->last_error < 0) return (boot->last_error); /* repeated error */ if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: got %d bytes ", datlen); switch (boot->pof_state) { case POF_READ_FILE_HEAD: if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: checking file header"); if (datlen != sizeof(tPofFileHdr)) { boot->last_error = -EPOF_INTERNAL; break; } if (boot->buf.PofFileHdr.Magic != TAGFILEMAGIC) { boot->last_error = -EPOF_BAD_MAGIC; break; } /* Setup the new state and vars */ boot->Nrecs = (word) (boot->buf.PofFileHdr.N_PofRecs); /* limited to 65535 */ boot->pof_state = POF_READ_TAG_HEAD; /* now start with single tags */ boot->last_error = sizeof(tPofRecHdr); /* new length */ break; case POF_READ_TAG_HEAD: if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: checking tag header"); if (datlen != sizeof(tPofRecHdr)) { boot->last_error = -EPOF_INTERNAL; break; } boot->pof_recid = boot->buf.PofRecHdr.PofRecId; /* actual pof recid */ boot->pof_reclen = boot->buf.PofRecHdr.PofRecDataLen; /* total length */ boot->pof_recoffset = 0; /* no starting offset */ if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF: got record id=0x%lx length=%ld ", boot->pof_recid, boot->pof_reclen); boot->pof_state = POF_READ_TAG_DATA; /* now start with tag data */ if (boot->pof_reclen < BOOT_BUF_SIZE) boot->last_error = boot->pof_reclen; /* limit size */ else boot->last_error = BOOT_BUF_SIZE; /* maximum */ if (!boot->last_error) { /* no data inside record */ boot->pof_state = POF_READ_TAG_HEAD; /* now start with single tags */ boot->last_error = sizeof(tPofRecHdr); /* new length */ } break; case POF_READ_TAG_DATA: if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: getting tag data"); if (datlen != boot->last_error) { boot->last_error = -EPOF_INTERNAL; break; } if ((boot->last_error = pof_handle_data(card, datlen)) < 0) return (boot->last_error); /* an error occurred */ boot->pof_recoffset += datlen; if (boot->pof_recoffset >= boot->pof_reclen) { boot->pof_state = POF_READ_TAG_HEAD; /* now start with single tags */ boot->last_error = sizeof(tPofRecHdr); /* new length */ } else { if (boot->pof_reclen - boot->pof_recoffset < BOOT_BUF_SIZE) boot->last_error = boot->pof_reclen - boot->pof_recoffset; /* limit size */ else boot->last_error = BOOT_BUF_SIZE; /* maximum */ } break; default: boot->last_error = -EPOF_INTERNAL; /* unknown state */ break; } /* switch (boot->pof_state) */ return (boot->last_error); } /* pof_write_buffer */
int pof_write_buffer(hysdn_card * card, int datlen) { struct boot_data *boot = card->boot; if (!boot) return (-EFAULT); if (boot->last_error < 0) return (boot->last_error); if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: got %d bytes ", datlen); switch (boot->pof_state) { case POF_READ_FILE_HEAD: if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: checking file header"); if (datlen != sizeof(tPofFileHdr)) { boot->last_error = -EPOF_INTERNAL; break; } if (boot->buf.PofFileHdr.Magic != TAGFILEMAGIC) { boot->last_error = -EPOF_BAD_MAGIC; break; } boot->Nrecs = (unsigned short)(boot->buf.PofFileHdr.N_PofRecs); boot->pof_state = POF_READ_TAG_HEAD; boot->last_error = sizeof(tPofRecHdr); break; case POF_READ_TAG_HEAD: if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: checking tag header"); if (datlen != sizeof(tPofRecHdr)) { boot->last_error = -EPOF_INTERNAL; break; } boot->pof_recid = boot->buf.PofRecHdr.PofRecId; boot->pof_reclen = boot->buf.PofRecHdr.PofRecDataLen; boot->pof_recoffset = 0; if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF: got record id=0x%lx length=%ld ", boot->pof_recid, boot->pof_reclen); boot->pof_state = POF_READ_TAG_DATA; if (boot->pof_reclen < BOOT_BUF_SIZE) boot->last_error = boot->pof_reclen; else boot->last_error = BOOT_BUF_SIZE; if (!boot->last_error) { boot->pof_state = POF_READ_TAG_HEAD; boot->last_error = sizeof(tPofRecHdr); } break; case POF_READ_TAG_DATA: if (card->debug_flags & LOG_POF_WRITE) hysdn_addlog(card, "POF write: getting tag data"); if (datlen != boot->last_error) { boot->last_error = -EPOF_INTERNAL; break; } if ((boot->last_error = pof_handle_data(card, datlen)) < 0) return (boot->last_error); boot->pof_recoffset += datlen; if (boot->pof_recoffset >= boot->pof_reclen) { boot->pof_state = POF_READ_TAG_HEAD; boot->last_error = sizeof(tPofRecHdr); } else { if (boot->pof_reclen - boot->pof_recoffset < BOOT_BUF_SIZE) boot->last_error = boot->pof_reclen - boot->pof_recoffset; else boot->last_error = BOOT_BUF_SIZE; } break; default: boot->last_error = -EPOF_INTERNAL; break; } return (boot->last_error); }