mme_parser.y 16.3 KB
Newer Older
Cedric Roux's avatar
Cedric Roux committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/* For development only : */
%debug
%error-verbose

%parse-param {struct mme_config_s *mme_config_p}

/* Keep track of location */
%locations
%defines
%pure-parser

%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "mme_config.h"
#include "mme_parser.h"

void yyerror (YYLTYPE *llocp, struct mme_config_s *mme_config_p, const char *s);

extern int yywrap();
extern int yylex();

/* The Lex parser prototype */
int fddlex(YYSTYPE *lvalp, YYLTYPE *llocp);
%}

/* Values returned by lex for token */
%union {
    char         *string;   /* The string is allocated by strdup in lex.*/
    int           integer;  /* Store integer values */
}

%token LEX_ERROR

%token <string> QSTRING
%token <integer> INTEGER

44 45
%token EMERGENCY_ATTACH_SUPPORTED
%token UNAUTHENTICATED_IMSI_SUPPORTED
Cedric Roux's avatar
Cedric Roux committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
%token S6A_CONF
%token MAX_UE
%token MAX_ENB
%token ITTI_QUEUE_SIZE
%token SCTP_INSTREAMS
%token SCTP_OUTSTREAMS
%token MME_CODE
%token MME_GID
%token PLMN_Y
%token REALM
%token RELATIVE_CAP
%token S1AP_OUTCOME_TIMER
%token MME_STATISTIC_TIMER
%token SGW_INTERFACE_NAME_FOR_S11
%token SGW_IP_ADDRESS_FOR_S11
%token SGW_IP_NETMASK_FOR_S11
%token SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP
%token SGW_IP_ADDRESS_FOR_S1U_S12_S4_UP
%token SGW_IP_NETMASK_FOR_S1U_S12_S4_UP
%token SGW_INTERFACE_NAME_FOR_S5_S8_UP
%token SGW_IP_ADDRESS_FOR_S5_S8_UP
%token SGW_IP_NETMASK_FOR_S5_S8_UP
%token PGW_INTERFACE_NAME_FOR_S5_S8
%token PGW_IP_ADDRESS_FOR_S5_S8
%token PGW_IP_NETMASK_FOR_S5_S8
%token PGW_INTERFACE_NAME_FOR_SGI
%token PGW_IP_ADDR_FOR_SGI
%token PGW_IP_NETMASK_FOR_SGI
%token MME_INTERFACE_NAME_FOR_S1_MME
%token MME_IP_ADDRESS_FOR_S1_MME
%token MME_IP_NETMASK_FOR_S1_MME
%token MME_INTERFACE_NAME_FOR_S11_MME
%token MME_IP_ADDRESS_FOR_S11_MME
%token MME_IP_NETMASK_FOR_S11_MME

%%
conffile:       /* If options not provided, we will default values */
    | conffile s6aconf
84 85
    | conffile emergency_attach_supported
    | conffile unauthenticated_imsi_supported
Cedric Roux's avatar
Cedric Roux committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    | conffile maxenb
    | conffile maxue
    | conffile mmec
    | conffile mmegid
    | conffile plmn
    | conffile realm
    | conffile relative_capacity
    | conffile itti_queue_size
    | conffile s1ap_outcome_timer
    | conffile mme_statistic_timer
    | conffile sgw_interface_name_for_S11
    | conffile sgw_ip_address_for_S11
    | conffile sgw_ip_netmask_for_S11
    | conffile sgw_interface_name_for_S1u_S12_S4_up
    | conffile sgw_ip_address_for_S1u_S12_S4_up
    | conffile sgw_ip_netmask_for_S1u_S12_S4_up
    | conffile sgw_interface_name_for_S5_S8_up
    | conffile sgw_ip_address_for_S5_S8_up
    | conffile sgw_ip_netmask_for_S5_S8_up
    | conffile pgw_interface_name_for_S5_S8
    | conffile pgw_ip_address_for_S5_S8
    | conffile pgw_ip_netmask_for_S5_S8
    | conffile pgw_interface_name_for_SGI
    | conffile pgw_ip_addr_for_SGI
    | conffile pgw_ip_netmask_for_SGI
    | conffile mme_interface_name_for_S1_MME
    | conffile mme_ip_address_for_S1_MME
    | conffile mme_ip_netmask_for_S1_MME
    | conffile mme_interface_name_for_S11_MME
    | conffile mme_ip_address_for_S11_MME
    | conffile mme_ip_netmask_for_S11_MME
    | conffile sctp_instreams
    | conffile sctp_outstreams
    | conffile errors
    {
        yyerror(&yylloc, mme_config_p, "An error occurred while parsing the configuration file");
        return EINVAL;
    }
    ;

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
emergency_attach_supported: EMERGENCY_ATTACH_SUPPORTED '=' INTEGER ';'
    {
        if ($3 != 0 && $3 != 1) {
            yyerror(&yylloc, mme_config_p, "Invalid value (possible values are 0 or 1");
            return EINVAL;
        }
        mme_config_p->emergency_attach_supported = $3;
    };

