pibfile.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed pibfile (struct _file_ const * file);
  11. *
  12. * pib.h
  13. *
  14. * confirm that pib->file is a valid PIB file; determine if the
  15. * file is a panther/lynx image chain or flat file and call the
  16. * correct functions;
  17. *
  18. * Contributor(s):
  19. * Charles Maier <cmaier@qca.qualcomm.com>
  20. *
  21. *--------------------------------------------------------------------*/
  22. #ifndef PIBFILE_SOURCE
  23. #define PIBFILE_SOURCE
  24. #include <stdio.h>
  25. #include <stdint.h>
  26. #include <unistd.h>
  27. #include <memory.h>
  28. #include <errno.h>
  29. #include "../tools/memory.h"
  30. #include "../tools/files.h"
  31. #include "../tools/error.h"
  32. #include "../pib/pib.h"
  33. signed pibfile (struct _file_ const * file)
  34. {
  35. uint32_t version;
  36. if (read (file->file, & version, sizeof (version)) != sizeof (version))
  37. {
  38. error (1, errno, FILE_CANTREAD, file->name);
  39. }
  40. if (lseek (file->file, 0, SEEK_SET))
  41. {
  42. error (1, errno, FILE_CANTHOME, file->name);
  43. }
  44. if (LE32TOH (version) == 0x60000000)
  45. {
  46. return (- 1);
  47. }
  48. if (LE32TOH (version) == 0x00010001)
  49. {
  50. return (panther_pib_file (file));
  51. }
  52. return (lightning_pib_file (file));
  53. }
  54. #endif