2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2010 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
26 * \brief Utility, generate dot file from Refdrence Manifest (RM)
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
29 * cleanup 2011-01-22 SM
31 * RM/UML State Diagram -> DOT --(graphviz)--> Graph(PNG,JPG etc)
37 cd tests/data/ThinkpadX200_Fedora12
39 ../../../src/rm2dot -p 0 -o bios_pcr0.dot platform_rm.xml
40 dot -Tpng bios_pcr0.dot -o bios_pcr0.png
43 ../../../src/rm2dot -p 4 -o grub_pcr4.dot runtime_rm.xml
44 dot -Tpng grub_pcr4.dot -o grub_pcr4.png
55 #include <sys/types.h>
56 #include <sys/socket.h>
57 #include <netinet/in.h>
65 int verbose = 0; /**< DEBUG */
71 fprintf(stderr, "usage: rm2dot [options] RMfile \n");
72 fprintf(stderr, "\t-o output\tset output file (default is stdout)\n");
73 fprintf(stderr, "\t-p pcrindex\tset PCR index\n");
74 fprintf(stderr, "\t-l level\tset snapshot level (0 or 1)\n");
75 fprintf(stderr, "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n");
76 fprintf(stderr, "\n");
82 int main(int argc, char *argv[]) {
87 char *input_filename = NULL;
88 char *output_filename = NULL;
95 while ((c = getopt(argc, argv, "do:p:l:h")) != EOF) {
102 output_filename = optarg;
105 pcr_index = atoi(optarg);
108 level = atoi(optarg);
119 input_filename = argv[0];
121 /* Read RM(XML) file */
123 if (input_filename == NULL) {
124 printf("ERROR missing XMLfile\n");
129 /* new pts context */
130 conf = newPtsConfig();
136 ctx = newPtsContext(conf);
143 rc = readRmFile(ctx, input_filename, 0);
144 if (rc != PTS_SUCCESS) {
145 printf("ERROR readRmFile\n");
150 ss = getSnapshotFromTable(ctx->ss_table, pcr_index, 0);
151 } else if (level == 1) {
152 ss = getSnapshotFromTable(ctx->ss_table, pcr_index, 1);
154 printf("ERROR bad level %d\n", level);
158 rc = writeDotModel(ss->fsm_binary, output_filename);
159 if (rc != PTS_SUCCESS) {
160 printf("ERROR writeDotModel\n");