unauthenticated_imsi_supported: UNAUTHENTICATED_IMSI_SUPPORTED '=' INTEGER ';'
    {
        if ($3 != 0 && $3 != 1) {
            yyerror(&yylloc, mme_config_p, "Invalid value (possible values are 0 or 1");
            return EINVAL;
        }
        mme_config_p->unauthenticated_imsi_supported = $3;
    };

Cedric Roux's avatar
Cedric Roux committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
mme_statistic_timer: MME_STATISTIC_TIMER '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        }
        mme_config_p->mme_statistic_timer = $3;
    }
    ;

s1ap_outcome_timer: S1AP_OUTCOME_TIMER '=' INTEGER ';'
    {
        /* 0 is not a valid value here */
        if ($3 <= 0 || $3 >= (1 << (8 * sizeof(mme_config_p->s1ap_config.outcome_drop_timer_sec)))) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        }
        mme_config_p->s1ap_config.outcome_drop_timer_sec = $3;
    }
    ;

s6aconf: S6A_CONF '=' QSTRING ';'
    {
        mme_config_p->s6a_config.conf_file = $3;
    }
    ;

maxenb: MAX_ENB '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        }
        mme_config_p->max_eNBs = (uint32_t)$3;
    }
    ;

maxue: MAX_UE '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        }
        mme_config_p->max_ues = (uint32_t)$3;
    }
    ;

mmec: MME_CODE '=' mmeclist ';'
    ;

mmeclist:
    {
        yyerror(&yylloc, mme_config_p, "Empty value is not allowed");
        return EINVAL;
    }
    | mmecvalue ',' mmeclist
    | mmecvalue
    ;

mmecvalue: INTEGER
    {
        if (mme_config_p->gummei.nb_mmec == 256) {
            yyerror(&yylloc, mme_config_p, "Reached maximum number of mmec");
            return EINVAL;
        }
        if ($1 >= 256) {
            yyerror(&yylloc, mme_config_p, "Value exceed limit <= 255");
            return EINVAL;
        }
        mme_config_p->gummei.nb_mmec++;
        mme_config_p->gummei.mmec = realloc(mme_config_p->gummei.mmec,
                                            mme_config_p->gummei.nb_mmec * sizeof(uint8_t));
        mme_config_p->gummei.mmec[mme_config_p->gummei.nb_mmec-1] = (uint8_t)$1;
    }
    ;

mmegid: MME_GID '=' mmegidlist ';'
    ;

mmegidlist:
    {
        yyerror(&yylloc, mme_config_p, "Empty value is not allowed");
        return EINVAL;
    }
    | mmegidvalue
    | mmegidvalue ',' mmegidlist
    ;

mmegidvalue: INTEGER
    {
        if (mme_config_p->gummei.nb_mme_gid == 65535) {
            yyerror(&yylloc, mme_config_p, "Reached maximum number of mmegid");
            return EINVAL;
        }
        if ($1 >= 65356) {
            yyerror(&yylloc, mme_config_p, "Value exceed limit <= 65535");
            return EINVAL;
        }
        mme_config_p->gummei.nb_mme_gid++;
        mme_config_p->gummei.mme_gid = realloc(mme_config_p->gummei.mme_gid,
                                               mme_config_p->gummei.nb_mme_gid * sizeof(uint16_t));
        mme_config_p->gummei.mme_gid[mme_config_p->gummei.nb_mme_gid-1] = (uint16_t)$1;
    }
    ;

