Commit fb5b6130 authored by npzacs's avatar npzacs
Browse files

Open all files in aacs.c

parent 0235dc59
......@@ -382,6 +382,23 @@ static AACS_FILE_H *_file_open(AACS *aacs, const char *file)
return fp;
}
static MKB *_mkb_open(AACS *aacs)
{
AACS_FILE_H *fp;
MKB *mkb;
fp = _file_open(aacs, "AACS/MKB_RO.inf");
if (!fp) {
DEBUG(DBG_AACS | DBG_CRIT, "Error opening MKB file (AACS/MKB_RO.inf)\n");
return NULL;
}
mkb = mkb_read(fp);
file_close(fp);
return mkb;
}
static int _calc_mk(AACS *aacs, uint8_t *mk, pk_list *pkl, dk_list *dkl)
{
int a, num_uvs = 0;
......@@ -396,7 +413,7 @@ static int _calc_mk(AACS *aacs, uint8_t *mk, pk_list *pkl, dk_list *dkl)
DEBUG(DBG_AACS, "Calculate media key...\n");
if ((mkb = mkb_open(aacs->path))) {
if ((mkb = _mkb_open(aacs))) {
aacs->mkb_version = mkb_version(mkb);
_update_rl(mkb);
......@@ -443,7 +460,6 @@ static int _calc_mk(AACS *aacs, uint8_t *mk, pk_list *pkl, dk_list *dkl)
return AACS_ERROR_NO_PK;
}
DEBUG(DBG_AACS | DBG_CRIT, "Error opening %s/AACS/MKB_RO.inf\n", aacs->path);
return AACS_ERROR_CORRUPTED_DISC;
}
......@@ -1046,7 +1062,7 @@ int aacs_get_mkb_version(AACS *aacs)
{
if (!aacs->mkb_version) {
MKB *mkb;
if ((mkb = mkb_open(aacs->path))) {
if ((mkb = _mkb_open(aacs))) {
aacs->mkb_version = mkb_version(mkb);
mkb_close(mkb);
}
......
......@@ -54,40 +54,22 @@ static const uint8_t *_record(MKB *mkb, uint8_t type, size_t *rec_len)
return NULL;
}
MKB *mkb_open(const char *path)
MKB *mkb_read(AACS_FILE_H *fp)
{
AACS_FILE_H *fp = NULL;
char *f_name;
MKB *mkb = malloc(sizeof(MKB));
f_name = str_printf("%s/AACS/MKB_RO.inf", path);
file_seek(fp, 0, SEEK_END);
mkb->size = file_tell(fp);
file_seek(fp, 0, SEEK_SET);
DEBUG(DBG_MKB, "Opening MKB %s...\n", f_name);
fp = file_open(f_name, "rb");
mkb->buf = malloc(mkb->size);
X_FREE(f_name);
file_read(fp, mkb->buf, mkb->size);
if (fp) {
file_seek(fp, 0, SEEK_END);
mkb->size = file_tell(fp);
file_seek(fp, 0, SEEK_SET);
DEBUG(DBG_MKB, "MKB size: %u\n", (unsigned)mkb->size);
DEBUG(DBG_MKB, "MKB version: %d\n", mkb_version(mkb));
mkb->buf = malloc(mkb->size);
file_read(fp, mkb->buf, mkb->size);
DEBUG(DBG_MKB, "MKB size: %u\n", (unsigned)mkb->size);
DEBUG(DBG_MKB, "MKB version: %d\n", mkb_version(mkb));
file_close(fp);
return mkb;
}
DEBUG(DBG_MKB, "Error opening MKB!\n");
X_FREE(mkb);
return NULL;
return mkb;
}
MKB *mkb_init(uint8_t *data, int len)
......
......@@ -27,7 +27,9 @@
typedef struct mkb MKB;
AACS_PRIVATE MKB *mkb_open(const char *path); // init MKB
struct aacs_file_s;
AACS_PRIVATE MKB *mkb_read(struct aacs_file_s *fp); // init MKB
AACS_PRIVATE MKB *mkb_init(uint8_t *data, int len); // init MKB from data
AACS_PRIVATE void mkb_close(MKB *mkb); // free MKB
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment