fix_asn1 4.27 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
7
8
9
RRC_Rel14=(
  "SystemInformation-r8-IEs.h" 562e3c3aeb7c6d76d722f31bf24488a26e627f33 "fix_asn1.data/RRC.rel14/SystemInformation-r8-IEs.h.diff"
)

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

X2AP_Rel11_2=(
15
  "X2ap-CriticalityDiagnostics-IE-List.h" ae96308b37fcbcbf39da5012e42968135fc5f27b "fix_asn1.data/X2AP.rel11.2/X2ap-CriticalityDiagnostics-IE-List.h.diff"
16
17
  "NativeInteger.c"                       1a55f5402fd363318cf5444ffe1f67530dcf66ff "fix_asn1.data/X2AP.rel11.2/NativeInteger.c.diff"
  "constr_SET_OF.c"                       808cbbdf19b118c0bdb04e3acf2cbe6e4133be2b "fix_asn1.data/X2AP.rel11.2/constr_SET_OF.c.diff"
Cedric Roux's avatar
Cedric Roux committed
18
19
20
)

S1AP_Rel10_5=(
21
22
  "NativeInteger.c" 1a55f5402fd363318cf5444ffe1f67530dcf66ff "fix_asn1.data/S1AP.rel10.5/NativeInteger.c.diff"
  "constr_SET_OF.c" 808cbbdf19b118c0bdb04e3acf2cbe6e4133be2b "fix_asn1.data/S1AP.rel10.5/constr_SET_OF.c.diff"
Cedric Roux's avatar
Cedric Roux committed
23
24
)

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

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

45
46
47
48
49
50
  # 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
51
52
53
54
55
56
57

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

58
function patch_file()
Cedric Roux's avatar
Cedric Roux committed
59
{
60
61
  local patch="$1"
  local file="$2"
Cedric Roux's avatar
Cedric Roux committed
62

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

65
  patch "$file" "$OPENAIR_DIR/cmake_targets/tools/$patch"
Cedric Roux's avatar
Cedric Roux committed
66
67
  if [ $? -ne 0 ]
  then
68
    error "patching of $file with $OPENAIR_DIR/cmake_targets/tools/$patch failed"
Cedric Roux's avatar
Cedric Roux committed
69
70
71
  fi
}

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

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

  case "$version" in
Cedric Roux's avatar
Cedric Roux committed
101
102
103
104
    Rel14 )
      echo "patching RRC files release 14"
      apply_patches "$directory" RRC_Rel14 ${#RRC_Rel14[*]}
      ;;
Cedric Roux's avatar
Cedric Roux committed
105
106
    Rel10 )
      echo "patching RRC files release 10"
107
      apply_patches "$directory" RRC_Rel10 ${#RRC_Rel10[*]}
Cedric Roux's avatar
Cedric Roux committed
108
      ;;
109
110
111
    Rel8 )
      echo "patching RRC files release 8 TODO?"
      ;;
Cedric Roux's avatar
Cedric Roux committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    * )
      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"
126
      apply_patches "$directory" X2AP_Rel11_2 ${#X2AP_Rel11_2[*]}
Cedric Roux's avatar
Cedric Roux committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
      ;;
    * )
      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"
142
      apply_patches "$directory" S1AP_Rel10_5 ${#S1AP_Rel10_5[*]}
Cedric Roux's avatar
Cedric Roux committed
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
179
180
181
182
183
184
185
      ;;
    * )
      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 "$@"