realm: REALM '=' QSTRING ';'
    {
        mme_config_p->realm = $3;
        mme_config_p->realm_length = strlen(mme_config_p->realm);
    }
    ;

plmn: PLMN_Y '=' plmnlist ';'
    ;

plmnlist:
    {
        yyerror(&yylloc, mme_config_p, "Empty value is not allowed");
        return EINVAL;
    }
    | plmnvalue
    | plmnvalue ',' plmnlist
    ;

plmnvalue: INTEGER '.' INTEGER ':' INTEGER
    {
        if (mme_config_p->gummei.nb_plmns == 32) {
            yyerror(&yylloc, mme_config_p, "Reached maximum number of plmns");
            return EINVAL;
        }
        if ($1 > 999 || $3 > 999) {
            yyerror(&yylloc, mme_config_p, "PLMN value exceed limit <= 999");
            return EINVAL;
        }
        if ($5 > 65535) {
            yyerror(&yylloc, mme_config_p, "TAC value exceed limit <= 65535");
            return EINVAL;
        }
        mme_config_p->gummei.nb_plmns++;
        mme_config_p->gummei.plmn_mcc = realloc(mme_config_p->gummei.plmn_mcc,
                                                mme_config_p->gummei.nb_plmns * sizeof(uint16_t));
        mme_config_p->gummei.plmn_mnc = realloc(mme_config_p->gummei.plmn_mnc,
                                                mme_config_p->gummei.nb_plmns * sizeof(uint16_t));
        mme_config_p->gummei.plmn_tac = realloc(mme_config_p->gummei.plmn_tac,
                                                mme_config_p->gummei.nb_plmns * sizeof(uint16_t));
        mme_config_p->gummei.plmn_mcc[mme_config_p->gummei.nb_plmns-1] = (uint16_t)$1;
        mme_config_p->gummei.plmn_mnc[mme_config_p->gummei.nb_plmns-1] = (uint16_t)$3;
        mme_config_p->gummei.plmn_tac[mme_config_p->gummei.nb_plmns-1] = (uint16_t)$5;
    }
    ;

relative_capacity: RELATIVE_CAP '=' INTEGER ';'
    {
        if ($3 >= 256 || $3 < 0) {
            yyerror(&yylloc, mme_config_p, "Value exceed limit <= 255");
            return EINVAL;
        }
        mme_config_p->relative_capacity = $3;
    }
    ;

itti_queue_size: ITTI_QUEUE_SIZE '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        }
        mme_config_p->itti_config.queue_size = (uint32_t)$3;
    }
    ;

sctp_instreams: SCTP_INSTREAMS '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->sctp_config.in_streams = (uint16_t)$3;
    }
    ;

sctp_outstreams: SCTP_OUTSTREAMS '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->sctp_config.out_streams = (uint16_t)$3;
    }
    ;

sgw_interface_name_for_S11: SGW_INTERFACE_NAME_FOR_S11 '=' QSTRING ';'
    {
        mme_config_p->ipv4.sgw_interface_name_for_S11 = $3;
    }
    ;

sgw_ip_address_for_S11: SGW_IP_ADDRESS_FOR_S11 '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.sgw_ip_address_for_S11 = inp.s_addr;
        }
    }
    ;

sgw_ip_netmask_for_S11: SGW_IP_NETMASK_FOR_S11 '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.sgw_ip_netmask_for_S11 = (uint16_t)$3;
    }
    ;

sgw_interface_name_for_S1u_S12_S4_up: SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP '=' QSTRING ';'
    {
        mme_config_p->ipv4.sgw_interface_name_for_S1u_S12_S4_up = $3;
    }
    ;

sgw_ip_address_for_S1u_S12_S4_up: SGW_IP_ADDRESS_FOR_S1U_S12_S4_UP '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.sgw_ip_address_for_S1u_S12_S4_up = inp.s_addr;
        }
    }
    ;

sgw_ip_netmask_for_S1u_S12_S4_up: SGW_IP_NETMASK_FOR_S1U_S12_S4_UP '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.sgw_ip_netmask_for_S1u_S12_S4_up = (uint16_t)$3;
    }
    ;

