fix_asn1 3.85 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

Cedric Roux's avatar
Cedric Roux committed
6
RRC_Rel14=(
Cedric Roux's avatar
Cedric Roux committed
7
  "SystemInformation-r8-IEs.h" 4df485c5ddf2540eca271876cdc512caa19b0890 "fix_asn1.data/RRC.rel14/SystemInformation-r8-IEs.h.diff"
oai's avatar
oai committed
8
  "SystemInformation-NB-r13-IEs.h" 6d91332d5c39205819b06e5e36efe62ff8e5b33b "fix_asn1.data/RRC.rel14/SystemInformation-NB-r13-IEs.h.diff"
Cedric Roux's avatar
Cedric Roux committed
9 10
)

Cedric Roux's avatar
Cedric Roux committed
11
RRC_Rel10=(
12
  "SystemInformation-r8-IEs.h" 603cd6615cff36ec7020692d72c0d6de7c4859cb "fix_asn1.data/RRC.rel10/SystemInformation-r8-IEs.h.diff"
Cedric Roux's avatar
Cedric Roux committed
13 14 15
)

X2AP_Rel11_2=(
16
  "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
17 18
)

19 20 21
red_color="$(tput setaf 1)"
green_color="$(tput setaf 2)"
reset_color="$(tput sgr0)"
Cedric Roux's avatar
Cedric Roux committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

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

39 40 41 42 43 44
  # 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
45 46 47 48 49 50 51

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

52
function patch_file()
Cedric Roux's avatar
Cedric Roux committed
53
{
54 55
  local patch="$1"
  local file="$2"
Cedric Roux's avatar
Cedric Roux committed
56

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

59
  patch "$file" "$OPENAIR_DIR/cmake_targets/tools/$patch"
Cedric Roux's avatar
Cedric Roux committed
60 61
  if [ $? -ne 0 ]
  then
62
    error "patching of $file with $OPENAIR_DIR/cmake_targets/tools/$patch failed"
Cedric Roux's avatar
Cedric Roux committed
63 64 65
  fi
}

66
function apply_patches()
Cedric Roux's avatar
Cedric Roux committed
67 68 69 70 71 72 73 74
{
  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
75
  local patch
Cedric Roux's avatar
Cedric Roux committed
76 77 78 79 80 81 82
  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}
83
    item=$array[$((i+2))]; patch=${!item}
Cedric Roux's avatar
Cedric Roux committed
84
    check_sha1 "$directory/$file" "$sha1"
85
    patch_file "$patch" "$directory/$file"
Cedric Roux's avatar
Cedric Roux committed
86 87 88 89 90 91 92 93 94
  done
}

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

  case "$version" in
Cedric Roux's avatar
Cedric Roux committed
95 96 97 98
    Rel14 )
      echo "patching RRC files release 14"
      apply_patches "$directory" RRC_Rel14 ${#RRC_Rel14[*]}
      ;;
Cedric Roux's avatar
Cedric Roux committed
99 100
    Rel10 )
      echo "patching RRC files release 10"
101
      apply_patches "$directory" RRC_Rel10 ${#RRC_Rel10[*]}
Cedric Roux's avatar
Cedric Roux committed
102
      ;;
103 104 105
    Rel8 )
      echo "patching RRC files release 8 TODO?"
      ;;
Cedric Roux's avatar
Cedric Roux committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119
    * )
      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"
120
      apply_patches "$directory" X2AP_Rel11_2 ${#X2AP_Rel11_2[*]}
Cedric Roux's avatar
Cedric Roux committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134
      ;;
    * )
      error unknwon/unhandled X2AP version \'"$version"\'
      ;;
  esac
}

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

  case "$version" in
    R10 )
135
      #nothing to do anymore (fixes went to asn1c)
Cedric Roux's avatar
Cedric Roux committed
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 170 171 172 173 174 175 176 177 178
      ;;
    * )
      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 "$@"