fix_asn1 3.71 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> <patch to apply to file>
Cedric Roux's avatar
Cedric Roux committed
5 6

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

X2AP_Rel11_2=(
11 12 13
  "X2ap-CriticalityDiagnostics-IE-List.h" f0e2414992bfacfbc4b9fd15c977241d6d7fabeb "fix_asn1.data/X2AP.rel11.2/X2ap-CriticalityDiagnostics-IE-List.h.diff"
  "NativeInteger.c"                       e23034083a0fb9d4a2e523e2a64286161e621f27 "fix_asn1.data/X2AP.rel11.2/NativeInteger.c.diff"
  "constr_SET_OF.c"                       5fb65da648a57ea61f008fa226b707cf343c1c0c "fix_asn1.data/X2AP.rel11.2/constr_SET_OF.c.diff"
Cedric Roux's avatar
Cedric Roux committed
14 15 16
)

S1AP_Rel10_5=(
17 18
  "NativeInteger.c" e23034083a0fb9d4a2e523e2a64286161e621f27 "fix_asn1.data/S1AP.rel10.5/NativeInteger.c.diff"
  "constr_SET_OF.c" 5fb65da648a57ea61f008fa226b707cf343c1c0c "fix_asn1.data/S1AP.rel10.5/constr_SET_OF.c.diff"
Cedric Roux's avatar
Cedric Roux committed
19 20
)

21 22 23
red_color="$(tput setaf 1)"
green_color="$(tput setaf 2)"
reset_color="$(tput sgr0)"
Cedric Roux's avatar
Cedric Roux committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

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

  local computed_sha1=$(sha1sum "$file" | cut -f 1 -d ' ')

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

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

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

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

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

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

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

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

  case "$version" in
    R10 )
      echo "patching S1AP files release 10.5"
129
      apply_patches "$directory" S1AP_Rel10_5 ${#S1AP_Rel10_5[*]}
Cedric Roux's avatar
Cedric Roux committed
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 170 171 172
      ;;
    * )
      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 "$@"