/* writes a "protective" MBR */ static int write_pmbr(int fd, struct dk_gpt *vtoc) { dk_efi_t dk_ioc; struct mboot mb; uchar_t *cp; diskaddr_t size_in_lba; uchar_t *buf; int len; len = (vtoc->efi_lbasize == 0) ? sizeof (mb) : vtoc->efi_lbasize; buf = calloc(len, 1); /* * Preserve any boot code and disk signature if the first block is * already an MBR. */ dk_ioc.dki_lba = 0; dk_ioc.dki_length = len; /* LINTED -- always longlong aligned */ dk_ioc.dki_data = (efi_gpt_t *)buf; if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) { (void *) memcpy(&mb, buf, sizeof (mb)); bzero(&mb, sizeof (mb)); mb.signature = LE_16(MBB_MAGIC); } else { (void *) memcpy(&mb, buf, sizeof (mb)); if (mb.signature != LE_16(MBB_MAGIC)) { bzero(&mb, sizeof (mb)); mb.signature = LE_16(MBB_MAGIC); } } bzero(&mb.parts, sizeof (mb.parts)); cp = (uchar_t *)&mb.parts[0]; /* bootable or not */ *cp++ = 0; /* beginning CHS; 0xffffff if not representable */ *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; /* OS type */ *cp++ = EFI_PMBR; /* ending CHS; 0xffffff if not representable */ *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; /* starting LBA: 1 (little endian format) by EFI definition */ *cp++ = 0x01; *cp++ = 0x00; *cp++ = 0x00; *cp++ = 0x00; /* ending LBA: last block on the disk (little endian format) */ size_in_lba = vtoc->efi_last_lba; if (size_in_lba < 0xffffffff) { *cp++ = (size_in_lba & 0x000000ff); *cp++ = (size_in_lba & 0x0000ff00) >> 8; *cp++ = (size_in_lba & 0x00ff0000) >> 16; *cp++ = (size_in_lba & 0xff000000) >> 24; } else {
/* * Convert current UNIX time into a PCFS timestamp (which is in local time). * * Since the "seconds" field of that is only accurate to 2sec precision, * we allow for the optional (used only for creation times on FAT) "msec" * parameter that takes the fractional part. */ static void getNow(struct pctime *pctp, uchar_t *msec) { time_t now; struct tm tm; ushort_t tim, dat; /* * Disable daylight savings corrections - Solaris PCFS doesn't * support such conversions yet. Save timestamps in local time. */ daylight = 0; (void) time(&now); (void) localtime_r(&now, &tm); dat = (tm.tm_year - 80) << YEARSHIFT; dat |= tm.tm_mon << MONSHIFT; dat |= tm.tm_mday << DAYSHIFT; tim = tm.tm_hour << HOURSHIFT; tim |= tm.tm_min << MINSHIFT; tim |= (tm.tm_sec / 2) << SECSHIFT; /* * Sanity check. If we overflow the PCFS timestamp range * we set the time to 01/01/1980, 00:00:00 */ if (dat < 80 || dat > 227) dat = tim = 0; pctp->pct_date = LE_16(dat); pctp->pct_time = LE_16(tim); if (msec) *msec = (tm.tm_sec & 1) ? 100 : 0; }
/* ARGSUSED */ static int i40e_switch_rsrcs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { i40e_t i40e; int i; if (!(flags & DCMD_ADDRSPEC)) { mdb_warn("::i40e_switch_rsrcs does not operate globally\n"); return (DCMD_USAGE); } if (mdb_vread(&i40e, sizeof (i40e_t), addr) != sizeof (i40e_t)) { mdb_warn("failed to read i40e_t at %p", addr); return (DCMD_ERR); } mdb_printf("%-28s %-12s %-8s %-8s %s\n", "TYPE", "GUARANTEE", "TOTAL", "USED", "UNALLOCED"); for (i = 0; i < i40e.i40e_switch_rsrc_actual; i++) { i40e_switch_rsrc_t rsrc; uintptr_t raddr = (uintptr_t)i40e.i40e_switch_rsrcs + i * sizeof (i40e_switch_rsrc_t); const char *name; if (mdb_vread(&rsrc, sizeof (i40e_switch_rsrc_t), raddr) != sizeof (i40e_switch_rsrc_t)) { mdb_warn("failed to read i40e_switch_rsrc_t %d at %p", i, raddr); return (DCMD_ERR); } if (rsrc.resource_type <= RSRC_MAX) { name = i40e_switch_rsrc_names[rsrc.resource_type]; } else { char *buf; size_t s = mdb_snprintf(NULL, 0, "Unknown type (%d)", rsrc.resource_type); buf = mdb_alloc(s + 1, UM_GC | UM_SLEEP); (void) mdb_snprintf(buf, s + 1, "Unknown type (%d)", rsrc.resource_type); name = buf; } mdb_printf("%-28s %-12d %-8d %-8d %d\n", name, LE_16(rsrc.guaranteed), LE_16(rsrc.total), LE_16(rsrc.used), LE_16(rsrc.total_unalloced)); } return (DCMD_OK); }
static inline void oce_rx_insert_tag(mblk_t *mp, uint16_t vtag) { struct ether_vlan_header *ehp; (void) memmove(mp->b_rptr - VLAN_TAGSZ, mp->b_rptr, 2 * ETHERADDRL); mp->b_rptr -= VLAN_TAGSZ; ehp = (struct ether_vlan_header *)voidptr(mp->b_rptr); ehp->ether_tpid = htons(ETHERTYPE_VLAN); ehp->ether_tci = LE_16(vtag); }
static int vmd_probe(AVProbeData *p) { if (p->buf_size < 2) return 0; /* check if the first 2 bytes of the file contain the appropriate size * of a VMD header chunk */ if (LE_16(&p->buf[0]) != VMD_HEADER_SIZE - 2) return 0; /* only return half certainty since this check is a bit sketchy */ return AVPROBE_SCORE_MAX / 2; }
static int mm_probe(AVProbeData *p) { /* the first chunk is always the header */ if (p->buf_size < MM_PREAMBLE_SIZE) return 0; if (LE_16(&p->buf[0]) != MM_TYPE_HEADER) return 0; if (LE_32(&p->buf[2]) != MM_HEADER_LEN_V && LE_32(&p->buf[2]) != MM_HEADER_LEN_AV) return 0; /* only return half certainty since this check is a bit sketchy */ return AVPROBE_SCORE_MAX / 2; }
static int flic_probe(AVProbeData *p) { int magic_number; if (p->buf_size < 6) return 0; magic_number = LE_16(&p->buf[4]); if ((magic_number != FLIC_FILE_MAGIC_1) && (magic_number != FLIC_FILE_MAGIC_2)) return 0; return AVPROBE_SCORE_MAX; }
static int flic_read_packet(AVFormatContext *s, AVPacket *pkt) { FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data; ByteIOContext *pb = &s->pb; int packet_read = 0; unsigned int size; int magic; int ret = 0; unsigned char preamble[FLIC_PREAMBLE_SIZE]; while (!packet_read) { if ((ret = get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE)) != FLIC_PREAMBLE_SIZE) { ret = AVERROR_IO; break; } size = LE_32(&preamble[0]); magic = LE_16(&preamble[4]); if (((magic == FLIC_CHUNK_MAGIC_1) || (magic == FLIC_CHUNK_MAGIC_2)) && size > FLIC_PREAMBLE_SIZE) { if (av_new_packet(pkt, size)) { ret = AVERROR_IO; break; } pkt->stream_index = flic->video_stream_index; pkt->pts = flic->pts; pkt->pos = url_ftell(pb); memcpy(pkt->data, preamble, FLIC_PREAMBLE_SIZE); ret = get_buffer(pb, pkt->data + FLIC_PREAMBLE_SIZE, size - FLIC_PREAMBLE_SIZE); if (ret != size - FLIC_PREAMBLE_SIZE) { av_free_packet(pkt); ret = AVERROR_IO; } flic->pts += flic->frame_pts_inc; packet_read = 1; } else { /* not interested in this chunk */ url_fseek(pb, size - 6, SEEK_CUR); } } return ret; }
/* * Reads the master fdisk partition table from the device assuming that it has * a valid table. * MBR is supposed to be of 512 bytes no matter what the device block size is. */ static int fdisk_read_master_part_table(ext_part_t *epp) { struct dk_minfo_ext dkmp_ext; struct dk_minfo dkmp; uchar_t *buf; int sectsize; int size = sizeof (struct ipart); int cpcnt = FD_NUMPART * size; if (lseek(epp->dev_fd, 0, SEEK_SET) < 0) { return (EIO); } if (ioctl(epp->dev_fd, DKIOCGMEDIAINFOEXT, &dkmp_ext) < 0) { if (ioctl(epp->dev_fd, DKIOCGMEDIAINFO, &dkmp) < 0) { return (EIO); } sectsize = dkmp.dki_lbsize; } else { sectsize = dkmp_ext.dki_lbsize; } if (sectsize < 512) { return (EIO); } buf = calloc(sectsize, sizeof (uchar_t)); if (buf == NULL) { return (ENOMEM); } if (read(epp->dev_fd, buf, sectsize) < sectsize) { free(buf); return (EIO); } /*LINTED*/ if (LE_16((*(uint16_t *)&buf[510])) != MBB_MAGIC) { bzero(epp->mtable, cpcnt); free(buf); return (FDISK_EBADMAGIC); } bcopy(&buf[FDISK_PART_TABLE_START], epp->mtable, cpcnt); free(buf); return (FDISK_SUCCESS); }
int main(int argc, char *argv[]) { unsigned char test_value32[5] = "\xFE\xDC\xBA\x10"; u_int32_t le_uint32 = ((((u_int32_t)(test_value32[3])) << 24) | (((u_int32_t)(test_value32[2])) << 16) | (((u_int32_t)(test_value32[1])) << 8) | (((u_int32_t)(test_value32[0])) << 0)); u_int32_t le_uint16 = ((((u_int32_t)(test_value32[1])) << 8) | (((u_int32_t)(test_value32[0])) << 0)); u_int32_t be_uint32 = ((((u_int32_t)(test_value32[0])) << 24) | (((u_int32_t)(test_value32[1])) << 16) | (((u_int32_t)(test_value32[2])) << 8) | (((u_int32_t)(test_value32[3])) << 0)); u_int32_t be_uint16 = ((((u_int32_t)(test_value32[0])) << 8) | (((u_int32_t)(test_value32[1])) << 0)); printf("test_value32: %2hhx%2hhx%2hhx%2hhx\n", test_value32[0], test_value32[1], test_value32[2], test_value32[3]); printf("test_value32 as u_int32_t: %04x\n", *(u_int32_t*)test_value32); printf("le_uint32: %04x\n", le_uint32); printf ("LE_32(le_uint32): %08x\n", LE_32(&le_uint32)); printf("test_value16 as u_int16_t: %04x\n", *(u_int16_t*)test_value32); printf("le_uint16: %04x\n", le_uint16); printf ("LE_16(le_uint16): %04hx\n", LE_16(&le_uint16)); printf("be_uint32: %04x\n", be_uint32); printf ("BE_32(be_uint32): %08x\n", BE_32(&be_uint32)); printf("test_value16 as u_int16_t: %04x\n", *(u_int16_t*)test_value32); printf("be_uint16: %04x\n", be_uint16); printf ("BE_16(be_uint16): %04hx\n", BE_16(&be_uint16)); }
/* writes a "protective" MBR */ static int write_pmbr(int fd, struct dk_gpt *vtoc) { dk_efi_t dk_ioc; struct mboot mb; uchar_t *cp; diskaddr_t size_in_lba; mb.signature = LE_16(MBB_MAGIC); bzero(&mb.parts, sizeof (mb.parts)); cp = (uchar_t *)&mb.parts[0]; /* bootable or not */ *cp++ = 0; /* beginning CHS; 0xffffff if not representable */ *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; /* OS type */ *cp++ = EFI_PMBR; /* ending CHS; 0xffffff if not representable */ *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; /* starting LBA: 1 (little endian format) by EFI definition */ *cp++ = 0x01; *cp++ = 0x00; *cp++ = 0x00; *cp++ = 0x00; /* ending LBA: last block on the disk (little endian format) */ size_in_lba = vtoc->efi_last_lba; if (size_in_lba < 0xffffffff) { *cp++ = (size_in_lba & 0x000000ff); *cp++ = (size_in_lba & 0x0000ff00) >> 8; *cp++ = (size_in_lba & 0x00ff0000) >> 16; *cp++ = (size_in_lba & 0xff000000) >> 24; } else {
static int efi_read(int fd, struct dk_gpt *vtoc) { int i, j; int label_len; int rval = 0; int md_flag = 0; struct dk_minfo disk_info; dk_efi_t dk_ioc; efi_gpt_t *efi; efi_gpe_t *efi_parts; struct dk_cinfo dki_info; uint32_t user_length; /* * get the partition number for this file descriptor. */ if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) { if (efi_debug) (void) fprintf(stderr, "DKIOCINFO errno 0x%x\n", errno); switch (errno) { case EIO: return (VT_EIO); case EINVAL: return (VT_EINVAL); default: return (VT_ERROR); } } if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) && (strncmp(dki_info.dki_dname, "md", 3) == 0)) { md_flag++; } /* get the LBA size */ if (ioctl(fd, DKIOCGMEDIAINFO, (caddr_t)&disk_info) == -1) { if (efi_debug) { (void) fprintf(stderr, "assuming LBA 512 bytes %d\n", errno); } disk_info.dki_lbsize = DEV_BSIZE; } if (disk_info.dki_lbsize == 0) { if (efi_debug) { (void) fprintf(stderr, "efi_read: assuming LBA 512 bytes\n"); } disk_info.dki_lbsize = DEV_BSIZE; } /* * Read the EFI GPT to figure out how many partitions we need * to deal with. */ dk_ioc.dki_lba = 1; if (NBLOCKS(vtoc->efi_nparts, disk_info.dki_lbsize) < 34) { label_len = EFI_MIN_ARRAY_SIZE + disk_info.dki_lbsize; } else { label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) + disk_info.dki_lbsize; if (label_len % disk_info.dki_lbsize) { /* pad to physical sector size */ label_len += disk_info.dki_lbsize; label_len &= ~(disk_info.dki_lbsize - 1); } } if ((dk_ioc.dki_data = calloc(label_len, 1)) == NULL) return (VT_ERROR); dk_ioc.dki_length = label_len; user_length = vtoc->efi_nparts; efi = dk_ioc.dki_data; if (md_flag) { if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) { switch (errno) { case EIO: return (VT_EIO); default: return (VT_ERROR); } } } else if ((rval = check_label(fd, &dk_ioc)) == VT_EINVAL) { /* no valid label here; try the alternate */ dk_ioc.dki_lba = disk_info.dki_capacity - 1; dk_ioc.dki_length = disk_info.dki_lbsize; rval = check_label(fd, &dk_ioc); if (rval != 0) { /* * This is a workaround for legacy systems. * * In the past, the last sector of SCSI disk was * invisible on x86 platform. At that time, backup * label was saved on the next to the last sector. * It is possible for users to move a disk from * previous solaris system to present system. */ dk_ioc.dki_lba = disk_info.dki_capacity - 2; dk_ioc.dki_length = disk_info.dki_lbsize; rval = check_label(fd, &dk_ioc); if (efi_debug && (rval == 0)) { (void) fprintf(stderr, "efi_read: primary label corrupt; " "using legacy EFI backup label\n"); } } if (rval == 0) { if (efi_debug) { (void) fprintf(stderr, "efi_read: primary label corrupt; " "using backup\n"); } dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA); vtoc->efi_flags |= EFI_GPT_PRIMARY_CORRUPT; vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries); /* * partitions are between last usable LBA and * backup partition header */ dk_ioc.dki_data++; dk_ioc.dki_length = disk_info.dki_capacity - dk_ioc.dki_lba - 1; dk_ioc.dki_length *= disk_info.dki_lbsize; if (dk_ioc.dki_length > (len_t)label_len) { rval = VT_EINVAL; } else { rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc); } } } if (rval < 0) { free(efi); return (rval); } /* partitions start in the next block */ /* LINTED -- always longlong aligned */ efi_parts = (efi_gpe_t *)(((char *)efi) + disk_info.dki_lbsize); /* * Assemble this into a "dk_gpt" struct for easier * digestibility by applications. */ vtoc->efi_version = LE_32(efi->efi_gpt_Revision); vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries); vtoc->efi_part_size = LE_32(efi->efi_gpt_SizeOfPartitionEntry); vtoc->efi_lbasize = disk_info.dki_lbsize; vtoc->efi_last_lba = disk_info.dki_capacity - 1; vtoc->efi_first_u_lba = LE_64(efi->efi_gpt_FirstUsableLBA); vtoc->efi_last_u_lba = LE_64(efi->efi_gpt_LastUsableLBA); UUID_LE_CONVERT(vtoc->efi_disk_uguid, efi->efi_gpt_DiskGUID); /* * If the array the user passed in is too small, set the length * to what it needs to be and return */ if (user_length < vtoc->efi_nparts) { return (VT_EINVAL); } for (i = 0; i < vtoc->efi_nparts; i++) { UUID_LE_CONVERT(vtoc->efi_parts[i].p_guid, efi_parts[i].efi_gpe_PartitionTypeGUID); for (j = 0; j < sizeof (conversion_array) / sizeof (struct uuid_to_ptag); j++) { if (bcmp(&vtoc->efi_parts[i].p_guid, &conversion_array[j].uuid, sizeof (struct uuid)) == 0) { vtoc->efi_parts[i].p_tag = j; break; } } if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) continue; vtoc->efi_parts[i].p_flag = LE_16(efi_parts[i].efi_gpe_Attributes.PartitionAttrs); vtoc->efi_parts[i].p_start = LE_64(efi_parts[i].efi_gpe_StartingLBA); vtoc->efi_parts[i].p_size = LE_64(efi_parts[i].efi_gpe_EndingLBA) - vtoc->efi_parts[i].p_start + 1; for (j = 0; j < EFI_PART_NAME_LEN; j++) { vtoc->efi_parts[i].p_name[j] = (uchar_t)LE_16(efi_parts[i].efi_gpe_PartitionName[j]); } UUID_LE_CONVERT(vtoc->efi_parts[i].p_uguid, efi_parts[i].efi_gpe_UniquePartitionGUID); } free(efi); return (dki_info.dki_partition); }
static int efi_read(int fd, struct dk_gpt *vtoc) { int i, j; int label_len; int rval = 0; int md_flag = 0; int vdc_flag = 0; struct dk_minfo disk_info; dk_efi_t dk_ioc; efi_gpt_t *efi; efi_gpe_t *efi_parts; struct dk_cinfo dki_info; uint32_t user_length; boolean_t legacy_label = B_FALSE; /* * get the partition number for this file descriptor. */ if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) { if (efi_debug) { (void) fprintf(stderr, "DKIOCINFO errno 0x%x\n", errno); } switch (errno) { case EIO: return (VT_EIO); case EINVAL: return (VT_EINVAL); default: return (VT_ERROR); } } if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) && (strncmp(dki_info.dki_dname, "md", 3) == 0)) { md_flag++; } else if ((strncmp(dki_info.dki_cname, "vdc", 4) == 0) && (strncmp(dki_info.dki_dname, "vdc", 4) == 0)) { /* * The controller and drive name "vdc" (virtual disk client) * indicates a LDoms virtual disk. */ vdc_flag++; } /* get the LBA size */ if (ioctl(fd, DKIOCGMEDIAINFO, (caddr_t)&disk_info) == -1) { if (efi_debug) { (void) fprintf(stderr, "assuming LBA 512 bytes %d\n", errno); } disk_info.dki_lbsize = DEV_BSIZE; } if (disk_info.dki_lbsize == 0) { if (efi_debug) { (void) fprintf(stderr, "efi_read: assuming LBA 512 bytes\n"); } disk_info.dki_lbsize = DEV_BSIZE; } /* * Read the EFI GPT to figure out how many partitions we need * to deal with. */ dk_ioc.dki_lba = 1; if (NBLOCKS(vtoc->efi_nparts, disk_info.dki_lbsize) < 34) { label_len = EFI_MIN_ARRAY_SIZE + disk_info.dki_lbsize; } else { label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) + disk_info.dki_lbsize; if (label_len % disk_info.dki_lbsize) { /* pad to physical sector size */ label_len += disk_info.dki_lbsize; label_len &= ~(disk_info.dki_lbsize - 1); } } if ((dk_ioc.dki_data = calloc(label_len, 1)) == NULL) return (VT_ERROR); dk_ioc.dki_length = disk_info.dki_lbsize; user_length = vtoc->efi_nparts; efi = dk_ioc.dki_data; if (md_flag) { dk_ioc.dki_length = label_len; if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) { switch (errno) { case EIO: return (VT_EIO); default: return (VT_ERROR); } } } else if ((rval = check_label(fd, &dk_ioc)) == VT_EINVAL) { /* * No valid label here; try the alternate. Note that here * we just read GPT header and save it into dk_ioc.data, * Later, we will read GUID partition entry array if we * can get valid GPT header. */ /* * This is a workaround for legacy systems. In the past, the * last sector of SCSI disk was invisible on x86 platform. At * that time, backup label was saved on the next to the last * sector. It is possible for users to move a disk from previous * solaris system to present system. Here, we attempt to search * legacy backup EFI label first. */ dk_ioc.dki_lba = disk_info.dki_capacity - 2; dk_ioc.dki_length = disk_info.dki_lbsize; rval = check_label(fd, &dk_ioc); if (rval == VT_EINVAL) { /* * we didn't find legacy backup EFI label, try to * search backup EFI label in the last block. */ dk_ioc.dki_lba = disk_info.dki_capacity - 1; dk_ioc.dki_length = disk_info.dki_lbsize; rval = check_label(fd, &dk_ioc); if (rval == 0) { legacy_label = B_TRUE; if (efi_debug) (void) fprintf(stderr, "efi_read: primary label corrupt; " "using EFI backup label located on" " the last block\n"); } } else { if ((efi_debug) && (rval == 0)) (void) fprintf(stderr, "efi_read: primary label" " corrupt; using legacy EFI backup label " " located on the next to last block\n"); } if (rval == 0) { dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA); vtoc->efi_flags |= EFI_GPT_PRIMARY_CORRUPT; vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries); /* * Partition tables are between backup GPT header * table and ParitionEntryLBA (the starting LBA of * the GUID partition entries array). Now that we * already got valid GPT header and saved it in * dk_ioc.dki_data, we try to get GUID partition * entry array here. */ /* LINTED */ dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data + disk_info.dki_lbsize); if (legacy_label) dk_ioc.dki_length = disk_info.dki_capacity - 1 - dk_ioc.dki_lba; else dk_ioc.dki_length = disk_info.dki_capacity - 2 - dk_ioc.dki_lba; dk_ioc.dki_length *= disk_info.dki_lbsize; if (dk_ioc.dki_length > ((len_t)label_len - sizeof (*dk_ioc.dki_data))) { rval = VT_EINVAL; } else { /* * read GUID partition entry array */ rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc); } } } else if (rval == 0) { dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA); /* LINTED */ dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data + disk_info.dki_lbsize); dk_ioc.dki_length = label_len - disk_info.dki_lbsize; rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc); } else if (vdc_flag && rval == VT_ERROR && errno == EINVAL) { /* * When the device is a LDoms virtual disk, the DKIOCGETEFI * ioctl can fail with EINVAL if the virtual disk backend * is a ZFS volume serviced by a domain running an old version * of Solaris. This is because the DKIOCGETEFI ioctl was * initially incorrectly implemented for a ZFS volume and it * expected the GPT and GPE to be retrieved with a single ioctl. * So we try to read the GPT and the GPE using that old style * ioctl. */ dk_ioc.dki_lba = 1; dk_ioc.dki_length = label_len; rval = check_label(fd, &dk_ioc); } if (rval < 0) { free(efi); return (rval); } /* LINTED -- always longlong aligned */ efi_parts = (efi_gpe_t *)(((char *)efi) + disk_info.dki_lbsize); /* * Assemble this into a "dk_gpt" struct for easier * digestibility by applications. */ vtoc->efi_version = LE_32(efi->efi_gpt_Revision); vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries); vtoc->efi_part_size = LE_32(efi->efi_gpt_SizeOfPartitionEntry); vtoc->efi_lbasize = disk_info.dki_lbsize; vtoc->efi_last_lba = disk_info.dki_capacity - 1; vtoc->efi_first_u_lba = LE_64(efi->efi_gpt_FirstUsableLBA); vtoc->efi_last_u_lba = LE_64(efi->efi_gpt_LastUsableLBA); vtoc->efi_altern_lba = LE_64(efi->efi_gpt_AlternateLBA); UUID_LE_CONVERT(vtoc->efi_disk_uguid, efi->efi_gpt_DiskGUID); /* * If the array the user passed in is too small, set the length * to what it needs to be and return */ if (user_length < vtoc->efi_nparts) { return (VT_EINVAL); } for (i = 0; i < vtoc->efi_nparts; i++) { UUID_LE_CONVERT(vtoc->efi_parts[i].p_guid, efi_parts[i].efi_gpe_PartitionTypeGUID); for (j = 0; j < sizeof (conversion_array) / sizeof (struct uuid_to_ptag); j++) { if (bcmp(&vtoc->efi_parts[i].p_guid, &conversion_array[j].uuid, sizeof (struct uuid)) == 0) { vtoc->efi_parts[i].p_tag = j; break; } } if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) continue; vtoc->efi_parts[i].p_flag = LE_16(efi_parts[i].efi_gpe_Attributes.PartitionAttrs); vtoc->efi_parts[i].p_start = LE_64(efi_parts[i].efi_gpe_StartingLBA); vtoc->efi_parts[i].p_size = LE_64(efi_parts[i].efi_gpe_EndingLBA) - vtoc->efi_parts[i].p_start + 1; for (j = 0; j < EFI_PART_NAME_LEN; j++) { vtoc->efi_parts[i].p_name[j] = (uchar_t)LE_16( efi_parts[i].efi_gpe_PartitionName[j]); } UUID_LE_CONVERT(vtoc->efi_parts[i].p_uguid, efi_parts[i].efi_gpe_UniquePartitionGUID); } free(efi); return (dki_info.dki_partition); }
// note: This decoder assumes the format 0x62 data always comes in // stereo flavor static int dk3_adpcm_decode_block(unsigned short *output, unsigned char *input, int block_size) { int sum_pred; int diff_pred; int sum_index; int diff_index; int diff_channel; int in_ptr = 0x10; int out_ptr = 0; unsigned char last_byte = 0; unsigned char nibble; int decode_top_nibble_next = 0; // ADPCM work variables int sign; int delta; int step; int diff; sum_pred = LE_16(&input[10]); diff_pred = LE_16(&input[12]); SE_16BIT(sum_pred); SE_16BIT(diff_pred); diff_channel = diff_pred; sum_index = input[14]; diff_index = input[15]; while (in_ptr < block_size - !decode_top_nibble_next) // while (in_ptr < 2048) { // process the first predictor of the sum channel DK3_GET_NEXT_NIBBLE(); step = adpcm_step[sum_index]; sign = nibble & 8; delta = nibble & 7; diff = step >> 3; if (delta & 4) diff += step; if (delta & 2) diff += step >> 1; if (delta & 1) diff += step >> 2; if (sign) sum_pred -= diff; else sum_pred += diff; CLAMP_S16(sum_pred); sum_index += adpcm_index[nibble]; CLAMP_0_TO_88(sum_index); // process the diff channel predictor DK3_GET_NEXT_NIBBLE(); step = adpcm_step[diff_index]; sign = nibble & 8; delta = nibble & 7; diff = step >> 3; if (delta & 4) diff += step; if (delta & 2) diff += step >> 1; if (delta & 1) diff += step >> 2; if (sign) diff_pred -= diff; else diff_pred += diff; CLAMP_S16(diff_pred); diff_index += adpcm_index[nibble]; CLAMP_0_TO_88(diff_index); // output the first pair of stereo PCM samples diff_channel = (diff_channel + diff_pred) / 2; output[out_ptr++] = sum_pred + diff_channel; output[out_ptr++] = sum_pred - diff_channel; // process the second predictor of the sum channel DK3_GET_NEXT_NIBBLE(); step = adpcm_step[sum_index]; sign = nibble & 8; delta = nibble & 7; diff = step >> 3; if (delta & 4) diff += step; if (delta & 2) diff += step >> 1; if (delta & 1) diff += step >> 2; if (sign) sum_pred -= diff; else sum_pred += diff; CLAMP_S16(sum_pred); sum_index += adpcm_index[nibble]; CLAMP_0_TO_88(sum_index); // output the second pair of stereo PCM samples output[out_ptr++] = sum_pred + diff_channel; output[out_ptr++] = sum_pred - diff_channel; } return out_ptr; }
static int vmd_read_header(AVFormatContext *s, AVFormatParameters *ap) { VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; ByteIOContext *pb = &s->pb; AVStream *st; unsigned int toc_offset; unsigned char *raw_frame_table; int raw_frame_table_size; offset_t current_offset; int i, j; unsigned int total_frames; int64_t video_pts_inc = 0; int64_t current_video_pts = 0; unsigned char chunk[BYTES_PER_FRAME_RECORD]; int lastframe = 0; /* fetch the main header, including the 2 header length bytes */ url_fseek(pb, 0, SEEK_SET); if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE) return AVERROR_IO; vmd->audio_sample_counter = 0; vmd->audio_frame_divisor = 1; vmd->audio_block_align = 1; /* start up the decoders */ st = av_new_stream(s, 0); if (!st) return AVERROR_NOMEM; av_set_pts_info(st, 33, 1, 90000); vmd->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_VMDVIDEO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = LE_16(&vmd->vmd_header[12]); st->codec->height = LE_16(&vmd->vmd_header[14]); st->codec->time_base.num = 1; st->codec->time_base.den = 10; st->codec->extradata_size = VMD_HEADER_SIZE; st->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(st->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE); /* if sample rate is 0, assume no audio */ vmd->sample_rate = LE_16(&vmd->vmd_header[804]); if (vmd->sample_rate) { st = av_new_stream(s, 0); if (!st) return AVERROR_NOMEM; av_set_pts_info(st, 33, 1, 90000); vmd->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_VMDAUDIO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->channels = vmd->audio_channels = (vmd->vmd_header[811] & 0x80) ? 2 : 1; st->codec->sample_rate = vmd->sample_rate; st->codec->block_align = vmd->audio_block_align = LE_16(&vmd->vmd_header[806]); if (st->codec->block_align & 0x8000) { st->codec->bits_per_sample = 16; st->codec->block_align = -(st->codec->block_align - 0x10000); vmd->audio_block_align = -(vmd->audio_block_align - 0x10000); } else { st->codec->bits_per_sample = 8; } st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_sample * st->codec->channels; /* for calculating pts */ vmd->audio_frame_divisor = st->codec->channels; video_pts_inc = 90000; video_pts_inc *= st->codec->block_align; video_pts_inc /= st->codec->sample_rate; video_pts_inc /= st->codec->channels; } else { /* if no audio, assume 10 frames/second */ video_pts_inc = 90000 / 10; } toc_offset = LE_32(&vmd->vmd_header[812]); vmd->frame_count = LE_16(&vmd->vmd_header[6]); vmd->frames_per_block = LE_16(&vmd->vmd_header[18]); url_fseek(pb, toc_offset, SEEK_SET); raw_frame_table = NULL; vmd->frame_table = NULL; raw_frame_table_size = vmd->frame_count * 6; raw_frame_table = av_malloc(raw_frame_table_size); vmd->frame_table = av_malloc(vmd->frame_count * vmd->frames_per_block * sizeof(vmd_frame_t)); if (!raw_frame_table || !vmd->frame_table) { av_free(raw_frame_table); av_free(vmd->frame_table); return AVERROR_NOMEM; } if (get_buffer(pb, raw_frame_table, raw_frame_table_size) != raw_frame_table_size) { av_free(raw_frame_table); av_free(vmd->frame_table); return AVERROR_IO; } total_frames = 0; for (i = 0; i < vmd->frame_count; i++) { current_offset = LE_32(&raw_frame_table[6 * i + 2]); /* handle each entry in index block */ for (j = 0; j < vmd->frames_per_block; j++) { int type; uint32_t size; get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD); type = chunk[0]; size = LE_32(&chunk[2]); if(!size) continue; switch(type) { case 1: /* Audio Chunk */ vmd->frame_table[total_frames].frame_offset = current_offset; vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index; vmd->frame_table[total_frames].frame_size = size; memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD); total_frames++; break; case 2: /* Video Chunk */ vmd->frame_table[total_frames].frame_offset = current_offset; vmd->frame_table[total_frames].frame_size = size; vmd->frame_table[total_frames].stream_index = vmd->video_stream_index; memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD); vmd->frame_table[total_frames].pts = current_video_pts; if (lastframe) { vmd->frame_table[lastframe].pts = current_video_pts - video_pts_inc; } lastframe = total_frames; total_frames++; break; } current_offset += size; } current_video_pts += video_pts_inc; } av_free(raw_frame_table); vmd->current_frame = 0; vmd->frame_count = total_frames; return 0; }
/* * read the PS file pointed to by fd and create a cache based on it */ int init_disk_cache(int fd) { UINT32 num_keys = get_num_keys_in_file(fd); UINT16 i; UINT64 tmp_offset; int rc = 0, offset; struct key_disk_cache *tmp, *prev = NULL; BYTE srk_blob[2048]; TSS_KEY srk_key; #ifdef TSS_DEBUG int valid_keys = 0; #endif MUTEX_LOCK(disk_cache_lock); if (num_keys == 0) { key_disk_cache_head = NULL; MUTEX_UNLOCK(disk_cache_lock); return 0; } else { key_disk_cache_head = tmp = calloc(1, sizeof(struct key_disk_cache)); if (tmp == NULL) { LogError("malloc of %zd bytes failed.", sizeof(struct key_disk_cache)); rc = -1; goto err_exit; } } /* make sure the file pointer is where we expect, just after the number * of keys on disk at the head of the file */ offset = lseek(fd, TSSPS_KEYS_OFFSET, SEEK_SET); if (offset == ((off_t) - 1)) { LogError("lseek: %s", strerror(errno)); rc = -1; goto err_exit; } for (i=0; i<num_keys; i++) { offset = lseek(fd, 0, SEEK_CUR); if (offset == ((off_t) - 1)) { LogError("lseek: %s", strerror(errno)); rc = -1; goto err_exit; } tmp->offset = offset; #ifdef TSS_DEBUG if (offset == 0) LogDebug("Storing key with file offset==0!!!"); #endif /* read UUID */ if ((rc = read_data(fd, (void *)&tmp->uuid, sizeof(TSS_UUID)))) { LogError("%s", __FUNCTION__); goto err_exit; } /* read parent UUID */ if ((rc = read_data(fd, (void *)&tmp->parent_uuid, sizeof(TSS_UUID)))) { LogError("%s", __FUNCTION__); goto err_exit; } /* pub data size */ if ((rc = read_data(fd, &tmp->pub_data_size, sizeof(UINT16)))) { LogError("%s", __FUNCTION__); goto err_exit; } tmp->pub_data_size = LE_16(tmp->pub_data_size); DBG_ASSERT(tmp->pub_data_size <= 2048 && tmp->pub_data_size > 0); /* blob size */ if ((rc = read_data(fd, &tmp->blob_size, sizeof(UINT16)))) { LogError("%s", __FUNCTION__); goto err_exit; } tmp->blob_size = LE_16(tmp->blob_size); DBG_ASSERT(tmp->blob_size <= 4096 && tmp->blob_size > 0); /* vendor data size */ if ((rc = read_data(fd, &tmp->vendor_data_size, sizeof(UINT32)))) { LogError("%s", __FUNCTION__); goto err_exit; } tmp->vendor_data_size = LE_32(tmp->vendor_data_size); /* cache flags */ if ((rc = read_data(fd, &tmp->flags, sizeof(UINT16)))) { LogError("%s", __FUNCTION__); goto err_exit; } tmp->flags = LE_16(tmp->flags); #ifdef TSS_DEBUG if (tmp->flags & CACHE_FLAG_VALID) valid_keys++; #endif /* fast forward over the pub key */ offset = lseek(fd, tmp->pub_data_size, SEEK_CUR); if (offset == ((off_t) - 1)) { LogError("lseek: %s", strerror(errno)); rc = -1; goto err_exit; } /* if this is the SRK, load it into memory, since its already loaded in * the chip */ if (!memcmp(&SRK_UUID, &tmp->uuid, sizeof(TSS_UUID))) { /* read SRK blob from disk */ if ((rc = read_data(fd, srk_blob, tmp->blob_size))) { LogError("%s", __FUNCTION__); goto err_exit; } tmp_offset = 0; if ((rc = UnloadBlob_TSS_KEY(&tmp_offset, srk_blob, &srk_key))) goto err_exit; /* add to the mem cache */ if ((rc = mc_add_entry_init(SRK_TPM_HANDLE, SRK_TPM_HANDLE, &srk_key, &SRK_UUID))) { LogError("Error adding SRK to mem cache."); destroy_key_refs(&srk_key); goto err_exit; } destroy_key_refs(&srk_key); } else { /* fast forward over the blob */ offset = lseek(fd, tmp->blob_size, SEEK_CUR); if (offset == ((off_t) - 1)) { LogError("lseek: %s", strerror(errno)); rc = -1; goto err_exit; } /* fast forward over the vendor data */ offset = lseek(fd, tmp->vendor_data_size, SEEK_CUR); if (offset == ((off_t) - 1)) { LogError("lseek: %s", strerror(errno)); rc = -1; goto err_exit; } } tmp->next = calloc(1, sizeof(struct key_disk_cache)); if (tmp->next == NULL) { LogError("malloc of %zd bytes failed.", sizeof(struct key_disk_cache)); rc = -1; goto err_exit; } prev = tmp; tmp = tmp->next; } /* delete the dangling, unfilled cache entry */ free(tmp); prev->next = NULL; rc = 0; LogDebug("%s: found %d valid key(s) on disk.\n", __FUNCTION__, valid_keys); err_exit: MUTEX_UNLOCK(disk_cache_lock); return rc; }
/* * Get the PQI configuration table parameters. * Currently using for heart-beat counter scratch-pad register. */ int pqisrc_process_config_table(pqisrc_softstate_t *softs) { int ret = PQI_STATUS_FAILURE; uint32_t config_table_size; uint32_t section_off; uint8_t *config_table_abs_addr; struct pqi_conf_table *conf_table; struct pqi_conf_table_section_header *section_hdr; config_table_size = softs->pqi_cap.conf_tab_sz; if (config_table_size < sizeof(*conf_table) || config_table_size > PQI_CONF_TABLE_MAX_LEN) { DBG_ERR("Invalid PQI conf table length of %u\n", config_table_size); return ret; } conf_table = os_mem_alloc(softs, config_table_size); if (!conf_table) { DBG_ERR("Failed to allocate memory for PQI conf table\n"); return ret; } config_table_abs_addr = (uint8_t *)(softs->pci_mem_base_vaddr + softs->pqi_cap.conf_tab_off); PCI_MEM_GET_BUF(softs, config_table_abs_addr, softs->pqi_cap.conf_tab_off, (uint8_t*)conf_table, config_table_size); if (memcmp(conf_table->sign, PQI_CONF_TABLE_SIGNATURE, sizeof(conf_table->sign)) != 0) { DBG_ERR("Invalid PQI config signature\n"); goto out; } section_off = LE_32(conf_table->first_section_off); while (section_off) { if (section_off+ sizeof(*section_hdr) >= config_table_size) { DBG_ERR("PQI config table section offset (%u) beyond \ end of config table (config table length: %u)\n", section_off, config_table_size); break; } section_hdr = (struct pqi_conf_table_section_header *)((uint8_t *)conf_table + section_off); switch (LE_16(section_hdr->section_id)) { case PQI_CONF_TABLE_SECTION_GENERAL_INFO: case PQI_CONF_TABLE_SECTION_FIRMWARE_FEATURES: case PQI_CONF_TABLE_SECTION_FIRMWARE_ERRATA: case PQI_CONF_TABLE_SECTION_DEBUG: break; case PQI_CONF_TABLE_SECTION_HEARTBEAT: softs->heartbeat_counter_off = softs->pqi_cap.conf_tab_off + section_off + offsetof(struct pqi_conf_table_heartbeat, heartbeat_counter); softs->heartbeat_counter_abs_addr = (uint64_t *)(softs->pci_mem_base_vaddr + softs->heartbeat_counter_off); ret = PQI_STATUS_SUCCESS; break; default: DBG_ERR("unrecognized PQI config table section ID: 0x%x\n", LE_16(section_hdr->section_id)); break; } section_off = LE_16(section_hdr->next_section_off); }
/* * Process a received frame. The node associated with the sender * should be supplied. If nothing was found in the node table then * the caller is assumed to supply a reference to ic_bss instead. * The RSSI and a timestamp are also supplied. The RSSI data is used * during AP scanning to select a AP to associate with; it can have * any units so long as values have consistent units and higher values * mean ``better signal''. The receive timestamp is currently not used * by the 802.11 layer. */ int ieee80211_input(ieee80211com_t *ic, mblk_t *mp, struct ieee80211_node *in, int32_t rssi, uint32_t rstamp) { struct ieee80211_frame *wh; struct ieee80211_key *key; uint8_t *bssid; int hdrspace; int len; uint16_t rxseq; uint8_t dir; uint8_t type; uint8_t subtype; uint8_t tid; uint8_t qos; if (mp->b_flag & M_AMPDU) { /* * Fastpath for A-MPDU reorder q resubmission. Frames * w/ M_AMPDU marked have already passed through here * but were received out of order and been held on the * reorder queue. When resubmitted they are marked * with the M_AMPDU flag and we can bypass most of the * normal processing. */ IEEE80211_LOCK(ic); wh = (struct ieee80211_frame *)mp->b_rptr; type = IEEE80211_FC0_TYPE_DATA; dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK; subtype = IEEE80211_FC0_SUBTYPE_QOS; hdrspace = ieee80211_hdrspace(ic, wh); /* optimize */ /* clear driver/net80211 flags before passing up */ mp->b_flag &= ~M_AMPDU; goto resubmit_ampdu; } ASSERT(in != NULL); in->in_inact = in->in_inact_reload; type = (uint8_t)-1; /* undefined */ len = MBLKL(mp); if (len < sizeof (struct ieee80211_frame_min)) { ieee80211_dbg(IEEE80211_MSG_ANY, "ieee80211_input: " "too short (1): len %u", len); goto out; } /* * Bit of a cheat here, we use a pointer for a 3-address * frame format but don't reference fields past outside * ieee80211_frame_min w/o first validating the data is * present. */ wh = (struct ieee80211_frame *)mp->b_rptr; if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) != IEEE80211_FC0_VERSION_0) { ieee80211_dbg(IEEE80211_MSG_ANY, "ieee80211_input: " "discard pkt with wrong version %x", wh->i_fc[0]); goto out; } dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK; type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; IEEE80211_LOCK(ic); if (!(ic->ic_flags & IEEE80211_F_SCAN)) { switch (ic->ic_opmode) { case IEEE80211_M_STA: bssid = wh->i_addr2; if (!IEEE80211_ADDR_EQ(bssid, in->in_bssid)) goto out_exit_mutex; break; case IEEE80211_M_IBSS: case IEEE80211_M_AHDEMO: if (dir != IEEE80211_FC1_DIR_NODS) { bssid = wh->i_addr1; } else if (type == IEEE80211_FC0_TYPE_CTL) { bssid = wh->i_addr1; } else { if (len < sizeof (struct ieee80211_frame)) { ieee80211_dbg(IEEE80211_MSG_ANY, "ieee80211_input: too short(2):" "len %u\n", len); goto out_exit_mutex; } bssid = wh->i_addr3; } if (type != IEEE80211_FC0_TYPE_DATA) break; /* * Data frame, validate the bssid. */ if (!IEEE80211_ADDR_EQ(bssid, ic->ic_bss->in_bssid) && !IEEE80211_ADDR_EQ(bssid, wifi_bcastaddr)) { /* not interested in */ ieee80211_dbg(IEEE80211_MSG_INPUT, "ieee80211_input: not to bss %s\n", ieee80211_macaddr_sprintf(bssid)); goto out_exit_mutex; } /* * For adhoc mode we cons up a node when it doesn't * exist. This should probably done after an ACL check. */ if (in == ic->ic_bss && ic->ic_opmode != IEEE80211_M_HOSTAP && !IEEE80211_ADDR_EQ(wh->i_addr2, in->in_macaddr)) { /* * Fake up a node for this newly * discovered member of the IBSS. */ in = ieee80211_fakeup_adhoc_node(&ic->ic_sta, wh->i_addr2); if (in == NULL) { /* NB: stat kept for alloc failure */ goto out_exit_mutex; } } break; default: goto out_exit_mutex; } in->in_rssi = (uint8_t)rssi; in->in_rstamp = rstamp; if (!(type & IEEE80211_FC0_TYPE_CTL)) { if (IEEE80211_QOS_HAS_SEQ(wh)) { tid = ((struct ieee80211_qosframe *)wh)-> i_qos[0] & IEEE80211_QOS_TID; if (TID_TO_WME_AC(tid) >= WME_AC_VI) ic->ic_wme.wme_hipri_traffic++; tid++; } else { tid = IEEE80211_NONQOS_TID; } rxseq = LE_16(*(uint16_t *)wh->i_seq); if ((in->in_flags & IEEE80211_NODE_HT) == 0 && (wh->i_fc[1] & IEEE80211_FC1_RETRY) && (rxseq - in->in_rxseqs[tid]) <= 0) { /* duplicate, discard */ ieee80211_dbg(IEEE80211_MSG_INPUT, "ieee80211_input: duplicate", "seqno <%u,%u> fragno <%u,%u> tid %u", rxseq >> IEEE80211_SEQ_SEQ_SHIFT, in->in_rxseqs[tid] >> IEEE80211_SEQ_SEQ_SHIFT, rxseq & IEEE80211_SEQ_FRAG_MASK, in->in_rxseqs[tid] & IEEE80211_SEQ_FRAG_MASK, tid); ic->ic_stats.is_rx_dups++; goto out_exit_mutex; } in->in_rxseqs[tid] = rxseq; } }
static int str_read_packet(AVFormatContext *s, AVPacket *ret_pkt) { ByteIOContext *pb = &s->pb; StrDemuxContext *str = (StrDemuxContext *)s->priv_data; unsigned char sector[RAW_CD_SECTOR_SIZE]; int channel; int packet_read = 0; int ret = 0; AVPacket *pkt; while (!packet_read) { if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) return AVERROR_IO; channel = sector[0x11]; if (channel >= 32) return AVERROR_INVALIDDATA; switch (sector[0x12] & CDXA_TYPE_MASK) { case CDXA_TYPE_DATA: case CDXA_TYPE_VIDEO: /* check if this the video channel we care about */ if (channel == str->video_channel) { int current_sector = LE_16(§or[0x1C]); int sector_count = LE_16(§or[0x1E]); int frame_size = LE_32(§or[0x24]); int bytes_to_copy; // printf("%d %d %d\n",current_sector,sector_count,frame_size); /* if this is the first sector of the frame, allocate a pkt */ pkt = &str->tmp_pkt; if (current_sector == 0) { if (av_new_packet(pkt, frame_size)) return AVERROR_IO; pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE; pkt->stream_index = str->channels[channel].video_stream_index; // pkt->pts = str->pts; /* if there is no audio, adjust the pts after every video * frame; assume 15 fps */ if (str->audio_channel != -1) str->pts += (90000 / 15); } /* load all the constituent chunks in the video packet */ bytes_to_copy = frame_size - current_sector*VIDEO_DATA_CHUNK_SIZE; if (bytes_to_copy>0) { if (bytes_to_copy>VIDEO_DATA_CHUNK_SIZE) bytes_to_copy=VIDEO_DATA_CHUNK_SIZE; memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE, sector + VIDEO_DATA_HEADER_SIZE, bytes_to_copy); } if (current_sector == sector_count-1) { *ret_pkt = *pkt; return 0; } } break; case CDXA_TYPE_AUDIO: #ifdef PRINTSTUFF printf (" dropping audio sector\n"); #endif #if 1 /* check if this the video channel we care about */ if (channel == str->audio_channel) { pkt = ret_pkt; if (av_new_packet(pkt, 2304)) return AVERROR_IO; memcpy(pkt->data,sector+24,2304); pkt->stream_index = str->channels[channel].audio_stream_index; //pkt->pts = str->pts; return 0; } #endif break; default: /* drop the sector and move on */ #ifdef PRINTSTUFF printf (" dropping other sector\n"); #endif break; } if (url_feof(pb)) return AVERROR_IO; } return ret; }
static int str_read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = &s->pb; StrDemuxContext *str = (StrDemuxContext *)s->priv_data; AVStream *st; unsigned char sector[RAW_CD_SECTOR_SIZE]; int start; int i; int channel; /* initialize context members */ str->pts = 0; str->audio_channel = -1; /* assume to audio or video */ str->video_channel = -1; str->video_chunk = NULL; /* skip over any RIFF header */ if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE) return AVERROR_IO; if (LE_32(§or[0]) == RIFF_TAG) start = RIFF_HEADER_SIZE; else start = 0; url_fseek(pb, start, SEEK_SET); /* check through the first 32 sectors for individual channels */ for (i = 0; i < 32; i++) { if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) return AVERROR_IO; //printf("%02x %02x %02x %02x\n",sector[0x10],sector[0x11],sector[0x12],sector[0x13]); channel = sector[0x11]; if (channel >= 32) return AVERROR_INVALIDDATA; switch (sector[0x12] & CDXA_TYPE_MASK) { case CDXA_TYPE_DATA: case CDXA_TYPE_VIDEO: /* check if this channel gets to be the dominant video channel */ if (str->video_channel == -1) { /* qualify the magic number */ if (LE_32(§or[0x18]) != STR_MAGIC) break; str->video_channel = channel; str->channels[channel].type = STR_VIDEO; str->channels[channel].width = LE_16(§or[0x28]); str->channels[channel].height = LE_16(§or[0x2A]); /* allocate a new AVStream */ st = av_new_stream(s, 0); if (!st) return AVERROR_NOMEM; av_set_pts_info(st, 64, 1, 15); str->channels[channel].video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MDEC; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = str->channels[channel].width; st->codec->height = str->channels[channel].height; } break; case CDXA_TYPE_AUDIO: /* check if this channel gets to be the dominant audio channel */ if (str->audio_channel == -1) { int fmt; str->audio_channel = channel; str->channels[channel].type = STR_AUDIO; str->channels[channel].channels = (sector[0x13] & 0x01) ? 2 : 1; str->channels[channel].sample_rate = (sector[0x13] & 0x04) ? 18900 : 37800; str->channels[channel].bits = (sector[0x13] & 0x10) ? 8 : 4; /* allocate a new AVStream */ st = av_new_stream(s, 0); if (!st) return AVERROR_NOMEM; av_set_pts_info(st, 64, 128, str->channels[channel].sample_rate); str->channels[channel].audio_stream_index = st->index; fmt = sector[0x13]; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_XA; st->codec->codec_tag = 0; /* no fourcc */ st->codec->channels = (fmt&1)?2:1; st->codec->sample_rate = (fmt&4)?18900:37800; // st->codec->bit_rate = 0; //FIXME; st->codec->block_align = 128; } break; default: /* ignore */ break; } } if (str->video_channel != -1) av_log (s, AV_LOG_DEBUG, " video channel = %d, %d x %d %d\n", str->video_channel, str->channels[str->video_channel].width, str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index); if (str->audio_channel != -1) av_log (s, AV_LOG_DEBUG, " audio channel = %d, %d Hz, %d channels, %d bits/sample %d\n", str->audio_channel, str->channels[str->audio_channel].sample_rate, str->channels[str->audio_channel].channels, str->channels[str->audio_channel].bits,str->channels[str->audio_channel].audio_stream_index); /* back to the start */ url_fseek(pb, start, SEEK_SET); return 0; }
static int mm_read_packet(AVFormatContext *s, AVPacket *pkt) { MmDemuxContext *mm = (MmDemuxContext *)s->priv_data; ByteIOContext *pb = &s->pb; unsigned char preamble[MM_PREAMBLE_SIZE]; unsigned char pal[MM_PALETTE_SIZE]; unsigned int type, length; int i; while(1) { if (get_buffer(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { return AVERROR_IO; } type = LE_16(&preamble[0]); length = LE_16(&preamble[2]); switch(type) { case MM_TYPE_PALETTE : url_fseek(pb, 4, SEEK_CUR); /* unknown data */ if (get_buffer(pb, pal, MM_PALETTE_SIZE) != MM_PALETTE_SIZE) return AVERROR_IO; url_fseek(pb, length - (4 + MM_PALETTE_SIZE), SEEK_CUR); for (i=0; i<MM_PALETTE_COUNT; i++) { int r = pal[i*3 + 0]; int g = pal[i*3 + 1]; int b = pal[i*3 + 2]; mm->palette_control.palette[i] = (r << 16) | (g << 8) | (b); /* repeat palette, where each components is multiplied by four */ mm->palette_control.palette[i+128] = (r << 18) | (g << 10) | (b<<2); } mm->palette_control.palette_changed = 1; break; case MM_TYPE_INTER : case MM_TYPE_INTRA : case MM_TYPE_INTRA_HH : case MM_TYPE_INTER_HH : case MM_TYPE_INTRA_HHV : case MM_TYPE_INTER_HHV : /* output preamble + data */ if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE)) return AVERROR_NOMEM; memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE); if (get_buffer(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) return AVERROR_IO; pkt->size = length + MM_PREAMBLE_SIZE; pkt->stream_index = 0; pkt->pts = mm->video_pts++; return 0; case MM_TYPE_AUDIO : if (av_get_packet(&s->pb, pkt, length)<0) return AVERROR_NOMEM; pkt->size = length; pkt->stream_index = 1; pkt->pts = mm->audio_pts++; return 0; default : av_log(NULL, AV_LOG_INFO, "mm: unknown chunk type 0x%x\n", type); url_fseek(pb, length, SEEK_CUR); } } return 0; }
static int decode_rle(CamtasiaContext *c, unsigned int srcsize) { unsigned char *src = c->decomp_buf; unsigned char *output, *output_end; int p1, p2, line=c->height, pos=0, i; uint16_t pix16; uint32_t pix32; output = c->pic.data[0] + (c->height - 1) * c->pic.linesize[0]; output_end = c->pic.data[0] + (c->height) * c->pic.linesize[0]; while(src < c->decomp_buf + srcsize) { p1 = *src++; if(p1 == 0) { //Escape code p2 = *src++; if(p2 == 0) { //End-of-line output = c->pic.data[0] + (--line) * c->pic.linesize[0]; if (line < 0) return -1; pos = 0; continue; } else if(p2 == 1) { //End-of-picture return 0; } else if(p2 == 2) { //Skip p1 = *src++; p2 = *src++; line -= p2; if (line < 0) return -1; pos += p1; output = c->pic.data[0] + line * c->pic.linesize[0] + pos * (c->bpp / 8); continue; } // Copy data if (output + p2 * (c->bpp / 8) > output_end) { src += p2 * (c->bpp / 8); continue; } if ((c->bpp == 8) || (c->bpp == 24)) { for(i = 0; i < p2 * (c->bpp / 8); i++) { *output++ = *src++; } // RLE8 copy is actually padded - and runs are not! if(c->bpp == 8 && (p2 & 1)) { src++; } } else if (c->bpp == 16) { for(i = 0; i < p2; i++) { pix16 = LE_16(src); src += 2; *(uint16_t*)output = pix16; output += 2; } } else if (c->bpp == 32) { for(i = 0; i < p2; i++) { pix32 = LE_32(src); src += 4; *(uint32_t*)output = pix32; output += 4; } } pos += p2; } else { //Run of pixels int pix[4]; //original pixel switch(c->bpp){ case 8: pix[0] = *src++; break; case 16: pix16 = LE_16(src); src += 2; *(uint16_t*)pix = pix16; break; case 24: pix[0] = *src++; pix[1] = *src++; pix[2] = *src++; break; case 32: pix32 = LE_32(src); src += 4; *(uint32_t*)pix = pix32; break; } if (output + p1 * (c->bpp / 8) > output_end) continue; for(i = 0; i < p1; i++) { switch(c->bpp){ case 8: *output++ = pix[0]; break; case 16: *(uint16_t*)output = pix16; output += 2; break; case 24: *output++ = pix[0]; *output++ = pix[1]; *output++ = pix[2]; break; case 32: *(uint32_t*)output = pix32; output += 4; break; } } pos += p1; } } av_log(c->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n"); return 1; }
/* * the following routines load code onto ipw2200 hardware */ int ipw2200_load_uc(struct ipw2200_softc *sc, uint8_t *buf, size_t size) { int ntries, i; uint16_t *w; ipw2200_csr_put32(sc, IPW2200_CSR_RST, IPW2200_RST_STOP_MASTER | ipw2200_csr_get32(sc, IPW2200_CSR_RST)); for (ntries = 0; ntries < 5; ntries++) { if (ipw2200_csr_get32(sc, IPW2200_CSR_RST) & IPW2200_RST_MASTER_DISABLED) break; drv_usecwait(10); } if (ntries == 5) { IPW2200_WARN((sc->sc_dip, CE_CONT, "ipw2200_load_uc(): timeout waiting for master")); return (DDI_FAILURE); } ipw2200_imem_put32(sc, 0x3000e0, 0x80000000); drv_usecwait(5000); ipw2200_csr_put32(sc, IPW2200_CSR_RST, ~IPW2200_RST_PRINCETON_RESET & ipw2200_csr_get32(sc, IPW2200_CSR_RST)); drv_usecwait(5000); ipw2200_imem_put32(sc, 0x3000e0, 0); drv_usecwait(1000); ipw2200_imem_put32(sc, IPW2200_IMEM_EVENT_CTL, 1); drv_usecwait(1000); ipw2200_imem_put32(sc, IPW2200_IMEM_EVENT_CTL, 0); drv_usecwait(1000); ipw2200_imem_put8(sc, 0x200000, 0x00); ipw2200_imem_put8(sc, 0x200000, 0x40); drv_usecwait(1000); for (w = (uint16_t *)(uintptr_t)buf; size > 0; w++, size -= 2) ipw2200_imem_put16(sc, 0x200010, LE_16(*w)); ipw2200_imem_put8(sc, 0x200000, 0x00); ipw2200_imem_put8(sc, 0x200000, 0x80); /* * try many times to wait the upload is ready, 2000times */ for (ntries = 0; ntries < 2000; ntries++) { uint8_t val; val = ipw2200_imem_get8(sc, 0x200000); if (val & 1) break; drv_usecwait(1000); /* wait for a while */ } if (ntries == 2000) { IPW2200_WARN((sc->sc_dip, CE_WARN, "ipw2200_load_uc(): timeout waiting for ucode init.\n")); return (DDI_FAILURE); } for (i = 0; i < 7; i++) (void) ipw2200_imem_get32(sc, 0x200004); ipw2200_imem_put8(sc, 0x200000, 0x00); return (DDI_SUCCESS); }
static int avs_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t * buf, int buf_size) { avs_context_t *const avs = avctx->priv_data; AVFrame *picture = data; AVFrame *const p = (AVFrame *) & avs->picture; uint8_t *table, *vect, *out; int i, j, x, y, stride, vect_w = 3, vect_h = 3; int sub_type; avs_block_type_t type; GetBitContext change_map; if (avctx->reget_buffer(avctx, p)) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } p->reference = 1; p->pict_type = FF_P_TYPE; p->key_frame = 0; out = avs->picture.data[0]; stride = avs->picture.linesize[0]; sub_type = buf[0]; type = buf[1]; buf += 4; if (type == AVS_PALETTE) { int first, last; uint32_t *pal = (uint32_t *) avs->picture.data[1]; first = LE_16(buf); last = first + LE_16(buf + 2); buf += 4; for (i=first; i<last; i++, buf+=3) pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2); sub_type = buf[0]; type = buf[1]; buf += 4; } if (type != AVS_VIDEO) return -1; switch (sub_type) { case AVS_I_FRAME: p->pict_type = FF_I_TYPE; p->key_frame = 1; case AVS_P_FRAME_3X3: vect_w = 3; vect_h = 3; break; case AVS_P_FRAME_2X2: vect_w = 2; vect_h = 2; break; case AVS_P_FRAME_2X3: vect_w = 2; vect_h = 3; break; default: return -1; } table = buf + (256 * vect_w * vect_h); if (sub_type != AVS_I_FRAME) { int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h); init_get_bits(&change_map, table, map_size); table += map_size; } for (y=0; y<198; y+=vect_h) { for (x=0; x<318; x+=vect_w) { if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) { vect = &buf[*table++ * (vect_w * vect_h)]; for (j=0; j<vect_w; j++) { out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j]; out[(y + 1) * stride + x + j] = vect[(1 * vect_w) + j]; if (vect_h == 3) out[(y + 2) * stride + x + j] = vect[(2 * vect_w) + j]; } } } if (sub_type != AVS_I_FRAME) align_get_bits(&change_map); } *picture = *(AVFrame *) & avs->picture; *data_size = sizeof(AVPicture); return buf_size; }
/* * Procedure to walk through the extended partitions and build a Singly * Linked List out of the data. */ static int fdisk_read_extpart(ext_part_t *epp) { struct ipart *fdp, *ext_fdp; int i = 0, j = 0, ext_part_found = 0, lpart = 5; off_t secnum, offset; logical_drive_t *temp, *ep_ptr; unsigned char *ext_buf; int sectsize = epp->disk_geom.sectsize; if ((ext_buf = (uchar_t *)malloc(sectsize)) == NULL) { return (ENOMEM); } fdp = epp->mtable; for (i = 0; (i < FD_NUMPART) && (!ext_part_found); i++, fdp++) { if (fdisk_is_dos_extended(LE_8(fdp->systid))) { ext_part_found = 1; secnum = LE_32(fdp->relsect); offset = secnum * sectsize; epp->ext_beg_sec = secnum; epp->ext_end_sec = secnum + LE_32(fdp->numsect) - 1; epp->ext_beg_cyl = FDISK_SECT_TO_CYL(epp, epp->ext_beg_sec); epp->ext_end_cyl = FDISK_SECT_TO_CYL(epp, epp->ext_end_sec); /*LINTED*/ while (B_TRUE) { if (lseek(epp->dev_fd, offset, SEEK_SET) < 0) { return (EIO); } if (read(epp->dev_fd, ext_buf, sectsize) < sectsize) { return (EIO); } /*LINTED*/ ext_fdp = (struct ipart *) (&ext_buf[FDISK_PART_TABLE_START]); if ((LE_32(ext_fdp->relsect) == 0) && (epp->logical_drive_count == 0)) { /* No logical drives defined */ epp->first_ebr_is_null = 0; return (FDISK_ENOLOGDRIVE); } temp = fdisk_alloc_ld_node(); temp->abs_secnum = secnum; temp->logdrive_offset = LE_32(ext_fdp->relsect); temp ->numsect = LE_32(ext_fdp->numsect); if (epp->ld_head == NULL) { /* adding first logical drive */ if (temp->logdrive_offset > MAX_LOGDRIVE_OFFSET) { /* out of order */ temp->abs_secnum += temp->logdrive_offset; temp->logdrive_offset = 0; } } temp->begcyl = FDISK_SECT_TO_CYL(epp, temp->abs_secnum); temp->endcyl = FDISK_SECT_TO_CYL(epp, temp->abs_secnum + temp->logdrive_offset + temp->numsect - 1); /* * Check for sanity of logical drives */ if (fdisk_validate_logical_drive(epp, temp->abs_secnum, temp->logdrive_offset, temp->numsect)) { epp->corrupt_logical_drives = 1; free(temp); return (FDISK_EBADLOGDRIVE); } temp->parts[0] = *ext_fdp; ext_fdp++; temp->parts[1] = *ext_fdp; if (epp->ld_head == NULL) { epp->ld_head = temp; epp->sorted_ld_head = temp; ep_ptr = temp; epp->logical_drive_count = 1; } else { ep_ptr->next = temp; ep_ptr = temp; fdisk_ext_place_in_sorted_list(epp, temp); epp->logical_drive_count++; } /*LINTED*/ if (LE_16((*(uint16_t *)&ext_buf[510])) != MBB_MAGIC) { epp->invalid_bb_sig[j++] = lpart; temp->modified = FDISK_MINOR_WRITE; } if (LE_32(ext_fdp->relsect) == 0) break; else { secnum = LE_32(fdp->relsect) + LE_32(ext_fdp->relsect); offset = secnum * sectsize; } lpart++; } } } return (FDISK_SUCCESS); }
static int flic_read_header(AVFormatContext *s, AVFormatParameters *ap) { FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data; ByteIOContext *pb = &s->pb; unsigned char header[FLIC_HEADER_SIZE]; AVStream *st; int speed; int magic_number; flic->pts = 0; /* load the whole header and pull out the width and height */ if (get_buffer(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE) return AVERROR_IO; magic_number = LE_16(&header[4]); speed = LE_32(&header[0x10]); /* initialize the decoder streams */ st = av_new_stream(s, 0); if (!st) return AVERROR_NOMEM; flic->video_stream_index = st->index; st->codec.codec_type = CODEC_TYPE_VIDEO; st->codec.codec_id = CODEC_ID_FLIC; st->codec.codec_tag = 0; /* no fourcc */ st->codec.width = LE_16(&header[0x08]); st->codec.height = LE_16(&header[0x0A]); if (!st->codec.width || !st->codec.height) return AVERROR_INVALIDDATA; /* send over the whole 128-byte FLIC header */ st->codec.extradata_size = FLIC_HEADER_SIZE; st->codec.extradata = av_malloc(FLIC_HEADER_SIZE); memcpy(st->codec.extradata, header, FLIC_HEADER_SIZE); av_set_pts_info(st, 33, 1, 90000); /* Time to figure out the framerate: If there is a FLIC chunk magic * number at offset 0x10, assume this is from the Bullfrog game, * Magic Carpet. */ if (LE_16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { flic->frame_pts_inc = FLIC_MC_PTS_INC; /* rewind the stream since the first chunk is at offset 12 */ url_fseek(pb, 12, SEEK_SET); /* send over abbreviated FLIC header chunk */ av_free(st->codec.extradata); st->codec.extradata_size = 12; st->codec.extradata = av_malloc(12); memcpy(st->codec.extradata, header, 12); } else if (magic_number == FLIC_FILE_MAGIC_1) { /* * in this case, the speed (n) is number of 1/70s ticks between frames: * * pts n * frame # * -------- = ----------- => pts = n * (90000/70) * frame # * 90000 70 * * therefore, the frame pts increment = n * 1285.7 */ flic->frame_pts_inc = speed * 1285.7; } else if (magic_number == FLIC_FILE_MAGIC_2) { /* * in this case, the speed (n) is number of milliseconds between frames: * * pts n * frame # * -------- = ----------- => pts = n * 90 * frame # * 90000 1000 * * therefore, the frame pts increment = n * 90 */ flic->frame_pts_inc = speed * 90; } else return AVERROR_INVALIDDATA; if (flic->frame_pts_inc == 0) flic->frame_pts_inc = FLIC_DEFAULT_PTS_INC; return 0; }
static int ms_adpcm_decode_block(unsigned short *output, unsigned char *input, int channels, int block_size) { int current_channel = 0; int coeff_idx; int idelta[2]; int sample1[2]; int sample2[2]; int coeff1[2]; int coeff2[2]; int stream_ptr = 0; int out_ptr = 0; int upper_nibble = 1; int nibble; int snibble; // signed nibble int predictor; if (channels != 1) channels = 2; if (block_size < 7 * channels) return -1; // fetch the header information, in stereo if both channels are present coeff_idx = check_coeff(input[stream_ptr]); coeff1[0] = ms_adapt_coeff1[coeff_idx]; coeff2[0] = ms_adapt_coeff2[coeff_idx]; stream_ptr++; if (channels == 2) { coeff_idx = check_coeff(input[stream_ptr]); coeff1[1] = ms_adapt_coeff1[coeff_idx]; coeff2[1] = ms_adapt_coeff2[coeff_idx]; stream_ptr++; } idelta[0] = LE_16(&input[stream_ptr]); stream_ptr += 2; if (channels == 2) { idelta[1] = LE_16(&input[stream_ptr]); stream_ptr += 2; } sample1[0] = LE_16(&input[stream_ptr]); stream_ptr += 2; if (channels == 2) { sample1[1] = LE_16(&input[stream_ptr]); stream_ptr += 2; } sample2[0] = LE_16(&input[stream_ptr]); stream_ptr += 2; if (channels == 2) { sample2[1] = LE_16(&input[stream_ptr]); stream_ptr += 2; } if (channels == 1) { output[out_ptr++] = sample2[0]; output[out_ptr++] = sample1[0]; } else { output[out_ptr++] = sample2[0]; output[out_ptr++] = sample2[1]; output[out_ptr++] = sample1[0]; output[out_ptr++] = sample1[1]; } while (stream_ptr < block_size) { // get the next nibble if (upper_nibble) nibble = snibble = input[stream_ptr] >> 4; else nibble = snibble = input[stream_ptr++] & 0x0F; upper_nibble ^= 1; SE_4BIT(snibble); // should this really be a division and not a shift? // coefficients were originally scaled by for, which might have // been an optimization for 8-bit CPUs _if_ a shift is correct predictor = ( ((sample1[current_channel] * coeff1[current_channel]) + (sample2[current_channel] * coeff2[current_channel])) / 64) + (snibble * idelta[current_channel]); CLAMP_S16(predictor); sample2[current_channel] = sample1[current_channel]; sample1[current_channel] = predictor; output[out_ptr++] = predictor; // compute the next adaptive scale factor (a.k.a. the variable idelta) idelta[current_channel] = (ms_adapt_table[nibble] * idelta[current_channel]) / 256; CLAMP_ABOVE_16(idelta[current_channel]); // toggle the channel current_channel ^= channels - 1; }
static int fallback_io_tcp_connect(void *data, const char *host, int port, int *need_abort) { struct hostent *h; int i, s; #ifdef USE_GETHOSTBYNAME h = gethostbyname(host); if (h == NULL) { lprintf("mms: unable to resolve host: %s\n", host); return -1; } char **h_addr_list = h->h_addr_list; #else char sport[10]; snprintf (sport, 10, "%d", port); struct addrinfo *res; for (;;) { int err = getaddrinfo (host, sport, NULL, &res); if (need_abort && *need_abort) { if (res) { freeaddrinfo(res); } return -1; } if (err == EAI_AGAIN) { lprintf ("getaddrinfo again\n"); continue; } else if (err == 0) { lprintf ("getaddrinfo success\n"); break; } lprintf ("getaddrinfo err: %d\n", err); return -1; } #endif s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { lprintf("mms: failed to create socket: %s\n", strerror(errno)); return -1; } if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1) { lprintf("mms: failed to set socket flags: %s\n", strerror(errno)); return -1; } #ifdef USE_GETHOSTBYNAME for (i = 0; h_addr_list[i]; i++) { struct in_addr ia; struct sockaddr_in sin; memcpy (&ia, h_addr_list[i], 4); sin.sin_family = AF_INET; sin.sin_addr = ia; sin.sin_port = htons(port); #else struct addrinfo *rp; for (rp = res; rp != NULL; rp = rp->ai_next) { struct sockaddr_in sin; memset (&sin, 0, sizeof (sin)); int l = rp->ai_addrlen; if (l > sizeof (sin)) { l = sizeof (sin); } memcpy (&sin, rp->ai_addr, l); #endif time_t t = time (NULL); int error = 0; while (!need_abort || !(*need_abort)) { int res = connect(s, (struct sockaddr *)&sin, sizeof(sin)); if (res == -1 && (errno == EINPROGRESS || errno == EALREADY)) { if (time (NULL) - t > 3) { error = -1; break; } usleep(100000); continue; } else if (res == -1 && errno == EISCONN) { break; } else if (res == -1) { error = -1; break; } } if (need_abort && *need_abort) { lprintf ("fallback_io_tcp_connect: aborted\n"); s = -1; break; } // if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) ==-1 && errno != EINPROGRESS) { // continue; // } if (error) { continue; } #ifndef USE_GETHOSTBYNAME if (res) { freeaddrinfo(res); } #endif return s; } #ifndef USE_GETHOSTBYNAME if (res) { freeaddrinfo(res); } #endif close(s); return -1; } static mms_io_t fallback_io = { &fallback_io_select, NULL, &fallback_io_read, NULL, &fallback_io_write, NULL, &fallback_io_tcp_connect, NULL, }; static mms_io_t default_io = { &fallback_io_select, NULL, &fallback_io_read, NULL, &fallback_io_write, NULL, &fallback_io_tcp_connect, NULL, }; #define io_read(io, args...) ((io) ? (io)->read(io->read_data , ## args) : default_io.read(NULL , ## args)) #define io_write(io, args...) ((io) ? (io)->write(io->write_data , ## args) : default_io.write(NULL , ## args)) #define io_select(io, args...) ((io) ? (io)->select(io->select_data , ## args) : default_io.select(NULL , ## args)) #define io_connect(io, args...) ((io) ? (io)->connect(io->connect_data , ## args) : default_io.connect(NULL , ## args)) static int get_guid (unsigned char *buffer, int offset) { int i; GUID g; g.Data1 = LE_32(buffer + offset); g.Data2 = LE_16(buffer + offset + 4); g.Data3 = LE_16(buffer + offset + 6); for(i = 0; i < 8; i++) { g.Data4[i] = buffer[offset + 8 + i]; } for (i = 1; i < GUID_END; i++) { if (!memcmp(&g, &guids[i].guid, sizeof(GUID))) { lprintf("mmsh: GUID: %s\n", guids[i].name); return i; } } lprintf("mmsh: unknown GUID: 0x%x, 0x%x, 0x%x, " "{ 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx }\n", g.Data1, g.Data2, g.Data3, g.Data4[0], g.Data4[1], g.Data4[2], g.Data4[3], g.Data4[4], g.Data4[5], g.Data4[6], g.Data4[7]); return GUID_ERROR; }
static int ms_adpcm_decode_block(unsigned short *output, unsigned char *input, int channels, int block_size) { int current_channel = 0; int idelta[2]; int sample1[2]; int sample2[2]; int coeff1[2]; int coeff2[2]; int stream_ptr = 0; int out_ptr = 0; int upper_nibble = 1; int nibble; int snibble; // signed nibble int predictor; // fetch the header information, in stereo if both channels are present if (input[stream_ptr] > 6) mp_msg(MSGT_DECAUDIO, MSGL_WARN, "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", input[stream_ptr]); coeff1[0] = ms_adapt_coeff1[input[stream_ptr]]; coeff2[0] = ms_adapt_coeff2[input[stream_ptr]]; stream_ptr++; if (channels == 2) { if (input[stream_ptr] > 6) mp_msg(MSGT_DECAUDIO, MSGL_WARN, "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", input[stream_ptr]); coeff1[1] = ms_adapt_coeff1[input[stream_ptr]]; coeff2[1] = ms_adapt_coeff2[input[stream_ptr]]; stream_ptr++; } idelta[0] = LE_16(&input[stream_ptr]); stream_ptr += 2; SE_16BIT(idelta[0]); if (channels == 2) { idelta[1] = LE_16(&input[stream_ptr]); stream_ptr += 2; SE_16BIT(idelta[1]); } sample1[0] = LE_16(&input[stream_ptr]); stream_ptr += 2; SE_16BIT(sample1[0]); if (channels == 2) { sample1[1] = LE_16(&input[stream_ptr]); stream_ptr += 2; SE_16BIT(sample1[1]); } sample2[0] = LE_16(&input[stream_ptr]); stream_ptr += 2; SE_16BIT(sample2[0]); if (channels == 2) { sample2[1] = LE_16(&input[stream_ptr]); stream_ptr += 2; SE_16BIT(sample2[1]); } if (channels == 1) { output[out_ptr++] = sample2[0]; output[out_ptr++] = sample1[0]; } else { output[out_ptr++] = sample2[0]; output[out_ptr++] = sample2[1]; output[out_ptr++] = sample1[0]; output[out_ptr++] = sample1[1]; } while (stream_ptr < block_size) { // get the next nibble if (upper_nibble) nibble = snibble = input[stream_ptr] >> 4; else nibble = snibble = input[stream_ptr++] & 0x0F; upper_nibble ^= 1; SE_4BIT(snibble); predictor = ( ((sample1[current_channel] * coeff1[current_channel]) + (sample2[current_channel] * coeff2[current_channel])) / 256) + (snibble * idelta[current_channel]); CLAMP_S16(predictor); sample2[current_channel] = sample1[current_channel]; sample1[current_channel] = predictor; output[out_ptr++] = predictor; // compute the next adaptive scale factor (a.k.a. the variable idelta) idelta[current_channel] = (ms_adapt_table[nibble] * idelta[current_channel]) / 256; CLAMP_ABOVE_16(idelta[current_channel]); // toggle the channel current_channel ^= channels - 1; }
TSS_RESULT psfile_get_all_cache_entries(int fd, UINT32 *size, struct key_disk_cache **c) { UINT32 i, num_keys = psfile_get_num_keys(fd); int offset; TSS_RESULT result; struct key_disk_cache *tmp = NULL; if (num_keys == 0) { *size = 0; *c = NULL; return TSS_SUCCESS; } /* make sure the file pointer is where we expect, just after the number * of keys on disk at the head of the file */ offset = lseek(fd, TSSPS_KEYS_OFFSET, SEEK_SET); if (offset == ((off_t)-1)) { LogDebug("lseek: %s", strerror(errno)); return TSPERR(TSS_E_INTERNAL_ERROR); } if ((tmp = malloc(num_keys * sizeof(struct key_disk_cache))) == NULL) { LogDebug("malloc of %zu bytes failed.", num_keys * sizeof(struct key_disk_cache)); return TSPERR(TSS_E_OUTOFMEMORY); } for (i = 0; i < num_keys; i++) { offset = lseek(fd, 0, SEEK_CUR); if (offset == ((off_t)-1)) { LogDebug("lseek: %s", strerror(errno)); result = TSPERR(TSS_E_INTERNAL_ERROR); goto err_exit; } tmp[i].offset = offset; /* read UUID */ if ((result = read_data(fd, &tmp[i].uuid, sizeof(TSS_UUID)))) { LogDebug("%s", __FUNCTION__); goto err_exit; } /* read parent UUID */ if ((result = read_data(fd, &tmp[i].parent_uuid, sizeof(TSS_UUID)))) { LogDebug("%s", __FUNCTION__); goto err_exit; } /* pub data size */ if ((result = read_data(fd, &tmp[i].pub_data_size, sizeof(UINT16)))) { LogDebug("%s", __FUNCTION__); goto err_exit; } tmp[i].pub_data_size = LE_16(tmp[i].pub_data_size); DBG_ASSERT(tmp[i].pub_data_size <= 2048); /* blob size */ if ((result = read_data(fd, &tmp[i].blob_size, sizeof(UINT16)))) { LogDebug("%s", __FUNCTION__); goto err_exit; } tmp[i].blob_size = LE_16(tmp[i].blob_size); DBG_ASSERT(tmp[i].blob_size <= 4096); /* vendor data size */ if ((result = read_data(fd, &tmp[i].vendor_data_size, sizeof(UINT32)))) { LogDebug("%s", __FUNCTION__); goto err_exit; } tmp[i].vendor_data_size = LE_32(tmp[i].vendor_data_size); /* cache flags */ if ((result = read_data(fd, &tmp[i].flags, sizeof(UINT16)))) { LogDebug("%s", __FUNCTION__); goto err_exit; } tmp[i].flags = LE_16(tmp[i].flags); /* fast forward over the pub key */ offset = lseek(fd, tmp[i].pub_data_size, SEEK_CUR); if (offset == ((off_t)-1)) { LogDebug("lseek: %s", strerror(errno)); result = TSPERR(TSS_E_INTERNAL_ERROR); goto err_exit; } /* fast forward over the blob */ offset = lseek(fd, tmp[i].blob_size, SEEK_CUR); if (offset == ((off_t)-1)) { LogDebug("lseek: %s", strerror(errno)); result = TSPERR(TSS_E_INTERNAL_ERROR); goto err_exit; } /* ignore vendor data for user ps */ } *size = num_keys; *c = tmp; return TSS_SUCCESS; err_exit: free(tmp); return result; }