fix_asn1 3.46 KB
Newer Older
Cedric Roux's avatar
Cedric Roux committed
1 2 3
#!/bin/bash

# in those arrays, each line is:
4
#   <file> <sha1sum of file (without line 4 which changes depending on the location of the files)> <patch to apply to file>
Cedric Roux's avatar
Cedric Roux committed
5 6

RRC_Rel10=(
7
  "SystemInformation-r8-IEs.h" 603cd6615cff36ec7020692d72c0d6de7c4859cb "fix_asn1.data/RRC.rel10/SystemInformation-r8-IEs.h.diff"
Cedric Roux's avatar
Cedric Roux committed
8 9 10
)

X2AP_Rel11_2=(
11
  "X2ap-CriticalityDiagnostics-IE-List.h" ae96308b37fcbcbf39da5012e42968135fc5f27b "fix_asn1.data/X2AP.rel11.2/X2ap-CriticalityDiagnostics-IE-List.h.diff"
Cedric Roux's avatar
Cedric Roux committed
12 13
)

14 15 16
red_color="$(tput setaf 1)"
green_color="$(tput setaf 2)"
reset_color="$(tput sgr0)"
Cedric Roux's avatar
Cedric Roux committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

function error()
{
  echo -e "$red_color"ERROR: "$@""$reset_color"
  exit 1
}

function check_sha1()
{
  local file="$1"
  local target_sha1="$2"

  if [ ! -f "$file" ]
  then
    error "$file: no such file"
  fi

34 35 36 37 38 39
  # we don't use the line 4 of the file
  # it contains the location of the ASN1 grammar
  # and this location is not the same on every
  # installation (this is for *.h files, for *.c
  # files it's no big deal to skip that line)
  local computed_sha1=$(sed 4d "$file" | sha1sum | cut -f 1 -d ' ')
Cedric Roux's avatar
Cedric Roux committed
40 41 42 43 44 45 46

  if [ "$target_sha1" != "$computed_sha1" ]
  then
    error "$file: wrong SHA1"
  fi
}

47
function patch_file()
Cedric Roux's avatar
Cedric Roux committed
48
{
49 50
  local patch="$1"
  local file="$2"
Cedric Roux's avatar
Cedric Roux committed
51

52
  echo -e "$green_color""patch file $file with $OPENAIR_DIR/cmake_targets/tools/$patch""$reset_color"
Cedric Roux's avatar
Cedric Roux committed
53

54
  patch "$file" "$OPENAIR_DIR/cmake_targets/tools/$patch"
Cedric Roux's avatar
Cedric Roux committed
55 56
  if [ $? -ne 0 ]
  then
57
    error "patching of $file with $OPENAIR_DIR/cmake_targets/tools/$patch failed"
Cedric Roux's avatar
Cedric Roux committed
58 59 60
  fi
}

61
function apply_patches()
Cedric Roux's avatar
Cedric Roux committed
62 63 64 65 66 67 68 69
{
  local directory="$1"
  local array=$2
  local len=$3       # the length could be computed locally but the way to do it is not clear to me [CROUX]

  local i
  local file
  local sha1
70
  local patch
Cedric Roux's avatar
Cedric Roux committed
71 72 73 74 75 76 77
  local item

  for (( i = 0; i < $len; i += 3 ))
  do
    # special bash syntax to access the array
    item=$array[$i];       file=${!item}
    item=$array[$((i+1))]; sha1=${!item}
78
    item=$array[$((i+2))]; patch=${!item}
Cedric Roux's avatar
Cedric Roux committed
79
    check_sha1 "$directory/$file" "$sha1"
80
    patch_file "$patch" "$directory/$file"
Cedric Roux's avatar
Cedric Roux committed
81 82 83 84 85 86 87 88 89 90 91
  done
}

function patch_rrc()
{
  local directory="$1"
  local version="$2"

  case "$version" in
    Rel10 )
      echo "patching RRC files release 10"
92
      apply_patches "$directory" RRC_Rel10 ${#RRC_Rel10[*]}
Cedric Roux's avatar
Cedric Roux committed
93
      ;;
94 95 96
    Rel8 )
      echo "patching RRC files release 8 TODO?"
      ;;
Cedric Roux's avatar
Cedric Roux committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110
    * )
      error unknwon/unhandled RRC version \'"$version"\'
      ;;
  esac
}

function patch_x2ap()
{
  local directory="$1"
  local version="$2"

  case "$version" in
    R11 )
      echo "patching X2AP files release 11.2"
111
      apply_patches "$directory" X2AP_Rel11_2 ${#X2AP_Rel11_2[*]}
Cedric Roux's avatar
Cedric Roux committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125
      ;;
    * )
      error unknwon/unhandled X2AP version \'"$version"\'
      ;;
  esac
}

function patch_s1ap()
{
  local directory="$1"
  local version="$2"

  case "$version" in
    R10 )
126
      #nothing to do anymore (fixes went to asn1c)
Cedric Roux's avatar
Cedric Roux committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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
      ;;
    * )
      error unknwon/unhandled S1AP version \'"$version"\'
      ;;
  esac
}

function main()
{
  if [ $# -ne 3 ]
  then
    echo "ERROR: pass <output directory> <module> <version>"
    exit 1
  fi

  if [ x"$OPENAIR_DIR" = x ]
  then
    error "the variable OPENAIR_DIR is not set"
  fi

  local directory="$1"
  local module="$2"
  local version="$3"

  case "$module" in
    RRC )
      patch_rrc "$directory" "$version"
      ;;
    X2AP )
      patch_x2ap "$directory" "$version"
      ;;
    S1AP )
      patch_s1ap "$directory" "$version"
      ;;
    * )
      error unknown module "$module"
      ;;
  esac

  exit 0
}

main "$@"