sgw_interface_name_for_S5_S8_up: SGW_INTERFACE_NAME_FOR_S5_S8_UP '=' QSTRING ';'
    {
        mme_config_p->ipv4.sgw_interface_name_for_S5_S8_up = $3;
    }
    ;

sgw_ip_address_for_S5_S8_up: SGW_IP_ADDRESS_FOR_S5_S8_UP '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.sgw_ip_address_for_S5_S8_up = inp.s_addr;
        }
    }
    ;

sgw_ip_netmask_for_S5_S8_up: SGW_IP_NETMASK_FOR_S5_S8_UP '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.sgw_ip_netmask_for_S5_S8_up = (uint16_t)$3;
    }
    ;

pgw_interface_name_for_S5_S8: PGW_INTERFACE_NAME_FOR_S5_S8 '=' QSTRING ';'
    {
        mme_config_p->ipv4.pgw_interface_name_for_S5_S8 = $3;
    }
    ;

pgw_ip_address_for_S5_S8: PGW_IP_ADDRESS_FOR_S5_S8 '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.pgw_ip_address_for_S5_S8 = inp.s_addr;
        }
    }
    ;

pgw_ip_netmask_for_S5_S8: PGW_IP_NETMASK_FOR_S5_S8 '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.pgw_ip_netmask_for_S5_S8 = (uint16_t)$3;
    }
    ;

pgw_interface_name_for_SGI: PGW_INTERFACE_NAME_FOR_SGI '=' QSTRING ';'
    {
        mme_config_p->ipv4.pgw_interface_name_for_SGI = $3;
    }
    ;

pgw_ip_addr_for_SGI: PGW_IP_ADDR_FOR_SGI '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.pgw_ip_addr_for_SGI = inp.s_addr;
        }
    }
    ;

pgw_ip_netmask_for_SGI: PGW_IP_NETMASK_FOR_SGI '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.pgw_ip_netmask_for_SGI = (uint16_t)$3;
    }
    ;

mme_interface_name_for_S1_MME: MME_INTERFACE_NAME_FOR_S1_MME '=' QSTRING ';'
    {
        mme_config_p->ipv4.mme_interface_name_for_S1_MME = $3;
    }
    ;

mme_ip_address_for_S1_MME: MME_IP_ADDRESS_FOR_S1_MME '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.mme_ip_address_for_S1_MME = inp.s_addr;
        }
    }
    ;

mme_ip_netmask_for_S1_MME: MME_IP_NETMASK_FOR_S1_MME '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.mme_ip_netmask_for_S1_MME = (uint16_t)$3;
    }
    ;

mme_interface_name_for_S11_MME: MME_INTERFACE_NAME_FOR_S11_MME '=' QSTRING ';'
    {
        mme_config_p->ipv4.mme_interface_name_for_S11 = $3;
    }
    ;

mme_ip_address_for_S11_MME: MME_IP_ADDRESS_FOR_S11_MME '=' QSTRING ';'
    {
        struct in_addr inp;
        if ( inet_aton($3, &inp ) < 0 ) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else {
            mme_config_p->ipv4.mme_ip_address_for_S11 = inp.s_addr;
        }
    }
    ;

mme_ip_netmask_for_S11_MME: MME_IP_NETMASK_FOR_S11_MME '=' INTEGER ';'
    {
        if ($3 <= 0) {
            yyerror(&yylloc, mme_config_p, "Invalid value");
            return EINVAL;
        } else if ($3 > UINT16_MAX) {
            yyerror(&yylloc, mme_config_p, "Value exceed container");
            return EINVAL;
        }
        mme_config_p->ipv4.mme_ip_netmask_for_S11 = (uint16_t)$3;
    }
    ;


    /* Lexical or syntax error */
errors: LEX_ERROR
    | error
    ;
%%

void yyerror(YYLTYPE *llocp, struct mme_config_s *mme_config_p, const char *str)
{
    fprintf(stderr, "Error in %s ( on line %i column %i -> line %i column %i) : %s\n",
            mme_config_p->config_file, llocp->first_line, llocp->first_column,
            llocp->last_line, llocp->last_column, str);
}