14fe996c2SAndrew Jeffery // SPDX-License-Identifier: Apache-2.0 24fe996c2SAndrew Jeffery // Copyright (C) 2018 IBM Corp. 31770ce89SAndrew Jeffery 41770ce89SAndrew Jeffery #include <assert.h> 51770ce89SAndrew Jeffery #include <sys/mman.h> 61770ce89SAndrew Jeffery #include <sys/types.h> 71770ce89SAndrew Jeffery #include <sys/stat.h> 81770ce89SAndrew Jeffery #include <unistd.h> 91770ce89SAndrew Jeffery 10*26558dbbSAndrew Jeffery #include "mboxd.h" 11*26558dbbSAndrew Jeffery #include "protocol.h" 12457a6e5fSAndrew Jeffery #include "transport_mbox.h" 131770ce89SAndrew Jeffery 141770ce89SAndrew Jeffery #include "test/mbox.h" 151770ce89SAndrew Jeffery #include "test/system.h" 161770ce89SAndrew Jeffery 171770ce89SAndrew Jeffery #define FLAGS 0xc3 181770ce89SAndrew Jeffery 19b5685b38SAndrew Jeffery static const uint8_t get_info[] = { 20b5685b38SAndrew Jeffery 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 21b5685b38SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 22b5685b38SAndrew Jeffery }; 23b5685b38SAndrew Jeffery 241770ce89SAndrew Jeffery static const uint8_t command[] = { 251770ce89SAndrew Jeffery 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00, 261770ce89SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS 271770ce89SAndrew Jeffery }; 281770ce89SAndrew Jeffery 29b5685b38SAndrew Jeffery uint8_t data[3] = { 0xaa, 0x55, 0xaa }; 30b5685b38SAndrew Jeffery 311770ce89SAndrew Jeffery #define MEM_SIZE 3 321770ce89SAndrew Jeffery #define ERASE_SIZE 1 331770ce89SAndrew Jeffery #define N_WINDOWS 1 341770ce89SAndrew Jeffery #define WINDOW_SIZE 1 351770ce89SAndrew Jeffery 361770ce89SAndrew Jeffery int main(void) 371770ce89SAndrew Jeffery { 381770ce89SAndrew Jeffery struct mbox_context *ctx; 391770ce89SAndrew Jeffery struct stat details; 401770ce89SAndrew Jeffery uint8_t *map; 411770ce89SAndrew Jeffery int rc; 421770ce89SAndrew Jeffery 431770ce89SAndrew Jeffery system_set_reserved_size(MEM_SIZE); 441770ce89SAndrew Jeffery system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); 451770ce89SAndrew Jeffery 461770ce89SAndrew Jeffery ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 47b5685b38SAndrew Jeffery rc = mbox_set_mtd_data(ctx, data, sizeof(data)); 48b5685b38SAndrew Jeffery assert(rc == 0); 49b5685b38SAndrew Jeffery 50b5685b38SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); 51b5685b38SAndrew Jeffery assert(rc == 1); 521770ce89SAndrew Jeffery 535335f093SAndrew Jeffery protocol_events_set(ctx, FLAGS, EVENT_TRIGGER); 541770ce89SAndrew Jeffery 551770ce89SAndrew Jeffery rc = mbox_command_dispatch(ctx, command, sizeof(command)); 561770ce89SAndrew Jeffery assert(rc == 1); 571770ce89SAndrew Jeffery 581770ce89SAndrew Jeffery rc = fstat(ctx->fds[MBOX_FD].fd, &details); 591770ce89SAndrew Jeffery assert(rc == 0); 601770ce89SAndrew Jeffery 611770ce89SAndrew Jeffery map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE, 621770ce89SAndrew Jeffery ctx->fds[MBOX_FD].fd, 0); 631770ce89SAndrew Jeffery assert(map != MAP_FAILED); 641770ce89SAndrew Jeffery 65b5685b38SAndrew Jeffery assert(details.st_size >= 16); 66b5685b38SAndrew Jeffery assert(map[15] == 0xc0); 671770ce89SAndrew Jeffery 68b5685b38SAndrew Jeffery return 0; 691770ce89SAndrew Jeffery } 70